コード例 #1
0
ファイル: domain.py プロジェクト: sofyan48/domba-api
def add_ns_default(zone_key, record_key):
    record_data = {
        "key": record_key,
        "value": "@",
        "zone": zone_key,
        "type": "5",
        "ttl": "6",
        "created_at": utils.get_datetime(),
        "serial": False
    }

    try:
        model.insert_data("record", record_key, record_data)
    except Exception as e:
        return response(401, message=str(e))

    default_ns = os.environ.get("DEFAULT_NS", os.getenv("DEFAULT_NS"))
    default_ns = default_ns.split(" ")
    for i in default_ns:
        content_key = utils.get_last_key("content")
        content_data = {
            "key": content_key,
            "value": i,
            "record": record_key,
            "created_at": utils.get_datetime()
        }
        try:
            model.insert_data("content", content_key, content_data)
        except Exception as e:
            return response(401, message=str(e))
コード例 #2
0
ファイル: domain.py プロジェクト: sofyan48/domba-api
def add_cname_default(zone_key, record_key, zone_name):
    record_data = {
        "key": record_key,
        "value": "www",
        "zone": zone_key,
        "type": "2",
        "ttl": "6",
        "created_at": utils.get_datetime(),
        "serial": False
    }

    try:
        model.insert_data("record", record_key, record_data)
    except Exception as e:
        return response(401, message=str(e))

    content_key = utils.get_last_key("content")
    content_data = {
        "key": content_key,
        "value": zone_name + ".",
        "record": record_key,
        "created_at": utils.get_datetime()
    }
    try:
        model.insert_data("content", content_key, content_data)
    except Exception as e:
        return response(401, message=str(e))
コード例 #3
0
ファイル: domain.py プロジェクト: sofyan48/domba-api
def add_soa_record(zone_key, record_key):
    record_data = {
        "key": record_key,
        "value": "@",
        "zone": zone_key,
        "type": "4",
        "ttl": "6",
        "created_at": utils.get_datetime(),
        "serial": False
    }

    try:
        model.insert_data("record", record_key, record_data)
    except Exception as e:
        return response(401, message=str(e))

    date_data = utils.soa_time_set() + "01"
    default_soa_content = os.environ.get("DEFAULT_SOA_CONTENT",
                                         os.getenv("DEFAULT_SOA_CONTENT"))
    default_soa_serial = os.environ.get("DEFAULT_SOA_SERIAL",
                                        os.getenv("DEFAULT_SOA_SERIAL"))
    content_value = default_soa_content + " " + date_data + " " + default_soa_serial
    content_key = utils.get_last_key("content")
    content_data = {
        "key": content_key,
        "value": content_value,
        "record": record_key,
        "created_at": utils.get_datetime()
    }
    try:
        model.insert_data("content", content_key, content_data)
    except Exception as e:
        return response(401, message=str(e))
コード例 #4
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('content', type=str, required=True)
        parser.add_argument('id_record', type=str, required=True)
        args = parser.parse_args()
        content = args["content"]
        content = content.lower()
        record = args["id_record"]

        key = utils.get_last_key("content")

        # Check Relation
        if model.check_relation("record", record):
            return response(401,
                            message="Relation to Record error Check Your Key")
        # Validation
        if validation.content_validation(record, content):
            return response(401, message="Named Error")
        if validation.count_character(content):
            return response(401, message="Count Character Error")

        data = {
            "key": key,
            "value": content,
            "record": record,
            "created_at": utils.get_datetime()
        }
        try:
            model.insert_data("content", key, data)
        except Exception as e:
            return response(401, message=str(e))
        else:
            return response(200, data=data, message="Inserted")
コード例 #5
0
ファイル: user.py プロジェクト: sofyan48/domba-api
    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")
コード例 #6
0
ファイル: serial.py プロジェクト: sofyan48/domba-api
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('value', type=str, required=True)
        parser.add_argument('name', type=str, required=True)
        parser.add_argument('id_record', type=str, required=True)
        args = parser.parse_args()
        serial = args["value"]
        name = args["name"]
        record_key = args["id_record"]
        key = utils.get_last_key("serial")

        # Check Relation
        if model.check_relation("record", record_key):
            return response(401,
                            message="Relation to Record error Check Your Key")

        # Validation
        if not utils.check_record_serial(record_key):
            return response(401, message="No Serial Record")

        data = {
            "key": key,
            "value": serial,
            "name": name,
            "record": record_key,
            "created_at": utils.get_datetime()
        }
        try:
            model.insert_data("serial", key, data)
        except Exception as e:
            return response(401, message=str(e))
        else:
            return response(200, data=data, message="Inserted")
コード例 #7
0
ファイル: zone.py プロジェクト: sofyan48/domba-api
    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")
コード例 #8
0
ファイル: domain.py プロジェクト: sofyan48/domba-api
    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")
コード例 #9
0
ファイル: ttl.py プロジェクト: sofyan48/domba-api
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('ttl', type=str, required=True)
     args = parser.parse_args()
     ttl = args["ttl"]
     key = utils.get_last_key("ttl")
     data = {"key": key, "value": ttl}
     try:
         model.insert_data("ttl", key, data)
     except Exception as e:
         return response(401, message=str(e))
     else:
         return response(200, data=data, message="Inserted")