Documentation ¶
Index ¶
- Constants
- func EnsureManagementAccountIdMatchesDisk(managementAccountId string) error
- func Getenv() (creds aws.Credentials)
- func NewAccountNotFound(tags ...string) error
- func Setenv(creds aws.Credentials) (err error)
- func WriteManagementAccountIdToDisk(managementAccountId string) error
- type Account
- func (a *Account) AdministratorRoleName() string
- func (a *Account) Config(ctx context.Context, cfg *Config, roleName string, duration time.Duration) (*Config, error)
- func (a *Account) MarshalJSON() ([]byte, error)
- func (a *Account) Quality() (quality string, err error)
- func (a *Account) String() string
- type AccountNotFound
- type Config
- func (c *Config) ACM() *acm.Client
- func (c *Config) APIGateway() *apigateway.Client
- func (c *Config) APIGatewayV2() *apigatewayv2.Client
- func (c *Config) AccountId(ctx context.Context) (string, error)
- func (c *Config) AssumeManagementRole(ctx context.Context, roleName string, duration time.Duration) (*Config, error)
- func (c *Config) AssumeRole(ctx context.Context, accountId string, roleName string, duration time.Duration) (*Config, error)
- func (c *Config) AssumeRoleARN(ctx context.Context, roleARN string, duration time.Duration) (*Config, error)
- func (c *Config) AssumeServiceRole(ctx context.Context, domain, environment, quality string, roleName string, ...) (*Config, error)
- func (c *Config) AssumeSpecialRole(ctx context.Context, name string, roleName string, duration time.Duration) (*Config, error)
- func (c *Config) AssumeSubstrateRole(ctx context.Context, roleName string, duration time.Duration) (*Config, error)
- func (c *Config) BootstrapCredentials(ctx context.Context) (callerIdentity *sts.GetCallerIdentityOutput, err error)
- func (c *Config) ClearCachedAccounts() error
- func (c *Config) CloudFront() *cloudfront.Client
- func (c *Config) CloudTrail() *cloudtrail.Client
- func (c *Config) CloudWatchLogs() *cloudwatchlogs.Client
- func (c *Config) Copy() *Config
- func (c *Config) DescribeOrganization(ctx context.Context) (*Organization, error)
- func (c *Config) DynamoDB() *dynamodb.Client
- func (c *Config) EC2() *ec2.Client
- func (c *Config) FindAccount(ctx context.Context, f func(*Account) bool) (*Account, error)
- func (c *Config) FindAccounts(ctx context.Context, f func(*Account) bool) (accounts []*Account, err error)
- func (c *Config) FindAdminAccount(ctx context.Context, quality string) (*Account, error)
- func (c *Config) FindAdminAccounts(ctx context.Context) ([]*Account, error)
- func (c *Config) FindManagementAccount(ctx context.Context) (*Account, error)
- func (c *Config) FindServiceAccount(ctx context.Context, domain, environment, quality string) (*Account, error)
- func (c *Config) FindSpecialAccount(ctx context.Context, name string) (*Account, error)
- func (c *Config) FindSubstrateAccount(ctx context.Context) (*Account, error)
- func (c *Config) GetCallerIdentity(ctx context.Context) (*sts.GetCallerIdentityOutput, error)
- func (c *Config) IAM() *iam.Client
- func (c *Config) Identity(ctx context.Context) (*Identity, error)
- func (c *Config) IdentityStore() *identitystore.Client
- func (c *Config) Lambda() *lambda.Client
- func (c *Config) ListAccounts(ctx context.Context) (accounts []*Account, err error)
- func (c *Config) MustAccountId(ctx context.Context) string
- func (c *Config) MustDescribeOrganization(ctx context.Context) *Organization
- func (c *Config) MustGetCallerIdentity(ctx context.Context) *sts.GetCallerIdentityOutput
- func (c *Config) OrganizationReader(ctx context.Context) (*Config, error)
- func (c *Config) Organizations() *organizations.Client
- func (c *Config) RAM() *ram.Client
- func (c *Config) Region() string
- func (c *Config) Regional(region string) *Config
- func (c *Config) Retrieve(ctx context.Context) (aws.Credentials, error)
- func (c *Config) Route53() *route53.Client
- func (c *Config) S3() *s3.Client
- func (c *Config) SSO() *sso.Client
- func (c *Config) SSOAdmin() *ssoadmin.Client
- func (c *Config) STS() *sts.Client
- func (c *Config) SecretsManager() *secretsmanager.Client
- func (c *Config) ServiceQuotas() *servicequotas.Client
- func (c *Config) SetCredentials(ctx context.Context, creds aws.Credentials) (callerIdentity *sts.GetCallerIdentityOutput, err error)
- func (c *Config) Tags(ctx context.Context) (tagging.Map, error)
- func (c *Config) Telemetry() *telemetry.Event
- func (c *Config) WaitUntilCredentialsWork(ctx context.Context) (callerIdentity *sts.GetCallerIdentityOutput, err error)
- type Identity
- type ManagementAccountMismatchError
- type NonManagementAccountError
- type Organization
- type OrganizationReaderError
Constants ¶
const ( CachedOrganizationFilename = ".substrate.organization.json" // cached on disk (obviously) TooManyRequestsException = "TooManyRequestsException" UnrecognizedClientException = "UnrecognizedClientException" )
const ( AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID" AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY" AWS_SESSION_TOKEN = "AWS_SESSION_TOKEN" SUBSTRATE_CREDENTIALS_EXPIRATION = "SUBSTRATE_CREDENTIALS_EXPIRATION" )
const ( AWSOrganizationsNotInUseException = "AWSOrganizationsNotInUseException" AccessDenied = "AccessDenied" )
const ( AccountsFilename = "substrate.accounts.txt" CachedAccountsFilename = ".substrate.accounts.json" // cached on disk (obviously) MemoizedAccountsTTL = time.Hour // memoized in memory )
const ( ManagementAccountIdFilename = "substrate.management-account-id" OldManagementAccountIdFilename = "substrate.master-account-id" )
const WaitUntilCredentialsWorkTries = 18 // approximately seconds; API Gateway won't wait longer than 29 seconds, anyway
Variables ¶
This section is empty.
Functions ¶
func Getenv ¶
func Getenv() (creds aws.Credentials)
func NewAccountNotFound ¶
func Setenv ¶
func Setenv(creds aws.Credentials) (err error)
Types ¶
type Account ¶
func (*Account) AdministratorRoleName ¶
func (*Account) MarshalJSON ¶
type AccountNotFound ¶
type AccountNotFound string
func (AccountNotFound) Error ¶
func (err AccountNotFound) Error() string
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func (*Config) APIGateway ¶
func (c *Config) APIGateway() *apigateway.Client
func (*Config) APIGatewayV2 ¶
func (c *Config) APIGatewayV2() *apigatewayv2.Client
func (*Config) AssumeManagementRole ¶
func (c *Config) AssumeManagementRole( ctx context.Context, roleName string, duration time.Duration, ) (*Config, error)
AssumeManagementRole assumes the given role in the organization's management account. It can only be called on a *Config with the Administrator role in an admin account, Substrate role or user in the Substrate account, or the OrganizationAdministrator or Substrate role or user already in the management account. The duration parameter is limited to an AWS-enforced maximum of 3600 when the *Config receiving the call has a role instead of a user, which is called role chaining. See <https://aws.amazon.com/premiumsupport/knowledge-center/iam-role-chaining-limit/> for more information.
func (*Config) AssumeRole ¶
func (c *Config) AssumeRole( ctx context.Context, accountId string, roleName string, duration time.Duration, ) (*Config, error)
AssumeRole assumes the given role in the given account and returns a new *Config there. It can be called on any *Config but is most often (and most effectively) called on one with the Administrator role in an admin account, the Substrate role or user in the Substrate account, or the OrganizationAdministrator or Substrate role or user in the management account.
func (*Config) AssumeRoleARN ¶
func (*Config) AssumeServiceRole ¶
func (c *Config) AssumeServiceRole( ctx context.Context, domain, environment, quality string, roleName string, duration time.Duration, ) (*Config, error)
AssumeServiceRole assumes the given role in the service account identified by the given domain, environment, and quality. It can be called on any *Config but is most often (and most effectively) called on one with the Administrator role in an admin account, the Substrate role or user in the Substrate account, or the OrganizationAdministrator or Substrate role or user in the management account.
func (*Config) AssumeSpecialRole ¶
func (c *Config) AssumeSpecialRole( ctx context.Context, name string, roleName string, duration time.Duration, ) (*Config, error)
AssumeSpecialRole assumes the given role in the named special account. It can be called on any *Config but is most often (and most effectively) called on one with the Administrator role in an admin account, the Substrate role or user in the Substrate account, or the OrganizationAdministrator or Substrate role or user in the management account.
func (*Config) AssumeSubstrateRole ¶
func (c *Config) AssumeSubstrateRole( ctx context.Context, roleName string, duration time.Duration, ) (*Config, error)
AssumeSubstrateRole assumes the given role in the Substrate account. It can be called on any *Config but is most often (and most effectively) called from Administrator or Substrate in the Substrate account or OrganizationAdministrator or Substrate in the management account. It's for times when you want to be sure you're in the Substrate account.
func (*Config) BootstrapCredentials ¶
func (*Config) ClearCachedAccounts ¶
func (*Config) CloudFront ¶
func (c *Config) CloudFront() *cloudfront.Client
func (*Config) CloudTrail ¶
func (c *Config) CloudTrail() *cloudtrail.Client
func (*Config) CloudWatchLogs ¶
func (c *Config) CloudWatchLogs() *cloudwatchlogs.Client
func (*Config) DescribeOrganization ¶
func (c *Config) DescribeOrganization(ctx context.Context) (*Organization, error)
func (*Config) FindAccount ¶
FindAccount returns the first *Account for which the given acceptance test function returns true. This may be called from any account.
func (*Config) FindAccounts ¶
func (c *Config) FindAccounts( ctx context.Context, f func(*Account) bool, ) (accounts []*Account, err error)
FindAccounts returns all []*Account for which the given acceptance test function returns true. This may be called from any account. We expect to find an account that matches so if we don't we remove the cache file and try once more.
func (*Config) FindAdminAccount ¶
FindAdminAccount returns the *Account for the admin account with the given quality. This may be called from any account.
func (*Config) FindAdminAccounts ¶
FindAdminAccounts returns an *Account for every admin account. This will, in practice, never return more than one account, but it does so without the caller having to know the quality ahead of time. Thankfully, it's also deprecated the moment it's introduced since admin accounts are going away in favor of the singular and simplified Substrate account. This may be called from any account.
func (*Config) FindManagementAccount ¶
FindManagementAccount returns the *Account for the management account. This may be called from any account.
func (*Config) FindServiceAccount ¶
func (c *Config) FindServiceAccount(ctx context.Context, domain, environment, quality string) (*Account, error)
FindServiceAccount returns the *Account for the admin account with the given domain, environment, and quality. This may be called from any account.
func (*Config) FindSpecialAccount ¶
FindSpecialAccount returns the *Account for the admin account with the given name. This may be called from any account.
func (*Config) FindSubstrateAccount ¶
FindSubstrateAccount returns the *Account for the Substrate account or nil (with a nil error) if the organization has not yet run `substrate setup`. This may be called from any account.
func (*Config) GetCallerIdentity ¶
func (*Config) IdentityStore ¶
func (c *Config) IdentityStore() *identitystore.Client
func (*Config) ListAccounts ¶
ListAccounts returns all the accounts in the organization in a single slice. For a higher-level interface, see accounts.Grouped. This may be called from any account.
func (*Config) MustDescribeOrganization ¶
func (c *Config) MustDescribeOrganization(ctx context.Context) *Organization
func (*Config) MustGetCallerIdentity ¶
func (c *Config) MustGetCallerIdentity(ctx context.Context) *sts.GetCallerIdentityOutput
func (*Config) OrganizationReader ¶
func (*Config) Organizations ¶
func (c *Config) Organizations() *organizations.Client
func (*Config) SecretsManager ¶
func (c *Config) SecretsManager() *secretsmanager.Client
func (*Config) ServiceQuotas ¶
func (c *Config) ServiceQuotas() *servicequotas.Client
func (*Config) SetCredentials ¶
func (c *Config) SetCredentials( ctx context.Context, creds aws.Credentials, ) ( callerIdentity *sts.GetCallerIdentityOutput, err error, )
SetCredentials reconfigures the receiver to use the given credentials (whether root, user, or session credentials) and waits until they begin working (which concerns mostly user credentials). It returns the caller identity because it's already gone to the trouble of getting it and callers often need it right afterward, anyway.
func (*Config) WaitUntilCredentialsWork ¶
func (c *Config) WaitUntilCredentialsWork(ctx context.Context) ( callerIdentity *sts.GetCallerIdentityOutput, err error, )
WaitUntilCredentialsWork waits in a sleeping loop until the configured credentials (whether provided via SetCredentials or discovered in environment variables or an IAM instance profile) work, which it tests using both sts:GetCallerIdentity and organizations:DescribeOrganization. This seems silly but IAM is an eventually consistent global service so it's not guaranteed that newly created credentials will work immediately. In fact, even just testing via sts:GetCallerIdentity is demonstrably not good enough as `substrate setup`, when run with root credentials, will fail a significant fraction of the time because, though sts:GetCallerIdentity succeeded, the credentials haven't yet become visible to other services. Thus, organizations:DescribeOrganization was chosen as a second test to ensure the credentials really, actually work. Typically when this has to wait it waits about five seconds.
type ManagementAccountMismatchError ¶
type ManagementAccountMismatchError string
func (ManagementAccountMismatchError) Error ¶
func (err ManagementAccountMismatchError) Error() string
type NonManagementAccountError ¶
type NonManagementAccountError struct {
// contains filtered or unexported fields
}
func (NonManagementAccountError) Error ¶
func (err NonManagementAccountError) Error() string
type Organization ¶
type Organization = types.Organization
type OrganizationReaderError ¶
type OrganizationReaderError struct {
// contains filtered or unexported fields
}
func NewOrganizationReaderError ¶
func NewOrganizationReaderError(err error, roleName string) *OrganizationReaderError
func (*OrganizationReaderError) Err ¶
func (err *OrganizationReaderError) Err() error
func (*OrganizationReaderError) Error ¶
func (err *OrganizationReaderError) Error() string