Go - Secret.Put()

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

import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
if err != nil {
return
}
versionRef, 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"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
secret, err := nitric.NewSecret("secret-name").With(nitric.SecretPutting)
if err != nil {
return
}
versionRef, err := secret.Put(context.TODO(), []byte("content"))
if err != nil {
return
}
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()

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