Go - Secret.Version.Access()

Retrieves the value from a version of a secret.

import (
  "fmt"

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

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

  value, err := secret.Latest().Access(context.TODO())
  if err != nil {
    return
  }

  fmt.Println(value.AsString())

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

Parameters

  • Name
    ctx
    Required
    Required
    Type
    context
    Description

    The context of the call, used for tracing.

Examples

Access the latest version of a secret

import (
  "fmt"

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

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

  value, err := secret.Latest().Access(context.TODO())
  if err != nil {
    return
  }

  fmt.Println(value.AsString())

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

Access a specific version of a secret

import (
  "context"
  "fmt"

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

func main() {
  secret, err := nitric.NewSecret("secret-name").Allow(nitric.SecretAccess)
  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)
  }
}