ecs

package
v0.0.67 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AWS_REGION                             = "AWS_REGION"
	AWS_DEFAULT_REGION                     = "AWS_DEFAULT_REGION"
	AWS_CONTAINER_CREDENTIALS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
)

env keys

View Source
const (
	DefaultMetadataEndpointHost = "http://169.254.170.2"
)

defaults

Variables

View Source
var (
	ErrUnableToDetermineAwsRegion                    = errors.New("unable to determine AWS region")
	ErrUnableToGetAwsCredentials                     = errors.New("unable to get AWS credentials")
	ErrEnvAwsContainerCredentialsRelativeURIIsNotSet = errors.New(fmt.Sprintf("env %s is not set", AWS_CONTAINER_CREDENTIALS_RELATIVE_URI)) //nolint:revive,gosimple // because the return types of errors.New and fmt.Errorf are not the same, and I explicitly choose to use errors.New.
)

errors

View Source
var (
	DefaultTokenSourceConfigScopes = []string{"https://www.googleapis.com/auth/cloud-platform"}
)

defaults

Functions

func CredentialsFromJSON

func CredentialsFromJSON(ctx context.Context, jsonData []byte, opts ...CredentialsFromJSONOption) (*google.Credentials, error)

func NewTokenSource

func NewTokenSource(ctx context.Context, jsonData []byte, opts ...TokenSourceOption) (oauth2.TokenSource, error)

NewTokenSource creates a new token source from Google Workload Identity Federation JSON configuration.

The documentation here mentions the method of Workload Identity Federation using EC2 Instance Metadata, but it does not mention the method of Federation using ECS Metadata. Additionally, golang.org/x/oauth2/google/externalaccount does not support ECS Metadata by default. Therefore, it is possible to enable Federation using ECS Metadata by implementing the golang.org/x/oauth2/google/externalaccount.AwsSecurityCredentialsSupplier interface and replacing it in the Config.

example:

data, _ := os.ReadFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
ts, _ := NewTokenSource(ctx, data)
client, _ := storage.NewClient(ctx, option.WithCredentials(&google.Credentials{TokenSource: ts}))

func TokenSourceConfigFromJSON

func TokenSourceConfigFromJSON(jsonData []byte, opts ...TokenSourceOption) (*externalaccount.Config, error)

TokenSourceConfigFromJSON creates a new token source config from Google Workload Identity Federation JSON configuration.

The documentation here mentions the method of Workload Identity Federation using EC2 Instance Metadata, but it does not mention the method of Federation using ECS Metadata. Additionally, golang.org/x/oauth2/google/externalaccount does not support ECS Metadata by default. Therefore, it is possible to enable Federation using ECS Metadata by implementing the golang.org/x/oauth2/google/externalaccount.AwsSecurityCredentialsSupplier interface and replacing it in the Config.

example:

data, _ := os.ReadFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
cfg, _ := TokenSourceConfigFromJSON(data)
ts, _ := externalaccount.NewTokenSource(ctx, cfg)
client, _ := storage.NewClient(ctx, option.WithCredentials(&google.Credentials{TokenSource: ts}))

Types

type AwsEcsSecurityCredentialsSupplier

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

AwsEcsSecurityCredentialsSupplier is a supplier for AWS security credentials.

func (*AwsEcsSecurityCredentialsSupplier) AwsRegion

func (*AwsEcsSecurityCredentialsSupplier) AwsSecurityCredentials

type CredentialsFromJSONOption

type CredentialsFromJSONOption interface {
	// contains filtered or unexported methods
}

func WithCredentialsFromJSONOptionParams

func WithCredentialsFromJSONOptionParams(params google.CredentialsParams) CredentialsFromJSONOption

WithCredentialsFromJSONOptionParams sets the google.CredentialsParams for google.CredentialsFromJSONWithParams.

func WithCredentialsFromJSONOptionTokenSourceConfigOptions

func WithCredentialsFromJSONOptionTokenSourceConfigOptions(tokenSourceConfigOptions ...TokenSourceOption) CredentialsFromJSONOption

WithCredentialsFromJSONOptionTokenSourceConfigOptions sets the TokenSourceConfigOption for the credentials. This allows customization of the token source configuration when creating credentials from JSON.

type CredentialsFromJSONOptionParams

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

type CredentialsFromJSONOptionTokenSourceConfigOption

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

type TokenSourceConfigOptionAwsContainerCredentialsRelativeURI

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

type TokenSourceConfigOptionAwsEcsMetadataEndpointHost

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

type TokenSourceConfigOptionDefaultAwsRegion

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

type TokenSourceConfigOptionHTTPClient

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

type TokenSourceConfigOptionScopes

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

type TokenSourceOption

type TokenSourceOption interface {
	// contains filtered or unexported methods
}

func WithTokenSourceOptionAwsContainerCredentialsRelativeURI

func WithTokenSourceOptionAwsContainerCredentialsRelativeURI(uri string) TokenSourceOption

WithTokenSourceOptionAwsContainerCredentialsRelativeURI sets the AWS container credentials relative URI.

func WithTokenSourceOptionAwsEcsMetadataEndpointHost

func WithTokenSourceOptionAwsEcsMetadataEndpointHost(host string) TokenSourceOption

WithTokenSourceOptionAwsEcsMetadataEndpointHost sets the AWS ECS Metadata Endpoint host.

func WithTokenSourceOptionDefaultAwsRegion

func WithTokenSourceOptionDefaultAwsRegion(region string) TokenSourceOption

WithTokenSourceOptionDefaultAwsRegion sets the default AWS region.

func WithTokenSourceOptionHTTPClient

func WithTokenSourceOptionHTTPClient(httpClient *http.Client) TokenSourceOption

WithTokenSourceOptionHTTPClient sets the HTTP client to be used by the AwsEcsSecurityCredentialsSupplier. This allows for custom configurations such as timeouts, transport settings, and other HTTP client options.

func WithTokenSourceOptionScopes

func WithTokenSourceOptionScopes(scopes []string) TokenSourceOption

WithTokenSourceOptionScopes sets the scopes.

Jump to

Keyboard shortcuts

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