Beispiel #1
0
def _GetSqliteStore(sqlite_credential_file=None, sqlite_access_token_file=None):
  """Get a sqlite-based Credential Store."""
  sqlite_credential_file = (sqlite_credential_file or
                            config.Paths().credentials_db_path)
  files.PrivatizeFile(sqlite_credential_file)
  credential_store = SqliteCredentialStore(sqlite_credential_file)

  sqlite_access_token_file = (sqlite_access_token_file or
                              config.Paths().access_token_db_path)
  files.PrivatizeFile(sqlite_access_token_file)
  access_token_cache = AccessTokenCache(sqlite_access_token_file)
  return CredentialStoreWithCache(credential_store, access_token_cache)
Beispiel #2
0
def ExportPrivateKey(private_key_output_file, private_key_bytes):
    """Export a private key to a filename, printing a warning to the user.

  Args:
    private_key_output_file: The path of the file to export to.
    private_key_bytes: The content in byte format to export.
  """

    try:
        # Make sure this file is only accesible to the running user before writing.
        files.PrivatizeFile(private_key_output_file)
        files.WriteFileContents(private_key_output_file, private_key_bytes)
        # Make file readable only by owner.
        os.chmod(private_key_output_file, 0o400)
        log.warning(KEY_OUTPUT_WARNING.format(private_key_output_file))
    except (files.Error, OSError, IOError):
        raise exceptions.FileOutputError(
            "Error writing to private key output file named '{}'".format(
                private_key_output_file))