paramstore

package module
v0.0.0-...-6b51096 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 11 Imported by: 0

README

paramstore

+ 🍱 A Go abstraction over AWS SSM Parameter Store: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html.

GitHub License CI/CD Codecov

Usage

Below is a basic example of how to get started with this package:

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/jmpa-io/paramstore"
)

func main() {

	// setup tracing.
	ctx := context.TODO()

	// setup client.
	c, err := paramstore.New(ctx, paramstore.WithAWSRegion("ap-southeast-2"))
	if err != nil {
		fmt.Printf("failed to setup client: %v\n", err)
		os.Exit(1)
	}

	// read parameter.
	p, err := c.Get(ctx, "/path/to/my/parameter")
	if err != nil {
		fmt.Printf("failed to get parameter: %v", err)
		os.Exit(1)
	}
	fmt.Printf("%+v\n", p)
}

For more explicit examples, see the cmd/*/main.go files for details.

License

This work is published under the MIT license.

Please see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client defines a client for this package.

func New

func New(ctx context.Context, options ...Option) (*Client, error)

New creates and returns a new Client. The client itself is set up with tracing & logging. Additional options can be provided to modify its behavior, via the options slice. The client is used for interacting with parameters in AWS SSM Parameter Store.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, names ...string) (errs error)

Delete deletes one or more params from paramstore.

func (*Client) Get

func (c *Client) Get(ctx context.Context, name string) (out *Parameter, err error)

Get retrieves a single param from paramstore.

func (*Client) GetMultiple

func (c *Client) GetMultiple(ctx context.Context, names ...string) (out Parameters, errs error)

GetMultiple retrieves one or more params from paramstore.

func (*Client) Put

func (c *Client) Put(ctx context.Context, parameters Parameters) (errs error)

Put uploads one or more params to paramstore.

type ErrClientFailedToLoadAWSConfig

type ErrClientFailedToLoadAWSConfig struct {
	// contains filtered or unexported fields
}

func (ErrClientFailedToLoadAWSConfig) Error

ErrClientFailedToLoadAWSConfig is returned when the AWS config isn't able to be loaded from the AWS SDK being used in the client. This may occur when the environment isn't configured correctly to use the `awscli` for example.

type ErrClientFailedToSetOption

type ErrClientFailedToSetOption struct {
	// contains filtered or unexported fields
}

ErrClientFailedToSetOption is returned when an option encounters an error when trying to be set with the client.

func (ErrClientFailedToSetOption) Error

type Option

type Option func(*Client) error

Option configures a paramstore client.

func WithAWSRegion

func WithAWSRegion(region string) Option

WithAWSRegion configures the AWS region used in the client.

func WithBatchSize

func WithBatchSize(size int) Option

WithBatchSize configures the batchSize used by the client when retrieving from or uploading to paramstore.

func WithDecryption

func WithDecryption(decryption bool) Option

WithDecryption configures the decryption used by the client when retrieving from AWS SSM Parameter Store. This option must be given to decrypt any parameters returned to this client.

func WithLogLevel

func WithLogLevel(level slog.Level) Option

WithLogLevel sets the log level for the default logger.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger configures the logger used in the client.

type Parameter

type Parameter struct {
	Name      string        // The name of the parameter.
	Value     string        // The value of the parameter.
	Type      ParameterType // The type of the parameter.
	Overwrite bool          // Used to overwrite existing parameters during Put().
}

Parameter is a thin wrapper over ssm/types.Parameter.

type ParameterType

type ParameterType types.ParameterType

ParameterType is a thin wrapper over ssm/types.ParameterType. NOTE: This type exists to reduce the number of packages that anyone using this package needs to explicitly import into their own programs.

type Parameters

type Parameters []Parameter

Parameters is a slice of Parameter.

func (Parameters) ToSliceString

func (parameters Parameters) ToSliceString() (out []string)

ToSliceString converts a Params slice of names into a slice string.

Directories

Path Synopsis
cmd
get

Jump to

Keyboard shortcuts

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