Beispiel #1
0
    def revoke_key(cls, org_id: int, api_key: str):
        """Revoke api key."""
        current_app.logger.debug('<revoke_key ')
        consumer_endpoint: str = current_app.config.get('API_GW_CONSUMERS_API_URL')
        gw_api_key: str = current_app.config.get('API_GW_KEY')
        email_id = cls._get_email_id(org_id)

        RestService.patch(
            f'{consumer_endpoint}/mc/v1/consumers/{email_id}/apiKeys/{api_key}?action=removeAccess',
            additional_headers={'x-apikey': gw_api_key},
            data=dict(apiAccess='ALL_API'),
            generate_token=False
        )
Beispiel #2
0
    def revoke_key(cls, org_id: int, api_key: str):
        """Revoke api key."""
        current_app.logger.debug('<revoke_key ')
        check_auth(one_of_roles=(ADMIN, STAFF), org_id=org_id)
        # Find the environment for this key, based on it consumer changes.
        email_id: str = None
        for key in cls.get_api_keys(org_id)['consumer']['consumerKey']:
            if key['apiKey'] == api_key:
                email_id = key['email']
                break
        if not email_id:
            raise BusinessException(Error.DATA_NOT_FOUND, Exception())
        env = 'sandbox'
        if email_id == cls._get_email_id(org_id, 'prod'):
            env = 'prod'
        consumer_endpoint = cls._get_api_consumer_endpoint(env)
        gw_api_key = cls._get_api_gw_key(env)

        RestService.patch(
            f'{consumer_endpoint}/mc/v1/consumers/{email_id}/apikeys/{api_key}?action=revoke',
            additional_headers={'x-apikey': gw_api_key},
            data=dict(apiAccess='ALL_API'),
            generate_token=False
        )