Skip to content

Commit d2bcd25

Browse files
authored
Merge pull request #773 from anaik91/feat/proxy-endpoint-unifier-enhancements
feat: added enhancements to endpoint-unifier
2 parents 484d2fe + a235361 commit d2bcd25

File tree

5 files changed

+205
-73
lines changed

5 files changed

+205
-73
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
*.jar
99
*.iml
1010
.idea
11+
__pycache__/
12+
test/transformed/
13+
test/transformed_zipped_bundles/
14+
venv/

tools/proxy-endpoint-unifier/README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Apigee API Proxy Endpoint Unifier
22

3-
Apigee X and hybrid have a limitation of hosting up to 5 Proxy Endpoints per API Proxy. Apigee Edge has no such limitation.
3+
Apigee X and hybrid have a limitation of hosting up to [10 Proxy Endpoints](https://cloud.google.com/apigee/docs/api-platform/reference/limits#api-proxies) per API Proxy. Apigee Edge has no such limitation.
44
The objective of this tool is to take a proxy bundle and intelligently convert its proxy endpoints into logically
55
grouped conditional flows, in order to stay within the Proxy Endpoint limit.
66

@@ -27,6 +27,40 @@ This is not an officially supported Google product.
2727
gcp_project_id=xxx-xxx-xxx # Apigee Project for proxy validation
2828
```
2929

30+
Folder Structure of `input_apis`
31+
32+
```
33+
apis/
34+
├── <exaple_api_1>
35+
│   └── apiproxy
36+
│   ├── exaple_api_1.xml
37+
│   ├── manifests
38+
│   │   └── manifest.xml
39+
│   ├── policies
40+
│   │   ├── example.xml
41+
│   ├── proxies
42+
│   │   ├── example.xml
43+
│   ├── resources
44+
│   │   └── jsc
45+
│   │   ├── example.js
46+
│   └── targets
47+
│   ├── default.xml
48+
├── <exaple_api_2>
49+
│   └── apiproxy
50+
│   ├── exaple_api_2.xml
51+
│   ├── manifests
52+
│   │   └── manifest.xml
53+
│   ├── policies
54+
│   │   ├── example.xml
55+
│   ├── proxies
56+
│   │   ├── example.xml
57+
│   ├── resources
58+
│   │   └── jsc
59+
│   │   ├── example.js
60+
│   └── targets
61+
│   ├── default.xml
62+
```
63+
3064
* If enabling validation, please run the following command to authenticate against Apigee APIs:
3165

3266
```

tools/proxy-endpoint-unifier/input.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
input_apis=test/api_bundles
1717
processed_apis=test/transformed
1818
proxy_bundle_directory=test/transformed_zipped_bundles
19-
proxy_endpoint_count=4
19+
proxy_endpoint_count=10
2020
debug=false
2121

2222
[validate]

tools/proxy-endpoint-unifier/main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ def main():
3434
proxies = utils.list_dir(proxy_dir)
3535
final_dict = {}
3636
processed_dict = {}
37+
if validation_enabled:
38+
utils.is_token_valid(os.getenv('APIGEE_ACCESS_TOKEN', ''))
3739

3840
for each_dir in proxies:
3941
each_proxy_dict = utils.read_proxy_artifacts(
4042
f"{proxy_dir}/{each_dir}/apiproxy",
41-
utils.parse_proxy_root(f"{proxy_dir}/{each_dir}/apiproxy")
43+
utils.parse_proxy_root(f"{proxy_dir}/{each_dir}/apiproxy") # noqa
4244
)
4345
if len(each_proxy_dict) > 0:
4446
each_proxy_rel = utils.get_proxy_objects_relationships(
@@ -72,20 +74,21 @@ def main():
7274
'ProxyEndpoints': []
7375
}
7476
for each_path, pes in each_group.items():
75-
each_pe = '-'.join(pes)
76-
merged_pes[each_pe] = utils.merge_proxy_endpoints(
77+
each_merged_pe = utils.merge_proxy_endpoints(
7778
processing_final_dict[each_api],
7879
each_path,
7980
pes
8081
)
82+
each_merged_pe_name = each_merged_pe['ProxyEndpoint']['@name']
83+
merged_pes[each_merged_pe_name] = each_merged_pe
8184
merged_objects[f"{each_api}_{index}"]['Name'] = f"{final_dict[each_api]['proxyName']}_{index}" # noqa
8285
merged_objects[f"{each_api}_{index}"]['Policies'].extend( # noqa
8386
[ item for pe in pes for item in processed_dict[each_api][pe]['Policies']]) # noqa
8487
merged_objects[f"{each_api}_{index}"]['TargetEndpoints'].extend( # noqa
8588
[ item for pe in pes for item in processed_dict[each_api][pe]['TargetEndpoints']]) # noqa
8689
merged_objects[f"{each_api}_{index}"]['Policies'] = list(set(merged_objects[f"{each_api}_{index}"]['Policies'])) # noqa
8790
merged_objects[f"{each_api}_{index}"]['TargetEndpoints'] = list(set(merged_objects[f"{each_api}_{index}"]['TargetEndpoints'])) # noqa
88-
merged_objects[f"{each_api}_{index}"]['ProxyEndpoints'].append(each_pe) # noqa
91+
merged_objects[f"{each_api}_{index}"]['ProxyEndpoints'].append(each_merged_pe_name) # noqa
8992

9093
for each_api, grouped_api in bundled_group.items():
9194
for index, each_group in enumerate(grouped_api):

0 commit comments

Comments
 (0)