Skip to content

Instantly share code, notes, and snippets.

@chamilad
Last active November 25, 2018 02:52
Show Gist options
  • Save chamilad/057bc353a48847519a4cfb09f18220eb to your computer and use it in GitHub Desktop.
Save chamilad/057bc353a48847519a4cfb09f18220eb to your computer and use it in GitHub Desktop.
Figure out upsert logic
# If there is no matching API, an API create request is done.
# If a matching API is there, but no matching version, a version would be added
# If both a matching API with a matching version exists, the API would not be created.
for api_request in request_json_content["apis"]:
api_name_exists, api_id = api_utils.api_name_exists(api_request["name"], apimgt_url, access_token,
verify_ssl)
if api_name_exists:
# Check if the same version exists
api_version_exists, _ = api_utils.api_version_exists(api_request["name"], api_request["version"],
apimgt_url, access_token, verify_ssl)
if api_version_exists:
# Do not create the same version
print "\t%s:%s \t :Exists. Skipping..." % (api_request["name"], api_request["version"])
continue
else:
# Add as a new version
print "\t%s:%s \t :Adding version..." % (api_request["name"], api_request["version"])
api_utils.add_api_version(api_id, api_request["version"], apimgt_url, access_token, verify_ssl)
else:
# Create API
print "\t%s:%s \t :Creating..." % (api_request["name"], api_request["version"])
# build create request
# ....
# ....
# ....
successful = api_utils.create_api(create_req_body, apimgt_url, access_token, verify_ssl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment