credentials

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package credentials handles fetching and formatting AWS temporary credentials.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDisplay

func FormatDisplay(creds *AWSCredentials, profileName string) string

FormatDisplay returns a styled string showing credentials in a readable format.

func FormatExportCommands

func FormatExportCommands(creds *AWSCredentials, profileName string) string

FormatExportCommands returns shell export commands for the credentials.

Types

type AWSCredentials

type AWSCredentials struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
	Expiration      time.Time
}

AWSCredentials holds temporary AWS credentials.

func GetCredentials

func GetCredentials(
	ctx context.Context,
	client SSOClient,
	accessToken string,
	accountID string,
	roleName string,
) (*AWSCredentials, error)

GetCredentials fetches temporary AWS credentials for the given account and role.

type DiscoveredAccount

type DiscoveredAccount struct {
	AccountID   string
	AccountName string
	Email       string
}

DiscoveredAccount holds account info returned from SSO ListAccounts.

func ListAccounts

func ListAccounts(ctx context.Context, client SSOClient, accessToken string) ([]DiscoveredAccount, error)

ListAccounts discovers all AWS accounts accessible with the given SSO token. It handles pagination automatically, returning all accounts in a single slice.

type DiscoveredRole

type DiscoveredRole struct {
	AccountID string
	RoleName  string
}

DiscoveredRole holds role info returned from SSO ListAccountRoles.

func ListAccountRoles

func ListAccountRoles(ctx context.Context, client SSOClient, accessToken string, accountID string) ([]DiscoveredRole, error)

ListAccountRoles discovers all roles available for the given account. It handles pagination automatically, returning all roles in a single slice.

type SSOClient

type SSOClient interface {
	GetRoleCredentials(ctx context.Context, params *sso.GetRoleCredentialsInput, optFns ...func(*sso.Options)) (*sso.GetRoleCredentialsOutput, error)
	ListAccounts(ctx context.Context, params *sso.ListAccountsInput, optFns ...func(*sso.Options)) (*sso.ListAccountsOutput, error)
	ListAccountRoles(ctx context.Context, params *sso.ListAccountRolesInput, optFns ...func(*sso.Options)) (*sso.ListAccountRolesOutput, error)
}

SSOClient defines the interface for SSO operations (for testability).

func NewSSOClient

func NewSSOClient(ctx context.Context, region string) (SSOClient, error)

NewSSOClient creates a real SSO client for the given region. It loads the default AWS config internally. If you already have a loaded aws.Config, use NewSSOClientFromConfig instead to avoid duplicate loads.

func NewSSOClientFromConfig

func NewSSOClientFromConfig(cfg aws.Config) SSOClient

NewSSOClientFromConfig creates a real SSO client from a pre-loaded AWS config. It configures adaptive retry mode with up to 10 attempts to handle API rate limiting (HTTP 429) when discovering roles across many accounts.

Jump to

Keyboard shortcuts

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