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
Returns an %Ecto.Changeset{}
for tracking credential changes.
Examples
iex> change_credential(credential)
%Ecto.Changeset{data: %Credential{}}
Creates a credential.
Examples
iex> create_credential(%{field: value})
{:ok, %Credential{}}
iex> create_credential(%{field: bad_value})
{:error, %Ecto.Changeset{}}
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)
@spec get_schema(String.t()) :: Lightning.Credentials.Schema.t()
Creates a credential schema from credential json schema.
Checks if a given Credential
has any associated Step
activity.
Parameters
_credential
: ACredential
struct. Only theid
field is used by the function.
Returns
true
if there's at least oneStep
associated with the givenCredential
.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.
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"]
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}]
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.
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
: ACredential
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{}}
@spec sensitive_values_for(Ecto.UUID.t() | Lightning.Credentials.Credential.t() | nil) :: [any()]
Updates a credential.
Examples
iex> update_credential(credential, %{field: new_value})
{:ok, %Credential{}}
iex> update_credential(credential, %{field: bad_value})
{:error, %Ecto.Changeset{}}