pac_files

The following methods allow for interaction with the ZIA PAC Files API endpoints.

Methods are accessible via zia.pac_files

Copyright (c) 2023, Zscaler Inc.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

class PacFilesAPI

Bases: APIClient

A Client object for the Rule labels resource.

add_pac_file(**kwargs)

Adds a new custom PAC file after validating the PAC content.

Parameters:
  • name (str) – The name of the new PAC file.

  • description (str) – The description of the new PAC file.

  • domain (str) – The domain of your organization to which the PAC file applies.

  • pac_commit_message (str) – Commit msg entered when saving the PAC file version as indicated by the pacVersion field.

  • pac_verification_status (str) – Verification status of the PAC file and if any errors are identified in the syntax. Supported Values: VERIFY_NOERR, VERIFY_ERR, NOVERIFY

  • pac_version_status (str) – Version status of the new PAC file. Supported Values: DEPLOYED, STAGE, LKG

  • pac_content (str) – The actual PAC file content to be validated and cloned.

Keyword Arguments:

pairs. (Additional optional parameters as key-value)

Returns:

The newly added PAC file resource record.

Return type:

Tuple

Example

>>> pac_file = zia.add_pac_file(
...     name="Test_Pac_File_01",
...     description="Test_Pac_File_01",
...     domain="bd-hashicorp.com",
...     pac_commit_message="Test_Pac_File_01",
...     pac_verification_status="VERIFY_NOERR",
...     pac_version_status="DEPLOYED",
...     pac_content="function FindProxyForURL(url, host) { return 'PROXY gateway.example.com:80'; }")
clone_pac_file(pac_id, pac_version, **kwargs)

Clones an existing PAC file by creating a new PAC file based on the specified PAC ID and version.

Parameters:
  • pac_id (int) – The unique identifier of the PAC file to be cloned.

  • pac_version (str) – The specific version of the PAC file to be cloned.

  • name (str) – The name of the new PAC file.

  • description (str) – The description of the new PAC file.

  • domain (str) – The domain associated with the new PAC file.

  • pac_commit_message (str) – Commit message for the new PAC file.

  • pac_verification_status (str) – Verification status of the new PAC file. Supported Values: VERIFY_NOERR, VERIFY_ERR, NOVERIFY

  • pac_version_status (str) – Version status of the new PAC file. Supported Values: DEPLOYED, STAGE, LKG

  • pac_content (str) – The actual PAC file content to be validated and cloned.

  • delete_version (int, optional) – Specifies the PAC file version to replace if the version limit of 10 is reached.

Keyword Arguments:

pairs. (Additional optional parameters as key-value)

Returns:

The newly cloned PAC file resource record.

Return type:

Tuple

Example

>>> pac_file = zia.clone_pac_file(
...     pac_id=12345,
...     pac_version="1",
...     name="Cloned_Pac_File_01",
...     description="Cloned_Pac_File_01",
...     domain="bd-hashicorp.com",
...     pac_commit_message="Clone of Test_Pac_File_01",
...     pac_verification_status="VERIFY_NOERR",
...     pac_version_status="DEPLOYED",
...     pac_content="function FindProxyForURL(url, host) { return 'PROXY gateway.example.com:80'; }",
...     delete_version=5
... )
delete_pac_file(pac_id)

Deletes an existing PAC file including all of its versions based on the specified ID

Parameters:

pac_id (str) – Specifies the ID of the PAC file

Returns:

A tuple containing the response object and error (if any).

Return type:

tuple

Example

>>> _, _, error = client.zia.pac_files.delete_pac_file('18805')
>>> if error:
...     print(f"Error deleting pac file: {error}")
...     return
... print(f"Pac File with ID '18805'} deleted successfully.")
get_pac_file(pac_id, query_params=None)

Retrieves all versions of a PAC file based on the specified ID

Parameters:
  • {dict} (query_params) –

    Map of query parameters for the request.

    [query_params.filter] {str}: Excludes specific information about the PAC file

    from the response such as the PAC file content. Available values: pac_content

  • pac_id (int) – The unique identifier for the Pac File.

Returns:

A tuple containing (Pac File instance, Response, error).

Return type:

tuple

Examples

Gets a list of all pac files including the pac content.

>>> pac_files, _, error = client.zia.pac_files.get_pac_file('18805')
>>> if error:
...     print(f"Error fetching PAC files by ID: {error}")
...     return
... print(f"Total PAC file versions fetched: {len(pac_files)}")
... for version in pac_files:
...     print(version.as_dict())

Gets a list of all pac files excluding the pac content.

>>> pac_files, _, error = client.zia.pac_files.get_pac_file('18805', query_params={'filter': 'pac_content'})
>>> if error:
...     print(f"Error fetching PAC files by ID: {error}")
...     return
... print(f"Total PAC file versions fetched: {len(pac_files)}")
... for version in pac_files:
...     print(version.as_dict())
get_pac_file_version(pac_id, pac_version, query_params=None)

Returns the PAC file version details for a given PAC ID and version.

Parameters:
  • {dict} (query_params) –

    Map of query parameters for the request.

    [query_params.filter] {str, optional}: Excludes specific information about the PAC file

    the response such as the PAC file content. Accepts only the value ‘pac_content’

  • pac_id (str) – The unique identifier for the PAC file.

  • pac_version (str) – The specific version of the PAC file.

Returns:

The PAC file version resource record.

Gets a list of all pac files excluding the pac content.

>>> pac_files, _, error = client.zia.pac_files.get_pac_file_version(pac_id='18805', pac_version='1',
... query_params={'filter': 'pac_content'})
>>> if error:
...     print(f"Error fetching pac_file by ID: {error}")
...     return
... print(f"Fetched pac_file by ID: {pac_file.as_dict()}")

Return type:

Tuple

list_pac_files(query_params=None)

Lists pac files in your organization with pagination. A subset of pac files can be returned that match a supported filter expression or query.

Parameters:

{dict} (query_params) –

Map of query parameters for the request. [query_params.search] {str}: Search string for filtering results.

[query_params.filter] {str}: Excludes specific information about the PAC file

from the response such as the PAC file content Available values: pac_content

[query_params.page] {str}: Specifies the page offset

[query_params.page_size] {str}: Specifies the page size. The default size is 100.

Returns:

A tuple containing (list of Pac Files instances, Response, error)

Return type:

tuple

Examples

Retrieves the list of all PAC files in deployed state

>>> pac_file_list, _, error = client.zia.pac_files.list_pac_files()
>>> if error:
...     print(f"Error listing all pac files: {error}")
...     return
... print(f"Total pac files found: {len(pac_file_list)}")

Examples

Retrieves the list of all PAC files in deployed state excluding pac_content

>>> pac_file_list, _, error = client.zia.pac_files.list_pac_files(query_params={
... 'search': 'kerberos.pac', 'filter':'pac_content'})
>>> if error:
...     print(f"Error listing all pac files: {error}")
...     return
... print(f"Total pac files found: {len(pac_file_list)}")
update_pac_file(pac_id, pac_version, pac_version_action, new_lkg_ver=None, **kwargs)

Performs the specified action on the PAC file version and updates the file status. Supported actions include deploying, staging, unstaging, and marking or unmarking the file as last known good version.

Parameters:
  • pac_id (int) – The unique identifier of the PAC file to be updated.

  • pac_version (int) – The specific version of the PAC file to be updated.

  • pac_version_action (str) – Action to perform on the PAC version. Supported Values: DEPLOY, STAGE, LKG, UNSTAGE, REMOVE_LKG

  • new_lkg_ver (int, optional) – Specifies a different version to be marked as the last known good version if the action is removing the current last known good version.

Keyword Arguments:

including (Additional optional parameters as key-value pairs,) –

  • name (str): The name of the PAC file.

  • description (str): Description of the PAC file.

  • domain (str): The domain associated with the PAC file.

  • 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.

Returns:

A tuple containing (updated PAC file resource record, Response, error).

Return type:

tuple

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
... )
validate_pac_file(pac_file_content)

Sends the PAC file content for validation and returns the validation result.

Parameters:

pac_file_content (str) – The PAC file content to be validated.

Returns:

A tuple containing (validation result, Response, error).

Return type:

tuple

Example

To validate PAC file content:

>>> pac_file_content = '''
>>> function FindProxyForURL(url, host) {
>>>     return "PROXY gateway.example.com:80";
>>> }
>>> '''
>>> validation_result, response, error = client.zia.validate_pac_file(pac_file_content)
>>> if error:
...     print(f"Validation failed: {error}")
... elif validation_result.get("success", False):
...     print("PAC file is valid.")
... else:
...     print("PAC file validation failed.")