Go - Secret.Version()

Returns a reference to a known version of a secret.

import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  version := secret.Version("the-version-id")

  if err := nitric.Run(); err != nil {
    fmt.Println(err)
  }
}

Parameters

  • Name
    version
    Required
    Required
    Type
    string
    Description

    The version ID. This value is returned from secret.Put().

Examples

Return a reference to a known secret version

import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  version := secret.Version("the-version-id")

  if err := nitric.Run(); err != nil {
    fmt.Println(err)
  }
}

Access the value of a known secret version

import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  version, err := secret.Version("the-version-id").Access(context.TODO())
  if err != nil {
    fmt.Println(err)
    return
  }

  fmt.Println(version.AsString())

  if err := nitric.Run(); err != nil {
    fmt.Println(err)
  }
}

See also