def add_policy(): """ Add policy. Returns: """ logging.debug(json.dumps(request.json)) name = request.json["name"] tags = request.json["tags"] projects = request.json["projects"] schedule_name = request.json["schedulename"] client = ndb.Client() with client.context(): res = SchedulesModel.query(SchedulesModel.Name == schedule_name).get() if not res: return "not found", 404 policy_model = PolicyModel() policy_model.Name = name policy_model.Tags = tags policy_model.Projects = projects policy_model.Schedule = schedule_name policy_model.key = ndb.Key("PolicyModel", name) policy_model.put() return "ok", 200
def add_policy(): """ Add policy. Returns: """ logging.debug(json.dumps(request.json)) name = request.json["name"] display_name = request.json.get("displayname", name) tags = request.json["tags"] projects = request.json["projects"] schedule_name = request.json["schedulename"] with client.context(): res = SchedulesModel.query(SchedulesModel.Name == schedule_name).get() if not res: return "Schedule '{}' not found.".format(schedule_name), 404 policy_model = PolicyModel() policy_model.Name = name policy_model.DisplayName = display_name policy_model.Tags = tags policy_model.Projects = projects policy_model.Schedule = schedule_name policy_model.key = ndb.Key("PolicyModel", name) policy_model.put() return "ok", 200
def add_policy(): """ Add policy. Returns: """ logging.debug(json.dumps(request.json)) name = request.json['name'] tags = request.json['tags'] projects = request.json['projects'] schedule_name = request.json['schedulename'] res = SchedulesModel.query(SchedulesModel.Name == schedule_name).get() if not res: return 'not found', 404 policy_model = PolicyModel() policy_model.Name = name policy_model.Tags = tags policy_model.Projects = projects policy_model.Schedule = schedule_name policy_model.key = ndb.Key('PolicyModel', name) policy_model.put() return 'ok', 200