Skip to content

Commit

Permalink
Bugfix/fix paging for api catalog (#53)
Browse files Browse the repository at this point in the history
* Added pageSize query param to api catalog call.

* Added page_size parameter, defaulting it to 100.

* Fixed linting issues
  • Loading branch information
lbajada authored Jun 6, 2024
1 parent 8b6a0fd commit 794ebc5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ As there is no API to create or update Portal Documentation on Apigee, this scri

**refresh_token** - Same as in **upload_spec.py**.

**page_size** - The amount of elements to return for API calls that have paging. Default is 100.

## upload_theme.py

This python script leverages Apigee internal APIs to maintain an apigee portal look and feel, by modifiying logos, stylesheets etc. This script uses a custom configuration file described below, to reference different theme resoures.
Expand Down
3 changes: 2 additions & 1 deletion automation/check_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def main():
else:
sys.exit(0)
else:
raise Exception('Certificate name not found!')
print('Certificate name not found!')
sys.exit(1)


if __name__ == '__main__':
Expand Down
11 changes: 7 additions & 4 deletions automation/upload_api_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def product_exists(name: str, org_name: str) -> bool:
'https://api.enterprise.apigee.com/v1/organizations/{}/apiproducts'.format(org_name))

if response.status_code != 200:
raise Exception(print_error(response))
print_error(response)
raise response.raise_for_status()

for product_name in response.json():
if product_name == name:
Expand All @@ -38,7 +39,8 @@ def create_api_product(org_name: str, product_json: str):
json=product_json)

if response.status_code != 201:
raise Exception(print_error(response))
print_error(response)
raise response.raise_for_status()

print("Successfully created API Product with name '{}'.".format(
product_json['name']))
Expand All @@ -53,7 +55,8 @@ def update_api_product(org_name: str, product_json: str):
org_name, product_name), json=product_json)

if response.status_code != 200:
raise Exception(print_error(response))
print_error(response)
raise response.raise_for_status()

print("Successfully updated API Product with name '{}'.".format(product_name))

Expand Down Expand Up @@ -123,7 +126,7 @@ def main():
# Name is mandatory in the JSON file, otherwise we would not know
# whether we want to create or update.
if 'name' not in product:
raise Exception(
raise IOError(
print_error('API Product name not specified in JSON file.'))

exists: bool = product_exists(product_name, org_name)
Expand Down
14 changes: 11 additions & 3 deletions automation/upload_portal_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ def spec_exists(org_name: str, spec_name: str) -> bool:

def documentation_exists(
spec_name: str,
portal_name: str) -> ApiDoc:
portal_name: str,
page_size: int) -> ApiDoc:
"""Retrieves a list of API Products exposed on a portal and checks if
there is an existing one using the given spec name."""

response = REQUEST.get(
'https://apigee.com/portals/api/sites/{}/apidocs'.format(portal_name))
'https://apigee.com/portals/api/sites/{}/apidocs?pageSize={}'.format(portal_name, page_size))

if response.status_code != 200:
raise RestException(utils.print_error(response))
Expand Down Expand Up @@ -156,6 +157,10 @@ def parse_args():
'-rt',
'--refresh_token',
help='apigee refresh token')
req_grp.add_argument(
'-pgs',
'--page_size',
help='page size for API calls that use paging - default is 100')

parsed = parser.parse_args()

Expand All @@ -177,6 +182,9 @@ def main():
password = args.password
refresh_token = args.refresh_token

# Some API calls make use of paging, if the page size is not defined, we default it to 100.
page_size = 100 if args.page_size is None else args.page_size

data = open(doc_path, 'r', encoding='utf8').read()
doc = json.loads(data)

Expand Down Expand Up @@ -210,7 +218,7 @@ def main():
# the spec ID dynamically.
doc.update({'specContent': spec_id})

api_doc = documentation_exists(spec_name, current_portal.id)
api_doc = documentation_exists(spec_name, current_portal.id, page_size)
if api_doc:
print("API Doc already exists.")
try:
Expand Down
9 changes: 6 additions & 3 deletions automation/upload_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def get_specs_folder(org_name: str) -> Folder:
'https://apigee.com/dapi/api/organizations/{}/specs/folder/home'.format(org_name))

if response.status_code != 200:
raise Exception(print_error(response))
print_error(response)
raise response.raise_for_status()

print('Successfully fetched OpenAPI Specs folder from Apigee.')

Expand Down Expand Up @@ -74,7 +75,8 @@ def create_empty_spec(org_name: str, folder_id: int, spec_name: str) -> Spec:
response = REQUEST.post(url, json=data)

if response.status_code != 200:
raise Exception(print_error(response))
print_error(response)
raise response.raise_for_status()

json = response.json()
print(
Expand All @@ -93,7 +95,8 @@ def update_spec(org_name: str, spec_id: int, spec_path: str):

response = REQUEST.put(url, data=data.encode('utf-8'))
if response.status_code != 200:
raise Exception(print_error(response))
print_error(response)
raise response.raise_for_status()

print('Successfully uploaded OpenAPI spec to Apigee!')

Expand Down

0 comments on commit 794ebc5

Please sign in to comment.