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)
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)
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)
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')
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())
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)
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)
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')