Skip to content

Commit

Permalink
feat: added support for comparing developers,apps,products
Browse files Browse the repository at this point in the history
  • Loading branch information
anaik91 committed Feb 3, 2025
1 parent 7c4f875 commit fdbbcc2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 26 deletions.
47 changes: 35 additions & 12 deletions core_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ def validate_artifacts(cfg, resources_list, export_data): # noqa pylint: disabl
'oauth',
True
)
target_resources = ['targetservers', 'flowhooks', 'resourcefiles', 'apis', 'sharedflows'] # noqa pylint: disable=C0301
target_resources = ['targetservers', 'flowhooks', 'resourcefiles',
'apis', 'sharedflows', 'org_keyvaluemaps',
'keyvaluemaps', 'apps', 'apiproducts',
'developers']
target_resource_list = []
if 'all' in resources_list:
target_resource_list = target_resources
Expand All @@ -256,21 +259,41 @@ def validate_artifacts(cfg, resources_list, export_data): # noqa pylint: disabl
resourcefiles = export_data['envConfig'][env]['resourcefiles']
flowhooks = export_data['envConfig'][env]['flowhooks']
keyvaluemaps = export_data['envConfig'][env]['kvms']
report[env + SEPERATOR +
'targetServers'] = apigee_validator.validate_env_targetservers(env, target_servers) # noqa pylint: disable=C0301
report[env + SEPERATOR +
if 'all' in resources_list or 'keyvaluemaps' in resources_list:
report[env + SEPERATOR +
'targetServers'] = apigee_validator.validate_env_targetservers(env, target_servers) # noqa pylint: disable=C0301
if 'all' in resources_list or 'resourcefiles' in resources_list:
report[env + SEPERATOR +
'resourcefiles'] = apigee_validator.validate_env_resourcefiles(env, resourcefiles) # noqa pylint: disable=C0301
report[env + SEPERATOR +
if 'all' in resources_list or 'flowhooks' in resources_list:
report[env + SEPERATOR +
'flowhooks'] = apigee_validator.validate_env_flowhooks(env, flowhooks) # noqa
report[env + SEPERATOR +
if 'all' in resources_list or 'keyvaluemaps' in resources_list:
report[env + SEPERATOR +
'keyvaluemaps'] = apigee_validator.validate_kvms(env, keyvaluemaps) # noqa

org_keyvaluemaps = export_data['orgConfig']['kvms']
report['org_keyvaluemaps'] = apigee_validator.validate_kvms(None, org_keyvaluemaps) # noqa
validation = apigee_validator.validate_proxy_bundles(export_dir)
# Todo # pylint: disable=W0511
# validate proxy unifier output bundles
report.update(validation)
if 'all' in resources_list or 'org_keyvaluemaps' in resources_list:
org_keyvaluemaps = export_data['orgConfig']['kvms']
report['org_keyvaluemaps'] = apigee_validator.validate_kvms(None, org_keyvaluemaps) # noqa
if 'all' in resources_list or 'developers' in resources_list:
developers = export_data['orgConfig']['developers']
report['developers'] = apigee_validator.validate_org_resource('developers', developers)
if 'all' in resources_list or 'apiproducts' in resources_list:
apiProducts = export_data['orgConfig']['apiProducts']
report['apiProducts'] = apigee_validator.validate_org_resource('apiProducts', apiProducts)
if 'all' in resources_list or 'apps' in resources_list:
apps = export_data['orgConfig']['apps']
report['apps'] = apigee_validator.validate_org_resource('apps', apps)
if 'all' in resources_list or 'apis' in resources_list:
validation = apigee_validator.validate_proxy_bundles(export_dir, 'apis')
# Todo # pylint: disable=W0511
# validate proxy unifier output bundles
report.update(validation)
if 'all' in resources_list or 'sharedflows' in resources_list:
validation = apigee_validator.validate_proxy_bundles(export_dir, 'sharedflows')
# Todo # pylint: disable=W0511
# validate proxy unifier output bundles
report.update(validation)
return report


Expand Down
50 changes: 36 additions & 14 deletions validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ def __init__(self, project_id, token, env_type, target_export_data):
self.xorhybrid = ApigeeNewGen(project_id, token, env_type)
self.target_export_data = target_export_data

def validate_org_resource(self, resource_type, resources):
"""Validates environment keyvaluemaps.
Args:
env (str): Environment name.
keyvaluemaps (dict): A dictionary of target
server configurations.
Returns:
list: A list of validated keyvaluemaps
objects with importability status and
reasons.
"""
validation_resources = []
target_resources = self.target_export_data.get('orgConfig', {}).get(resource_type, {}).keys() # noqa pylint: disable=C0301
for each_obj, obj in resources.items():
obj['importable'], obj['reason'] = True, []
if each_obj in target_resources:
obj['imported'] = True
else:
obj['imported'] = False
validation_resources.append(obj)
return validation_resources

def validate_kvms(self, env, keyvaluemaps):
"""Validates environment keyvaluemaps.
Expand Down Expand Up @@ -174,7 +198,7 @@ def validate_env_resourcefile_resource(self, metadata):
return True, []
return False, errors

def validate_proxy_bundles(self, export_dir):
def validate_proxy_bundles(self, export_dir, api_type):
"""Validates proxy bundles.
Args:
Expand All @@ -185,20 +209,18 @@ def validate_proxy_bundles(self, export_dir):
dict: Validation results for APIs and
sharedflows.
"""
apis = self.target_export_data.get('orgConfig', {}).get('apis', {}).keys() # noqa pylint: disable=C0301
sharedflows = self.target_export_data.get('orgConfig', {}).get('sharedflows', {}).keys() # noqa pylint: disable=C0301
apis_sf_list = {'apis': apis, 'sharedflows': sharedflows}
objects = self.target_export_data.get('orgConfig', {}).get(api_type, {}).keys() # noqa pylint: disable=C0301
objects_list = {api_type: objects}
validation = {'apis': [], 'sharedflows': []}
for each_api_type in ['apis', 'sharedflows']:
bundle_dir = f"{export_dir}/{each_api_type}"
for proxy_bundle in list_dir(bundle_dir):
each_validation = self.validate_proxy(bundle_dir, each_api_type, proxy_bundle) # noqa pylint: disable=C0301
api_name = proxy_bundle.split(".zip")[0]
if api_name in apis_sf_list[each_api_type]:
each_validation['imported'] = True
else:
each_validation['imported'] = False
validation[each_api_type].append(each_validation)
bundle_dir = f"{export_dir}/{api_type}"
for proxy_bundle in list_dir(bundle_dir):
each_validation = self.validate_proxy(bundle_dir, api_type, proxy_bundle) # noqa pylint: disable=C0301
api_name = proxy_bundle.split(".zip")[0]
if api_name in objects_list[api_type]:
each_validation['imported'] = True
else:
each_validation['imported'] = False
validation[api_type].append(each_validation)
return validation

@retry()
Expand Down

0 comments on commit fdbbcc2

Please sign in to comment.