# Redact/reveal

> To try it out today, email us at <support@vgs.io>

## Working with Vault

This page demonstrates how Larky is flexible and shows its benefit of doing many different things within one piece of code which can be placed under one route filter. The code is ready for use together with `curl` examples.

### Larky code sample

There is an example of code below which does different types of body manipulations:

* Redact of `card_number` in two different formats and Persistent storage
* Redact of `cvv` in Volatile storage
* Reveal of `secret` value
* Setting the new values into the new fields
* Removing the old fields from the body

```python
load('@stdlib/json', 'json')
load("@stdlib//builtins", builtins="builtins")
load("@vgs//vault", "vault")

def process(input, ctx):
    body = json.loads(str(input.body))

    # reading data from body
    card = body['card_number']
    cvv = body['cvv']
    alias4 = body['secret']

    # redact operation
    alias1 = vault.redact(card, storage='persistent', format='FPE_SIX_T_FOUR')
    alias2 = vault.redact(card, storage='persistent', format='UUID')
    alias3 = vault.redact(cvv, storage='volatile', format='UUID')

    # reveal operation
    secret = vault.reveal(alias4)

    # setting body
    body['card_6T4'] = alias1
    body['card_generic'] = alias2
    body['cvv_alias'] = alias3
    body['secret'] = secret

    # remove odd values
    body.pop('card_number')
    body.pop('cvv')

    # If you need to remove the alias
    # vault.delete(alias4)

    input.body = builtins.bytes(json.dumps(body))
    return input
```

### Testing

Request to send:

```bash
curl {VAULT_URL}/post \
  -H 'Content-Type: application/json' \
  -d '{
    "card_number": "4532251801577121",
    "cvv": "123",
    "secret": "tok_sandbox_vvLyaGWnxm5msxd8Zh3QS1"
  }'
```

Response example:

```json
{
  "card_6T4": "4532250530167121",
  "card_generic": "tok_sandbox_hUTo6bTm4kRrTKyoNfBCPm",
  "cvv_alias": "tok_sandbox_qjoDDEgRsvSUeGdkDNW6XA",
  "secret": "FNfcatCkg5yqh5mPBEwuxbbVFNfcatCkg5yqh5mPBEwuxbbV"
}
```

### Useful links

* [Supported formats](https://docs.verygoodsecurity.com/vault/tokens#alias-formats)
* [YAML file export/import](https://docs.verygoodsecurity.com/vault/developer-tools/vault-management/yaml)
