View Source Lightning.Credentials (Lightning v2.10.4)

The Credentials context.

Summary

Functions

Returns an %Ecto.Changeset{} for tracking credential changes.

Creates a credential.

Deletes a credential.

Gets a single credential.

Creates a credential schema from credential json schema.

Checks if a given Credential has any associated Step activity.

Given a credential and a user, returns a list of invalid projects—i.e., those that the credential is shared with but that the user does not have access to.

Retrieves all credentials based on the given context, either a Project or a User.

Perform, when called with %{"type" => "purge_deleted"} will find credentials that are ready for permanent deletion, set their bodies to null, and try to purge them.

Schedules a given credential for deletion.

Updates a credential.

Functions

Link to this function

basic_auth_for(credential)

View Source
Link to this function

cancel_scheduled_deletion(credential_id)

View Source
Link to this function

change_credential(credential, attrs \\ %{})

View Source

Returns an %Ecto.Changeset{} for tracking credential changes.

Examples

iex> change_credential(credential)
%Ecto.Changeset{data: %Credential{}}
Link to this function

create_credential(attrs \\ %{})

View Source

Creates a credential.

Examples

iex> create_credential(%{field: value})
{:ok, %Credential{}}

iex> create_credential(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

delete_credential(credential)

View Source

Deletes a credential.

Examples

iex> delete_credential(credential)
{:ok, %Credential{}}

iex> delete_credential(credential)
{:error, %Ecto.Changeset{}}

Gets a single credential.

Raises Ecto.NoResultsError if the Credential does not exist.

Examples

iex> get_credential!(123)
%Credential{}

iex> get_credential!(456)
** (Ecto.NoResultsError)
Link to this function

get_credential_by_project_credential(project_credential_id)

View Source
Link to this function

get_credential_for_update!(id)

View Source
@spec get_schema(String.t()) :: Lightning.Credentials.Schema.t()

Creates a credential schema from credential json schema.

Link to this function

has_activity_in_projects?(credential)

View Source

Checks if a given Credential has any associated Step activity.

Parameters

  • _credential: A Credential struct. Only the id field is used by the function.

Returns

  • true if there's at least one Step associated with the given Credential.
  • false otherwise.

Examples

iex> has_activity_in_projects?(%Credential{id: some_id})
true

iex> has_activity_in_projects?(%Credential{id: another_id})
false

Notes

This function leverages the association between Step and Credential to determine if any steps exist for a given credential. It's a fast check that does not load any records into memory, but simply checks for their existence.

Link to this function

invalid_projects_for_user(credential_id, user_id)

View Source

Given a credential and a user, returns a list of invalid projects—i.e., those that the credential is shared with but that the user does not have access to.

This is used to generate a validation error when a credential cannot be transferred.

Examples

iex> can_credential_be_shared_to_user(credential_id, user_id)
[]

iex> can_credential_be_shared_to_user(credential_id, user_id)
["52ea8758-6ce5-43d7-912f-6a1e1f11dc55"]
Link to this function

list_credentials(project)

View Source

Retrieves all credentials based on the given context, either a Project or a User.

Parameters

  • context: The Project or User struct to retrieve credentials for.

Returns

  • A list of credentials associated with the given Project or created by the given User.

Examples

When given a Project:

iex> list_credentials(%Project{id: 1})
[%Credential{project_id: 1}, %Credential{project_id: 1}]

When given a User:

iex> list_credentials(%User{id: 123})
[%Credential{user_id: 123}, %Credential{user_id: 123}]
Link to this function

maybe_refresh_token(credential)

View Source

Perform, when called with %{"type" => "purge_deleted"} will find credentials that are ready for permanent deletion, set their bodies to null, and try to purge them.

Link to this function

schedule_credential_deletion(credential)

View Source

Schedules a given credential for deletion.

The deletion date is determined based on the :purge_deleted_after_days configuration in the application environment. If this configuration is absent, the credential is scheduled for immediate deletion.

The function will also perform necessary side effects such as:

  • Removing associations of the credential.
  • Notifying the owner of the credential about the scheduled deletion.

Parameters

  • credential: A Credential struct that is to be scheduled for deletion.

Returns

  • {:ok, credential}: Returns an :ok tuple with the updated credential struct if the update was successful.
  • {:error, changeset}: Returns an :error tuple with the changeset if the update failed.

Examples

iex> schedule_credential_deletion(%Credential{id: some_id})
{:ok, %Credential{}}

iex> schedule_credential_deletion(%Credential{})
{:error, %Ecto.Changeset{}}
Link to this function

sensitive_values_for(id)

View Source
@spec sensitive_values_for(Ecto.UUID.t() | Lightning.Credentials.Credential.t() | nil) ::
  [any()]
Link to this function

update_credential(credential, attrs)

View Source

Updates a credential.

Examples

iex> update_credential(credential, %{field: new_value})
{:ok, %Credential{}}

iex> update_credential(credential, %{field: bad_value})
{:error, %Ecto.Changeset{}}