def clear_all_apis(access_key, secret_access_key, profile_name, session_token): log_entry("Clearing APIs for all regions") clear_count = 0 for region in regions: args, help_str = get_fireprox_args(access_key, secret_access_key, profile_name, session_token, "list", region) fp = FireProx(args, help_str) active_apis = fp.list_api() count = len(active_apis) err = "skipping" if count != 0: err = "removing" log_entry("Region: {}, found {} APIs configured, {}".format( region, count, err)) for api in active_apis: if "fireprox" in api['name']: fp.delete_api(api['id']) clear_count += 1 log_entry("APIs removed: {}".format(clear_count))
def destroy_apis(apis, access_key, secret_access_key, profile_name, session_token): for api_key in apis: args, help_str = get_fireprox_args(access_key, secret_access_key, profile_name, session_token, "delete", api_key, api_id = apis[api_key]['api_gateway_id']) fp = FireProx(args, help_str) log_entry('Destroying API ({}) in region {}'.format(args['api_id'], api_key)) fp.delete_api(args["api_id"])
def create_api(access_key, secret_access_key, profile_name, session_token, region, url): args, help_str = get_fireprox_args(access_key, secret_access_key, profile_name, session_token, "create", region, url=url) fp = FireProx(args, help_str) resource_id, proxy_url = fp.create_api(url) return {"api_gateway_id": resource_id, "proxy_url": proxy_url}
def list_apis(access_key, secret_access_key, profile_name, session_token): for region in regions: args, help_str = get_fireprox_args(access_key, secret_access_key, profile_name, session_token, "list", region) fp = FireProx(args, help_str) active_apis = fp.list_api() log_entry("Region: {} - total APIs: {}".format(region, len(active_apis))) if len(active_apis) != 0: for api in active_apis: log_entry( "API Info -- ID: {}, Name: {}, Created Date: {}".format( api['id'], api['name'], api['createdDate']))
def destroy_single_api(api, access_key, secret_access_key, profile_name, session_token): log_entry("Destroying single API, locating region...") for region in regions: args, help_str = get_fireprox_args(access_key, secret_access_key, profile_name, session_token, "list", region) fp = FireProx(args, help_str) active_apis = fp.list_api() for api1 in active_apis: if api1['id'] == api: log_entry( "API found in region {}, destroying...".format(region)) fp.delete_api(api) return log_entry("API not found")