Facebook
From Tiny Crane, 2 Years ago, written in Python.
This paste is a reply to Re: Re: Re: Re: Re: Re: Re: Untitled from Rude Porcupine - view diff
Embed
Download Paste or View Raw
Hits: 177
  1. import json
  2. import os
  3. import click
  4. import sys
  5. from aihub.domain.auth import AuthSettings
  6.  
  7. class AuthFileManager(object):
  8.     """
  9.    Manages .ai-auth file in the current directory
  10.    """
  11.  
  12.     AUTH_FILE_PATH = os.path.join(os.getcwd() + "/.ai-auth")
  13.  
  14.     @classmethod
  15.     def set_auth(self, auth_settings):
  16.         with open(self.AUTH_FILE_PATH, "w") as file:
  17.             file.write(json.dumps(auth_settings.to_dict()))
  18.  
  19.     @classmethod
  20.     def get_auth(self):
  21.         if not os.path.isfile(self.AUTH_FILE_PATH):
  22.             raise Exception("Missing .ai-auth file")
  23.  
  24.         with open(self.AUTH_FILE_PATH, "r") as file:
  25.             auth_settings = json.loads(file.read())
  26.  
  27.         return AuthSettings.from_dict(auth_settings)
  28.  
  29.     @classmethod
  30.     def exists_auth(self):
  31.         is_init_already = os.path.isfile(self.AUTH_FILE_PATH)
  32.         if is_init_already is False:
  33.             click.echo(click.style('[INFO] Please login first.', fg='yellow'))
  34.             sys.exit()

Replies to Re: Re: Re: Re: Re: Re: Re: Re: Untitled rss

Title Name Language When
Re: Re: Re: Re: Re: Re: Re: Re: Re: Untitled Round Prairie Dog python 2 Years ago.