TypeDB.User (TypeDB v0.2.0)

Copy Markdown View Source

User administration.

Most of these endpoints require administrator rights; a non-admin user can generally read and update only its own record.

{:ok, usernames} = TypeDB.User.list(conn)
:ok = TypeDB.User.create(conn, "alice", "s3cret")
:ok = TypeDB.User.set_password(conn, "alice", "even-more-s3cret")
:ok = TypeDB.User.delete(conn, "alice")

Summary

Functions

Creates a user with the given password.

Creates a user, raising on failure.

Deletes a user.

Deletes a user, raising on failure.

Returns whether a user exists.

Returns a username, or an error when the user does not exist.

Returns a username, raising when the user does not exist.

Lists all usernames.

Lists all usernames, raising on failure.

Replaces a user's password.

Replaces a user's password, raising on failure.

Functions

create(conn, username, password)

@spec create(TypeDB.Connection.t(), String.t(), String.t()) ::
  :ok | {:error, TypeDB.Error.t()}

Creates a user with the given password.

create!(conn, username, password)

@spec create!(TypeDB.Connection.t(), String.t(), String.t()) :: :ok

Creates a user, raising on failure.

delete(conn, username)

@spec delete(TypeDB.Connection.t(), String.t()) :: :ok | {:error, TypeDB.Error.t()}

Deletes a user.

delete!(conn, username)

@spec delete!(TypeDB.Connection.t(), String.t()) :: :ok

Deletes a user, raising on failure.

exists?(conn, username)

@spec exists?(TypeDB.Connection.t(), String.t()) :: boolean()

Returns whether a user exists.

Raises TypeDB.Error for anything other than a clean "not found" — an unreachable server, a rejected token, a 500. A boolean cannot express "I could not ask", and answering false to that question is the answer that makes a caller do the wrong thing: unless exists?(conn, x), do: create(conn, x) would try to create while the server is down. Use get/2 if you would rather branch on the error yourself.

get(conn, username)

@spec get(TypeDB.Connection.t(), String.t()) ::
  {:ok, String.t()} | {:error, TypeDB.Error.t()}

Returns a username, or an error when the user does not exist.

get!(conn, username)

@spec get!(TypeDB.Connection.t(), String.t()) :: String.t()

Returns a username, raising when the user does not exist.

list(conn)

@spec list(TypeDB.Connection.t()) :: {:ok, [String.t()]} | {:error, TypeDB.Error.t()}

Lists all usernames.

list!(conn)

@spec list!(TypeDB.Connection.t()) :: [String.t()]

Lists all usernames, raising on failure.

set_password(conn, username, password)

@spec set_password(TypeDB.Connection.t(), String.t(), String.t()) ::
  :ok | {:error, TypeDB.Error.t()}

Replaces a user's password.

Existing tokens issued to that user are not revoked by this call; they expire on their own schedule.

set_password!(conn, username, password)

@spec set_password!(TypeDB.Connection.t(), String.t(), String.t()) :: :ok

Replaces a user's password, raising on failure.