Пример #1
0
def delete():
    """
  Delete a user session.
  Removes the domain (config.DOMAIN) section from the native netrc file.
  """
    # Get the native netrc file.
    netrc = Netrc()

    # If our domain exists in the netrc file, remove it and save.
    if config.DOMAIN in netrc.keys():
        del netrc[config.DOMAIN]
        netrc.save()
Пример #2
0
def create(password=None):
    """
  Creates a new user session.

  Upserts a section to the netrc file, with the following specs:
    domain --> config.DOMAIN
      password --> 'password' param

  :param str password: Session token
  """
    # Get the native netrc file.
    netrc = Netrc()

    # Upsert domain/password group
    netrc[config.DOMAIN]['password'] = password

    # Save dat bish.
    netrc.save()
Пример #3
0
def set_auth():
    """Set HTTP auth (used by `requests`)
    """
    # In due course, we should use Github OAuth for this
    netrc_path = os.path.join(os.path.expanduser("~"), ".netrc")
    if not os.path.exists(netrc_path):
        with open(netrc_path, "w") as f:
            f.write("")
    netrc = Netrc()
    if netrc[JOB_SERVER]["password"]:
        login = netrc[JOB_SERVER]["login"]
        password = netrc[JOB_SERVER]["password"]
    else:
        login = input("Job server username: "******"login": login, "password": password}
        netrc.save()
    return (login, password)