Skip to content

Commit

Permalink
feat: added support for multiple proxy split
Browse files Browse the repository at this point in the history
  • Loading branch information
anaik91 committed Jan 17, 2024
1 parent dca8b29 commit 2e30f5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 3 additions & 4 deletions tools/proxy-endpoint-unifier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ def main():
utils.create_dir(proxy_bundle_directory)
proxy_endpoint_count = utils.get_proxy_endpoint_count(cfg)
proxies = utils.list_dir(proxy_dir)

final_dict = {}
processed_dict = {}

for each_dir in proxies:
each_proxy_dict = utils.read_proxy_artifacts(
f"{proxy_dir}/{each_dir}",
utils.parse_proxy_root(f"{proxy_dir}/{each_dir}")
f"{proxy_dir}/{each_dir}/apiproxy",
utils.parse_proxy_root(f"{proxy_dir}/{each_dir}/apiproxy")
)
if len(each_proxy_dict) > 0:
each_proxy_rel = utils.get_proxy_objects_relationships(
Expand Down Expand Up @@ -91,7 +90,7 @@ def main():
for each_api, grouped_api in bundled_group.items():
for index, each_group in enumerate(grouped_api):
utils.clone_proxies(
f"{proxy_dir}/{each_api}",
f"{proxy_dir}/{each_api}/apiproxy",
f"{proxy_dest_dir}/{each_api}_{index}",
merged_objects[f"{each_api}_{index}"],
merged_pes,
Expand Down
10 changes: 7 additions & 3 deletions tools/proxy-endpoint-unifier/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,28 @@ 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 2e30f5e

Please sign in to comment.