Created
November 25, 2018 03:12
-
-
Save chamilad/60a1022c7a3a07b4d2e60470223d7759 to your computer and use it in GitHub Desktop.
Upsert APIs from dev1 to dev2 environments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Get list of APIs from env1 | |
print "Getting the list of APIs from ENV1..." | |
all_apis_in_env1 = api_utils.get_all_apis(env1_apimgt_url, env1_access_token, verify_ssl) | |
#... | |
#... | |
#... | |
# 2. Iterate through APIs and check if exists in env2 | |
print "Checking for API status in ENV2..." | |
for api_to_propagate in all_apis_in_env1["list"]: | |
#... | |
# get the api definition from env 1 | |
api_definition_env1 = api_utils.get_api_by_id(api_to_propagate["id"], env1_apimgt_url, env1_access_token, | |
verify_ssl) | |
#... | |
#... | |
# check if API exists in env2 | |
api_exists_in_env2, api_id = api_utils.api_version_exists(api_definition_env1["name"], | |
api_definition_env1["version"], | |
env2_apimgt_url, env2_access_token, verify_ssl) | |
if api_exists_in_env2: | |
# 3. If exists, update API | |
api_definition_env1["id"] = api_id | |
print "Updating API %s in ENV2..." % api_definition_env1["name"] | |
api_utils.update_api(api_definition_env1, env2_apimgt_url, env2_access_token, verify_ssl) | |
else: | |
# 4 If doesn't exist, create API in env2 | |
print "Creating API %s in ENV2..." % api_definition_env1["name"] | |
api_utils.create_api(api_definition_env1, env2_apimgt_url, env2_access_token, verify_ssl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment