Skip to content

[FEATURE] Create new Pac Version #238

@CyberPaschk

Description

@CyberPaschk

Problem Statement
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
--> Currently I can see that in the SDK under the class pac_file exist an update but this does not create a new version of the PAC (from 1-->2).
In my opinion this woud be very helpful for the full automation of PAC

Proposed Solution
I already created a class locally in the SDK and tested this. Maybe you can add this?

    def create_new_pac_version(
            self,
            pac_id: str,
            pac_version: str,
            pac_commit_message: str,
            pac_verification_status: str,
            pac_version_status: str,
            pac_content: str,
            **kwargs,
        ) -> Box:
            """
            Performs to create a new PAC Version 

            Args:
                pac_id (str): The unique identifier of the PAC file to be updated.
                pac_version (str): The specific version of the PAC file to be updated.
                pac_commit_message (str): Commit message for the PAC file.
                pac_verification_status (str): Verification status of the PAC file.
                                            Supported Values: `VERIFY_NOERR`, `VERIFY_ERR`, `NOVERIFY`
                pac_version_status (str): Version status of the PAC file.
                                        Supported Values: `DEPLOYED`, `STAGE`, `LKG`
                pac_content (str): The actual PAC file content to be updated.


            Keyword Args:
                Additional optional parameters as key-value pairs.

            Returns:
                Box: The updated PAC file resource record.


            Example:
                >>> pac_file = zia.update_pac_file(
                        pac_id="12345",
                        pac_version="1",
                        pac_version_action="DEPLOY",
                        name="Update_Pac_File_01",
                        description="Update_Pac_File_01",
                        domain="bd-hashicorp.com",
                        pac_commit_message="Update_Pac_File_01",
                        pac_verification_status="VERIFY_NOERR",
                        pac_version_status="DEPLOYED",
                        pac_content="function FindProxyForURL(url, host) { return 'PROXY gateway.example.com:80'; }",
                        new_lkg_ver=5
                    )
            """
            # Step 1: Validate the PAC content
            validation_result = self.validate_pac_file(pac_content)
            if not validation_result.success:
                raise Exception("PAC content validation failed: {}".format(validation_result))

            # Step 2: Construct the URL with mandatory parameters and optional newLKGVer
            url = f"/pacFiles/{pac_id}/version/{pac_version}"

            # Step 3: Construct the payload with required fields
            payload = {
                "pacCommitMessage": pac_commit_message,
                "pacVerificationStatus": pac_verification_status,
                "pacVersionStatus": pac_version_status,
                "pacContent": pac_content,
            }

            # Add any additional optional parameters
            for key, value in kwargs.items():
                payload[snake_to_camel(key)] = value

            # Step 4: Make the request to update the PAC file
            response = self.rest.post(url, json=payload)
            if isinstance(response, Response):
                if response.status_code != 200:
                    raise Exception(f"API call failed with status {response.status_code}: {response.json()}")
                return Box(response.json())
            return response

Additional Context
I also opened a Ticket for Zscaler since automation is a topic I can choose:
Case Number : 05342084 : zscaler SDK ZIAClientHelper [ thread::z0BsQLiWcP-DfFDdEvCYVFs:: ]

I already tested the class in our dev cloud / Pacs and can confirm this is working well.

Metadata

Metadata

Assignees

Projects

Status

⚙️ In development

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions