Go - Secret.Access()
Returns a the value of the latest iteration of a secret.
import ("context""github.com/nitrictech/go-sdk/nitric""github.com/nitrictech/go-sdk/nitric/secrets")func main() {secret := nitric.NewSecret("secret-name").Allow(secrets.SecretAccess)latestSecret := secret.Access(context.TODO())nitric.Run()}
Notes
Access()
is most useful when you always want the most recent secret values from the secrets manager. Database credentials and API keys are good examples of secrets where the latest value is usually what you want.
For symmetric encryption, you'll need to retrieve the version of the secret used to encrypt a value when you try to decrypt it again. In those cases Access()
isn't a good choice, use AccessVersion() instead.
Examples
Get a reference to the latest secret version
import ("context""github.com/nitrictech/go-sdk/nitric""github.com/nitrictech/go-sdk/nitric/secrets")func main() {secret := nitric.NewSecret("secret-name").Allow(secrets.SecretAccess)latest := secret.Access(context.TODO())nitric.Run()}
Access the latest value 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.Access(context.TODO())if err != nil {return}fmt.Println(value.AsString())nitric.Run()}
See Secret.AccessVersion() for more details.
Last updated on Nov 8, 2024