Documentation
¶
Overview ¶
Default AWS SSO configuration constants used for generating properly formatted config files with standard attributes.
Package setlist provides utilities for managing AWS SSO configurations.
It simplifies the process of generating AWS CLI configuration files for organizations using AWS SSO by parsing AWS Organizations and Permission Sets to build a complete .aws/config file with all permission sets provisioned across AWS member accounts.
The package includes functionality for AWS API interactions, config file generation, nickname mapping for accounts, and structured error handling.
Index ¶
- Constants
- Variables
- func AllPermissionSets(ctx context.Context, client SSOAdminClient, instanceArn string) ([]types.PermissionSet, error)
- func FilterAccounts(accounts []orgtypes.Account, include, exclude []AWSAccountId) ([]orgtypes.Account, error)
- func FilterPermissionSets(permissionSets []ssotypes.PermissionSet, include, exclude []string) ([]ssotypes.PermissionSet, error)
- func ListAccounts(ctx context.Context, client OrganizationsClient) ([]types.Account, error)
- func ListPermissionsRequired() []string
- func ParseNicknameMapping(mapping string) (map[string]string, error)
- func ParsePermissionSetList(s string) ([]string, error)
- func PermissionSets(ctx context.Context, client SSOAdminClient, instanceArn string, ...) ([]types.PermissionSet, error)
- func SsoInstance(ctx context.Context, client SSOAdminClient) (types.InstanceMetadata, error)
- type AWSAccountId
- type ConfigFile
- type FileBuilder
- type GenerateInput
- type HTTPDoer
- type IdentityStoreId
- type OrganizationsClient
- type Profile
- type ProfileDescription
- type ProfileName
- type Region
- type ReleaseInfo
- type RoleName
- type SSOAdminClient
- type SessionDuration
- type SessionName
- type UpdateInfo
Constants ¶
const DefaultNicknamePrefix string = "NoNickname"
DefaultNicknamePrefix defines the prefix used for accounts without explicit nicknames.
const (
// GithubAPI is the URL to check for the latest release
GithubAPI = "https://api.github.com/repos/scottbrown/setlist/releases/latest"
)
const SSOAccountIdKey string = "sso_account_id"
SSOAccountIdKey is the key used for specifying the AWS account ID in a profile.
const SSORegionKey string = "sso_region"
SSORegionKey is the attribute key for specifying the AWS region.
const SSORegistrationScopesKey string = "sso_registration_scopes"
SSORegistrationScopesKey defines the key for SSO registration scopes.
const SSORegistrationScopesValue string = "sso:account:access"
SSORegistrationScopesValue defines the default value for SSO registration scopes.
const SSORoleNameKey string = "sso_role_name"
SSORoleNameKey is the key used for defining the IAM role name.
const SSOSessionAttrKey string = "sso_session"
SSOSessionAttrKey is the attribute key for storing the SSO session name.
const SSOSessionSectionKey string = "sso-session"
SSOSessionSectionKey is the key used for defining an SSO session in configuration files.
const SSOStartUrlKey string = "sso_start_url"
SSOStartUrlKey is the attribute key for the AWS SSO start URL.
Variables ¶
var AccountIdPattern = regexp.MustCompile("^[0-9]{12}$")
var ErrEmptyString = errors.New("cannot be an empty string")
var ErrInvalidAWSAccountIdLength = fmt.Errorf("invalid length for AWS account id")
var ErrMutuallyExclusiveFilters = errors.New("include and exclude filters are mutually exclusive")
var ErrWrongFormat = errors.New("invalid format")
var VERSION = "1.2.1"
VERSION defines the current version of the Setlist application. This is displayed in the CLI help output and used in release artifacts.
Functions ¶
func AllPermissionSets ¶ added in v1.3.0
func AllPermissionSets(ctx context.Context, client SSOAdminClient, instanceArn string) ([]types.PermissionSet, error)
AllPermissionSets retrieves all permission sets defined in an SSO instance. It paginates through the ListPermissionSets API to collect all ARNs, then calls DescribePermissionSet for each to get the full details.
func FilterAccounts ¶ added in v1.3.0
func FilterAccounts(accounts []orgtypes.Account, include, exclude []AWSAccountId) ([]orgtypes.Account, error)
FilterAccounts filters a list of AWS accounts based on include and exclude lists. If include is non-empty, only accounts in the include list are returned. If exclude is non-empty, accounts in the exclude list are removed. Setting both include and exclude is an error.
func FilterPermissionSets ¶ added in v1.3.0
func FilterPermissionSets(permissionSets []ssotypes.PermissionSet, include, exclude []string) ([]ssotypes.PermissionSet, error)
FilterPermissionSets filters a list of permission sets based on include and exclude lists. If include is non-empty, only permission sets whose name appears in the include list are returned. If exclude is non-empty, permission sets whose name appears in the exclude list are removed. Setting both include and exclude is an error.
func ListAccounts ¶
ListAccounts retrieves all accounts within an AWS Organization using the provided Organizations client. It handles pagination automatically to ensure all accounts are retrieved, even when the organization contains a large number of accounts. The function respects context cancellation for proper timeout handling.
func ListPermissionsRequired ¶ added in v1.2.0
func ListPermissionsRequired() []string
ListPermissionsRequired returns a slice of AWS IAM permission strings that are required for this application to function correctly. These permissions are needed to access AWS Organizations and SSO Admin APIs.
func ParseNicknameMapping ¶
ParseNicknameMapping parses a comma-delimited string of account ID to nickname mappings into a map. The expected format is "accountID1=nickname1,accountID2=nickname2". This enables users to reference AWS accounts by friendly names rather than numeric IDs. The function validates the format and returns appropriate errors for malformed input.
func ParsePermissionSetList ¶ added in v1.3.0
ParsePermissionSetList parses a comma-delimited string of permission set names into a slice of strings. Empty tokens are skipped and whitespace is trimmed.
func PermissionSets ¶
func PermissionSets(ctx context.Context, client SSOAdminClient, instanceArn string, accountId string) ([]types.PermissionSet, error)
PermissionSets retrieves the list of permission sets provisioned to an account.
func SsoInstance ¶
func SsoInstance(ctx context.Context, client SSOAdminClient) (types.InstanceMetadata, error)
SsoInstance retrieves the AWS SSO instance metadata from the AWS account. AWS SSO allows only a single instance per organization, so this function returns the first (and only) instance found. It validates that required fields exist in the response and returns an error if the SSO service is not properly configured.
Types ¶
type AWSAccountId ¶ added in v1.3.0
type AWSAccountId string
func NewAWSAccountId ¶ added in v1.3.0
func NewAWSAccountId(id string) (AWSAccountId, error)
func ParseAccountIdList ¶ added in v1.3.0
func ParseAccountIdList(s string) ([]AWSAccountId, error)
ParseAccountIdList parses a comma-delimited string of AWS account IDs into a slice of AWSAccountId. Each ID is validated against the expected 12-digit format.
func (AWSAccountId) String ¶ added in v1.3.0
func (aai AWSAccountId) String() string
type ConfigFile ¶
type ConfigFile struct {
SessionName string // Name of the SSO session
IdentityStoreId IdentityStoreId // The unique identity store ID
FriendlyName string // Alt name used for the SSO instance
Region Region // AWS region
Profiles []Profile // List of AWS profiles
NicknameMapping map[string]string // Mapping of account IDs to nicknames
}
ConfigFile represents the structure of an AWS CLI configuration file, including session details, profiles, and nickname mappings. It contains all the information needed to generate a complete AWS config file for use with AWS SSO authentication.
func Generate ¶ added in v1.3.0
func Generate(ctx context.Context, input GenerateInput) (ConfigFile, error)
Generate orchestrates the full config file generation workflow. It retrieves the SSO instance, lists and filters accounts, gathers permission sets, and assembles a ConfigFile ready for output.
func (ConfigFile) HasNickname ¶
func (c ConfigFile) HasNickname(accountId string) bool
HasNickname determines whether an account has a mapped nickname.
func (*ConfigFile) StartURL ¶
func (c *ConfigFile) StartURL() string
StartURL constructs the AWS SSO start URL based on the IdentityStoreId or FriendlyName.
type FileBuilder ¶
type FileBuilder struct {
Config ConfigFile
}
FileBuilder is responsible for generating an INI-formatted configuration file based on the provided AWS SSO configuration. It handles creating sections for the default profile, SSO session, and individual profiles.
func NewFileBuilder ¶
func NewFileBuilder(configFile ConfigFile) FileBuilder
NewFileBuilder creates a new FileBuilder instance with the given configuration.
func (*FileBuilder) Build ¶
func (f *FileBuilder) Build() (*ini.File, error)
Build generates an INI file based on the configuration. It adds a default section, an SSO section, and profile sections for each configured profile. If a nickname mapping exists, it creates an additional profile section for the nickname.
type GenerateInput ¶ added in v1.3.0
type GenerateInput struct {
SSOClient SSOAdminClient
OrgClient OrganizationsClient
SessionName string
Region string
FriendlyName string
NicknameMapping string
IncludeAccounts string
ExcludeAccounts string
IncludePermissionSets string
ExcludePermissionSets string
}
GenerateInput holds all the parameters needed to generate an AWS config file.
type IdentityStoreId ¶ added in v1.3.0
type IdentityStoreId string
func NewIdentityStoreId ¶ added in v1.3.0
func NewIdentityStoreId(id string) (IdentityStoreId, error)
func (IdentityStoreId) String ¶ added in v1.3.0
func (i IdentityStoreId) String() string
type OrganizationsClient ¶ added in v1.2.0
type OrganizationsClient interface {
ListAccounts(ctx context.Context, params *organizations.ListAccountsInput, optFns ...func(*organizations.Options)) (*organizations.ListAccountsOutput, error)
}
Define interface for the Organizations client to make testing easier
type Profile ¶
type Profile struct {
Name ProfileName
Description ProfileDescription
SessionDuration SessionDuration
SessionName SessionName
AccountId AWSAccountId
RoleName RoleName
}
Profile represents an AWS SSO profile configuration. It stores information about a permission set, including its metadata and the account it belongs to. This is used to generate AWS CLI profile configurations in the output file.
type ProfileDescription ¶ added in v1.3.0
type ProfileDescription string
func NewProfileDescription ¶ added in v1.3.0
func NewProfileDescription(desc string) (ProfileDescription, error)
func (ProfileDescription) String ¶ added in v1.3.0
func (pd ProfileDescription) String() string
type ProfileName ¶ added in v1.3.0
type ProfileName string
func NewProfileName ¶ added in v1.3.0
func NewProfileName(name string) (ProfileName, error)
func (ProfileName) String ¶ added in v1.3.0
func (pn ProfileName) String() string
type ReleaseInfo ¶ added in v1.3.0
type ReleaseInfo struct {
TagName string `json:"tag_name"`
Name string `json:"name"`
PublishedAt time.Time `json:"published_at"`
HTMLURL string `json:"html_url"`
}
ReleaseInfo represents the GitHub API response for a release
type SSOAdminClient ¶ added in v1.2.0
type SSOAdminClient interface {
ListInstances(ctx context.Context, params *ssoadmin.ListInstancesInput, optFns ...func(*ssoadmin.Options)) (*ssoadmin.ListInstancesOutput, error)
ListPermissionSets(ctx context.Context, params *ssoadmin.ListPermissionSetsInput, optFns ...func(*ssoadmin.Options)) (*ssoadmin.ListPermissionSetsOutput, error)
ListPermissionSetsProvisionedToAccount(ctx context.Context, params *ssoadmin.ListPermissionSetsProvisionedToAccountInput, optFns ...func(*ssoadmin.Options)) (*ssoadmin.ListPermissionSetsProvisionedToAccountOutput, error)
DescribePermissionSet(ctx context.Context, params *ssoadmin.DescribePermissionSetInput, optFns ...func(*ssoadmin.Options)) (*ssoadmin.DescribePermissionSetOutput, error)
}
Define interface for the SSO Admin client to make testing easier
type SessionDuration ¶ added in v1.3.0
type SessionDuration string
func NewSessionDuration ¶ added in v1.3.0
func NewSessionDuration(duration string) (SessionDuration, error)
func (SessionDuration) String ¶ added in v1.3.0
func (sd SessionDuration) String() string
type SessionName ¶ added in v1.3.0
type SessionName string
func NewSessionName ¶ added in v1.3.0
func NewSessionName(name string) (SessionName, error)
func (SessionName) String ¶ added in v1.3.0
func (sn SessionName) String() string
type UpdateInfo ¶ added in v1.3.0
type UpdateInfo struct {
CurrentVersion string
LatestVersion string
ReleaseURL string
ReleaseDate time.Time
}
UpdateInfo contains information about an available update
func CheckForUpdates ¶ added in v1.3.0
func CheckForUpdates(ctx context.Context, client HTTPDoer) (*UpdateInfo, error)
CheckForUpdates compares the current version with the latest release and returns information about a newer version if available