TransformΒΆ
Encode/Decode ExampleΒΆ
hvac.api.secrets_engines.Transform.encode()
hvac.api.secrets_engines.Transform.decode()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
input_value = '1111-1111-1111-1111'
role_name = 'hvac-role'
transformation_name = 'hvac-fpe-credit-card'
transformations = [transformation_name]
# Create a role and a transformation
client.secrets.transform.create_or_update_role(
name=role_name,
transformations=transformations,
)
client.secrets.transform.create_or_update_transformation(
name=transformation_name,
transform_type='fpe',
template='builtin/creditcardnumber',
tweak_source='internal',
allowed_roles=[role_name],
)
# Use the role/transformation combination to encode a value
encode_response = client.secrets.transform.encode(
role_name=role_name,
value=input_value,
transformation=transformation_name,
)
print('The encoded value is: %s' % encode_response['data']['encoded_value'])
# Use the role/transformation combination to decode a value
decode_response = client.secrets.transform.decode(
role_name=role_name,
value=encode_response['data']['encoded_value'],
transformation=transformation_name,
)
print('The decoded value is: %s' % decode_response['data']['decoded_value'])
The encoded value is: ...
The decoded value is: 1111-1111-1111-1111
Create/Update RoleΒΆ
hvac.api.secrets_engines.Transform.create_or_update_role()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
client.secrets.transform.create_or_update_role(
name='hvac-role',
transformations=[
'hvac-fpe-credit-card',
],
)
Read RoleΒΆ
hvac.api.secrets_engines.Transform.read_role()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
role_name = 'hvac-role'
client.secrets.transform.create_or_update_role(
name=role_name,
transformations=[
'hvac-fpe-credit-card',
],
)
read_response = client.secrets.transform.read_role(
name=role_name,
)
print('Role "{}" has the following transformations configured: {}'.format(
role_name,
', '.join(read_response['data']['transformations']),
))
Role "hvac-role" has the following transformations configured: hvac-fpe-credit-card
List RolesΒΆ
hvac.api.secrets_engines.Transform.list_roles()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
client.secrets.transform.create_or_update_role(
name='hvac-role',
transformations=[
'hvac-fpe-credit-card',
],
)
list_response = client.secrets.transform.list_roles()
print('List of transform role names: {}'.format(
', '.join(list_response['data']['keys']),
))
List of transform role names: hvac-role
Delete RoleΒΆ
hvac.api.secrets_engines.Transform.delete_role()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
role_name = 'hvac-role'
# Create a role
client.secrets.transform.create_or_update_role(
name=role_name,
transformations=[
'hvac-fpe-credit-card',
],
)
# Subsequently delete it...
client.secrets.transform.delete_role(
name=role_name,
)
Create/Update TransformationΒΆ
hvac.api.secrets_engines.Transform.create_or_update_transformation()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
transformation_name = 'hvac-fpe-credit-card'
template = 'builtin/creditcardnumber'
client.secrets.transform.create_or_update_transformation(
name=transformation_name,
transform_type='fpe',
template=template,
tweak_source='internal',
allowed_roles=[
'test-role'
],
)
Read TransformationΒΆ
hvac.api.secrets_engines.Transform.read_transformation()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
transformation_name = 'hvac-fpe-credit-card'
template = 'builtin/creditcardnumber'
client.secrets.transform.create_or_update_transformation(
name=transformation_name,
transform_type='fpe',
template=template,
tweak_source='internal',
allowed_roles=[
'hvac-role'
],
)
read_response = client.secrets.transform.read_transformation(
name=transformation_name,
)
print('Transformation "{}" has the following type configured: {}'.format(
transformation_name,
read_response['data']['type'],
))
Transformation "hvac-fpe-credit-card" has the following type configured: fpe
List TransformationsΒΆ
hvac.api.secrets_engines.Transform.list_transformations()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
transformation_name = 'hvac-fpe-credit-card'
template = 'builtin/creditcardnumber'
client.secrets.transform.create_or_update_transformation(
name=transformation_name,
transform_type='fpe',
template=template,
tweak_source='internal',
allowed_roles=[
'hvac-role'
],
)
list_response = client.secrets.transform.list_transformations()
print('List of transformations: {}'.format(
', '.join(list_response['data']['keys']),
))
List of transformations: hvac-fpe-credit-card
Delete TransformationΒΆ
hvac.api.secrets_engines.Transform.delete_transformation()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
transformation_name = 'hvac-fpe-credit-card'
template = 'builtin/creditcardnumber'
# Create a transformation
client.secrets.transform.create_or_update_transformation(
name=transformation_name,
transform_type='fpe',
template=template,
tweak_source='internal',
allowed_roles=[
'hvac-role'
],
)
# Subsequently delete it...
client.secrets.transform.delete_role(
name=role_name,
)
Create/Update TemplateΒΆ
hvac.api.secrets_engines.Transform.create_or_update_template()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
template_name = 'hvac-template'
create_response = client.secrets.transform.create_or_update_template(
name=template_name,
template_type='regex',
pattern='(\\d{9})',
alphabet='builtin/numeric',
)
Read TemplateΒΆ
hvac.api.secrets_engines.Transform.read_template()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
template_name = 'hvac-template'
client.secrets.transform.create_or_update_template(
name=template_name,
template_type='regex',
pattern='(\\d{9})',
alphabet='builtin/numeric',
)
read_response = client.secrets.transform.read_template(
name=template_name,
)
print('Template "{}" has the following type configured: {}'.format(
template_name,
read_response['data']['type'],
))
Template "hvac-template" has the following type configured: regex
List TemplatesΒΆ
hvac.api.secrets_engines.Transform.list_templates()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
template_name = 'hvac-template'
client.secrets.transform.create_or_update_template(
name=template_name,
template_type='regex',
pattern='(\\d{9})',
alphabet='builtin/numeric',
)
list_response = client.secrets.transform.list_templates()
print('List of templates: {}'.format(
', '.join(list_response['data']['keys']),
))
List of templates: builtin/creditcardnumber, builtin/socialsecuritynumber, hvac-template
Delete TemplateΒΆ
hvac.api.secrets_engines.Transform.delete_template()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
template_name = 'hvac-template'
client.secrets.transform.create_or_update_template(
name=template_name,
template_type='regex',
pattern='(\\d{9})',
alphabet='builtin/numeric',
)
# Subsequently delete it...
client.secrets.transform.delete_template(
name=template_name,
)
Create/Update AlphabetΒΆ
hvac.api.secrets_engines.Transform.create_or_update_alphabet()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
alphabet_name = 'hvac-alphabet'
alphabet_value = 'abc'
client.secrets.transform.create_or_update_alphabet(
name=alphabet_name,
alphabet=alphabet_value,
)
Read AlphabetΒΆ
hvac.api.secrets_engines.Transform.read_alphabet()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
alphabet_name = 'hvac-alphabet'
alphabet_value = 'abc'
client.secrets.transform.create_or_update_alphabet(
name=alphabet_name,
alphabet=alphabet_value,
)
read_response = client.secrets.transform.read_alphabet(
name=alphabet_name,
)
print('Alphabet "{}" has this jazz: {}'.format(
alphabet_name,
read_response['data']['alphabet'],
))
Alphabet "hvac-alphabet" has this jazz: abc
List AlphabetsΒΆ
hvac.api.secrets_engines.Transform.list_alphabets()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
alphabet_name = 'hvac-alphabet'
alphabet_value = 'abc'
client.secrets.transform.create_or_update_alphabet(
name=alphabet_name,
alphabet=alphabet_value,
)
list_response = client.secrets.transform.list_alphabets()
print('List of alphabets: {}'.format(
', '.join(list_response['data']['keys']),
))
List of alphabets: builtin/alphalower, ..., hvac-alphabet
Delete AlphabetΒΆ
hvac.api.secrets_engines.Transform.delete_alphabet()
import hvac
client = hvac.Client(url='https://127.0.0.1:8200')
alphabet_name = 'hvac-alphabet'
alphabet_value = 'abc'
# Create an alphabet
client.secrets.transform.create_or_update_alphabet(
name=alphabet_name,
alphabet=alphabet_value,
)
# Subsequently delete it...
client.secrets.transform.delete_alphabet(
name=alphabet_name,
)