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, 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')
def post(self, namespace, account, service_name): """ Toggle a service in a given account Use this method to toggle the service in an account * Send a JSON object with the following json. ``` { "enabled": true, <- required "region": "all" <- optional } ``` * Specify the account ID/name and service name in the request URL path. """ g.metric_tags.update( {'endpoint': 'service.toggle_service_for_account'}) service_region_arguments.parse_args(request) json_data = request.get_json(force=True) enabled = json_data['enabled'] region = json_data.get('region', 'all') if not isinstance(enabled, bool): return {'enabled': 'Value of enabled must be True or False'}, 400 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: for status in service['status']: if status['region'] == 'all': status['enabled'] = enabled elif status['region'] == region: status['enabled'] = enabled swag.update(account_data) return None, 204 return not_found_response('service')
def delete(self, namespace, account, service_name): """ Delete the service from the given account """ g.metric_tags.update( {'endpoint': 'service.delete_service_from_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: account_data['services'].remove(service) swag.update(account_data) return None, 204 return not_found_response('service')