Redact/reveal
To try it out today, email us at [email protected]
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 storageRedact of
cvv
in Volatile storageReveal of
secret
valueSetting the new values into the new fields
Removing the old fields from the body
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:
curl {VAULT_URL}/post \
-H 'Content-Type: application/json' \
-d '{
"card_number": "4532251801577121",
"cvv": "123",
"secret": "tok_sandbox_vvLyaGWnxm5msxd8Zh3QS1"
}'
Response example:
{
"card_6T4": "4532250530167121",
"card_generic": "tok_sandbox_hUTo6bTm4kRrTKyoNfBCPm",
"cvv_alias": "tok_sandbox_qjoDDEgRsvSUeGdkDNW6XA",
"secret": "FNfcatCkg5yqh5mPBEwuxbbVFNfcatCkg5yqh5mPBEwuxbbV"
}
Useful links
Last updated