Google Search MCP Server
by Claw256
[ash\_cloak](https://github.com/ash-project/ash_cloak)
v0.1.2
- GUIDES
- Modules
<!--THE END-->
<!--THE END-->
Search documentation of ash\_cloak
Settings
# [View Source](https://github.com/ash-project/ash_cloak "View Source") API Reference ash\_cloak v0.1.2
## [](api-reference.html#modules)Modules
[AshCloak](AshCloak.html)
An extension for encrypting attributes of a resource.
[AshCloak.Changes.Encrypt](AshCloak.Changes.Encrypt.html)
Takes an argument, and encrypts it into an attribute called `encrypted_{attribute}`
[AshCloak.Cloak.Options](AshCloak.Cloak.Options.html)
Mod Docs
[AshCloak.Info](AshCloak.Info.html)
Introspection functions for the [`AshCloak`](AshCloak.html) extension.
[Next Page → Home](readme.html)
[Hex Package](https://hex.pm/packages/ash_cloak/0.1.2) [Hex Preview](https://preview.hex.pm/preview/ash_cloak/0.1.2) Search HexDocs [Download ePub version](ash_cloak.epub "ePub version")
Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.32.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
[ash\_cloak](https://github.com/ash-project/ash_cloak)
v0.1.2
- GUIDES
- Modules
<!--THE END-->
<!--THE END-->
Search documentation of ash\_cloak
Settings
# [View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/changes/encrypt.ex#L1 "View Source") AshCloak.Changes.Encrypt (ash\_cloak v0.1.2)
Takes an argument, and encrypts it into an attribute called `encrypted_{attribute}`
# [](AshCloak.Changes.Encrypt.html#summary)Summary
## [Functions](AshCloak.Changes.Encrypt.html#functions)
[atomic(changeset, opts, \_)](AshCloak.Changes.Encrypt.html#atomic/3)
Callback implementation for [`Ash.Resource.Change.atomic/3`](../ash/3.4.1/Ash.Resource.Change.html#c:atomic/3).
[change(changeset, opts, \_)](AshCloak.Changes.Encrypt.html#change/3)
Callback implementation for [`Ash.Resource.Change.change/3`](../ash/3.4.1/Ash.Resource.Change.html#c:change/3).
# [](AshCloak.Changes.Encrypt.html#functions)Functions
[Link to this function](AshCloak.Changes.Encrypt.html#atomic/3 "Link to this function")
# atomic(changeset, opts, \_)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/changes/encrypt.ex#L19 "View Source")
Callback implementation for [`Ash.Resource.Change.atomic/3`](../ash/3.4.1/Ash.Resource.Change.html#c:atomic/3).
[Link to this function](AshCloak.Changes.Encrypt.html#change/3 "Link to this function")
# change(changeset, opts, \_)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/changes/encrypt.ex#L5 "View Source")
Callback implementation for [`Ash.Resource.Change.change/3`](../ash/3.4.1/Ash.Resource.Change.html#c:change/3).
[Hex Package](https://hex.pm/packages/ash_cloak/0.1.2) [Hex Preview](https://preview.hex.pm/preview/ash_cloak/0.1.2) Search HexDocs [Download ePub version](ash_cloak.epub "ePub version")
Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.32.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
[ash\_cloak](https://github.com/ash-project/ash_cloak)
v0.1.2
- GUIDES
- Modules
<!--THE END-->
<!--THE END-->
Search documentation of ash\_cloak
Settings
# [View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/deps/spark/lib/spark/dsl/extension.ex#L1022 "View Source") AshCloak.Cloak.Options (ash\_cloak v0.1.2)
Mod Docs
# [](AshCloak.Cloak.Options.html#summary)Summary
## [Functions](AshCloak.Cloak.Options.html#functions)
[attributes(value)](AshCloak.Cloak.Options.html#attributes/1)
Hello 3
[decrypt\_by\_default(value)](AshCloak.Cloak.Options.html#decrypt_by_default/1)
Hello 3
[on\_decrypt(value)](AshCloak.Cloak.Options.html#on_decrypt/1)
Hello 3
[vault(value)](AshCloak.Cloak.Options.html#vault/1)
Hello 3
# [](AshCloak.Cloak.Options.html#functions)Functions
[Link to this macro](AshCloak.Cloak.Options.html#attributes/1 "Link to this macro")
# attributes(value)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/deps/spark/lib/spark/dsl/extension.ex#L1022 "View Source") (macro)
Hello 3
[Link to this macro](AshCloak.Cloak.Options.html#decrypt_by_default/1 "Link to this macro")
# decrypt\_by\_default(value)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/deps/spark/lib/spark/dsl/extension.ex#L1022 "View Source") (macro)
Hello 3
[Link to this macro](AshCloak.Cloak.Options.html#on_decrypt/1 "Link to this macro")
# on\_decrypt(value)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/deps/spark/lib/spark/dsl/extension.ex#L1022 "View Source") (macro)
Hello 3
[Link to this macro](AshCloak.Cloak.Options.html#vault/1 "Link to this macro")
# vault(value)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/deps/spark/lib/spark/dsl/extension.ex#L1022 "View Source") (macro)
Hello 3
[Hex Package](https://hex.pm/packages/ash_cloak/0.1.2) [Hex Preview](https://preview.hex.pm/preview/ash_cloak/0.1.2) Search HexDocs [Download ePub version](ash_cloak.epub "ePub version")
Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.32.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
[ash\_cloak](https://github.com/ash-project/ash_cloak)
v0.1.2
- GUIDES
- Modules
<!--THE END-->
<!--THE END-->
Search documentation of ash\_cloak
Settings
# [View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak.ex#L1 "View Source") AshCloak (ash\_cloak v0.1.2)
An extension for encrypting attributes of a resource.
See the getting started guide for more information.
# [](AshCloak.html#summary)Summary
## [Functions](AshCloak.html#functions)
[cloak(body)](AshCloak.html#cloak/1)
Hello!
[encrypt\_and\_set(changeset, key, value)](AshCloak.html#encrypt_and_set/3)
Encrypts and writes to an encrypted attribute.
# [](AshCloak.html#functions)Functions
[Link to this macro](AshCloak.html#cloak/1 "Link to this macro")
# cloak(body)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak.ex#L41 "View Source") (macro)
Hello!
[Link to this function](AshCloak.html#encrypt_and_set/3 "Link to this function")
# encrypt\_and\_set(changeset, key, value)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak.ex#L50 "View Source")
```
@spec encrypt_and_set(Ash.Changeset.t(), attr :: atom(), term :: term()) ::
Ash.Changeset.t()
```
Encrypts and writes to an encrypted attribute.
If the changeset is pending (i.e not currently running the action), then it is added as a before\_action hook. Otherwise, it is run immediately
[Hex Package](https://hex.pm/packages/ash_cloak/0.1.2) [Hex Preview](https://preview.hex.pm/preview/ash_cloak/0.1.2) Search HexDocs [Download ePub version](ash_cloak.epub "ePub version")
Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.32.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
[ash\_cloak](https://github.com/ash-project/ash_cloak)
v0.1.2
- GUIDES
- Modules
<!--THE END-->
<!--THE END-->
Search documentation of ash\_cloak
Settings
# [View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L1 "View Source") AshCloak.Info (ash\_cloak v0.1.2)
Introspection functions for the [`AshCloak`](AshCloak.html) extension.
# [](AshCloak.Info.html#summary)Summary
## [Functions](AshCloak.Info.html#functions)
[cloak\_attributes(dsl\_or\_extended)](AshCloak.Info.html#cloak_attributes/1)
The attribute or attributes to encrypt. The attribute will be renamed to `encrypted_{attribute}`, and a calculation with the same name will be added.
[cloak\_attributes!(dsl\_or\_extended)](AshCloak.Info.html#cloak_attributes!/1)
The attribute or attributes to encrypt. The attribute will be renamed to `encrypted_{attribute}`, and a calculation with the same name will be added.
[cloak\_decrypt\_by\_default(dsl\_or\_extended)](AshCloak.Info.html#cloak_decrypt_by_default/1)
A list of attributes that should be decrypted (their calculation should be loaded) by default.
[cloak\_decrypt\_by\_default!(dsl\_or\_extended)](AshCloak.Info.html#cloak_decrypt_by_default!/1)
A list of attributes that should be decrypted (their calculation should be loaded) by default.
[cloak\_on\_decrypt(dsl\_or\_extended)](AshCloak.Info.html#cloak_on_decrypt/1)
A function to call when decrypting any value. Takes the resource, field, records, and calculation context. Must return `:ok` or `{:error, error}`
[cloak\_on\_decrypt!(dsl\_or\_extended)](AshCloak.Info.html#cloak_on_decrypt!/1)
A function to call when decrypting any value. Takes the resource, field, records, and calculation context. Must return `:ok` or `{:error, error}`
[cloak\_options(dsl\_or\_extended)](AshCloak.Info.html#cloak_options/1)
cloak DSL options
[cloak\_vault(dsl\_or\_extended)](AshCloak.Info.html#cloak_vault/1)
The vault to use to encrypt & decrypt the value
[cloak\_vault!(dsl\_or\_extended)](AshCloak.Info.html#cloak_vault!/1)
The vault to use to encrypt & decrypt the value
# [](AshCloak.Info.html#functions)Functions
[Link to this function](AshCloak.Info.html#cloak_attributes/1 "Link to this function")
# cloak\_attributes(dsl\_or\_extended)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L3 "View Source")
```
@spec cloak_attributes(dsl_or_extended :: module() | map()) ::
{:ok, [atom()]} | :error
```
The attribute or attributes to encrypt. The attribute will be renamed to `encrypted_{attribute}`, and a calculation with the same name will be added.
[Link to this function](AshCloak.Info.html#cloak_attributes!/1 "Link to this function")
# cloak\_attributes!(dsl\_or\_extended)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L3 "View Source")
```
@spec cloak_attributes!(dsl_or_extended :: module() | map()) :: [atom()] | no_return()
```
The attribute or attributes to encrypt. The attribute will be renamed to `encrypted_{attribute}`, and a calculation with the same name will be added.
[Link to this function](AshCloak.Info.html#cloak_decrypt_by_default/1 "Link to this function")
# cloak\_decrypt\_by\_default(dsl\_or\_extended)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L3 "View Source")
```
@spec cloak_decrypt_by_default(dsl_or_extended :: module() | map()) ::
{:ok, [atom()]} | :error
```
A list of attributes that should be decrypted (their calculation should be loaded) by default.
[Link to this function](AshCloak.Info.html#cloak_decrypt_by_default!/1 "Link to this function")
# cloak\_decrypt\_by\_default!(dsl\_or\_extended)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L3 "View Source")
```
@spec cloak_decrypt_by_default!(dsl_or_extended :: module() | map()) ::
[atom()] | no_return()
```
A list of attributes that should be decrypted (their calculation should be loaded) by default.
[Link to this function](AshCloak.Info.html#cloak_on_decrypt/1 "Link to this function")
# cloak\_on\_decrypt(dsl\_or\_extended)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L3 "View Source")
```
@spec cloak_on_decrypt(dsl_or_extended :: module() | map()) ::
{:ok, (any(), any(), any(), any() -> any()) | mfa()} | :error
```
A function to call when decrypting any value. Takes the resource, field, records, and calculation context. Must return `:ok` or `{:error, error}`
[Link to this function](AshCloak.Info.html#cloak_on_decrypt!/1 "Link to this function")
# cloak\_on\_decrypt!(dsl\_or\_extended)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L3 "View Source")
```
@spec cloak_on_decrypt!(dsl_or_extended :: module() | map()) ::
((any(), any(), any(), any() -> any()) | mfa()) | no_return()
```
A function to call when decrypting any value. Takes the resource, field, records, and calculation context. Must return `:ok` or `{:error, error}`
[Link to this function](AshCloak.Info.html#cloak_options/1 "Link to this function")
# cloak\_options(dsl\_or\_extended)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L3 "View Source")
```
@spec cloak_options(dsl_or_extended :: module() | map()) :: %{
required(atom()) => any()
}
```
cloak DSL options
Returns a map containing the and any configured or default values.
[Link to this function](AshCloak.Info.html#cloak_vault/1 "Link to this function")
# cloak\_vault(dsl\_or\_extended)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L3 "View Source")
```
@spec cloak_vault(dsl_or_extended :: module() | map()) :: {:ok, module()} | :error
```
The vault to use to encrypt & decrypt the value
[Link to this function](AshCloak.Info.html#cloak_vault!/1 "Link to this function")
# cloak\_vault!(dsl\_or\_extended)
[View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/lib/ash_cloak/info.ex#L3 "View Source")
```
@spec cloak_vault!(dsl_or_extended :: module() | map()) :: module() | no_return()
```
The vault to use to encrypt & decrypt the value
[Hex Package](https://hex.pm/packages/ash_cloak/0.1.2) [Hex Preview](https://preview.hex.pm/preview/ash_cloak/0.1.2) Search HexDocs [Download ePub version](ash_cloak.epub "ePub version")
Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.32.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
[ash\_cloak](https://github.com/ash-project/ash_cloak)
v0.1.2
- GUIDES
- Modules
<!--THE END-->
<!--THE END-->
Search documentation of ash\_cloak
Settings
# [View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/documentation/dsls/DSL:-AshCloak.md#L1 "View Source") DSL: AshCloak
An extension for encrypting attributes of a resource.
See the getting started guide for more information.
## [](dsl-ashcloak.html#cloak)cloak
Encrypt attributes of a resource
### [](dsl-ashcloak.html#options)Options
NameTypeDefaultDocs[`vault`](dsl-ashcloak.html#cloak-vault)`module`The vault to use to encrypt & decrypt the value[`attributes`](dsl-ashcloak.html#cloak-attributes)`atom | list(atom)``[]`The attribute or attributes to encrypt. The attribute will be renamed to `encrypted_{attribute}`, and a calculation with the same name will be added.[`decrypt_by_default`](dsl-ashcloak.html#cloak-decrypt_by_default)`atom | list(atom)``[]`A list of attributes that should be decrypted (their calculation should be loaded) by default.[`on_decrypt`](dsl-ashcloak.html#cloak-on_decrypt)`(any, any, any, any -> any) | mfa`A function to call when decrypting any value. Takes the resource, field, records, and calculation context. Must return `:ok` or `{:error, error}`
[← Previous Page How does AshCloak work?](how-does-ash-cloak-work.html)
[Next Page → Change Log](changelog.html)
[Hex Package](https://hex.pm/packages/ash_cloak/0.1.2) [Hex Preview](https://preview.hex.pm/preview/ash_cloak/0.1.2) ([current file](https://preview.hex.pm/preview/ash_cloak/0.1.2/show/documentation/dsls/DSL:-AshCloak.md)) Search HexDocs [Download ePub version](ash_cloak.epub "ePub version")
Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.32.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
[ash\_cloak](https://github.com/ash-project/ash_cloak)
v0.1.2
- GUIDES
- Modules
<!--THE END-->
<!--THE END-->
Search documentation of ash\_cloak
Settings
# [View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/documentation/tutorials/getting-started-with-ash-cloak.md#L1 "View Source") Get Started with AshCloak
## [](getting-started-with-ash-cloak.html#installation)Installation
Add `ash_cloak` to your list of dependencies in `mix.exs`:
```
{:ash_cloak, "~> 0.1.2"}
```
Follow [the cloak getting started guide](../cloak/readme.html) to add `cloak` as a dependency, as AshCloak does not add a vault implementation for you. Note that you do not need `cloak_ecto` because your Ash data layer will take care of this.
Alternatively you could use your own vault module that implements `encrypt!` and `decrypt!`, but we recommend using `Cloak` to achieve that goal. See the [cloak vault guide](../cloak/install.html#create-a-vault)
### [](getting-started-with-ash-cloak.html#add-the-ashcloak-extension-to-your-resource)Add the [`AshCloak`](AshCloak.html) extension to your resource
```
defmodule User do
use Ash.Resource, extensions: [AshCloak]
cloak do
# the vault to use to encrypt them
vault MyApp.Vault
# the attributes to encrypt
attributes [:address, :phone_number]
# This is just equivalent to always providing `load: fields` on all calls
decrypt_by_default [:address]
# An MFA or function to be invoked beforce any decryption
on_decrypt fn records, field, context ->
# Ash has policies that allow forbidding certain users to load data.
# You should generally use those for authorization rules, and
# only use this callback for auditing/logging.
Audit.user_accessed_encrypted_field(records, field, context)
if context.user.name == "marty" do
{:error, "No martys at the party!"}
else
:ok
end
end
end
end
```
[← Previous Page Home](readme.html)
[Next Page → How does AshCloak work?](how-does-ash-cloak-work.html)
[Hex Package](https://hex.pm/packages/ash_cloak/0.1.2) [Hex Preview](https://preview.hex.pm/preview/ash_cloak/0.1.2) ([current file](https://preview.hex.pm/preview/ash_cloak/0.1.2/show/documentation/tutorials/getting-started-with-ash-cloak.md)) Search HexDocs [Download ePub version](ash_cloak.epub "ePub version")
Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.32.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
[ash\_cloak](https://github.com/ash-project/ash_cloak)
v0.1.2
- GUIDES
- Modules
<!--THE END-->
<!--THE END-->
Search documentation of ash\_cloak
Settings
# [View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/documentation/topics/how-does-ash-cloak-work.md#L1 "View Source") How does AshCloak work?
## [](how-does-ash-cloak-work.html#rewrite-attributes-to-calculations)Rewrite attributes to calculations
First, AshCloak changes the name of each cloaked attribute to `encrypted_<name>`, and sets `public?: false` and `sensitive?: true`.
Then it adds a *calculation* matching the original attribute that, when loaded, will decrypt the given attribute and call any configured `on_decrypt` callbacks.
## [](how-does-ash-cloak-work.html#modify-actions)Modify Actions
AshCloak then goes through each action that accepts the attribute and removes the attribute from the accept list.
Then it adds an argument by the same name, and a `change` that encrypts the attribute value.
This `change` also deletes the argument from the arguments list and from the params. This is a small extra layer of security to prevent accidental leakage of the value.
## [](how-does-ash-cloak-work.html#add-preparation-and-change)Add `preparation` and `change`
Finally, it add a `preparation` and a `change` that will automatically load the corresponding calculations for any attribute in the `decrypt_by_default` list.
## [](how-does-ash-cloak-work.html#the-result)The result
The cloaked attribute will now seamlessly encrypt when writing and decrypt on request.
[← Previous Page Get Started with AshCloak](getting-started-with-ash-cloak.html)
[Next Page → DSL: AshCloak](dsl-ashcloak.html)
[Hex Package](https://hex.pm/packages/ash_cloak/0.1.2) [Hex Preview](https://preview.hex.pm/preview/ash_cloak/0.1.2) ([current file](https://preview.hex.pm/preview/ash_cloak/0.1.2/show/documentation/topics/how-does-ash-cloak-work.md)) Search HexDocs [Download ePub version](ash_cloak.epub "ePub version")
Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.32.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
[ash\_cloak](https://github.com/ash-project/ash_cloak)
v0.1.2
- GUIDES
- Modules
<!--THE END-->
<!--THE END-->
Search documentation of ash\_cloak
Settings
# [View Source](https://github.com/ash-project/ash_cloak/blob/v0.1.2/README.md#L1 "View Source") Home
 
 [](https://opensource.org/licenses/MIT) [](https://hex.pm/packages/ash_cloak) [](../ash_cloak.html)
# AshCloak
AshCloak is an [Ash](../ash.html) extension to seamlessly encrypt and decrypt attributes of your resources.
Encrypting attributes ensures that sensitive fields are not stored in the clear in your data layer.
AshCloak can be used with any Ash data layer.
It's recommended to use [Cloak](https://github.com/danielberkompas/cloak) as a vault implementation but you could also build your own.
## [](readme.html#tutorials)Tutorials
- [Get Started with AshCloak](getting-started-with-ash-cloak.html)
## [](readme.html#topics)Topics
- [How does AshCloak work?](how-does-ash-cloak-work.html)
## [](readme.html#reference)Reference
- [AshCloak DSL](dsl-ashcloak.html)
[← Previous Page API Reference](api-reference.html)
[Next Page → Get Started with AshCloak](getting-started-with-ash-cloak.html)
[Hex Package](https://hex.pm/packages/ash_cloak/0.1.2) [Hex Preview](https://preview.hex.pm/preview/ash_cloak/0.1.2) ([current file](https://preview.hex.pm/preview/ash_cloak/0.1.2/show/README.md)) Search HexDocs [Download ePub version](ash_cloak.epub "ePub version")
Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.32.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")