github.com/gofor-little/cfg

Securely load config data from AWS SecretsManager.


Keywords
aws, aws-sdk-go, aws-secretsmanager, golang, golang-pacakge
License
MIT
Install
go get github.com/gofor-little/cfg

Documentation

A package for loading config data from AWS SecretsManager

GitHub tag (latest SemVer pre-release) GitHub go.mod Go version License: MIT GitHub Workflow Status Go Report Card PkgGoDev

Introduction

  • Secure config loading.
  • Support AWS SecretsManager.
  • Easy JSON unmarshaling into a struct.

Example

package main

import (
	"context"

	"github.com/gofor-little/cfg"
)

type Config struct {
	SomeStringValue string `json:"someStringValue"`
	SomeIntValue    int    `json:"someIntValue"`
}

func main() {
	// Initialize the cfg package.
	if err := cfg.Initialize(context.Background(), "AWS_PROFILE", "AWS_REGION"); err != nil {
		panic(err)
	}

	// Load and parse the config data into the passed Config struct.
	config := &Config{}
	if err := cfg.Load(context.Background(), "AWS_SECRET_ARN", config); err != nil {
		panic(err)
	}
}

Testing

Ensure the following environment variables are set, usually with a .env file.

  • AWS_PROFILE (an AWS CLI profile name)
  • AWS_REGION (a valid AWS region)

Run go test -v ./... in the root directory.