def tag_one(self, gcp_object, project_id): try: org_labels = {} org_labels = gcp_object['labels'] except KeyError: pass labels = dict([('labelFingerprint', gcp_object.get('labelFingerprint', ''))]) labels['labels'] = self.gen_labels(gcp_object) for k, v in org_labels.items(): labels['labels'][k] = v try: zone = gcp_object['zone'] ind = zone.rfind('/') zone = zone[ind + 1:] self.batch.add(self.compute.instances().setLabels( project=project_id, zone=zone, instance=gcp_object['name'], body=labels), request_id=utils.get_uuid()) self.counter = self.counter + 1 if self.counter == 1000: self.do_batch() except errors.HttpError as e: logging.error(e) return 'ok', 200
def tag_one(self, gcp_object, project_id): labels = dict() gcp_object['project_id'] = project_id labels['labels'] = self.gen_labels(gcp_object) gcp_object.pop('project_id', None) if 'labels' in gcp_object: for key, val in labels['labels'].items(): gcp_object['labels'][key] = val else: gcp_object['labels'] = {} for key, val in labels['labels'].items(): gcp_object['labels'][key] = val try: self.batch.add( self.bigtable.projects().instances().partialUpdateInstance( name=gcp_object['name'], body=gcp_object, updateMask='labels'), request_id=utils.get_uuid()) self.counter = self.counter + 1 if self.counter == 1000: self.do_batch() except Exception as e: logging.error(e) return 'ok', 200
def __init__(self, con_name, onu_info, me_names, label_color): QTreeWidgetItem.__init__(self) self.__con_name = con_name self.__onu_info = onu_info self.__me_names = me_names self.__label_color = label_color self.__uuid = get_uuid() self.__setup_ui()
def new_acc(self): _uuid = utils.get_uuid() if db_persistence.is_exist(vk_id=self.peer_id): self.text = vk_dict.ALREADY_EXIST.format(id=_uuid) return self.text = vk_dict.NEW_ACC_MESSAGE.format(id=_uuid) db_persistence.insert_new_connection(_uuid=_uuid, vk_id=self.peer_id, user_name=self.from_user)
def gencloned(self): # DEVICETYPE SERVICE TYPE SERVICE ID os.system('clear') print('Which domain you want for the device cloned?\n') domain_rev = input("\nDomain '[NAME].local': ") # LOGIN ROUTE os.system('clear') print('Where the webpage is located?\n' 'folder/./file.ext or file.ext') web = input("\nWebpage location: ") FN = utils.get_friendlyname(None) MF = utils.get_manufacturer(None) MD = utils.get_model(None) UUID = utils.get_uuid(None) urn1 = utils.get_device(None) urn2 = utils.get_service(None) urn3 = utils.get_serviceid(None) xml = ('<?xml version="1.0"?>\r\n' '<root xmlns="urn:schemas-upnp-org:device-1-0">\r\n' '\t<specVersion>\r\n' '\t\t<major>1</major>\r\n' '\t\t<minor>0</minor>\r\n' '\t</specVersion>\r\n' '\t<URLBase>http://' + domain_rev + ':8008</URLBase>\r\n' '\t<device>\r\n' '\t\t<presentationURL>http://' + domain_rev + ':8008/' + web + '</presentationURL>\r\n' '\t\t<deviceType>' + urn1 + '</deviceType>\r\n' '\t\t<friendlyName>' + FN + '</friendlyName>\r\n' '\t\t<modelDescription>Connect to access</modelDescription>\r\n' '\t\t<manufacturer>' + MF + '</manufacturer>\r\n' '\t\t<modelName>' + MD + '</modelName>\r\n' '\t\t<UDN>' + UUID + '</UDN>\r\n' '\t\t<serviceList>\r\n' '\t\t\t<service>\r\n' '\t\t\t\t<serviceType>' + urn2 + '</serviceType>\r\n' '\t\t\t\t<serviceId>' + urn3 + '</serviceId>\r\n' '\t\t\t\t<controlURL>/ssdp/notfound</controlURL>\r\n' '\t\t\t\t<eventSubURL>/ssdp/notfound</eventSubURL>\r\n' '\t\t\t\t<SCPDURL>/ssdp/notfound</SCPDURL>\r\n' '\t\t\t</service>\r\n' '\t\t</serviceList>\r\n' '\t</device>\r\n' '</root>') tfile = open('ssdp.xml', 'w+') tfile.write(xml) tfile.close() os.system('clear') print('You want to start the server now or exit?') choose = input("\n1) Start the server or 2) Exit: ") os.system('clear') if choose == "1": server() elif choose == "2": BYE()
def tag_one(self, gcp_object, project_id): labels = dict() labels['labels'] = self.gen_labels(gcp_object) try: self.batch.add(self.storage.buckets().patch( bucket=gcp_object['name'], body=labels), request_id=utils.get_uuid()) self.counter = self.counter + 1 if self.counter == 1000: self.do_batch() except Exception as e: logging.error(e) return 'ok', 200
def tag_one_table(self, gcp_object): labels = dict() labels['labels'] = self.gen_labels(gcp_object) try: self.batch.add(self.bigquery.tables().patch( projectId=gcp_object['tableReference']['projectId'], body=labels, datasetId=gcp_object['tableReference']['datasetId'], tableId=gcp_object['tableReference']['tableId']), request_id=utils.get_uuid()) self.counter = self.counter + 1 if self.counter == 1000: self.do_batch() except Exception as e: logging.error(e) if self.counter > 0: self.do_batch()
def answerer(self, addr, st): date_format = formatdate(timeval=None, localtime=False, usegmt=True) UUID = utils.get_uuid(None) ssdp_reply = ('HTTP/1.1 200 OK\r\n' 'CACHE-CONTROL: max-age=1800\r\n' 'DATE: '+date_format+'\r\n' 'EXT:\r\n' 'LOCATION: http://'+local_ip+':8008/ssdp.xml\r\n' 'OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01\r\n' '01-NLS: '+UUID+'\r\n' 'SERVER: UPnP/1.0\r\n' 'ST: '+st+'\r\n' 'USN: '+UUID+'::'+st+'\r\n' 'BOOTID.UPNP.ORG: 0\r\n' 'CONFIGID.UPNP.ORG: 1\r\n' '\r\n\r\n' ) ssdp_reply = bytes(ssdp_reply, 'utf-8') sock.sendto(ssdp_reply, addr)
def tag_one(self, gcp_object, project_id): try: org_labels = {} org_labels = gcp_object['labels'] except KeyError: pass labels = dict([('labelFingerprint', gcp_object.get('labelFingerprint', ''))]) labels['labels'] = self.gen_labels(gcp_object) for k, v in org_labels.items(): labels['labels'][k] = v try: self.batch.add(self.compute.snapshots().setLabels( project=project_id, resource=gcp_object['name'], body=labels), request_id=utils.get_uuid()) self.counter = self.counter + 1 if self.counter == 1000: self.do_batch() except Exception as e: logging.error(e) return 'ok', 200
def post(self): """ 用户登录返回Token信息 :return: """ user_info = request.json username = user_info.get('username') password = user_info.get('password') if not username or not password: return self.fail("用户名和密码不可以为空") sql = """ select id as user_id, password, is_active from base_user_info where username = :username """ cur = db.session.execute(sql, {"username": username}) query_user = cur.fetchone() if not query_user: return self.fail("用户不存在") if not query_user['is_active']: return self.fail("该用户已经被锁定,请联系系统管理员") # todo 密码进行加密处理 if query_user['password'] != password: return self.fail("密码错误,请检查后重试") # todo 连续错误次数锁定账号 # todo 连续错误,要求前端输入验证码 # 生成token,返回前端 token = get_uuid() token_key = current_app.config['TOKEN_KEY'] % token current_app.redis.setex(token_key, 30 * 24 * 60 * 60, query_user['user_id']) return self.success({'token': token})
def discuss_unique_uuid(): uuid = get_uuid(DISCUSS_UUID_LENGTH) while Discuss.objects.filter(id=uuid).exists(): uuid = get_uuid(DISCUSS_UUID_LENGTH) return uuid
def post_unique_uuid(): uuid = get_uuid(POSTS_UUID_LENGTH) while Post.objects.filter(id=uuid).exists(): uuid = get_uuid(POSTS_UUID_LENGTH) return uuid