File: kv_v1.rst

package info (click to toggle)
python-hvac 2.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: python: 29,360; makefile: 42; sh: 14
file content (89 lines) | stat: -rw-r--r-- 2,443 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
KV - Version 1
==============

.. note::
    Every method under the :py:attr:`Kv class's v1 attribute<hvac.api.secrets_engines.Kv>` includes a `mount_point` parameter that can be used to address the KvV1 secret engine under a custom mount path. E.g., If enabling the KvV1 secret engine using Vault's CLI commands via `vault secrets enable -path=my-kvv1 -version=1 kv`", the `mount_point` parameter in :py:meth:`hvac.api.secrets_engines.KvV1` methods would be set to "my-kvv1".



Read a Secret
-------------

:py:meth:`hvac.api.secrets_engines.KvV1.read_secret`

.. code:: python

    import hvac
    client = hvac.Client()

    # The following path corresponds, when combined with the mount point, to a full Vault API route of "v1/secretz/hvac"
    mount_point = 'secretz'
    secret_path = 'hvac'

    read_secret_result = client.secrets.kv.v1.read_secret(
        path=secret_path,
        mount_point=mount_point,
    )
    print('The "psst" key under the secret path ("/v1/secret/hvac") is: {psst}'.format(
        psst=read_secret_result['data']['psst'],
    ))

List Secrets
------------

:py:meth:`hvac.api.secrets_engines.KvV1.list_secrets`

.. code:: python

    import hvac
    client = hvac.Client()

    list_secrets_result = client.secrets.kv.v1.list_secrets(path='hvac')

    print('The following keys found under the selected path ("/v1/secret/hvac"): {keys}'.format(
        keys=','.join(list_secrets_result['data']['keys']),
    ))

Create or Update a Secret
-------------------------

:py:meth:`hvac.api.secrets_engines.KvV1.create_or_update_secret`

.. code:: python

    import hvac
    client = hvac.Client()
    hvac_secret = {
        'psst': 'this is so secret yall',
    }

    client.secrets.kv.v1.create_or_update_secret(
        path='hvac',
        secret=hvac_secret,
    )

    read_secret_result = client.secrets.kv.v1.read_secret(
        path='hvac',
    )
    print('The "psst" key under the secret path ("/v1/secret/hvac") is: {psst}'.format(
        psst=read_secret_result['data']['psst'],
    ))

Delete a Secret
-------------------------------

:py:meth:`hvac.api.secrets_engines.KvV1.delete_secret`

.. code:: python

    import hvac
    client = hvac.Client()

    client.secrets.kv.v1.delete_secret(
        path='hvac',
    )

    # The following will raise a :py:class:`hvac.exceptions.InvalidPath` exception.
    read_secret_result = client.secrets.kv.v1.read_secret(
        path='hvac',
    )