示例#1
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('email', type=str, required=True)
        parser.add_argument('project_id', type=str, required=True)
        args = parser.parse_args()
        project_id = args["project_id"]
        email = args["email"]

        key = utils.get_last_key("user")

        if utils.check_unique("user", "email", email):
            return response(401, message="Duplicate email Detected")

        data = {
            "key": key,
            "email": email,
            "project_id": project_id,
            "state": "inserted",
            "created_at": utils.get_datetime()
        }
        try:
            model.insert_data("/user", key, data)
        except Exception as e:
            return response(401, message=str(e))
        else:
            return response(200, data=data, message="Inserted")
示例#2
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('zone', type=str, required=True)
        parser.add_argument('id_user', type=str, required=True)
        args = parser.parse_args()
        zone = args["zone"]
        zone = zone.lower()
        id_user = args["id_user"]

        key = utils.get_last_key("zone")

        if utils.check_unique("zone", "value", zone):
            return response(401, message="Duplicate zone Detected")

        if validation.zone_validation(zone):
            return response(401, message="Named Error")

        data = {
            "key": key,
            "value": zone,
            "created_at": utils.get_datetime(),
            "user": id_user,
        }
        try:
            model.insert_data("zone", key, data)
        except Exception as e:
            return response(401, message=str(e))
        else:
            return response(200, data=data, message="Inserted")
示例#3
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('zone', type=str, required=True)
        parser.add_argument('project_id', type=str, required=True)
        args = parser.parse_args()
        zone = args['zone']
        project_id = args['project_id']
        user = model.get_user_by_project_id(project_id)['key']
        zone_key = utils.get_last_key("zone")

        # Validation Unique Zone
        if utils.check_unique("zone", "value", zone):
            return response(401, message="Duplicate zone Detected")
        # Validation Zone Name
        if validation.zone_validation(zone):
            return response(401, message="Named Error")
        # Check Relation Zone to User
        if model.check_relation("user", user):
            return response(401,
                            message="Relation to user error Check Your Key")

        zone_data = {
            "key": zone_key,
            "value": zone,
            "created_at": utils.get_datetime(),
            "user": user,
        }
        try:
            model.insert_data("zone", zone_key, zone_data)
        except Exception as e:
            return response(401, message=str(e))
        else:

            # Adding Zone Config
            config_command = command.config_zone(zone, zone_key)
            producer.send(config_command)
            # ADDING DEFAULT RECORD
            record_key_soa = utils.get_last_key("record")
            add_soa_record(zone_key, record_key_soa)
            command.soa_default_command(record_key_soa)

            record_key_ns = utils.get_last_key("record")
            add_ns_default(zone_key, record_key_ns)
            command.ns_default_command(record_key_ns)

            record_key_cname = utils.get_last_key("record")
            add_cname_default(zone_key, record_key_cname, zone)
            json_command = command.record_insert(record_key_cname)
            producer.send(json_command)
            # DEFAULT RECORD END

            return response(200, data=zone_data, message="Inserted")
示例#4
0
    def put(self, key):
        parser = reqparse.RequestParser()
        parser.add_argument('email', type=str, required=True)
        parser.add_argument('project_id', type=str, required=True)
        args = parser.parse_args()
        project_id = args["project_id"]
        email = args["email"]
        if utils.check_unique("user", "email", email, key=key):
            return response(401, message="Duplicate email Detected")
        data_update = {
            "key": key,
            "email": email,
            "project_id": project_id,
            "state": "edited",
            "created_at": utils.get_datetime()
        }

        try:
            model.update("user", key, data_update)
        except Exception as e:
            return response(401, message=str(e))
        else:
            return response(200, data=data_update, message="Update Success")