Documentation
¶
Index ¶
- type AuthenticationToken
- type Config
- func (c *Config) ClearCache() error
- func (c *Config) DeviceFlow(ctx context.Context) (oauth2.TokenSource, *oauth2.Token, error)
- func (c *Config) LoadCache(ctx context.Context) (oauth2.TokenSource, *oauth2.Token, error)
- func (c *Config) OAuth2Config() *oauth2.Config
- func (c *Config) PKCE(ctx context.Context) (oauth2.TokenSource, *oauth2.Token, error)
- func (c *Config) PollDeviceFlow(ctx context.Context, resp *oauth2.DeviceAuthResponse) (oauth2.TokenSource, error)
- func (c *Config) Process()
- func (c *Config) SaveCache(token *oauth2.Token) error
- func (c *Config) StartDeviceFlow(ctx context.Context) (*oauth2.DeviceAuthResponse, error)
- func (c *Config) Token(ctx context.Context) (oauth2.TokenSource, error)
- func (c *Config) TokenFromCache(ctx context.Context) oauth2.TokenSource
- type ExternalConfig
- type InternalConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthenticationToken ¶
type AuthenticationToken string
AuthenticationToken is a token source that returns a constant token with the given value. This should be used for Service Account Tokens and Personal Access Tokens, so the rest of the CLI doesn't know the difference between what style of auth is being used.
type Config ¶
type Config struct {
InternalConfig
ExternalConfig
Environment string `flagvalue:"environment"`
// contains filtered or unexported fields
}
Config contains the configuration for authenticating with Infracost.
func (*Config) ClearCache ¶
func (*Config) DeviceFlow ¶
func (*Config) OAuth2Config ¶
OAuth2Config returns the OAuth2 config for authenticating with Auth0.
func (*Config) PollDeviceFlow ¶
func (c *Config) PollDeviceFlow(ctx context.Context, resp *oauth2.DeviceAuthResponse) (oauth2.TokenSource, error)
PollDeviceFlow is used by the LSP to poll for the token after StartDeviceFlow has been called. If the user has not completed the device flow, this function will return nil, nil, nil. If the user has completed the device flow and a token is available, this function will return a token source that can be used for authenticated requests. If there is an error during polling (e.g. network error), this function will return an error.
func (*Config) StartDeviceFlow ¶
StartDeviceFlow is used by the LSP which needs to start the device flow but cannot block waiting for the token. The caller is expected to call PollDeviceFlow The LSP will call PollDeviceFlow in a loop until it returns a token source, at which point the LSP can use the token source for authenticated requests. If PollDeviceFlow returns an error, the LSP should log the error and stop polling.
func (*Config) Token ¶
Token will attempt to retrieve an access token. If there is no cached token, or the cached token cannot be refreshed, then this function will prompt the user to log in.
func (*Config) TokenFromCache ¶
func (c *Config) TokenFromCache(ctx context.Context) oauth2.TokenSource
TokenFromCache will also attempt to retrieve an access token, like Token. But, it will not attempt to log in if there is no token or it could not be refreshed and will instead return a nil token source.
This function allows reuse of an earlier login attempt without risking the log in flow launching when the caller requires a non-interactive prompt (such as when logging errors).
type ExternalConfig ¶
type ExternalConfig struct {
// AuthenticationToken is an optional authentication token to use for authentication instead of requiring the
// user to authenticate with Auth0.
AuthenticationToken AuthenticationToken `env:"INFRACOST_CLI_AUTHENTICATION_TOKEN"`
// UseDeviceFlow indicates whether to use the device flow for authentication.
UseDeviceFlow bool `` /* 179-byte string literal not displayed */
// UseAccessTokenCache indicates whether to use the token cache for authentication.
UseAccessTokenCache bool `` /* 141-byte string literal not displayed */
}
ExternalConfig contains the configuration settings that end users should know about and can set.
type InternalConfig ¶
type InternalConfig struct {
// ClientID should the Auth0 Application Client ID.
ClientID string `env:"INFRACOST_CLI_OAUTH_CLIENT_ID" flag:"oauth-client-id;hidden" usage:"The client ID to use for authentication"`
// AuthEndpoint should be the Auth0 domain.
AuthEndpoint string `env:"INFRACOST_CLI_OAUTH_ENDPOINT" flag:"oauth-endpoint;hidden" usage:"The auth endpoint to use for authentication"`
// CallbackPort is the port to listen on for the callback from Auth0.
CallbackPort int `` /* 140-byte string literal not displayed */
// Audience is the expected audience of the token (i.e., the Infracost API URL).
Audience string `env:"INFRACOST_CLI_OAUTH_AUDIENCE" flag:"oauth-audience;hidden" usage:"The audience to use for authentication"`
// TokenCachePath is the path to the token cache file.
TokenCachePath string `env:"INFRACOST_CLI_OAUTH_TOKEN_CACHE_PATH" flag:"access-token-cache-path;hidden" usage:"The path to the token cache file"`
}
InternalConfig contains the configuration for authenticating with Auth0. End users should never be setting these directly, so the flags and environment variables are hidden. These are exposed as flags mainly to help with development and testing.