Пример #1
0
    def get(self, namespace, owner):
        """
        Returns a list of accounts for a given owner.
        """
        g.metric_tags.update({'endpoint': 'owner.list_accounts_with_owner'})
        swag.namespace = namespace
        account_data = swag.get_all("[?owner=='{}']".format(owner))

        if len(account_data) == 0:
            return jsonify([])
        else:
            return jsonify(account_data)
Пример #2
0
    def get(self, namespace, env):
        """
        Returns a list of accounts for a given environment.
        """
        g.metric_tags.update({'endpoint': 'environment.list_accounts_in_environment'})
        swag.namespace = namespace
        account_data = swag.get_all("[?environment=='{}']".format(env))

        if len(account_data) == 0:
            return jsonify([])
        else:
            return jsonify(account_data)
Пример #3
0
    def get(self, namespace, account_status):
        """
        Returns a list of accounts with the given account_status
        """
        g.metric_tags.update({'endpoint': 'accounts.get_accounts_with_status'})
        swag.namespace = namespace
        account_data = swag.get_all(
            "[?account_status=='{}']".format(account_status))

        if len(account_data) == 0:
            return jsonify([])
        elif len(account_data) == 1:
            return jsonify([account_data])
        else:
            return jsonify(account_data)
Пример #4
0
    def post(self, namespace, account, service_name):
        """
        Update service in an account
        Use this method to update the service in an account
        * Send a JSON object with the service schema.
        [Service Schema](https://github.com/Netflix-Skunkworks/swag-client/blob/master/swag_client/schemas/v2.py#L36)
        * Specify the account ID/name and service name in the request URL path.
        """
        g.metric_tags.update(
            {'endpoint': 'service.update_service_for_account'})
        json_data = request.get_json(force=True)

        swag.namespace = namespace
        account_data = get_account(account)

        if not account_data:
            return not_found_response('account')

        for service in account_data['services']:
            if service['name'] == service_name:
                account_data["services"].remove(service)
                account_data['services'].append(json_data)
                try:
                    swag.update(account_data)
                except ValidationError as e:
                    return e.messages, 400

                response = jsonify(json_data)
                response.status_code = 204
                return response

        return not_found_response('service')
Пример #5
0
 def get(self, namespace):
     """
     Returns all accounts in the namespace.
     Example: For a namespace `accounts`, a list of accounts will be returned based on [Account Schema](https://github.com/Netflix-Skunkworks/swag-client/blob/master/swag_client/schemas/v2.py#L43)
     """
     g.metric_tags.update({'endpoint': 'namespace.list_all'})
     swag.namespace = namespace
     return jsonify(swag.get_all())
Пример #6
0
    def get(self, namespace, service):
        """
        Returns a list of accounts with the given service.
        """
        g.metric_tags.update({'endpoint': 'service.all_accounts_with_service'})
        swag.namespace = namespace
        accounts = swag.get_service_enabled(service)

        return jsonify(accounts)
Пример #7
0
    def get(self, namespace, account):
        """
        Returns an account given a name or account ID.
        """
        g.metric_tags.update({'endpoint': 'accounts.get_single_account'})
        swag.namespace = namespace
        account_data = get_account(account)

        if not account_data:
            return not_found_response('account')
        else:
            return jsonify(account_data)
Пример #8
0
    def get(self, namespace, account, service_name):
        """
        Returns the service json for a given account and service name
        """
        g.metric_tags.update({'endpoint': 'service.get_service_for_account'})
        swag.namespace = namespace
        account_data = get_account(account)

        if not account_data:
            return not_found_response('account')

        for service in account_data['services']:
            if service['name'] == service_name:
                return jsonify(service)

        return not_found_response('service')