def delete_web_monitor(provider_name, env, identifier): try: provider_cls = get_provider_to(provider_name) provider = provider_cls(env) provider.delete_web_monitor(identifier) except Exception as e: print_exc() return response_invalid_request(str(e)) return response_ok()
def get_all_credential(provider_name): try: provider_cls = get_provider_to(provider_name) provider = provider_cls(None) return make_response( json.dumps(list(map(lambda x: x, provider.credential.all())), default=json_util.default)) except Exception as e: print_exc() # TODO Improve log return response_invalid_request(str(e))
def create_web_monitor(provider_name, env): data = json.loads(request.data or 'null') try: provider_cls = get_provider_to(provider_name) provider = provider_cls(env) web = provider.create_web_monitor(**data) except Exception as e: print_exc() return response_invalid_request(str(e)) return response_created(success=True, identifier=web.identifier)
def destroy_credential(provider_name, env): try: provider_cls = get_provider_to(provider_name) provider = provider_cls(env) deleted = provider.credential.delete() except Exception as e: print_exc() # TODO Improve log return response_invalid_request(str(e)) if deleted['n'] > 0: return response_ok() return response_not_found("{}-{}".format(provider_name, env))
def get_credential(provider_name, env): try: provider_cls = get_provider_to(provider_name) provider = provider_cls(env) credential = provider.credential.get_by(environment=env) except Exception as e: print_exc() # TODO Improve log return response_invalid_request(str(e)) if credential.count() == 0: return response_not_found('{}/{}'.format(provider_name, env)) return make_response(json.dumps(credential[0], default=json_util.default))
def get_web_monitor(provider_name, env, identifier_or_name): try: provider_cls = get_provider_to(provider_name) provider = provider_cls(env) except Exception as e: print_exc() return response_invalid_request(str(e)) host = provider.get_web_monitor(identifier_or_name) if not host: return response_not_found(identifier_or_name) return response_ok(**host.get_json)
def create_credential(provider_name, env): data = json.loads(request.data or 'null') if not data: logging.error("No data") return response_invalid_request("No data".format(data)) try: provider_cls = get_provider_to(provider_name) provider = provider_cls(env) success, message = provider.credential_add(data) except Exception as e: print_exc() # TODO Improve log return response_invalid_request(str(e)) if not success: return response_invalid_request(message) return response_created(success=success, id=str(message))