How to use _getRequestId method in autotest

Best Python code snippet using autotest_python

ACLClient.py

Source:ACLClient.py Github

copy

Full Screen

...49 self.handle('alluserinformation:aclproto', False, self._onAllUserInformation)50 self.currentRequestId = 151 self.requests = {}52 self.serverId = serverId53 def _getRequestId(self, request):54 requestId = self.currentRequestId55 self.currentRequestId += 156 self.requests[requestId] = request57 return requestId58 def _onLogin(self, proto, spec, message, body):59 self.loginResponse = body60 self.loginEvent.set()61 def login(self, userName, password):62 try:63 (loginSpec, loginRequest) = self.create("login:aclproto", True)64 loginRequest.userName = userName65 loginRequest.password = password66 import threading67 self.loginEvent = threading.Event()68 self.send(self.serverId, self.proto, loginSpec, loginRequest, self._getRequestId(loginRequest))69 self.loginEvent.wait()70 if 0 != self.loginResponse.status:71 raise Exception(self.loginResponse.message)72 else:73 return self.loginResponse.session74 except Exception as e :75 print e76 # 返回 0-0 这一假session77 return self.loginResponse.session78 def _onLogout(self, proto, spec, message, body):79 self.logoutResponse = body80 self.logoutEvent.set()81 def logout(self,session):82 try:83 (logoutSpec, logoutRequest) = self.create("logout:aclproto", True)84 logoutRequest.session = session85 import threading86 self.logoutEvent = threading.Event()87 self.send(self.serverId, self.proto, logoutSpec, logoutRequest, self._getRequestId(logoutRequest))88 self.logoutEvent.wait()89 if 0 != self.logoutResponse.status:90 raise Exception(self.logoutResponse.message)91 else:92 return self.logoutResponse.message93 except Exception as e:94 print e95 def _onAddResourceType(self, proto, spec, message, body):96 requestId = message.getRequestId()97 if requestId in self.requests:98 p = self.requests[requestId]99 if 0 != body.status:100 p.reject(Exception(body.message))101 else:102 p.fulfill(body.resourceTypeId)103 def addResourceType(self, session, name, description, permissions):104 try:105 p = Promise()106 (rSpec, rRequest) = self.create("addresourcetype:aclproto", True)107 rRequest.session = session108 rRequest.name = name109 rRequest.description = description110 rRequest.permissions = permissions111 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))112 return p113 except Exception as e :114 print e115 def _onDeleteResourceType(self, proto, spec, message, body):116 requestId = message.getRequestId()117 if requestId in self.requests:118 p = self.requests[requestId]119 if 0 != body.status:120 p.reject(Exception(body.message))121 else:122 p.fulfill(body.message)123 def deleteResourceType(self, session, resourceTypeId, force=False):124 try:125 p = Promise()126 (rSpec, rRequest) = self.create("deleteresourcetype:aclproto", True)127 rRequest.session = session128 rRequest.resourceTypeId = resourceTypeId129 rRequest.force = force130 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))131 return p132 except Exception as e:133 print e134 def _onListResourceType(self, proto, spec, message, body):135 requestId = message.getRequestId()136 if requestId in self.requests:137 p = self.requests[requestId]138 if 0 != body.status:139 p.reject(Exception(body.message))140 else:141 p.fulfill(body.resourceTypes)142 def listResourceType(self, session):143 try:144 p = Promise()145 (rSpec, rRequest) = self.create("listresourcetype:aclproto", True)146 rRequest.session = session147 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))148 return p149 except Exception as e:150 print e151 def _onAddResource(self, proto, spec, message, body):152 # self.addResourceResponse = body153 requestId = message.getRequestId()154 if requestId in self.requests:155 p = self.requests[requestId]156 if 0 != body.status:157 p.reject(Exception(body.message))158 else:159 p.fulfill(body.resourceId)160 def addResource(self, session, name, resourceTypeId, contentId, isGroup):161 try:162 p = Promise()163 (rSpec, rRequest) = self.create("addresource:aclproto", True)164 rRequest.session = session165 rRequest.resourceTypeId = resourceTypeId166 rRequest.name = name167 rRequest.contentId = contentId168 rRequest.isGroup = isGroup169 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))170 return p171 except Exception as e :172 print e173 def _onGetResources(self, proto, spec, message, body):174 requestId = message.getRequestId()175 if requestId in self.requests:176 p = self.requests[requestId]177 if 0 != body.status:178 p.reject(Exception(body.message))179 else:180 p.fulfill(body.resources)181 def getResources(self, session, roleId, resourceId, permissionIds):182 try:183 p = Promise()184 (rSpec, rRequest) = self.create("getresources:aclproto", True)185 rRequest.session = session186 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))187 return p188 except Exception as e:189 print e190 def _onAddResourceToGroup(self, proto, spec, message, body):191 requestId = message.getRequestId()192 if requestId in self.requests:193 p = self.requests[requestId]194 if 0 != body.status:195 p.reject(Exception(body.message))196 else:197 p.fulfill(body.message)198 def addResourceToGroup(self, session, groupId, resourceIds):199 try:200 p = Promise()201 (rSpec, rRequest) = self.create("addresourcetogroup:aclproto", True)202 rRequest.session = session203 rRequest.groupId = groupId204 rRequest.resourceIds = resourceIds205 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))206 return p207 except Exception as e:208 print e209 def _onRemoveResourceFromGroup(self, proto, spec, message, body):210 requestId = message.getRequestId()211 if requestId in self.requests:212 p = self.requests[requestId]213 if 0 != body.status:214 p.reject(Exception(body.message))215 else:216 p.fulfill(body.message)217 def removeResourceFromGroup(self, session, groupId, resourceIds):218 try:219 p = Promise()220 (rSpec, rRequest) = self.create("removeresourcefromgroup:aclproto", True)221 rRequest.session = session222 rRequest.groupId = groupId223 rRequest.resourceIds = resourceIds224 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))225 return p226 except Exception as e:227 print e228 def _onHasPermission(self, proto, spec, message, body):229 requestId = message.getRequestId()230 if requestId in self.requests:231 p = self.requests[requestId]232 if 0 != body.status:233 p.reject(Exception(body.message))234 else:235 p.fulfill(body.hasPerm)236 def hasPermission(self, session, resourceId, permission):237 try:238 p = Promise()239 (rSpec, rRequest) = self.create("haspermission:aclproto", True)240 rRequest.session = session241 rRequest.resourceId = resourceId242 rRequest.permission = permission243 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))244 return p245 except Exception as e:246 print e247 def _onAddRole(self, proto, spec, message, body):248 requestId = message.getRequestId()249 if requestId in self.requests:250 p = self.requests[requestId]251 if 0 != body.status:252 p.reject(Exception(body.message))253 else:254 p.fulfill(body.roleId)255 def addRole(self, session, roleName):256 try:257 p = Promise()258 (rSpec, rRequest) = self.create("addrole:aclproto", True)259 rRequest.session = session260 rRequest.roleName = roleName261 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))262 return p263 except Exception as e :264 print e265 def _onAddUser(self, proto, spec, message, body):266 requestId = message.getRequestId()267 if requestId in self.requests:268 p = self.requests[requestId]269 if 0 != body.status:270 p.reject(Exception(body.message))271 else:272 p.fulfill(body.userId)273 def addUser(self, session, userName, email, password, initalRole):274 try:275 p = Promise()276 (rSpec, rRequest) = self.create("adduser:aclproto", True)277 rRequest.session = session278 rRequest.userName = userName279 rRequest.email = email280 rRequest.password = password281 rRequest.roleId = initalRole282 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))283 return p284 except Exception as e:285 print e286 def _onSetRoleToUser(self, proto, spec, message, body):287 requestId = message.getRequestId()288 if requestId in self.requests:289 p = self.requests[requestId]290 if 0 != body.status:291 p.reject(Exception(body.message))292 else:293 p.fulfill(body.message)294 def setRoleToUser(self, session, userId, roleId):295 try:296 p = Promise()297 (rSpec, rRequest) = self.create("setroletouser:aclproto", True)298 rRequest.session = session299 rRequest.userId = userId300 rRequest.roleId = roleId301 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))302 return p303 except Exception as e:304 print e305 def _onClearRoleFromUser(self, proto, spec, message, body):306 requestId = message.getRequestId()307 if requestId in self.requests:308 p = self.requests[requestId]309 if 0 != body.status:310 p.reject(Exception(body.message))311 else:312 p.fulfill(body.message)313 def clearRoleFromUser(self, session, userId, roleId):314 try:315 p = Promise()316 (rSpec, rRequest) = self.create("clearroleofuser:aclproto", True)317 rRequest.session = session318 rRequest.userId = userId319 rRequest.roleId = roleId320 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))321 return p322 except Exception as e:323 print e324 def _onGrantToRole(self, proto, spec, message, body):325 requestId = message.getRequestId()326 if requestId in self.requests:327 p = self.requests[requestId]328 if 0 != body.status:329 p.reject(Exception(body.message))330 else:331 p.fulfill(body.message)332 def grantToRole(self, session, roleId, parentRoleIds):333 try:334 p = Promise()335 (rSpec, rRequest) = self.create("granttorole:aclproto", True)336 rRequest.session = session337 rRequest.roleId = roleId338 rRequest.parentsRoleId = parentRoleIds339 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))340 return p341 except Exception as e:342 print e343 def _onRevokeFromRole(self, proto, spec, message, body):344 requestId = message.getRequestId()345 if requestId in self.requests:346 p = self.requests[requestId]347 if 0 != body.status:348 p.reject(Exception(body.message))349 else:350 p.fulfill(body.message)351 def revokeFromRole(self, session, roleId, parentRoleIds):352 try:353 p = Promise()354 (rSpec, rRequest) = self.create("revokefromrole:aclproto", True)355 rRequest.session = session356 rRequest.roleId = roleId357 rRequest.parentsRoleId = parentRoleIds358 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))359 return p360 except Exception as e:361 print e362 def _onGrantResourceToRole(self, proto, spec, message, body):363 requestId = message.getRequestId()364 if requestId in self.requests:365 p = self.requests[requestId]366 if 0 != body.status:367 p.reject(Exception(body.message))368 else:369 p.fulfill(body.message)370 def grantResourceToRole(self, session, roleId, resourceId, permissionIds):371 try:372 p = Promise()373 (rSpec, rRequest) = self.create("grantresourcetorole:aclproto", True)374 rRequest.session = session375 rRequest.roleId = roleId376 rRequest.resourceId = resourceId377 rRequest.permissionIds = permissionIds378 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))379 return p380 except Exception as e:381 print e382 def _onRevokeResourceFromRole(self, proto, spec, message, body):383 requestId = message.getRequestId()384 if requestId in self.requests:385 p = self.requests[requestId]386 if 0 != body.status:387 p.reject(Exception(body.message))388 else:389 p.fulfill(body.message)390 def revokeResourceFromRole(self, session, roleId, resourceId):391 try:392 p = Promise()393 (rSpec, rRequest) = self.create("revokeresourcefromrole:aclproto", True)394 rRequest.session = session395 rRequest.roleId = roleId396 rRequest.resourceId = resourceId397 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))398 return p399 except Exception as e:400 print e401 def _onChangeRoleOfUser(self, proto, spec, message, body):402 requestId = message.getRequestId()403 if requestId in self.requests:404 p = self.requests[requestId]405 if 0 != body.status:406 p.reject(Exception(body.message))407 else:408 p.fulfill(body.status)409 def changeRoleOfUser(self, session, userId, roleId):410 try:411 p = Promise()412 (rSpec, rRequest) = self.create("changeroleofuser:aclproto", True)413 rRequest.session = session414 rRequest.userId = userId415 rRequest.roleId = roleId416 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))417 return p418 except Exception as e :419 print e420 def _onChangePassword(self, proto, spec, message, body):421 requestId = message.getRequestId()422 if requestId in self.requests:423 p = self.requests[requestId]424 if 0 != body.status:425 p.reject(Exception(body.message))426 else:427 p.fulfill(body.status)428 def changePassword(self, session,password):429 try:430 p = Promise()431 (rSpec, rRequest) = self.create("changepassword:aclproto", True)432 rRequest.session = session433 rRequest.password = password434 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))435 return p436 except Exception as e :437 print e438 def _onGetResources(self, proto, spec, message, body):439 requestId = message.getRequestId()440 if requestId in self.requests:441 p = self.requests[requestId]442 if 0 != body.status:443 p.reject(Exception(body.message))444 else:445 p.fulfill(body.resources)446 def getResources(self, session):447 try:448 p = Promise()449 (rSpec, rRequest) = self.create("getresources:aclproto", True)450 rRequest.session = session451 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))452 return p453 except Exception as e:454 print e455 def _onListOtherResource(self, proto, spec, message, body):456 requestId = message.getRequestId()457 if requestId in self.requests:458 p = self.requests[requestId]459 if 0 != body.status:460 p.reject(Exception(body.message))461 else:462 p.fulfill( body.resources)463 def listOtherResource(self, session,roleId):464 try:465 p = Promise()466 (rSpec, rRequest) = self.create("listotherresource:aclproto", True)467 rRequest.session = session468 rRequest.roleId = roleId469 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))470 return p471 except Exception as e:472 print e473 def _onGrantPermission(self, proto, spec, message, body):474 requestId = message.getRequestId()475 if requestId in self.requests:476 p = self.requests[requestId]477 if 0 != body.status:478 p.reject(Exception(body.message))479 else:480 p.fulfill(body.status)481 def grantPermission(self, session, roleId, resourceId, permissionId):482 try:483 p = Promise()484 (rSpec, rRequest) = self.create("grantpermission:aclproto", True)485 rRequest.session = session486 rRequest.roleId = roleId487 rRequest.resourceId = resourceId488 rRequest.permissionId = permissionId489 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))490 return p491 except Exception as e :492 print e493 def _onListUser(self, proto, spec, message, body):494 requestId = message.getRequestId()495 if requestId in self.requests:496 p = self.requests[requestId]497 if 0 != body.status:498 p.reject(Exception(body.message))499 else:500 p.fulfill(body.users)501 def listUser(self, session, userId=0):502 try:503 p = Promise()504 (rSpec, rRequest) = self.create("listuser:aclproto", True)505 rRequest.session = session506 rRequest.userId = userId507 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))508 return p509 except Exception as e :510 print e511 def _onChangeUserName(self, proto, spec, message, body):512 requestId = message.getRequestId()513 if requestId in self.requests:514 p = self.requests[requestId]515 if 0 != body.status:516 p.reject(Exception(body.message))517 else:518 p.fulfill( body.status)519 def changeUserName(self, session,userName):520 try:521 p = Promise()522 (rSpec, rRequest) = self.create("changeusername:aclproto", True)523 rRequest.session = session524 rRequest.userName = userName525 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))526 return p527 except Exception as e :528 print e529 def _onChangeRoleName(self, proto, spec, message, body):530 requestId = message.getRequestId()531 if requestId in self.requests:532 p = self.requests[requestId]533 if 0 != body.status:534 p.reject(Exception(body.message))535 else:536 p.fulfill( body.status )537 def changeRoleName(self, session,roleId,roleName):538 try:539 p = Promise()540 (rSpec, rRequest) = self.create("changerolename:aclproto", True)541 rRequest.session = session542 rRequest.roleId = roleId543 rRequest.roleName = roleName544 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))545 return p546 except Exception as e :547 print e548 def _onChangePublicKey(self, proto, spec, message, body):549 requestId = message.getRequestId()550 if requestId in self.requests:551 p = self.requests[requestId]552 if 0 != body.status:553 p.reject(Exception(body.message))554 else:555 p.fulfill(body.status)556 def changePublicKey(self, session,publicKey):557 try:558 p = Promise()559 (rSpec, rRequest) = self.create("changepublickey:aclproto", True)560 rRequest.session = session561 rRequest.publicKey = publicKey562 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))563 return p564 except Exception as e :565 print e566 def _onChangePrivateKey(self, proto, spec, message, body):567 requestId = message.getRequestId()568 if requestId in self.requests:569 p = self.requests[requestId]570 if 0 != body.status:571 p.reject(Exception(body.message))572 else:573 p.fulfill(body.status)574 def changePrivateKey(self, session,privateKey):575 try:576 p = Promise()577 (rSpec, rRequest) = self.create("changeprivatekey:aclproto", True)578 rRequest.session = session579 rRequest.privateKey = privateKey580 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))581 return p582 except Exception as e:583 print e584 def _onGetPublicKey(self, proto, spec, message, body):585 requestId = message.getRequestId()586 if requestId in self.requests:587 p = self.requests[requestId]588 if 0 != body.status:589 p.reject(Exception(body.message))590 else:591 p.fulfill(body.publicKey)592 def getPublicKey(self, session, userId):593 try:594 p = Promise()595 (rSpec, rRequest) = self.create("getpublickey:aclproto", True)596 rRequest.userId = userId597 rRequest.session = session598 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))599 return p600 except Exception as e:601 print e602 def _onDeleteResource(self, proto, spec, message, body):603 requestId = message.getRequestId()604 if requestId in self.requests:605 p = self.requests[requestId]606 if 0 != body.status:607 p.reject(Exception(body.message))608 else:609 p.fulfill(body.status)610 def deleteResource(self, session, resourceId):611 try:612 p = Promise()613 (rSpec, rRequest) = self.create("deleteresource:aclproto", True)614 rRequest.session = session615 rRequest.resourceId = resourceId616 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))617 return p618 except Exception as e :619 print e620 def _onDeleteUser(self, proto, spec, message, body):621 requestId = message.getRequestId()622 if requestId in self.requests:623 p = self.requests[requestId]624 if 0 != body.status:625 p.reject(Exception(body.message))626 else:627 p.fulfill(body.status)628 def deleteUser(self, session, userId):629 try:630 p = Promise()631 (rSpec, rRequest) = self.create("deleteuser:aclproto", True)632 rRequest.session = session633 rRequest.userId = userId634 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))635 return p636 except Exception as e :637 print e638 def _onDeleteRole(self, proto, spec, message, body):639 requestId = message.getRequestId()640 if requestId in self.requests:641 p = self.requests[requestId]642 if 0 != body.status:643 p.reject(Exception(body.message))644 else:645 p.fulfill(body.status)646 def deleteRole(self, session,roleId):647 try:648 p = Promise()649 (rSpec, rRequest) = self.create("deleterole:aclproto", True)650 rRequest.session = session651 rRequest.roleId = roleId652 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))653 return p654 except Exception as e :655 print e656 def _onListRoles(self, proto, spec, message, body):657 requestId = message.getRequestId()658 if requestId in self.requests:659 p = self.requests[requestId]660 if 0 != body.status:661 p.reject(Exception(body.message))662 else:663 p.fulfill(body.roles)664 def listRoles(self, session):665 try:666 p = Promise()667 (rSpec, rRequest) = self.create("listroles:aclproto", True)668 rRequest.session = session669 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))670 return p671 except Exception as e:672 print e673 def _onListLogin(self, proto, spec, message, body):674 requestId = message.getRequestId()675 if requestId in self.requests:676 p = self.requests[requestId]677 if 0 != body.status:678 p.reject(Exception(body.message))679 else:680 p.fulfill(body.logins)681 def listLogin(self, session):682 try:683 p = Promise()684 (rSpec, rRequest) = self.create("listlogin:aclproto", True)685 rRequest.session = session686 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))687 return p688 except Exception as e :689 print e690 def _onMyRole(self, proto, spec, message, body):691 requestId = message.getRequestId()692 if requestId in self.requests:693 p = self.requests[requestId]694 if 0 != body.status:695 p.reject(Exception(body.message))696 else:697 p.fulfill([body.roleId,body.roleName])698 def myRole(self, session):699 try:700 p = Promise()701 (rSpec, rRequest) = self.create("myrole:aclproto", True)702 rRequest.session = session703 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))704 return p705 except Exception as e :706 print e707 def _onMyInformation(self, proto, spec, message, body):708 requestId = message.getRequestId()709 if requestId in self.requests:710 p = self.requests[requestId]711 if 0 != body.status:712 p.reject(Exception(body.message))713 else:714 p.fulfill(body.information)715 def myInformation(self, session, reqName):716 try:717 p = Promise()718 (rSpec, rRequest) = self.create("myinformation:aclproto", True)719 rRequest.session = session720 rRequest.reqName = reqName721 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))722 return p723 except Exception as e:724 print e725 def _onChangeMyInformation(self, proto, spec, message, body):726 requestId = message.getRequestId()727 if requestId in self.requests:728 p = self.requests[requestId]729 if 0 != body.status:730 p.reject(Exception(body.message))731 else:732 p.fulfill(body.message)733 def changeMyInformation(self, session, reqDic):734 try:735 p = Promise()736 (rSpec, rRequest) = self.create("changemyinformation:aclproto", True)737 rRequest.session = session738 rRequest.reqDic = reqDic739 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))740 return p741 except Exception as e :742 print e743 def _onChangeMyPassword(self, proto, spec, message, body):744 requestId = message.getRequestId()745 if requestId in self.requests:746 p = self.requests[requestId]747 if 0 != body.status:748 p.reject(Exception(body.message))749 else:750 p.fulfill(body.status)751 def changeMyPassword(self, session,oldPassword, newPassword):752 try:753 p = Promise()754 (rSpec, rRequest) = self.create("changemypassword:aclproto", True)755 rRequest.session = session756 rRequest.oldPassword = oldPassword757 rRequest.newPassword = newPassword758 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))759 return p760 except Exception as e :761 print e762 def _onOtherInformation(self, proto, spec, message, body):763 requestId = message.getRequestId()764 if requestId in self.requests:765 p = self.requests[requestId]766 if 0 != body.status:767 p.reject(Exception(body.message))768 else:769 p.fulfill(body.information)770 def otherInformation(self, session, reqName, otherUserId):771 try:772 p = Promise()773 (rSpec, rRequest) = self.create("otherinformation:aclproto", True)774 rRequest.session = session775 rRequest.reqName = reqName776 rRequest.otherUserId = otherUserId777 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))778 return p779 except Exception as e:780 print e781 def _onAllUserInformation(self, proto, spec, message, body):782 requestId = message.getRequestId()783 if requestId in self.requests:784 p = self.requests[requestId]785 if 0 != body.status:786 p.reject(Exception(body.message))787 else:788 p.fulfill(body.information)789 def allUserInformation(self, session, reqName):790 try:791 p = Promise()792 (rSpec, rRequest) = self.create("alluserinformation:aclproto", True)793 rRequest.session = session794 rRequest.reqName = reqName795 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))796 return p797 except Exception as e:...

Full Screen

Full Screen

SecurityClient.py

Source:SecurityClient.py Github

copy

Full Screen

...16 self.handle('revokegrant:securityproto', False, self._onRevokeGrant)17 self.handle('listcontent:securityproto', False, self._onListContent)18 self.handle('deletecontent:securityproto', False, self._onDeleteContent)19 self.handle('checksharer:securityproto', False, self._onCheckSharer)20 def _getRequestId(self, request, func = None):21 requestId = self.currentRequestId22 self.currentRequestId += 123 if func is None:24 self.requests[requestId] = request25 else:26 self.requests[requestId] = (request , func)27 return requestId28 def _onDeleteContent(self, proto, spec, message, body):29 requestId = message.getRequestId()30 if requestId in self.requests:31 p = self.requests[requestId]32 if 0 != body.status:33 p.reject(Exception(body.message))34 else:35 p.fulfill('delete content success!')36 def deleteContent(self, session, contentId):37 try:38 p = Promise()39 (rSpec, rRequest) = self.create("deletecontent:securityproto", True)40 rRequest.session = session41 rRequest.contentId = contentId42 self.deleteContentResponse = None43 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))44 return p45 except Exception as e:46 print e47 def _onListContent(self, proto, spec, message, body):48 requestId = message.getRequestId()49 if requestId in self.requests:50 p = self.requests[requestId]51 if 0 != body.status:52 p.reject(Exception(body.message))53 else:54 p.fulfill(body.contents)55 def listContent(self, session):56 try:57 p = Promise()58 (rSpec, rRequest) = self.create("listcontent:securityproto", True)59 rRequest.session = session60 self.listContentResponse = None61 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))62 return p63 except Exception as e :64 print e65 def _onPutSeriesContent(self, proto, spec, message, body):66 requestId = message.getRequestId()67 if requestId in self.requests:68 p = self.requests[requestId]69 if 0 != body.status:70 p.reject(Exception(body.message))71 else:72 p.fulfill(body.ckIds)73 def putSeriesContent(self, session, seriesContent, publicKey):74 try:75 p = Promise()76 for i in seriesContent:77 enContent = myEncryption.aesEnctypt( i[2],i[1])78 enkey = myEncryption.rsaEncrypt(i[2], publicKey)79 i[1]=enContent80 i[2]=enkey81 (rSpec, rRequest) = self.create("putseriescontent:securityproto", True)82 rRequest.session = session83 s=[]84 for i in seriesContent:85 j = self.createGeneric("Content:SecurityProto")86 j.name = i[0]87 j.content = i[1]88 j.key = i[2]89 s.append(j)90 rRequest.seriesContent = s91 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))92 return p93 except Exception as e :94 print e95 def _onGetSeriesContent(self, proto, spec, message, body):96 requestId = message.getRequestId()97 if requestId in self.requests:98 p, decrypt = self.requests[requestId]99 if 0 != body.status:100 p.reject(Exception(body.message))101 else:102 contentDict={}103 for k,v in body.contentKeys.items():104 content = decrypt(v.key, v.content)105 contentDict[k]=content106 p.fulfill(contentDict)107 def getSeriesContent(self, session, contentIds, privateKey):108 try:109 p = Promise()110 (rSpec, rRequest) = self.create("getseriescontent:securityproto", True)111 rRequest.session = session112 cIds=[]113 for i in contentIds:114 cId = self.createGeneric("ConId:SecurityProto")115 cId.name=i[0]116 cId.contentId=i[1]117 cIds.append(cId)118 rRequest.contentIds = cIds119 def decrypt(enKey, enContent):120 key=myEncryption.rsaDecrypt(enKey, privateKey)121 content=myEncryption.aesDectypt(key, enContent)122 return content123 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p, decrypt))124 return p125 except Exception as e :126 print e127 def _onGetKeys(self, proto, spec, message, body):128 requestId = message.getRequestId()129 if requestId in self.requests:130 p, grants = self.requests[requestId]131 if 0 != body.status:132 # self.onGrantToOtherFailed(request.contentId, body.message)133 p.reject(Exception(body.message))134 else:135 grants( body.keys)136 p.fulfill('getkeysuccess')137 def _onPutKeys(self, proto, spec, message, body):138 requestId = message.getRequestId()139 if requestId in self.requests:140 p = self.requests[requestId]141 if 0 != body.status:142 p.reject(Exception(body.message))143 else:144 p.fulfill(body.keyIds)145 def putKeys(self,session, key, contentIds ,otherUserId , publicKey):146 try:147 p = Promise()148 enKey={}149 for k,v in key.items():150 enKey[k]=myEncryption.rsaEncrypt(v,publicKey)151 # newKey = myEncryption.rsaEncrypt(key,publicKey)152 # self.keyId = None153 kCIds=[]154 for k,v in contentIds.items():155 kCId = self.createGeneric("KeyContentId:SecurityProto")156 kCId.key=enKey[k]157 kCId.contentId=v158 kCId.userId=otherUserId159 kCIds.append(kCId)160 (rSpec, rRequest) = self.create("putkeys:securityproto", True)161 rRequest.session = session162 rRequest.KeyContentIds = kCIds163 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))164 return p165 except Exception as e :166 print e167 def grantSeriesToOther(self,session, contentIds, otherUserId , myPrivateKey, otherPublicKey):168 try:169 p = Promise()170 conIds ={}171 for k,v in contentIds.items():172 conIds[k]=v173 (rSpec, rRequest) = self.create("getkeys:securityproto", True)174 rRequest.session = session175 rRequest.contentIds = conIds176 def grants(keys):177 grantKey = {}178 for k,v in keys.items():179 grantKey[k] = myEncryption.rsaDecrypt(v, myPrivateKey)180 return self.putKeys( session, grantKey, contentIds, otherUserId, otherPublicKey)181 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p, grants))182 return p183 except Exception as e :184 print e185 def _onRevokeGrant(self, proto, spec, message, body):186 requestId = message.getRequestId()187 if requestId in self.requests:188 p = self.requests[requestId]189 if 0 != body.status:190 p.reject(Exception(body.message))191 else:192 p.fulfill(body.status)193 def revokeGrant(self,session, contentIds, otherUserId):194 try:195 p = Promise()196 (rSpec, rRequest) = self.create("revokegrant:securityproto", True)197 rRequest.session = session198 rRequest.contentIds = contentIds199 rRequest.otherUserId = otherUserId200 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))201 return p202 except Exception as e:203 print e204 def _onCheckSharer(self, proto, spec, message, body):205 requestId = message.getRequestId()206 if requestId in self.requests:207 p = self.requests[requestId]208 if 0 != body.status:209 p.reject(Exception(body.message))210 else:211 p.fulfill(body.sharer)212 def checkSharer(self, session, contentId):213 try:214 p = Promise()215 (rSpec, rRequest) = self.create("checksharer:securityproto", True)216 rRequest.session = session217 rRequest.contentId = contentId218 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))219 return p220 except Exception as e:...

Full Screen

Full Screen

templClient.py

Source:templClient.py Github

copy

Full Screen

...15 self.handle('createversion:templ_json', False, self._onCreateVersion)16 self.currentRequestId = 117 self.requests = {}18 self.serverId = serverId19 def _getRequestId(self, request):20 requestId = self.currentRequestId21 self.currentRequestId += 122 self.requests[requestId] = request23 return requestId24 def _onUpContent(self, proto, spec, message, body):25 requestId = message.getRequestId()26 if requestId in self.requests:27 p = self.requests[requestId]28 if 0 != body.status:29 p.reject(Exception(body.message))30 else:31 p.fulfill(body.message)32 def upContent(self, session, name, version, contents):#上传模板文件33 try:34 p = Promise()35 (rSpec, rRequest) = self.create("upcontent:templ_json", True)36 rRequest.session = session37 rRequest.name = name38 rRequest.version = version39 rRequest.contents = contents40 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))41 return p42 except Exception as e :43 print e44 def _onJsonRelation(self, proto, spec, message, body):45 requestId = message.getRequestId()46 if requestId in self.requests:47 p = self.requests[requestId]48 if 0 != body.status:49 p.reject(Exception(body.message))50 else:51 p.fulfill(body.message)52 def jsonRelation(self, session, JsonRelationName, version):#检查该模板版本的直接基类53 try:54 p = Promise()55 (rSpec, rRequest) = self.create("jsonrelation:templ_json", True)56 rRequest.session = session57 rRequest.JsonRelationName = JsonRelationName58 rRequest.version = version59 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))60 return p61 except Exception as e :62 print e63 def _onBaseCheck(self, proto, spec, message, body):64 requestId = message.getRequestId()65 if requestId in self.requests:66 p = self.requests[requestId]67 if 0 != body.status:68 p.reject(Exception(body.message))69 else:70 p.fulfill(body.message)71 def baseCheck(self, session, BaseName, version):#检查该模板所有的基类,包括基类的基类72 try:73 p = Promise()74 (rSpec, rRequest) = self.create("basecheck:templ_json", True)75 rRequest.session = session76 rRequest.BaseName = BaseName77 rRequest.version = version78 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))79 return p80 except Exception as e :81 print e82 def _onDownLoad(self, proto, spec, message, body):83 requestId = message.getRequestId()84 if requestId in self.requests:85 p = self.requests[requestId]86 if 0 != body.status:87 p.reject(Exception(body.message))88 else:89 p.fulfill(body.message)90 def downLoad(self, session, TemplName, version):#下载原始模板content内容91 try:92 p = Promise()93 (rSpec, rRequest) = self.create("download:templ_json", True)94 rRequest.session = session95 rRequest.TemplName = TemplName96 rRequest.version = version97 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))98 return p99 except Exception as e :100 print e101 def _onGetJsonCon(self, proto, spec, message, body):102 requestId = message.getRequestId()103 if requestId in self.requests:104 p = self.requests[requestId]105 if 0 != body.status:106 p.reject(Exception(body.message))107 else:108 p.fulfill(body.message)109 def getJsonCon(self, session, JsonAttrName, version):#获取对应模板,版本的Json内容110 try:111 p = Promise()112 (rSpec, rRequest) = self.create("getjsoncon:templ_json", True)113 rRequest.session = session114 rRequest.JsonAttrName = JsonAttrName115 rRequest.version = version116 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))117 return p118 except Exception as e :119 print e120 def _onGrantAuthority(self, proto, spec, message, body):121 requestId = message.getRequestId()122 if requestId in self.requests:123 p = self.requests[requestId]124 if 0 != body.status:125 p.reject(Exception(body.message))126 else:127 p.fulfill(body.message)128 def grantAuthority(self, session, userId):#授权操作129 try:130 p = Promise()131 (rSpec, rRequest) = self.create("grantauthority:templ_json", True)132 rRequest.session = session133 rRequest.name = userId134 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))135 return p136 except Exception as e :137 print e138 def _onTemplMerge(self, proto, spec, message, body):139 requestId = message.getRequestId()140 if requestId in self.requests:141 p = self.requests[requestId]142 if 0 != body.status:143 p.reject(Exception(body.message))144 else:145 p.fulfill(body.message)146 def templMerge(self, session):#模板合并147 try:148 p = Promise()149 (rSpec, rRequest) = self.create("templmerge:templ_json", True)150 rRequest.session = session151 # rRequest.name = userId152 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))153 return p154 except Exception as e :155 print e156 def _onCreateVersion(self, proto, spec, message, body):157 requestId = message.getRequestId()158 if requestId in self.requests:159 p = self.requests[requestId]160 if 0 != body.status:161 p.reject(Exception(body.message))162 else:163 p.fulfill(body.message)164 def createVersion(self, session, name, version, contents):#为已有模板创建新版本165 try:166 p = Promise()167 (rSpec, rRequest) = self.create("createversion:templ_json", True)168 rRequest.session = session169 rRequest.name = name170 rRequest.version = version171 rRequest.contents = contents172 self.send(self.serverId, self.proto, rSpec, rRequest, self._getRequestId(p))173 return p174 except Exception as e :...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful