Go - Secret.Put()

Store a new secret value.

import (
"context"
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/secrets"
)
func main() {
secret := nitric.NewSecret("secret-name").Allow(secrets.SecretPut)
versionName, err := secret.Put(context.TODO(), []byte("content"))
if err != nil {
return
}
nitric.Run()
}

Parameters

  • Name
    ctx
    Required
    Required
    Type
    context
    Description

    The context of the call, used for tracing.

  • Name
    secret
    Required
    Required
    Type
    []byte
    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

import (
"context"
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/secrets"
)
func main() {
secret := nitric.NewSecret("secret-name").Allow(secrets.SecretPut)
versionName, err := secret.Put(context.TODO(), []byte("content"))
if err != nil {
return
}
nitric.Run()
}

Get the id of a new secret version

Calling put() returns the ID of 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 secret.access()

import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/secrets"
)
func main() {
secret := nitric.NewSecret("secret-name").Allow(secrets.SecretAccess)
versionName, err := secret.Put(context.TODO(), []byte("content"))
if err != nil {
return
}
fmt.Println(versionName)
nitric.Run()
}
Last updated on Dec 19, 2024