aws-credscache-go

module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: MIT

README

AWS Credentials Cache for Go

This module provides credentials caching utilities that are compatible with the AWS CLI.

Motivation

The AWS SDK has an in-memory caching feature for credentials. However, it doesn't work effectively for short-lifespan processes like CLI.

nocache
An MFA token code will be requested every time. It's very bothering.

Although the AWS CLI saves credentials into $HOME/.aws/cli/cache, the AWS SDK does not support it. This module provides an easy way to apply a file-caching feature that has compatibility with the AWS CLI.

cache
cache shared with AWS CLI
You will input an MFA token code only once and can also share the cache with the AWS CLI.

See exmples for more details.

Installation

go get github.com/Aton-Kish/aws-credscache-go

Usage

package main

import (
	"context"
	"log"

	credscache "github.com/Aton-Kish/aws-credscache-go/sdkv2"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
)

func main() {
	cfg, err := config.LoadDefaultConfig(context.Background(), config.WithAssumeRoleCredentialOptions(func(options *stscreds.AssumeRoleOptions) {
		options.TokenProvider = stscreds.StdinTokenProvider
	}))
	if err != nil {
		log.Fatal(err)
	}

	// Inject file cache provider
	if _, err := credscache.InjectFileCacheProvider(&cfg); err != nil {
		log.Fatal(err)
	}

	// client := ec2.NewFromConfig(cfg)
}

See exmples for more details.

Development

Setup
go mod tidy
Generate code
rm -rf internal/mock
go generate ./...
Test
: simple
go test ./...
: verbose
go test -v ./...
Doc
go run golang.org/x/tools/cmd/godoc@latest -http ":6060"

License

This library is licensed under the MIT License, see LICENSE.

Directories

Path Synopsis
internal
mock/github.com/Aton-Kish/aws-credscache-go/sdkv1
Package mock_credscache is a generated GoMock package.
Package mock_credscache is a generated GoMock package.
mock/github.com/aws/aws-sdk-go-v2/aws
Package mock_aws is a generated GoMock package.
Package mock_aws is a generated GoMock package.
mock/github.com/aws/aws-sdk-go/aws/credentials
Package mock_credentials is a generated GoMock package.
Package mock_credentials is a generated GoMock package.
Package credscache provides credentials caching utilities for the AWS SDK for Go v1.
Package credscache provides credentials caching utilities for the AWS SDK for Go v1.
Package credscache provides credentials caching utilities for the AWS SDK for Go v2.
Package credscache provides credentials caching utilities for the AWS SDK for Go v2.

Jump to

Keyboard shortcuts

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