Python - secret.put()

Store a new secret value, creating a new version to store the value.

from nitric.resources import secret
from nitric.application import Nitric
keyRef = secret('apiKey').allow('put')
await keyRef.put(b"6c3199a3-094e-4797-bfc9-9ee2a7839286")
Nitric.run()

Parameters

  • Name
    secret
    Required
    Required
    Type
    string | bytes
    Description

    The new secret value to store in the secrets manager.

Notes

A new secret version is always created when calling put(), the versions will automatically be provided a unique id. This behavior is dependent on the underlying secrets manager.

Examples

Store a new secret value

from nitric.resources import secret
from nitric.application import Nitric
keyRef = secret('apiKey').allow('put')
await keyRef.put(b"6c3199a3-094e-4797-bfc9-9ee2a7839286")
Nitric.run()

Get the id of a new secret version

Calling put() returns a promise to a reference to the new secret version. Storing the ID of the new version can be useful if you need to retrieve that specific value again in future using version.access()

from nitric.resources import secret
from nitric.application import Nitric
key_ref = secret('apiKey').allow('put')
await key_ref.put(b"6c3199a3-094e-4797-bfc9-9ee2a7839286")
versionId = key_ref.version
Nitric.run()
Last updated on Nov 11, 2024