Skip to content

Commit

Permalink
fix: fixed pylint & flake8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
anaik91 committed Jan 29, 2025
1 parent ed7bbb4 commit 85516bb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion classic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python # noqa pylint: disable=R0801

# Copyright 2025 Google LLC
#
Expand Down
1 change: 0 additions & 1 deletion core_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"""

import os
import json
from pyvis.network import Network # pylint: disable=E0401
import networkx as nx # pylint: disable=E0401
from exporter import ApigeeExporter
Expand Down
35 changes: 20 additions & 15 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ def __init__(self, baseurl, org, token, auth_type, ssl_verify): # noqa pylint:
self.org = org
self.token = token
self.auth_type = auth_type
self.apigee = ( ApigeeNewGen(org, token, 'ENVIRONMENT_TYPE_UNSPECIFIED')
self.apigee = (ApigeeNewGen(org, token,
'ENVIRONMENT_TYPE_UNSPECIFIED')
if 'apigee.googleapis.com' in baseurl else
ApigeeClassic(baseurl, org,
token, self.auth_type,
ssl_verify=ssl_verify))
self.apigee_type = 'x' if 'apigee.googleapis.com' in baseurl else 'edge'
ApigeeClassic(baseurl, org, token,
self.auth_type, ssl_verify=ssl_verify))
self.apigee_type = ('x' if 'apigee.googleapis.com' in baseurl
else 'edge')
self.env_object_types = {
'targetservers': 'targetServers',
'keyvaluemaps': 'kvms',
Expand Down Expand Up @@ -132,7 +133,7 @@ def export_vhosts(self):
vhost_data = self.apigee.get_env_vhost(env, vhost)
self.export_data['envConfig'][env]['vhosts'][vhost] = vhost_data # noqa

def export_env_objects(self, env_objects_keys, export_dir):
def export_env_objects(self, env_objects_keys, export_dir): # noqa pylint: disable=R0912
"""Exports environment-level objects.
Retrieves and exports various environment-level objects based
Expand All @@ -145,7 +146,7 @@ def export_env_objects(self, env_objects_keys, export_dir):
types to export.
export_dir (str): The directory to export files to.
"""
for env in self.export_data.get('envConfig', {}):
for env in self.export_data.get('envConfig', {}): # noqa pylint: disable=R1702
for each_env_object_type in env_objects_keys:
env_objects = self.apigee.list_env_objects(
env, each_env_object_type)
Expand All @@ -161,7 +162,8 @@ def export_env_objects(self, env_objects_keys, export_dir):
f"{export_dir}/resourceFiles/{each_env_object['type']}") # noqa pylint: disable=W1203
obj_data = self.apigee.get_env_object(
env, each_env_object_type, each_env_object)
obj_data = obj_data if isinstance(obj_data,bytes) else obj_data.encode('utf-8')
obj_data = (obj_data if isinstance(obj_data, bytes)
else obj_data.encode('utf-8'))
write_file(
f"{export_dir}/resourceFiles/{each_env_object['type']}/{each_env_object['name']}", obj_data) # noqa pylint: disable=C0301
self.export_data['envConfig'][env][self.env_object_types[each_env_object_type]][each_env_object['name']] = { # noqa pylint: disable=C0301
Expand Down Expand Up @@ -191,7 +193,10 @@ def export_env_objects(self, env_objects_keys, export_dir):
certificate = self.apigee.get_env_object(
env, f"keystores/{each_env_object}/aliases", f"{alias_name}/certificate") # noqa pylint: disable=C0301
with open(f"{export_dir}/keystore_certificates/env-{env}/{each_env_object}/{alias_name}/certificate.pem", "wb") as f: # noqa pylint: disable=C0301
f.write(certificate) if isinstance(certificate, bytes) else f.write(certificate.encode('utf-8'))
if isinstance(certificate, bytes):
f.write(certificate)
else:
f.write(certificate.encode('utf-8'))
obj_data['alias_data'][alias_name] = alias_data
self.export_data['envConfig'][env][self.env_object_types[each_env_object_type] # noqa pylint: disable=C0301
][each_env_object] = obj_data # noqa pylint: disable=C0301
Expand All @@ -200,12 +205,11 @@ def export_env_objects(self, env_objects_keys, export_dir):
for each_env_object in env_objects:
logger.info( # noqa pylint: disable=W1203
f"Exporting {each_env_object_type} {each_env_object}") # noqa
if self.apigee_type == 'x' and each_env_object_type == 'keyvaluemaps':
if self.apigee_type == 'x' and each_env_object_type == 'keyvaluemaps': # noqa pylint: disable=C0301
obj_data = self.apigee.get_env_object(
env, each_env_object_type, f'{each_env_object}/entries')
env, each_env_object_type, f'{each_env_object}/entries') # noqa pylint: disable=C0301
else:
obj_data = self.apigee.get_env_object(
env, each_env_object_type, each_env_object)
obj_data = self.apigee.get_env_object(env, each_env_object_type, each_env_object) # noqa pylint: disable=C0301
self.export_data['envConfig'][env][self.env_object_types[each_env_object_type] # noqa pylint: disable=C0301
][each_env_object] = obj_data # noqa

Expand Down Expand Up @@ -249,7 +253,7 @@ def export_org_objects(self, org_objects_keys):
f"Exporting {each_org_object_type} {each_org_object}")
if self.apigee_type == 'x':
obj_data = self.apigee.get_org_object(
each_org_object_type, f'{each_org_object}/entries')
each_org_object_type, f'{each_org_object}/entries') # noqa pylint: disable=C0301
else:
obj_data = self.apigee.get_org_object(
each_org_object_type, each_org_object)
Expand All @@ -276,7 +280,8 @@ def developers_list(self):
developers = self.apigee.list_org_objects('developers')
developers_dict = {}
for developer in developers:
developer_data = self.apigee.get_org_object('developers', developer)
developer_data = self.apigee.get_org_object('developers',
developer)
developers_dict[developer_data['developerId']] = developer
return developers_dict

Expand Down
30 changes: 15 additions & 15 deletions nextgen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python # noqa pylint: disable=R0801

# Copyright 2025 Google LLC
#
Expand All @@ -24,7 +24,7 @@
from rest import RestClient


class ApigeeNewGen():
class ApigeeNewGen(): # noqa pylint: disable=R0902
"""A client for interacting with Apigee X or hybrid.
Provides methods to interact with Apigee X or hybrid environments,
Expand Down Expand Up @@ -80,7 +80,7 @@ def list_environments(self):
"""
return self.list_org_objects('environments')

def _apigee_object_util(self, org_object, each_org_object_data, expand=False):
def _apigee_object_util(self, org_object, each_org_object_data, expand=False): # noqa pylint: disable=C0301
expand_key = self.can_expand.get(org_object).get('expand_key')
id_key = self.can_expand.get(org_object).get('id')
objects = []
Expand Down Expand Up @@ -111,19 +111,19 @@ def list_org_objects(self, org_object):
}
start_url = f"{self.baseurl}/organizations/{self.project_id}/{org_object}" # noqa
each_org_object_data = self.client.get(start_url, params=params)
each_org_object = self._apigee_object_util(org_object, each_org_object_data)
each_org_object = self._apigee_object_util(org_object, each_org_object_data) # noqa pylint: disable=C0301
org_objects.extend(each_org_object)
while len(each_org_object) > 0:
start_key = each_org_object[-1]
params[next_key] = start_key
each_org_object_data = self.client.get(start_url, params=params)
each_org_object = self._apigee_object_util(org_object, each_org_object_data)
each_org_object_data = self.client.get(start_url, params=params) # noqa pylint: disable=C0301
each_org_object = self._apigee_object_util(org_object, each_org_object_data) # noqa pylint: disable=C0301
each_org_object.remove(start_key)
org_objects.extend(each_org_object)
else:
url = f"{self.baseurl}/organizations/{self.project_id}/{org_object}"
url = f"{self.baseurl}/organizations/{self.project_id}/{org_object}" # noqa pylint: disable=C0301
org_object_data = self.client.get(url)
org_objects.extend(self._apigee_object_util(org_object, org_object_data))
org_objects.extend(self._apigee_object_util(org_object, org_object_data)) # noqa pylint: disable=C0301
return org_objects

def list_org_objects_expand(self, org_object):
Expand All @@ -137,7 +137,7 @@ def list_org_objects_expand(self, org_object):
expand_param = ['developers', 'apiproducts']
next_key = self.requires_pagination.get(org_object, {}).get('next_key', None) # noqa
id_key = self.can_expand.get(org_object).get('id')
limit_key = self.requires_pagination.get(org_object, {}).get('limit', None)
limit_key = self.requires_pagination.get(org_object, {}).get('limit', None) # noqa pylint: disable=C0301
if next_key is None:
params = {}
else:
Expand All @@ -157,7 +157,7 @@ def list_org_objects_expand(self, org_object):
start_key = each_org_object[-1].get(id_key) # noqa
params[next_key] = start_key # noqa
each_org_object_data = self.client.get(start_url, params=params)
each_org_object = self._apigee_object_util(org_object, each_org_object_data, True) # noqa
each_org_object = self._apigee_object_util(org_object, each_org_object_data, True) # noqa pylint: disable=C0301
each_org_object.pop(0)
for each_item in each_org_object:
org_objects[each_item[id_key]] = each_item
Expand All @@ -178,7 +178,7 @@ def get_org_object(self, org_object, org_object_name):
if org_object == "resourcefiles":
return {}
org_object_name = urlencode(org_object_name)
url = f"{self.baseurl}/organizations/{self.project_id}/{org_object}/{org_object_name}" # noqa
url = f"{self.baseurl}/organizations/{self.project_id}/{org_object}/{org_object_name}" # noqa pylint: disable=C0301
org_object = self.client.get(url)
return org_object

Expand Down Expand Up @@ -261,7 +261,7 @@ def list_api_revisions(self, api_type, api_name):
Returns:
list: A list of revision numbers.
"""
url = f"{self.baseurl}/organizations/{self.project_id}/{api_type}/{api_name}/revisions" # noqa
url = f"{self.baseurl}/organizations/{self.project_id}/{api_type}/{api_name}/revisions" # noqa pylint: disable=C0301
revisions = self.client.get(url)
return revisions

Expand All @@ -276,7 +276,7 @@ def api_env_mapping(self, api_type, api_name):
Returns:
dict: A dictionary containing the deployment mapping.
"""
url = f"{self.baseurl}/organizations/{self.project_id}/{api_type}/{api_name}/deployments" # noqa
url = f"{self.baseurl}/organizations/{self.project_id}/{api_type}/{api_name}/deployments" # noqa pylint: disable=C0301
deployments_data = self.client.get(url)
if len(deployments_data) == 0:
return {'environment': []}
Expand All @@ -297,7 +297,7 @@ def list_apis_env(self, env_name):
Returns:
list: A list of API names deployed in the environment.
"""
url = f"{self.baseurl}/organizations/{self.project_id}/environments/{env_name}/deployments" # noqa
url = f"{self.baseurl}/organizations/{self.project_id}/environments/{env_name}/deployments" # noqa pylint: disable=C0301
deployments_data = self.client.get(url)
deployments = deployments_data.get('deployments')
apis_list = [api.get('apiProxy') for api in deployments]
Expand All @@ -315,7 +315,7 @@ def fetch_api_revision(self, api_type, api_name, revision, export_dir):
url = f"{self.baseurl}/organizations/{self.project_id}/{api_type}/{api_name}/revisions/{revision}?format=bundle" # noqa pylint: disable=C0301
bundle = self.client.file_get(url)
self._write_proxy_bundle(export_dir, api_name, bundle)

def _write_proxy_bundle(self, export_dir, file_name, data):
"""Writes a proxy bundle to a file.
Expand Down
3 changes: 1 addition & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,7 @@ def read_proxy_artifacts(dir_name, entrypoint):
os.path.join(dir_name, 'targets', f"{each_te}.xml"))
except Exception as error: # noqa pylint: disable=W1203,W0718
logger.error(f"Error: raised error in read_proxy_artifacts {error}") # noqa pylint: disable=W1203
finally:
return proxy_dict
return proxy_dict


def get_target_endpoints(proxy_endpoint_data):
Expand Down
2 changes: 1 addition & 1 deletion validator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python # noqa pylint: disable=R0801

# Copyright 2025 Google LLC
#
Expand Down

0 comments on commit 85516bb

Please sign in to comment.