From 9502151f7526e66e5d51286c0f2ba2e45db56b79 Mon Sep 17 00:00:00 2001 From: William Guilherme Date: Fri, 29 Mar 2024 01:54:22 -0700 Subject: [PATCH] Fixed additional flake8 linter issues --- zscaler/utils.py | 12 +++++++++--- zscaler/zia/__init__.py | 2 +- zscaler/zpa/certificates.py | 15 ++++++++++----- zscaler/zpa/provisioning.py | 23 ++++++++++++++++------- zscaler/zpa/scim_attributes.py | 15 ++++++++++----- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/zscaler/utils.py b/zscaler/utils.py index 68314799..4e9e20e3 100644 --- a/zscaler/utils.py +++ b/zscaler/utils.py @@ -445,13 +445,19 @@ def dump_response(logger, url: str, method: str, resp, params, request_uuid: str response_body = resp.text if from_cache: - log_lines.append(f"\n---[ ZSCALER SDK RESPONSE | ID:{request_uuid} | FROM CACHE | DURATION:{duration_ms}ms ]-------------------------------") + log_lines.append( + f"\n---[ ZSCALER SDK RESPONSE | ID:{request_uuid} | " + f"FROM CACHE | DURATION:{duration_ms}ms ]" + "-" * 31 + ) else: - log_lines.append(f"\n---[ ZSCALER SDK RESPONSE | ID:{request_uuid} | DURATION:{duration_ms}ms ]-------------------------------") + log_lines.append( + f"\n---[ ZSCALER SDK RESPONSE | ID:{request_uuid} | " + f"DURATION:{duration_ms}ms ]" + "-" * 46 + ) log_lines.append(f"{method} {full_url}") for key, value in response_headers_dict.items(): log_lines.append(f"{key}: {value}") if response_body and response_body != "" and response_body != "null": log_lines.append(f"\n{response_body}") - log_lines.append("--------------------------------------------------------------------") + log_lines.append("-" * 68) logger.info('\n'.join(log_lines)) diff --git a/zscaler/zia/__init__.py b/zscaler/zia/__init__.py index cd16a572..bf0df3d3 100644 --- a/zscaler/zia/__init__.py +++ b/zscaler/zia/__init__.py @@ -100,7 +100,7 @@ def __init__(self, cloud, timeout=240, cache=None, fail_safe=False, **kw): self.env_cloud = cloud or kw.get("cloud") or os.getenv(f"{self._env_base}_CLOUD") if not self.env_cloud: raise ValueError( - f"The cloud environment must be set via the 'cloud' argument or the {self._env_base}_CLOUD environment variable." + f"Cloud environment must be set via the 'cloud' argument or the {self._env_base}_CLOUD environment variable." ) # URL construction diff --git a/zscaler/zpa/certificates.py b/zscaler/zpa/certificates.py index 82de005a..ac4af5f5 100644 --- a/zscaler/zpa/certificates.py +++ b/zscaler/zpa/certificates.py @@ -34,13 +34,13 @@ def list_issued_certificates(self, **kwargs) -> BoxList: **kwargs: Optional keyword args. Keyword Args: - **max_items (int, optional): + max_items (int, optional): The maximum number of items to request before stopping iteration. - **max_pages (int, optional): + max_pages (int, optional): The maximum number of pages to request before stopping iteration. - **pagesize (int, optional): + pagesize (int, optional): Specifies the page size. The default size is 20, but the maximum size is 500. - **search (str, optional): + search (str, optional): The search string used to match against features and fields. Returns: @@ -51,7 +51,12 @@ def list_issued_certificates(self, **kwargs) -> BoxList: ... print(cert) """ - list, _ = self.rest.get_paginated_data(path="/clientlessCertificate/issued", data_key_name="list", **kwargs, api_version="v2") + list, _ = self.rest.get_paginated_data( + path="/clientlessCertificate/issued", + data_key_name="list", + **kwargs, + api_version="v2" + ) return list def list_all_certificates(self, **kwargs) -> BoxList: diff --git a/zscaler/zpa/provisioning.py b/zscaler/zpa/provisioning.py index 1ac32254..ac4bf16a 100644 --- a/zscaler/zpa/provisioning.py +++ b/zscaler/zpa/provisioning.py @@ -41,18 +41,17 @@ def list_provisioning_keys(self, key_type: str, **kwargs) -> BoxList: Args: key_type (str): The type of provisioning key, accepted values are: - ``connector`` and ``service_edge``. **kwargs: Optional keyword args. Keyword Args: - **max_items (int, optional): + max_items (int, optional): The maximum number of items to request before stopping iteration. - **max_pages (int, optional): + max_pages (int, optional): The maximum number of pages to request before stopping iteration. - **pagesize (int, optional): + pagesize (int, optional): Specifies the page size. The default size is 20, but the maximum size is 500. - **search (str, optional): + search (str, optional): The search string used to match against features and fields. Returns: @@ -70,7 +69,10 @@ def list_provisioning_keys(self, key_type: str, **kwargs) -> BoxList: ... print(key) """ - list, _ = self.rest.get_paginated_data(path=f"/associationType/{simplify_key_type(key_type)}/provisioningKey", data_key_name="list", **kwargs) + list, _ = self.rest.get_paginated_data( + path=f"/associationType/{simplify_key_type(key_type)}/provisioningKey", + data_key_name="list", **kwargs + ) return list def get_provisioning_key(self, key_id: str, key_type: str) -> Box: @@ -215,7 +217,14 @@ def update_provisioning_key(self, key_id: str, key_type: str, **kwargs) -> Box: for key, value in kwargs.items(): payload[snake_to_camel(key)] = value - resp = self.rest.put(f"associationType/{simplify_key_type(key_type)}/provisioningKey/{key_id}", json=payload).status_code + resp = self.rest.put( + f"associationType/{simplify_key_type(key_type)}/provisioningKey/{key_id}", + json=payload + ).status_code + + # Return the object if it was updated successfully + if not isinstance(resp, Response): + return self.get_provisioning_key(key_id, key_type=key_type) # Return the object if it was updated successfully if not isinstance(resp, Response): diff --git a/zscaler/zpa/scim_attributes.py b/zscaler/zpa/scim_attributes.py index 1c39b1e9..9007b99e 100644 --- a/zscaler/zpa/scim_attributes.py +++ b/zscaler/zpa/scim_attributes.py @@ -32,13 +32,13 @@ def list_attributes_by_idp(self, idp_id: str, **kwargs) -> BoxList: **kwargs: Optional keyword args. Keyword Args: - **max_items (int): + max_items (int): The maximum number of items to request before stopping iteration. - **max_pages (int): + max_pages (int): The maximum number of pages to request before stopping iteration. - **pagesize (int): + pagesize (int): Specifies the page size. The default size is 20, but the maximum size is 500. - **search (str, optional): + search (str, optional): The search string used to match against features and fields. Returns: @@ -49,7 +49,12 @@ def list_attributes_by_idp(self, idp_id: str, **kwargs) -> BoxList: ... pprint(scim_attribute) """ - list, _ = self.rest.get_paginated_data(path=f"/idp/{idp_id}/scimattribute", data_key_name="list", **kwargs, api_version="v1") + list, _ = self.rest.get_paginated_data( + path=f"/idp/{idp_id}/scimattribute", + data_key_name="list", + **kwargs, + api_version="v1" + ) return list def get_attribute(self, idp_id: str, attribute_id: str) -> Box: