Example #1
0
 def get_all():
     try:
         same_service = service_collection.find()
         if not same_service:
             raise Exception("There is not any service")
         Tools.result(True, same_service)
     except Exception as ex:
         return Tools.result(False, ex.args)
Example #2
0
 def admin_get_all_admins():
     try:
         same_admin = allowed_ip_collection.find({})
         if not same_admin:
             raise Exception("There is not any admin")
         return Tools.result(True, same_admin)
     except Exception as ex:
         return Tools.result(False, ex.args)
Example #3
0
 def get(service_name):
     try:
         same_service = service_collection.find_one({ServiceModelVN.ServiceName: service_name})
         if not service_name:
             raise Exception("This service not exists")
         return Tools.result(True, same_service)
     except Exception as ex:
         return Tools.result(False, ex.args)
Example #4
0
 def is_allowed(admin_ip):
     try:
         if not Tools.is_valid_ip(admin_ip):
             raise Exception("Invalid Ip")
         same_admin = allowed_ip_collection.find_one({AllowedIpModelVn.IP: admin_ip})
         if not same_admin:
             raise Exception("False")
         return Tools.result(True, "True")
     except Exception as ex:
         return Tools.result(False, ex.args)
Example #5
0
 def get(admin_id):
     try:
         if not ObjectId.is_valid(admin_id):
             raise Exception("Invalid admin id!")
         same_admin = allowed_ip_collection.find_one({AllowedIpModelVn.id: ObjectId(admin_id)})
         if not same_admin:
             raise Exception("This admin not exist!")
         return Tools.result(True, same_admin)
     except Exception as ex:
         return Tools.result(False, ex)
Example #6
0
 def delete(service_id):
     try:
         # todo: check if Ip has access or not
         same_service = service_collection.find_one({ServiceModelVN.id: ObjectId(service_id)})
         if not same_service:
             raise Exception("This service not exists")
         service_collection.delete_one({ServiceModelVN.id: same_service[ServiceModelVN.id]})
         return "Done"
     except Exception as ex:
         Tools.result(False, ex.args)
Example #7
0
 def add(service_name, url, database, port):
     try:
         # todo: check if Ip has access or not
         same_service = service_collection.find_one({ServiceModelVN.ServiceName: service_name}, {ServiceModelVN.id})
         if same_service:
             raise Exception("This service is exists")
         new_service = ServiceModel(ServiceName=service_name, Url=url, DataBaseString=database, Port=port).dict()
         new_service = service_collection.insert_one(new_service)
         return Tools.result(True, {"ServiceId": str(new_service.inserted_id)})
     except Exception as ex:
         return Tools.result(False, ex.args)
Example #8
0
 def add(admin_name, ip):
     try:
         if not Tools.is_valid_ip(ip):
             raise Exception("Invalid Ip")
         same_admin = allowed_ip_collection.find_one({AllowedIpModelVn.AdminName: admin_name}, {AllowedIpModelVn.id})
         if same_admin:
             raise Exception("This admin name already exist!")
         new_admin = AllowedIpModel(AdminName=admin_name, Ip=ip).dict()
         new_admin = allowed_ip_collection.insert_one(new_admin)
         return Tools.result(True, {"NewAdminId": str(new_admin.inserted_id)})
     except Exception as ex:
         return Tools.result(False, ex.args)
Example #9
0
    def update(admin_id, new_data):
        try:
            if not ObjectId.is_valid(admin_id):
                raise Exception("Invalid admin id!")
            same_admin = allowed_ip_collection.find_one({AllowedIpModelVn.id: ObjectId(admin_id)})
            if not same_admin:
                raise Exception("This admin not exist!")
            allowed_ip_collection.update_one({AllowedIpModelVn.id: same_admin[AllowedIpModelVn.id]},
                                             {"$set": {AllowedIpModelVn.AdminName: new_data[AllowedIpModelVn.AdminName],
                                                       AllowedIpModelVn.IP: new_data[AllowedIpModelVn.IP]}})
            return Tools.result(True, "done")

        except Exception as ex:
            return Tools.result(False, ex.args)
Example #10
0
 def update(service_id, new_data):
     try:
         # todo: check if Ip has access or not
         print(new_data)
         new_data = json.loads(new_data)
         same_service = service_collection.find_one({ServiceModelVN.id: ObjectId(service_id)})
         if not same_service:
             raise Exception("This service not exists")
         service_collection.update_one({ServiceModelVN.id: same_service[ServiceModelVN.id]},
                                       {"$set": {ServiceModelVN.ServiceName: new_data[ServiceModelVN.ServiceName],
                                                 ServiceModelVN.Url: new_data[ServiceModelVN.Url],
                                                 ServiceModelVN.DataBaseString: new_data[
                                                     ServiceModelVN.DataBaseString],
                                                 ServiceModelVN.Port: new_data[ServiceModelVN.Port]}})
         return Tools.result(True, "Done")
     except Exception as ex:
         return Tools.result(False, ex.args)