def resettoken(): cached = cache.get_item("microgear-"+microgear.gearkey+".cache") if cached : microgear.accesstoken = cached.get("accesstoken",{}) if "revokecode" in microgear.accesstoken : path = "/api/revoke/"+microgear.accesstoken["token"]+"/"+microgear.accesstoken["revokecode"] h = httplib2.Http(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])),".cache")) resp, content = h.request(microgear.gearauthsite+path, method="GET") if(resp.status==200): cache.delete_item("microgear-"+microgear.gearkey+".cache") else: on_error("Reset token error.") logging.error("Reset token error.") else: cache.delete_item("microgear-"+microgear.gearkey+".cache") logging.warning("Token is still, please check your key on Key Management.") microgear.accesstoken = None
def get_token(): logging.debug("Check stored token.") cached = cache.get_item("microgear-"+microgear.gearkey+".cache") if cached: if cached.get("accesstoken"): if not cached.get("key"): cached["key"] = microgear.gearkey cache.set_item("microgear-"+microgear.gearkey+".cache", cached) microgear.accesstoken = cached.get("accesstoken") for name,value in microgear.accesstoken.items(): microgear.accesstoken[name] = str(value) endpoint = microgear.accesstoken.get("endpoint").split("//")[1].split(":") microgear.gearexaddress = endpoint[0] microgear.gearexport = endpoint[1] elif cached.get("requesttoken"): get_accesstoken(cached) else: get_requesttoken(cached) else: cached = cache.set_item("microgear-"+microgear.gearkey+".cache", {"key": microgear.gearkey})
def resettoken(): cached = cache.get_item("microgear-" + microgear.gearkey + ".cache") if cached: microgear.accesstoken = cached.get("accesstoken", {}) if "revokecode" in microgear.accesstoken: path = "/api/revoke/" + microgear.accesstoken[ "token"] + "/" + microgear.accesstoken["revokecode"] h = httplib2.Http( os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), ".cache")) resp, content = h.request(microgear.gearauthsite + path, method="GET") if (resp.status == 200): cache.delete_item("microgear-" + microgear.gearkey + ".cache") else: on_error("Reset token error.") logging.error("Reset token error.") else: cache.delete_item("microgear-" + microgear.gearkey + ".cache") logging.warning( "Token is still, please check your key on Key Management.") microgear.accesstoken = None
def get_token(): logging.debug("Check stored token.") cached = cache.get_item("microgear-" + microgear.gearkey + ".cache") if cached: if cached.get("accesstoken"): if not cached.get("key"): cached["key"] = microgear.gearkey cache.set_item("microgear-" + microgear.gearkey + ".cache", cached) microgear.accesstoken = cached.get("accesstoken") for name, value in microgear.accesstoken.items(): microgear.accesstoken[name] = str(value) endpoint = microgear.accesstoken.get("endpoint").split( "//")[1].split(":") microgear.gearexaddress = endpoint[0] microgear.gearexport = endpoint[1] elif cached.get("requesttoken"): get_accesstoken(cached) else: get_requesttoken(cached) else: cached = cache.set_item("microgear-" + microgear.gearkey + ".cache", {"key": microgear.gearkey})
def resettoken(): cached = cache.get_item("microgear-" + microgear.gearkey + ".cache") if cached: microgear.accesstoken = cached.get("accesstoken", {}) if "revokecode" in microgear.accesstoken: path = "/api/revoke/" + microgear.accesstoken[ "token"] + "/" + microgear.accesstoken["revokecode"] url = "" if microgear.securemode: url = "https://" + microgear.gearauthsite + ":" + microgear.gearapisecureport + path else: url = "http://" + microgear.gearauthsite + ":" + microgear.gearapiport + path response = requests.get(url) if response.status_code == 200: cache.delete_item("microgear-" + microgear.gearkey + ".cache") else: on_error("Reset token error.") logging.error("Reset token error.") else: cache.delete_item("microgear-" + microgear.gearkey + ".cache") logging.warning( "Token is still, please check your key on Key Management.") microgear.accesstoken = None