Coverage for appr/auth.py : 27%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Store Auth object """
self.conf_directory = conf_directory home = os.path.expanduser("~") old_path = "%s/%s/auth_token" % (home, conf_directory) path = "%s/%s/auths.yaml" % (home, conf_directory) mkdir_p(os.path.join(home, conf_directory)) self.tokenfile = os.path.join(home, path) self._tokens = None self._retro_compat(old_path)
oldtoken = self._old_token(old) if oldtoken: if self.tokens is None or '*' not in self.tokens['auths']: self.add_token('*', oldtoken) os.remove(old)
if os.path.exists(path): with open(path, 'r') as tokenfile: return tokenfile.read() else: return None
def tokens(self): if self._tokens is None: if os.path.exists(self.tokenfile): with open(self.tokenfile, 'r') as tokenfile: self._tokens = yaml.load(tokenfile.read()) else: return None return self._tokens
if not self.tokens: return None if host is None or host not in self.tokens['auths']: host = '*' return self.tokens['auths'].get(host, None)
auths = self.tokens if auths is None: auths = {'auths': {}} auths['auths'][host] = value self._write_tokens(auths)
with open(self.tokenfile, 'w') as tokenfile: tokenfile.write( yaml.safe_dump(tokens, indent=2, default_style='"', default_flow_style=False))
auths = self.tokens if not auths or host not in auths['auths']: return None prev = auths['auths'].pop(host) self._write_tokens(auths) return prev |