gosecretsplus

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2019 License: MIT Imports: 7 Imported by: 0

README

gosecretsplus

Build Status Go Report Card MIT

A Golang module for interacting with AWS Secrets Manager.

Logging

Logging is disabled by default. To enable logging, call gosecretsplus.EnableLogging().

The Secret struct

The Secret struct describes a Secret via these fields:

  • Name (string) describes the name of the Secret.
  • Value (string) describes the value of the Secret.

Create a Secret if it doesn't exist, update if it it does

The following functions on the Secret struct will create the Secret in AWS if it doesn't exist already, or update it if it does:

  • Save(kmsKeyID string) (SaveResult, error)
  • SaveWithOptions(kmsKeyID string, opts SaveOptions) (SaveResult, error)

The SaveOptions struct contains the following fields:

  • ClientRequestToken (string) is the optional client request token to include in the request to AWS.

The SaveResult struct contains the following fields:

  • SecretARN (string) is the ARN of the Secret that was created or updated.

For example:

package main

import (
    "fmt"
    "github.com/cariad/gosecretsplus"
)

func main() {
    secret := gosecretsplus.Secret{Name: "bank-password", Value: "trustno1"}
    result, _ := secret.Save("arn:aws:kms:us-east-1:555000000000:key/fd0db8a4-9389-40c4-9dcf-6e7f91067af9")
    fmt.Println(result.SecretARN)
    // arn:aws:secretsmanager:us-east-1:807041577214:secret:bank-password-uk4NqB
}

Creating a Secret in AWS

These functions will not update a Secret if it already exists. You more than likely want to use the Save() function above.

The following functions on the Secret struct will create the Secret in AWS:

  • Create(kmsKeyID string) (CreateResult, error)
  • CreateWithOptions(kmsKeyID string, opts CreateOptions) (CreateResult, error)

The CreateOptions struct contains the following fields:

  • ClientRequestToken (string) is the optional client request token to include in the request to AWS.

The CreateResult struct contains the following fields:

  • SecretAlreadyExists (bool) indicates whether or not the Secret existed before the function was called.
  • SecretARN (string) is the ARN of the Secret that was created or updated.

Updating a Secret in AWS

These functions will not create a Secret if it doesn't already exist. You more than likely want to use the Save() function above.

The following functions on the Secret struct will update the Secret in AWS:

  • Update(kmsKeyID string) (UpdateResult, error)
  • UpdateWithOptions(kmsKeyID string, opts UpdateOptions) (UpdateResult, error)

The UpdateOptions struct contains the following fields:

  • ClientRequestToken (string) is the optional client request token to include in the request to AWS.

The UpdateResult struct contains the following fields:

  • SecretARN (string) is the ARN of the Secret that was created or updated.

Getting a Secret from AWS

Call GetSecret(id string) (Secret, error) to get a Secret from AWS.

For example:

package main

import (
    "fmt"
    "github.com/cariad/gosecretsplus"
)

func main() {
    secret, _ := gosecretsplus.GetSecret("bank-password")
    fmt.Println(secret.Value)
    // "trustno1"
}

Deleting a Secret from AWS

Call DeleteSecret(id string) (DeleteResult, error) to delete a Secret from AWS.

For example:

package main

import (
    "github.com/cariad/gosecretsplus"
)

func main() {
    gosecretsplus.DeleteSecret("bank-password")
}

Licence, credit & sponsorship

This project is published under the MIT Licence.

You don't owe me anything in return, but as an indie freelance coder there are two things I'd appreciate:

  • Credit. If your app or documentation has a credits page, please consider mentioning the projects you use.
  • Cash. If you want and are able to support future development, please consider becoming a patron or buying me a coffee. Thank you!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableLogging added in v1.3.0

func DisableLogging()

DisableLogging disables logging.

func EnableLogging added in v1.3.0

func EnableLogging()

EnableLogging enables logging.

Types

type CreateOptions

type CreateOptions struct {
	ClientRequestToken string
}

CreateOptions describes options for creating a Secret.

type CreateResult

type CreateResult struct {
	SecretAlreadyExists bool
	SecretARN           string
}

CreateResult describes the result of an attempt to create a Secret.

type DeleteOptions added in v1.1.0

type DeleteOptions struct {
	RecoveryWindowInDays int
}

DeleteOptions describes options for deleting a Secret.

type DeleteResult added in v1.1.0

type DeleteResult struct {
}

DeleteResult describes the result of deleting a Secret.

func DeleteSecret added in v1.1.0

func DeleteSecret(id string) (DeleteResult, error)

DeleteSecret will delete the Secret in AWS.

func DeleteSecretWithOptions added in v1.1.0

func DeleteSecretWithOptions(id string, opts DeleteOptions) (result DeleteResult, err error)

DeleteSecretWithOptions will delete the Secret in AWS with specific options.

type SaveOptions

type SaveOptions struct {
	ClientRequestToken string
}

SaveOptions describes options for saving a Secret.

func (SaveOptions) ToCreateOptions

func (o SaveOptions) ToCreateOptions() CreateOptions

ToCreateOptions converts the SaveOptions to CreateOptions.

func (SaveOptions) ToUpdateOptions

func (o SaveOptions) ToUpdateOptions() UpdateOptions

ToUpdateOptions converts the SaveOptions to UpdateOptions.

type SaveResult

type SaveResult struct {
	SecretARN string
}

SaveResult describes the result of an attempt to save a Secret.

type Secret

type Secret struct {
	Name  string
	Value string
}

Secret describes a secret.

func GetSecret added in v1.1.0

func GetSecret(secretID string) (secret Secret, err error)

GetSecret gets a Secret from AWS.

func (Secret) Create

func (s Secret) Create(kmsKeyID string) (CreateResult, error)

Create will attempt to create the Secret in AWS.

func (Secret) CreateWithOptions

func (s Secret) CreateWithOptions(kmsKeyID string, opts CreateOptions) (CreateResult, error)

CreateWithOptions will attempt to create the Secret in AWS with specific options.

func (Secret) Save

func (s Secret) Save(kmsKeyID string) (SaveResult, error)

Save will create/update the Secret in AWS.

func (Secret) SaveWithOptions

func (s Secret) SaveWithOptions(kmsKeyID string, opts SaveOptions) (result SaveResult, err error)

SaveWithOptions will create/update the Secret in AWS with specific options.

func (Secret) Update

func (s Secret) Update(kmsKeyID string) (UpdateResult, error)

Update will attempt to update the Secret in AWS.

func (Secret) UpdateWithOptions

func (s Secret) UpdateWithOptions(kmsKeyID string, opts UpdateOptions) (UpdateResult, error)

UpdateWithOptions will update the Secret in AWS with specific options.

type UpdateOptions

type UpdateOptions struct {
	ClientRequestToken string
}

UpdateOptions describes options for updating a Secret.

type UpdateResult

type UpdateResult struct {
	SecretARN string
}

UpdateResult describes the result of an attempt to update a Secret.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL