def create_log(logname, params): """Add a new log to the current account. If a JSON object is given, use that as the request parameters. Otherwise, use the name provided """ if params is not None: request_params = params else: request_params = { 'log': { 'name': logname } } headers = api_utils.generate_headers('rw') try: response = requests.post(_url(), json=request_params, headers=headers) if response_utils.response_error(response): sys.stderr.write('Create log failed, status code: %d' % response.status_code) sys.exit(1) elif response.status_code == 201: api_utils.pretty_print_string_as_json(response.text) except requests.exceptions.RequestException as error: sys.stderr.write(error) sys.exit(1)
def handle_api_key_response(response): """ Handle get api key response """ if response_utils.response_error(response): sys.exit(1) elif response.status_code in [200, 201]: api_utils.pretty_print_string_as_json(response.text)
def handle_get_log_response(response): """ Handle get log response """ if response_utils.response_error(response): sys.exit(1) elif response.status_code == 200: api_utils.pretty_print_string_as_json(response.text)
def handle_api_key_response(response): """ Handle get api key response """ if response_utils.response_error(response): sys.exit(1) elif response.status_code in [200, 201]: api_utils.pretty_print_string_as_json(response.text)
def handle_response(response, error_message, success_code, success_message=None): """Handle logset responses""" if response_utils.response_error(response): sys.stderr.write(error_message) sys.exit(1) elif response.status_code == success_code: if success_message: sys.stdout.write(success_message) else: api_utils.pretty_print_string_as_json(response.text)
def handle_response(response, error_message, success_code, success_message=None): """Handle logset responses""" if response_utils.response_error(response): sys.stderr.write(error_message) sys.exit(1) elif response.status_code == success_code: if success_message: sys.stdout.write(success_message) else: api_utils.pretty_print_string_as_json(response.text)
def replace_log(log_id, params): """ Replace the given log with the details provided """ headers = api_utils.generate_headers('rw') try: response = requests.put(_url(('logs', log_id))[1], json=params, headers=headers) if response_utils.response_error(response): sys.stderr.write('Update log failed.\n') sys.exit(1) elif response.status_code == 200: sys.stdout.write('Log: %s updated to:\n' % log_id) api_utils.pretty_print_string_as_json(response.text) except requests.exceptions.RequestException as error: sys.stderr.write(error) sys.exit(1)