def create_keyvaluemap_in_an_environment(self, environment, request_body): uri = CREATE_KEYVALUEMAP_IN_AN_ENVIRONMENT_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) body = json.loads(request_body) resp = requests.post(uri, headers=hdrs, json=body) resp.raise_for_status() return resp
def add_permissions_for_a_resource_to_a_user_role(self, request_body): uri = ADD_PERMISSIONS_FOR_A_RESOURCE_TO_A_USER_ROLE_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, role_name=self._role_name) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) body = json.loads(request_body) resp = requests.post(uri, headers=hdrs, json=body) resp.raise_for_status() return resp
def delete_a_user_role(self): uri = DELETE_A_USER_ROLE_PATH.format(api_url=APIGEE_ADMIN_API_URL, org=self._org_name, role_name=self._role_name) hdrs = auth.set_header( self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', }, ) resp = requests.delete(uri, headers=hdrs) resp.raise_for_status() return resp
def update_all_developer_attributes(self, request_body): uri = UPDATE_ALL_DEVELOPER_ATTRIBUTES_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, developer_email=self._developer_email) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) body = json.loads(request_body) resp = requests.post(uri, headers=hdrs, json=body) resp.raise_for_status() return resp
def delete_keyvaluemap_entry_in_an_environment(self, environment, entry_name): uri = DELETE_KEYVALUEMAP_ENTRY_IN_AN_ENVIRONMENT_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment, name=self._map_name, entry_name=entry_name, ) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.delete(uri, headers=hdrs) resp.raise_for_status() return resp
def get_a_keys_value_in_an_environment_scoped_keyvaluemap( self, environment, entry_name): uri = GET_A_KEYS_VALUE_IN_AN_ENVIRONMENT_SCOPED_KEYVALUEMAP_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment, name=self._map_name, entry_name=entry_name, ) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() return resp
def list_aliases(self, environment, prefix=None, format='json'): uri = LIST_ALIASES_PATH.format( api_url=APIGEE_ADMIN_API_URL, org_name=self._org_name, environment=environment, keystore_name=self._keystore_name, ) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() return KeystoresSerializer().serialize_details(resp, format, prefix=prefix)
def force_undeploy_api_proxy_revision(self, api_name, environment, revision_number): uri = FORCE_UNDEPLOY_API_PROXY_REVISION_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, api_name=api_name, revision_number=revision_number, environment=environment, ) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.delete(uri, headers=hdrs) resp.raise_for_status() return resp
def get_cert_details_from_a_keystore_or_truststore(self, environment, cert_name): uri = GET_CERT_DETAILS_FROM_A_KEYSTORE_OR_TRUSTSTORE_PATH.format( api_url=APIGEE_ADMIN_API_URL, org_name=self._org_name, environment=environment, keystore_name=self._keystore_name, cert_name=cert_name, ) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() return resp
def create_data_masks_for_an_api_proxy(self, request_body): uri = CREATE_DATA_MASKS_FOR_AN_API_PROXY_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, api_name=self._api_name) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) body = json.loads(request_body) resp = requests.post(uri, headers=hdrs, json=body) resp.raise_for_status() return resp
def list_virtual_hosts_for_an_environment(self, environment, prefix=None, format='json'): uri = LIST_VIRTUAL_HOSTS_FOR_AN_ENVIRONMENT_PATH.format( api_url=APIGEE_ADMIN_API_URL, org_name=self._org_name, environment=environment) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() return VirtualhostsSerializer().serialize_details(resp, format, prefix=prefix)
def add_api_product_to_key(self, developer, consumer_key, request_body): uri = ADD_API_PRODUCT_TO_KEY_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, developer=developer, name=self._app_name, consumer_key=consumer_key, ) hdrs = auth.set_header( self._auth, headers={'Accept': 'application/json', 'Content-Type': 'application/json'} ) body = json.loads(request_body) resp = requests.post(uri, headers=hdrs, json=body) resp.raise_for_status() return resp
def import_a_shared_flow(self, shared_flow_file, shared_flow_name): uri = IMPORT_A_SHARED_FLOW_PATH.format(api_url=APIGEE_ADMIN_API_URL, org=self._org_name) hdrs = auth.set_header(self._auth, { 'Accept': 'application/json', 'Content-Type': 'multipart/form-data' }) params = {'action': 'import', 'name': shared_flow_name} with open(shared_flow_file, 'rb') as f: resp = requests.post(uri, headers=hdrs, files={'file': ('sharedflow.zip', f)}, params=params) resp.raise_for_status() return resp
def remove_user_membership_in_role(self, user_email): uri = REMOVE_USER_MEMBERSHIP_IN_ROLE_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, role_name=self._role_name, user_email=user_email, ) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) resp = requests.delete(uri, headers=hdrs) resp.raise_for_status() return resp
def list_targetservers_in_an_environment(self, environment, prefix=None, format='json'): uri = LIST_TARGETSERVERS_IN_AN_ENVIRONMENT_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() return TargetserversSerializer().serialize_details(resp, format, prefix=prefix)
def create_a_user_role_in_an_organization(self): uri = CREATE_A_USER_ROLE_IN_AN_ORGANIZATION_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) roles = [] for role in self._role_name: roles.append({'name': role}) body = {'role': roles} resp = requests.post(uri, headers=hdrs, json=body) resp.raise_for_status() return resp
def verify_user_role_membership(self, user_email): uri = VERIFY_USER_ROLE_MEMBERSHIP_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, role_name=self._role_name, user_email=user_email, ) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() return resp
def list_keys_in_an_environment_scoped_keyvaluemap(self, environment, startkey, count): uri = LIST_KEYS_IN_AN_ENVIRONMENT_SCOPED_KEYVALUEMAP_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment, name=self._map_name, startkey=startkey, count=count, ) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() # return KeyvaluemapsSerializer().serialize_details(resp, 'json', prefix=prefix) return resp
def get_permissions(self, formatted=False, format='text', showindex=False, tablefmt='plain'): uri = GET_PERMISSIONS_PATH.format(api_url=APIGEE_ADMIN_API_URL, org=self._org_name, role_name=self._role_name) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() if formatted: return PermissionsSerializer().serialize_details( resp, format, showindex=showindex, tablefmt=tablefmt) return resp
def update_a_cache_in_an_environment(self, environment, request_body): uri = UPDATE_A_CACHE_IN_AN_ENVIRONMENT_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment, name=self._cache_name, ) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) body = json.loads(request_body) resp = requests.put(uri, headers=hdrs, json=body) resp.raise_for_status() return resp
def update_a_targetserver(self, environment, request_body): uri = UPDATE_A_TARGETSERVER_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment, name=self._targetserver_name, ) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) body = json.loads(request_body) resp = requests.put(uri, headers=hdrs, json=body) resp.raise_for_status() return resp
def deploy_a_shared_flow( self, environment, shared_flow_name, revision_number, override=False, delay=0, shared_flow_file=None, ): do_deployments_exist = False try: if self.get_shared_flow_revisions(shared_flow_name): do_deployments_exist = True except HTTPError as e: if e.response.status_code != 404: raise e if shared_flow_file: revision_number = int( self.import_a_shared_flow(shared_flow_file, shared_flow_name).json()['revision']) uri = DEPLOY_A_SHARED_FLOW_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment, shared_flow_name=shared_flow_name, revision_number=revision_number, ) options_dict = { 'override': 'true' if override else 'false', 'delay': f'{delay}' } params = add_to_dict_if_exists(options_dict) hdrs = auth.set_header(self._auth, {'Accept': 'application/json'}) console.echo(f'Deploying revision {revision_number}... ', end='', flush=True) resp = requests.post(uri, headers=hdrs, params=params) resp.raise_for_status() console.echo('Done') if do_deployments_exist: console.echo('Attempting undeployment... ') self.undeploy_shared_flow_revisions_in_environment( environment, shared_flow_name, except_revisions={revision_number}) console.echo('Done.') return resp
def set_developer_status(self, action): uri = SET_DEVELOPER_STATUS_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, developer_email=self._developer_email, action=action, ) hdrs = auth.set_header( self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/octet-stream' }, ) resp = requests.post(uri, headers=hdrs) resp.raise_for_status() return resp
def get_all_certs_from_a_keystore_or_truststore(self, environment, prefix=None, format='json'): uri = GET_ALL_CERTS_FROM_A_KEYSTORE_OR_TRUSTSTORE_PATH.format( api_url=APIGEE_ADMIN_API_URL, org_name=self._org_name, environment=environment, keystore_name=self._keystore_name, ) hdrs = auth.set_header(self._auth, headers={'Accept': 'application/json'}) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() return KeystoresSerializer().serialize_details(resp, format, prefix=prefix)
def create_a_consumer_key_and_secret( self, developer, consumer_key=None, consumer_secret=None, key_length=32, secret_length=32, key_suffix=None, key_delimiter='-', products=[], ): uri = CREATE_A_CONSUMER_KEY_AND_SECRET_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, developer=developer, name=self._app_name, ) hdrs = auth.set_header( self._auth, headers={'Accept': 'application/json', 'Content-Type': 'application/json'} ) # app = self.get_developer_app_details(developer) def _rand(length): return "".join( random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(length) ) if not consumer_key: consumer_key = _rand(key_length) if not consumer_secret: consumer_secret = _rand(secret_length) if key_suffix: consumer_key += key_delimiter consumer_key += key_suffix body = {'consumerKey': consumer_key, 'consumerSecret': consumer_secret} resp = requests.post(uri, headers=hdrs, json=body) resp.raise_for_status() if products: console.echo(resp.text) consumer_key = resp.json()['consumerKey'] request_body = json.dumps( {'apiProducts': products, 'attributes': resp.json()['attributes']} ) console.echo(f'Adding API Products {products} to consumerKey {consumer_key}') return self.add_api_product_to_key(developer, consumer_key, request_body) return resp
def create_an_entry_in_an_environment_scoped_kvm(self, environment, entry_name, entry_value): uri = CREATE_AN_ENTRY_IN_AN_ENVIRONMENT_SCOPED_KVM_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment, name=self._map_name, ) hdrs = auth.set_header(self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/json' }) body = {'name': entry_name, 'value': entry_value} resp = requests.post(uri, headers=hdrs, json=body) resp.raise_for_status() return resp
def add_a_user_to_a_role(self, user_email): uri = ADD_A_USER_TO_A_ROLE_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, role_name=self._role_name, user_email=user_email, ) hdrs = auth.set_header( self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', }, ) resp = requests.post(uri, headers=hdrs) resp.raise_for_status() return resp
def clear_all_cache_entries(self, environment): uri = CLEAR_ALL_CACHE_ENTRIES_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, environment=environment, name=self._cache_name, ) hdrs = auth.set_header( self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/octet-stream' }, ) resp = requests.post(uri, headers=hdrs) resp.raise_for_status() return resp
def delete_resource_from_permissions(self, resource_path): uri = DELETE_RESOURCE_FROM_PERMISSIONS_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, role_name=self._role_name, resource_path=resource_path, ) hdrs = auth.set_header( self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/octet-stream' }, ) resp = requests.delete(uri, headers=hdrs) resp.raise_for_status() return resp
def get_resource_permissions_for_a_specific_role(self, resource_path=""): uri = GET_RESOURCE_PERMISSIONS_FOR_A_SPECIFIC_ROLE_PATH.format( api_url=APIGEE_ADMIN_API_URL, org=self._org_name, role_name=self._role_name) if resource_path: uri += f'?path={resource_path}' hdrs = auth.set_header( self._auth, headers={ 'Accept': 'application/json', 'Content-Type': 'application/octet-stream' }, ) resp = requests.get(uri, headers=hdrs) resp.raise_for_status() return resp