def refreshAuthTokenInfo(self): arInDTO = AuthRefreshInDTO() arInDTO.appId = (Constant().readConfFile())[2] arInDTO.secret = (Constant().readConfFile())[3] authOutDTO = AuthOutDTO() result = Authentication().getAuthToken(Constant().clientInfo()) authOutDTO.setRefreshToken(json.loads(result)['refreshToken']) arInDTO.refreshToken = authOutDTO.getRefreshToken() return arInDTO
def auth(self): auTest = AuthenticationTest.AuthenticationTest() authentication = Authentication() ag = authentication.getAuthToken(Constant().clientInfo()) # print("====== get access token ======") # print("result:", ag + "\n") return ag
def invokeAPI(httpMethod, authUrl, payload, accessToken): nc = NorthApiClient() clientInfo = Constant().clientInfo() url = RestConstant.BASE_URL + clientInfo['platformIp'] + ":" + clientInfo[ 'platformPort'] + authUrl if accessToken == None: headers = {'Content-Type': 'application/json'} else: headers = { "app_key": clientInfo['appId'], "Authorization": "Bearer " + accessToken, "Content-Type": "application/json" } try: request = requests.Session() request.mount('https://', HTTPAdapter(pool_connections=10, pool_maxsize=10)) global response if httpMethod == "POST": response = requests.post(url, headers=headers, data=payload, cert=nc.cert, verify=False) elif httpMethod == "PUT": response = request.put(url, headers=headers, data=payload, cert=nc.cert, verify=False) elif httpMethod == "DELETE": response = request.delete(url, headers=headers, data=payload, cert=nc.cert, verify=False) elif httpMethod == "GET": response = request.get(url, headers=headers, data=payload, cert=nc.cert, verify=False) logging.info(url), logging.info(headers), logging.info(payload), logging.info(response.text) return response.text except ReadTimeout as e: logging.error(e) raise ReadTimeout(e) except ConnectionError as e: logging.error(e) raise ConnectionError(e) except RequestException as e: logging.error(e) raise RequestException(e) except Exception as e: logging.error(e) raise Exception(e)
def refreshDeviceKeyInfo(self): rdkInDTO = RefreshDeviceKeyInDTO() rdkInDTO.deviceId = deviceId rdkInDTO.nodeId = "SSSDAWSQAS" rdkInDTO.verifyCode = "SSSDAWSQAS11" return rdkInDTO if __name__ == "__main__": dmTest = DeviceManagementTest() authentication = Authentication() deviceManagement = DeviceManagement() # get accessToken at first result = Authentication().getAuthToken(Constant().clientInfo()) authOutDTO = AuthOutDTO() authOutDTO.setAccessToken(json.loads(result)['accessToken']) accessToken = authOutDTO.getAccessToken() # register a new device dr = deviceManagement.regDirectDevice(dmTest.regDirectDeviceInfo(), None, accessToken) print("====== register a new device ======") print("result:", dr + "\n") # get deviceId rddod = RegDirectDeviceOutDTO() rddod.setDeviceId(json.loads(dr)['deviceId']) deviceId = rddod.getDeviceId() print("deviceId==", deviceId + "\n")