Documentation
¶
Index ¶
Constants ¶
const ( ProdGovcloudURL = "https://api-gov.resim.ai/v1/" ProdAPIURL = "https://api.resim.ai/v1/" StagingAPIURL = "https://api.resim.io/v1/" ProdAuthURL = "https://resim.us.auth0.com/" DevAuthURL = "https://resim-dev.us.auth0.com/" CredentialCacheFilename = "cache.json" DefaultDevInteractiveClientID = "Rg1F0ZOCBmVYje4UVrS3BKIh4T2nCW9y" DefaultDevNonInteractiveClientID = "LLNl3xsbNLSd16gQyYsiEn3tbLDZo1gj" DefaultProdInteractiveClientID = "gTp1Y0kOyQ7QzIo2lZm0auGM6FJZZVvy" DefaultProdNonInteractiveClientID = "0Ip56H1LLAo6Dc6IfePaNzgpUxbJGyVI" // Viper/flag key names used for config binding. KeyURL = "url" KeyAuthURL = "auth-url" KeyClientID = "client-id" KeyClientSecret = "client-secret" KeyUsername = "username" KeyPassword = "password" KeyDevInteractiveClient = "dev-interactive-client" KeyProdInteractiveClient = "prod-interactive-client" KeyDevNonInteractiveClient = "dev-non-interactive-client" KeyProdNonInteractiveClient = "prod-non-interactive-client" )
Variables ¶
This section is empty.
Functions ¶
func NewAPIClient ¶
func NewAPIClient(ctx context.Context, cache CredentialCache, apiURL string) (*api.ClientWithResponses, error)
NewAPIClient creates an API client authenticated with the given credential cache.
func NewBFFClient ¶
func NewBFFClient(ctx context.Context, cache CredentialCache, apiURL string) (graphql.Client, error)
NewBFFClient creates a GraphQL BFF client authenticated with the given credential cache.
Types ¶
type AuthResult ¶
type AuthResult struct {
Cache *CredentialCache
APIURL string
}
func Authenticate ¶
func Authenticate(ctx context.Context, cfg Config) (*AuthResult, error)
Authenticate performs OAuth2 authentication using the provided config. It returns an AuthResult containing the credential cache and the resolved API URL (which may differ from Config.APIURL if govcloud mode is enabled).
type Config ¶
type Config struct {
APIURL string
AuthURL string
ClientID string
ClientSecret string
Username string
Password string
Govcloud bool
CacheDir string
DevInteractiveClientID string
ProdInteractiveClientID string
DevNonInteractiveClientID string
ProdNonInteractiveClientID string
// AuthMode optionally overrides auth mode inference.
// If empty, the mode is inferred from which credential fields are populated.
AuthMode AuthMode
// DeviceCodeOutput is the writer for device code prompts. Defaults to os.Stdout.
DeviceCodeOutput io.Writer
// DeviceCodeBrowserOpen opens a URL in the user's browser. Defaults to browser.OpenURL.
DeviceCodeBrowserOpen func(string) error
}
func ConfigFromViper ¶
ConfigFromViper builds a Config from a viper instance. The cacheDir parameter specifies where credential caches are stored (e.g., os.ExpandEnv("$HOME/.resim")). This preserves viper.IsSet() semantics for auth mode detection, so CI environments with empty env vars behave correctly.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config pre-filled with production defaults.
type CredentialCache ¶
type CredentialCache struct {
Tokens map[string]oauth2.Token `json:"tokens"`
TokenSource oauth2.TokenSource
ClientID string
}
func (*CredentialCache) Load ¶
func (c *CredentialCache) Load(cacheDir string) error
Load reads the credential cache from disk. Returns nil if the file does not exist. Returns an error if the file exists but is malformed or unreadable.
func (*CredentialCache) Save ¶
func (c *CredentialCache) Save(cacheDir string) error
Save writes the credential cache to disk. Creates the cache directory if needed.