Example #1
0
 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
Example #2
0
 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
Example #3
0
 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
Example #4
0
 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
Example #5
0
 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
Example #6
0
 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
Example #7
0
 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)
Example #8
0
 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
Example #9
0
 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
Example #10
0
 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
Example #11
0
 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)
Example #12
0
 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
Example #13
0
 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
Example #14
0
 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
Example #15
0
 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)
Example #16
0
 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
Example #17
0
 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
Example #18
0
 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
Example #19
0
 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
Example #20
0
 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
Example #21
0
 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
Example #22
0
 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
Example #23
0
 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
Example #24
0
 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)
Example #25
0
    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
Example #26
0
 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
Example #27
0
 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
Example #28
0
 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
Example #29
0
 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
Example #30
0
 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