AshVault.Info (AshVault v0.2.0)

Copy Markdown View Source

Introspection for the AshVault extension.

Spark.InfoGenerator generates the raw option readers — ash_vault_vault/1 and ash_vault_vault!/1, ash_vault_scope/1, ash_vault_attributes/1, ash_vault_decrypt_by_default/1, ash_vault_encrypt_nil?/1, ash_vault_scope_owner?/1, ash_vault_options/1, ash_vault_key_lifecycle_rotate/1, ash_vault_key_lifecycle_destroy/1 — plus ash_vault/1, which returns the encrypt entities.

Note the generator's naming rules: entity readers are named after the section path (hence ash_vault/1, not ash_vault_encrypt/1), ?-suffixed options get only a predicate function with no bang variant, and options with a non-nil default never return :error.

On top of those this module adds the helpers the extension itself uses.

Summary

Functions

ash_vault DSL entities

Shorthand for a list of encrypt entities with default options.

Shorthand for a list of encrypt entities with default options.

Encrypted fields whose decrypt calculation is loaded automatically.

Encrypted fields whose decrypt calculation is loaded automatically.

Encrypt nil rather than storing SQL NULL. Overridable per field.

Name of a generic action that destroys this scope's keys.

Name of a generic action that destroys this scope's keys.

ash_vault.key_lifecycle DSL options

Name of a generic action that rotates this scope's key.

Name of a generic action that rotates this scope's key.

ash_vault DSL options

The key scope: :tenant (AshVault.Scopes.AshTenant), :global (AshVault.Scopes.Global), or an AshVault.Scope module. Unrelated to Ash.Scope.

The key scope: :tenant (AshVault.Scopes.AshTenant), :global (AshVault.Scopes.Global), or an AshVault.Scope module. Unrelated to Ash.Scope.

This resource is the scope (the tenant/organization). Required for key_lifecycle.

The vault to encrypt and decrypt with. A module using AshVault.Vault, an MFA, or a fun/2 of (resource, context) -> vault_module.

The vault to encrypt and decrypt with. A module using AshVault.Vault, an MFA, or a fun/2 of (resource, context) -> vault_module.

The encrypt entities of a resource, without the attributes sugar.

Whether nil is encrypted for a field, resolving the per-field override against the section-level default.

One encrypted field by name, or nil.

The names of every encrypted field of a resource.

Every encrypted field of a resource, as %AshVault.Encrypted{} structs.

The encrypt ..., legacy: ... entities of a resource, as declared (named after the legacy attribute).

A legacy: field's legacy type and constraints.

One macaroon by name, or nil.

Every macaroon declared on a resource.

The normalize: strategy configured for a field, defaulting to :none.

The AshVault.Scope module for a resource's key scope.

Whether one field of a resource is searchable.

Every searchable field of a resource, as %AshVault.Encrypted{} structs.

The stable storage and cryptographic binding name of an encrypted field.

Resolve a logical field to its stable storage and binding name.

The vault module for a resource, resolving the fun/2 and MFA forms against the callback context.

Functions

ash_vault(dsl_or_extended)

@spec ash_vault(dsl_or_extended :: module() | map()) :: [struct()]

ash_vault DSL entities

ash_vault_attributes(dsl_or_extended)

@spec ash_vault_attributes(dsl_or_extended :: module() | map()) ::
  {:ok, [atom()]} | :error

Shorthand for a list of encrypt entities with default options.

ash_vault_attributes!(dsl_or_extended)

@spec ash_vault_attributes!(dsl_or_extended :: module() | map()) ::
  [atom()] | no_return()

Shorthand for a list of encrypt entities with default options.

ash_vault_decrypt_by_default(dsl_or_extended)

@spec ash_vault_decrypt_by_default(dsl_or_extended :: module() | map()) ::
  {:ok, [atom()]} | :error

Encrypted fields whose decrypt calculation is loaded automatically.

ash_vault_decrypt_by_default!(dsl_or_extended)

@spec ash_vault_decrypt_by_default!(dsl_or_extended :: module() | map()) ::
  [atom()] | no_return()

Encrypted fields whose decrypt calculation is loaded automatically.

ash_vault_encrypt_nil?(dsl_or_extended)

@spec ash_vault_encrypt_nil?(dsl_or_extended :: module() | map()) :: boolean()

Encrypt nil rather than storing SQL NULL. Overridable per field.

ash_vault_key_lifecycle_destroy(dsl_or_extended)

@spec ash_vault_key_lifecycle_destroy(dsl_or_extended :: module() | map()) ::
  {:ok, atom()} | :error

Name of a generic action that destroys this scope's keys.

ash_vault_key_lifecycle_destroy!(dsl_or_extended)

@spec ash_vault_key_lifecycle_destroy!(dsl_or_extended :: module() | map()) ::
  atom() | no_return()

Name of a generic action that destroys this scope's keys.

ash_vault_key_lifecycle_options(dsl_or_extended)

@spec ash_vault_key_lifecycle_options(dsl_or_extended :: module() | map()) :: %{
  required(atom()) => any()
}

ash_vault.key_lifecycle DSL options

Returns a map containing the and any configured or default values.

ash_vault_key_lifecycle_rotate(dsl_or_extended)

@spec ash_vault_key_lifecycle_rotate(dsl_or_extended :: module() | map()) ::
  {:ok, atom()} | :error

Name of a generic action that rotates this scope's key.

ash_vault_key_lifecycle_rotate!(dsl_or_extended)

@spec ash_vault_key_lifecycle_rotate!(dsl_or_extended :: module() | map()) ::
  atom() | no_return()

Name of a generic action that rotates this scope's key.

ash_vault_options(dsl_or_extended)

@spec ash_vault_options(dsl_or_extended :: module() | map()) :: %{
  required(atom()) => any()
}

ash_vault DSL options

Returns a map containing the and any configured or default values.

ash_vault_scope(dsl_or_extended)

@spec ash_vault_scope(dsl_or_extended :: module() | map()) ::
  {:ok, (:global | :tenant) | module()} | :error

The key scope: :tenant (AshVault.Scopes.AshTenant), :global (AshVault.Scopes.Global), or an AshVault.Scope module. Unrelated to Ash.Scope.

ash_vault_scope!(dsl_or_extended)

@spec ash_vault_scope!(dsl_or_extended :: module() | map()) ::
  ((:global | :tenant) | module()) | no_return()

The key scope: :tenant (AshVault.Scopes.AshTenant), :global (AshVault.Scopes.Global), or an AshVault.Scope module. Unrelated to Ash.Scope.

ash_vault_scope_owner?(dsl_or_extended)

@spec ash_vault_scope_owner?(dsl_or_extended :: module() | map()) :: boolean()

This resource is the scope (the tenant/organization). Required for key_lifecycle.

ash_vault_vault(dsl_or_extended)

@spec ash_vault_vault(dsl_or_extended :: module() | map()) ::
  {:ok, module() | mfa() | (any(), any() -> any())} | :error

The vault to encrypt and decrypt with. A module using AshVault.Vault, an MFA, or a fun/2 of (resource, context) -> vault_module.

ash_vault_vault!(dsl_or_extended)

@spec ash_vault_vault!(dsl_or_extended :: module() | map()) ::
  (module() | mfa() | (any(), any() -> any())) | no_return()

The vault to encrypt and decrypt with. A module using AshVault.Vault, an MFA, or a fun/2 of (resource, context) -> vault_module.

encrypt_entities(resource_or_dsl)

@spec encrypt_entities(module() | Spark.Dsl.t()) :: [AshVault.Encrypted.t()]

The encrypt entities of a resource, without the attributes sugar.

ash_vault/1 returns every entity in the section — macaroons too — so anything that wants encrypted fields reads them through here.

encrypt_nil?(resource_or_dsl, name)

@spec encrypt_nil?(module() | Spark.Dsl.t(), atom() | AshVault.Encrypted.t()) ::
  boolean()

Whether nil is encrypted for a field, resolving the per-field override against the section-level default.

encrypted_field(resource_or_dsl, name)

@spec encrypted_field(module() | Spark.Dsl.t(), atom()) ::
  AshVault.Encrypted.t() | nil

One encrypted field by name, or nil.

encrypted_field_names(resource_or_dsl)

@spec encrypted_field_names(module() | Spark.Dsl.t()) :: [atom()]

The names of every encrypted field of a resource.

encrypted_fields(resource_or_dsl)

@spec encrypted_fields(module() | Spark.Dsl.t()) :: [AshVault.Encrypted.t()]

Every encrypted field of a resource, as %AshVault.Encrypted{} structs.

This merges the attributes [...] sugar with the explicit encrypt entities, so it returns the same answer before and after AshVault.Transformers.ExpandAttributes has run. Explicit entities win over sugar of the same name, and order is entities-then-sugar.

legacy_fields(resource_or_dsl)

@spec legacy_fields(module() | Spark.Dsl.t()) :: [AshVault.Encrypted.t()]

The encrypt ..., legacy: ... entities of a resource, as declared (named after the legacy attribute).

legacy_type(encrypted)

@spec legacy_type(AshVault.Encrypted.t()) :: {module(), keyword()}

A legacy: field's legacy type and constraints.

macaroon(resource_or_dsl, name)

@spec macaroon(module() | Spark.Dsl.t(), atom()) ::
  AshVault.Macaroon.Definition.t() | nil

One macaroon by name, or nil.

macaroons(resource_or_dsl)

@spec macaroons(module() | Spark.Dsl.t()) :: [AshVault.Macaroon.Definition.t()]

Every macaroon declared on a resource.

normalize(resource_or_dsl, name)

The normalize: strategy configured for a field, defaulting to :none.

scope_module(resource_or_dsl)

@spec scope_module(module() | Spark.Dsl.t()) :: module()

The AshVault.Scope module for a resource's key scope.

searchable?(resource_or_dsl, name)

@spec searchable?(module() | Spark.Dsl.t(), atom()) :: boolean()

Whether one field of a resource is searchable.

searchable_fields(resource_or_dsl)

@spec searchable_fields(module() | Spark.Dsl.t()) :: [AshVault.Encrypted.t()]

Every searchable field of a resource, as %AshVault.Encrypted{} structs.

stored_as(encrypted)

@spec stored_as(AshVault.Encrypted.t()) :: atom()

The stable storage and cryptographic binding name of an encrypted field.

stored_as(resource_or_dsl, name)

@spec stored_as(module() | Spark.Dsl.t(), atom()) :: atom()

Resolve a logical field to its stable storage and binding name.

vault!(resource_or_dsl, context)

@spec vault!(module() | Spark.Dsl.t(), term()) :: module()

The vault module for a resource, resolving the fun/2 and MFA forms against the callback context.

The context handed here is always the normalized ash_context map built by AshVault.Context.Builder — %{tenant:, actor:, source_context:, phase:} — so a dynamic vault sees one shape on the write path, the read path and the lifecycle actions alike, rather than three different Ash callback structs.