Go - Secret.AccessVersion()

Retrieves the value from a version of a secret.

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)
value, err := secret.AccessVersion(context.TODO(), "latest")
if err != nil {
return
}
fmt.Println(value.AsString())
nitric.Run()
}

Parameters

  • Name
    ctx
    Required
    Required
    Type
    context
    Description

    The context of the call, used for tracing.

  • Name
    version
    Required
    Required
    Type
    string
    Description

    The ID of the secret version to access

Examples

Access the latest version of a secret

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)
value, err := secret.AccessVersion(context.TODO(), "latest")
if err != nil {
return
}
fmt.Println(value.AsString())
nitric.Run()
}

Access a specific version of a secret

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)
version, err := secret.AccessVersion(context.TODO(), "the-version-id")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(version.AsString())
nitric.Run()
}
Last updated on Dec 19, 2024