cfg

package module
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: MIT Imports: 7 Imported by: 1

README

A package for loading config data from AWS SecretsManager

GitHub tag (latest SemVer pre-release) GitHub go.mod Go version 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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SecretsManagerClient is used to fetch secrets from SecretsManager.
	SecretsManagerClient *secretsmanager.Client
)

Functions

func Initialize

func Initialize(ctx context.Context, profile string, region string) error

Initialize will initialize the cfg package. Both the profile and region parameters are optional if authentication can be achieved via another method. For example, environment variables or IAM roles.

func Load

func Load(ctx context.Context, secretARN string, v interface{}) error

Load fetches a secret from SecretsManager and parses the value into v using json.Unmarshal. To comply with json.Unmarshal's parameter requirements v cannot be nil or not a pointer.

func LoadString added in v0.3.0

func LoadString(ctx context.Context, secretARN string) (string, error)

Load fetches a secret from SecretsManager.

Types

This section is empty.

Jump to

Keyboard shortcuts

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