Skip to content

Commit

Permalink
fix: added virtualenv to pipeline.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
anaik91 committed Jan 23, 2024
1 parent 7c50710 commit a9ccfe8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 12 additions & 4 deletions tools/proxy-endpoint-unifier/pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ gcp_project_id=$APIGEE_X_ORG
EOF

# Install Dependencies
python3 -m pip install -r "$SCRIPTPATH/requirements.txt"
VENV_PATH="$SCRIPTPATH/venv"
python3 -m venv "$VENV_PATH"
# shellcheck source=/dev/null
. "$VENV_PATH/bin/activate"
pip install -r "$SCRIPTPATH/requirements.txt"

# Generate Gcloud Acccess Token
APIGEE_ACCESS_TOKEN="$(gcloud config config-helper --force-auth-refresh --format json | jq -r '.credential.access_token')"
export APIGEE_ACCESS_TOKEN

# Building API Proxy Bundle for Proxy containing more than 5 Proxy Endpoints
cd "$SCRIPTPATH/test/api_bundles"
rm -rf "$SCRIPTPATH/test/api_bundles/test.zip"
cd "$SCRIPTPATH/test/api_bundles/test-proxy"
rm -rf "$SCRIPTPATH/test/api_bundles/test-proxy/test.zip"
echo "Building original proxy bundle"
zip -q -r test.zip apiproxy/
cd "$SCRIPTPATH"
Expand All @@ -57,9 +61,13 @@ python3 -c "import os, sys ,json; \
from apigee import Apigee; \
x = Apigee(os.getenv('APIGEE_X_ORG')); \
x.set_auth_header(os.getenv('APIGEE_ACCESS_TOKEN')); \
r=x.validate_api('apis','test/api_bundles/test.zip'); \
r=x.validate_api('apis','test/api_bundles/test-proxy/test.zip'); \
print(json.dumps(r,indent=2))"
rm -rf "$SCRIPTPATH/test/api_bundles/test.zip"

# Running and Validating API Proxy Bundle after splitting the proxies
python3 "$SCRIPTPATH/main.py"

# deactivate venv & cleanup
deactivate
rm -rf "$VENV_PATH"
10 changes: 3 additions & 7 deletions tools/proxy-endpoint-unifier/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,24 @@ def parse_proxy_root(dir):
return {}
doc = parse_xml(file)
api_proxy = doc.get('APIProxy', {})
keys = ['Policies', 'ProxyEndpoints', 'Resources', 'Spec', 'TargetServers', 'TargetEndpoints' ] # noqa
for each_key in keys:
if api_proxy[each_key] is None:
api_proxy[each_key] = {}
proxy_endpoints = api_proxy.get('ProxyEndpoints', {}).get('ProxyEndpoint', {}) # noqa
target_endpoints = api_proxy.get('TargetEndpoints', {}).get('TargetEndpoint', {}) # noqa
policies = api_proxy.get('Policies', {}).get('Policy', {})
if len(proxy_endpoints) != 0:
if len(proxy_endpoints) == 0:
print('Proceeding with Filesystem parse of ProxyEndpoints')
doc['APIProxy']['ProxyEndpoints'] = {}
proxies = get_proxy_files(dir)
doc['APIProxy']['ProxyEndpoints']['ProxyEndpoint'] = proxies
else:
print('Skipping with Filesystem parse of ProxyEndpoints')
if len(target_endpoints) != 0:
if len(target_endpoints) == 0:
print('Proceeding with Filesystem parse of TargetEndpoints')
doc['APIProxy']['TargetEndpoints'] = {}
targets = get_proxy_files(dir, 'targets')
doc['APIProxy']['TargetEndpoints']['TargetEndpoint'] = targets
else:
print('Skipping with Filesystem parse of TargetEndpoints')
if len(policies) != 0:
if len(policies) == 0:
print('Proceeding with Filesystem parse of Policies')
doc['APIProxy']['Policies'] = {}
policies_list = get_proxy_files(dir, 'policies')
Expand Down

0 comments on commit a9ccfe8

Please sign in to comment.