Skip to content

Commit

Permalink
feat: added support for apigee target with DRZ support
Browse files Browse the repository at this point in the history
  • Loading branch information
anaik91 committed Feb 17, 2025
1 parent b49b63a commit af0156f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
11 changes: 7 additions & 4 deletions core_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def pre_validation_checks(cfg): # pylint: disable=R0914
"inputs": [
"SOURCE_URL", "SOURCE_ORG", "SOURCE_AUTH_TYPE",
"SOURCE_UI_URL", "SOURCE_APIGEE_VERSION",
"GCP_PROJECT_ID", "GCP_ENV_TYPE",
"TARGET_URL", "GCP_PROJECT_ID", "GCP_ENV_TYPE",
"API_URL", "TARGET_DIR", "SSL_VERIFICATION"],
"export": ["EXPORT_DIR", "EXPORT_FILE"],
"topology": [
Expand Down Expand Up @@ -129,12 +129,14 @@ def pre_validation_checks(cfg): # pylint: disable=R0914
return False

# check for target org
target_url = cfg.get('inputs', 'TARGET_URL')
gcp_project_id = cfg.get('inputs', 'GCP_PROJECT_ID')
gcp_token = get_access_token()
gcp_env_type = cfg.get('inputs', 'GCP_ENV_TYPE',
fallback=DEFAULT_GCP_ENV_TYPE)

xorhybrid = ApigeeNewGen(gcp_project_id, gcp_token, gcp_env_type)
xorhybrid = ApigeeNewGen(target_url, gcp_project_id,
gcp_token, gcp_env_type)
missing_permissions = xorhybrid.validate_permissions()
if len(missing_permissions) > 0:
logger.error( # pylint: disable=W1203
Expand Down Expand Up @@ -234,12 +236,13 @@ def validate_artifacts(cfg, resources_list, export_data): # noqa pylint: disabl
sf_export_dir = f"{target_export_dir}/sharedflows"
create_dir(api_export_dir)
create_dir(sf_export_dir)
target_url = cfg.get('inputs', 'TARGET_URL')
gcp_project_id = cfg.get('inputs', 'GCP_PROJECT_ID')
gcp_env_type = cfg.get('inputs', 'GCP_ENV_TYPE',
fallback=DEFAULT_GCP_ENV_TYPE)
gcp_token = get_access_token()
apigee_export = ApigeeExporter(
'https://apigee.googleapis.com/v1',
target_url,
gcp_project_id,
gcp_token,
'oauth',
Expand All @@ -259,7 +262,7 @@ def validate_artifacts(cfg, resources_list, export_data): # noqa pylint: disabl
target_export_data = apigee_export.get_export_data(target_resource_list, target_export_dir) # noqa pylint: disable=C0301
target_export_data['export'] = True
write_json(target_export_data_file, target_export_data)
apigee_validator = ApigeeValidator(gcp_project_id, gcp_token, gcp_env_type, target_export_data) # noqa pylint: disable=C0301
apigee_validator = ApigeeValidator(target_url, gcp_project_id, gcp_token, gcp_env_type, target_export_data) # noqa pylint: disable=C0301

for env, _ in export_data['envConfig'].items():
logger.info(f'Environment -- {env}') # pylint: disable=W1203
Expand Down
2 changes: 1 addition & 1 deletion exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ 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,
self.apigee = (ApigeeNewGen(baseurl, org, token,
'ENVIRONMENT_TYPE_UNSPECIFIED')
if 'apigee.googleapis.com' in baseurl else
ApigeeClassic(baseurl, org, token,
Expand Down
4 changes: 2 additions & 2 deletions nextgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ApigeeNewGen(): # noqa pylint: disable=R0902
Provides methods to interact with Apigee X or hybrid environments,
including creating and validating API proxies and shared flows.
"""
def __init__(self, project_id, token, env_type):
def __init__(self, baseurl, project_id, token, env_type):
"""Initializes the ApigeeNewGen client.
Args:
Expand All @@ -41,7 +41,7 @@ def __init__(self, project_id, token, env_type):
env_type (str): The environment type ('hybrid' or 'x').
Defaults to 'ENVIRONMENT_TYPE_UNSPECIFIED'.
"""
self.baseurl = 'https://apigee.googleapis.com/v1'
self.baseurl = baseurl
self.project_id = project_id
self.token = token
self.env_type = env_type or 'ENVIRONMENT_TYPE_UNSPECIFIED'
Expand Down
1 change: 1 addition & 0 deletions sample/inputs/opdk.input.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SOURCE_ORG=validate
SOURCE_AUTH_TYPE=basic
SOURCE_UI_URL=https://192.168.56.55/platform/
SOURCE_APIGEE_VERSION=OPDK
TARGET_URL=https://apigee.googleapis.com/v1
GCP_PROJECT_ID=sample-apigee-project-1
GCP_ENV_TYPE=ENVIRONMENT_TYPE_UNSPECIFIED
API_URL=https://apidocs.apigee.com/docs
Expand Down
1 change: 1 addition & 0 deletions sample/inputs/saas.input.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SOURCE_ORG=sample-saas-project-1
SOURCE_AUTH_TYPE=oauth
SOURCE_UI_URL=http://apigee.google
SOURCE_APIGEE_VERSION=SAAS
TARGET_URL=https://apigee.googleapis.com/v1
GCP_PROJECT_ID=sample-apigee-project-11
GCP_ENV_TYPE=ENVIRONMENT_TYPE_UNSPECIFIED
API_URL=https://apidocs.apigee.com/docs
Expand Down
1 change: 1 addition & 0 deletions sample/inputs/x.input.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SOURCE_ORG=apigee-org-1234
SOURCE_AUTH_TYPE=oauth
SOURCE_UI_URL=https://console.cloud.google.conm/apigee?project=apigee-org-1234
SOURCE_APIGEE_VERSION=SAAS
TARGET_URL=https://apigee.googleapis.com/v1
GCP_PROJECT_ID=apigee-org-4321
GCP_ENV_TYPE=ENVIRONMENT_TYPE_UNSPECIFIED
API_URL=https://apidocs.apigee.com/docs
Expand Down
4 changes: 2 additions & 2 deletions validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ApigeeValidator():
rules and compatibility checks.
"""

def __init__(self, project_id, token, env_type, target_export_data):
def __init__(self, baseurl, project_id, token, env_type, target_export_data): # noqa pylint: disable=R0913,W0012,R0917
"""Initializes ApigeeValidator.
Args:
Expand All @@ -50,7 +50,7 @@ def __init__(self, project_id, token, env_type, target_export_data):
('hybrid' or 'x').
"""
self.project_id = project_id
self.xorhybrid = ApigeeNewGen(project_id, token, env_type)
self.xorhybrid = ApigeeNewGen(baseurl, project_id, token, env_type)
self.target_export_data = target_export_data

def validate_org_resource(self, resource_type, resources):
Expand Down

0 comments on commit af0156f

Please sign in to comment.