Documentation
¶
Overview ¶
Package provider provides credential detection and provider discovery
Package provider provides factory functions for creating providers ¶
Package provider provides cloud provider abstractions and factory functions.
Package provider defines the core abstractions for multi-cloud support ¶
Package provider provides a registry for cloud providers
Index ¶
- func RegisterProvider(name string, factory Factory) error
- type BaseCredentials
- type Config
- type CredentialDetector
- type CredentialSource
- type Credentials
- type DefaultFactory
- type Factory
- type FactoryInterface
- type OfferingPricer
- type Provider
- func CreateAndValidateProvider(ctx context.Context, name string, config *Config) (Provider, error)
- func CreateProvider(name string, config *Config) (Provider, error)
- func CreateProviders(names []string) ([]Provider, error)
- func DetectAvailableProviders(ctx context.Context) ([]Provider, error)
- func DetectProvider(ctx context.Context, name string) (Provider, error)
- func GetOrDetectProviders(ctx context.Context, names []string) ([]Provider, error)
- func GetProvidersByNames(ctx context.Context, names []string) ([]Provider, error)
- type ProviderConfigdeprecated
- type PurchaseReconciler
- type RecommendationsClient
- type Registry
- func (r *Registry) GetAllProviders() []Provider
- func (r *Registry) GetAllProvidersWithErrors() ([]Provider, []error)
- func (r *Registry) GetProvider(name string) (Provider, error)
- func (r *Registry) GetProviderNames() []string
- func (r *Registry) GetProviderWithConfig(name string, config *Config) (Provider, error)
- func (r *Registry) IsRegistered(name string) bool
- func (r *Registry) Register(name string, factory Factory) error
- func (r *Registry) Unregister(name string)
- type ServiceClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterProvider ¶
RegisterProvider is a convenience function to register with the global registry.
Types ¶
type BaseCredentials ¶
type BaseCredentials struct {
Source CredentialSource
Valid bool
}
BaseCredentials provides a base implementation of Credentials interface.
func (BaseCredentials) GetType ¶
func (c BaseCredentials) GetType() string
func (BaseCredentials) IsValid ¶
func (c BaseCredentials) IsValid() bool
type Config ¶
type Config struct {
// Optional pre-resolved credentials. The AWS slot is typed because this
// module already depends on the AWS SDK core (see go.mod and the exchange
// package); the Azure and GCP slots are typed as `any` to keep this module
// free of Azure/GCP SDK dependencies. Providers type-assert to their
// expected concrete type; on a mismatch they log a warning and fall back
// to ambient credentials:
// - AzureTokenCredential: github.com/Azure/azure-sdk-for-go/sdk/azcore.TokenCredential
// - GCPTokenSource: golang.org/x/oauth2.TokenSource
// When unset (nil), providers fall back to ambient credentials
// (DefaultAzureCredential / Application Default Credentials).
AWSCredentialsProvider aws.CredentialsProvider // optional: override ambient AWS credentials
AzureTokenCredential any
GCPTokenSource any
// ProviderOverride, if non-nil, is returned directly by CreateProvider without
// going through the registry. Use this to inject a pre-built, pre-authenticated
// provider when the typed credential slots above aren't expressive enough.
ProviderOverride Provider
Name string
// Typed per-provider identity fields. Each provider only reads its own
// field and ignores the others, so a single Config can be reused across
// providers.
AWSProfile string // AWS named profile from ~/.aws/credentials or ~/.aws/config
AzureSubscriptionID string // Azure subscription ID (UUID)
GCPProjectID string // GCP project ID (e.g. "my-project")
Region string
CredentialPath string
Endpoint string // For custom endpoints
}
Config represents configuration for a provider.
type CredentialDetector ¶
type CredentialDetector struct {
// contains filtered or unexported fields
}
CredentialDetector detects available cloud credentials.
func NewCredentialDetector ¶
func NewCredentialDetector() *CredentialDetector
NewCredentialDetector creates a new credential detector.
type CredentialSource ¶
type CredentialSource string
CredentialSource represents the source of credentials.
const ( CredentialSourceEnvironment CredentialSource = "environment" CredentialSourceFile CredentialSource = "file" CredentialSourceIAMRole CredentialSource = "iam-role" CredentialSourceMSI CredentialSource = "managed-identity" CredentialSourceADC CredentialSource = "application-default" CredentialSourceCLI CredentialSource = "cli" )
type Credentials ¶
type Credentials interface {
IsValid() bool
GetType() string // "environment", "file", "iam-role", "msi", "adc", etc.
}
Credentials represents cloud provider credentials.
type DefaultFactory ¶
type DefaultFactory struct{}
DefaultFactory uses the real provider factory.
func (*DefaultFactory) CreateAndValidateProvider ¶
func (f *DefaultFactory) CreateAndValidateProvider(ctx context.Context, name string, cfg *Config) (Provider, error)
CreateAndValidateProvider creates and validates a provider using the real factory.
type FactoryInterface ¶
type FactoryInterface interface {
CreateAndValidateProvider(ctx context.Context, name string, cfg *Config) (Provider, error)
}
FactoryInterface allows creating cloud providers (enables testing).
type OfferingPricer ¶
type OfferingPricer interface {
GetOfferingDetails(ctx context.Context, rec common.Recommendation) (*common.OfferingDetails, error)
}
OfferingPricer is the optional pricing path used by mcp's spend cap and dry-run quotes. A ServiceClient that can price a recommendation from the provider's offering catalog implements it; callers type-assert for it.
type Provider ¶
type Provider interface {
// Identity
Name() string // "aws", "azure", "gcp"
DisplayName() string // "Amazon Web Services", "Microsoft Azure", "Google Cloud Platform"
// Authentication
IsConfigured() bool // Check if credentials are available
GetCredentials() (Credentials, error) // Get current credentials
ValidateCredentials(ctx context.Context) error // Validate credentials are working
// Accounts/Projects/Subscriptions
GetAccounts(ctx context.Context) ([]common.Account, error) // List all accessible accounts
// Regions
GetRegions(ctx context.Context) ([]common.Region, error) // List all available regions
GetDefaultRegion() string // Get default region for this provider
// Services
GetSupportedServices() []common.ServiceType // List services supported by this provider
GetServiceClient(ctx context.Context, service common.ServiceType, region string) (ServiceClient, error)
// Recommendations
GetRecommendationsClient(ctx context.Context) (RecommendationsClient, error)
}
Provider represents a cloud provider (AWS, Azure, GCP).
func CreateAndValidateProvider ¶
CreateAndValidateProvider creates and validates a provider.
func CreateProvider ¶
CreateProvider creates a provider instance by name. If config.ProviderOverride is set, it is returned directly without consulting the registry — this allows callers to inject a pre-built, pre-authenticated provider.
func CreateProviders ¶
CreateProviders creates multiple provider instances.
func DetectAvailableProviders ¶
DetectAvailableProviders scans for configured cloud credentials It checks all registered providers and returns those with valid credentials.
func DetectProvider ¶
DetectProvider detects a specific provider by name.
func GetOrDetectProviders ¶
GetOrDetectProviders gets specified providers or auto-detects available ones.
type ProviderConfig
deprecated
type ProviderConfig = Config
ProviderConfig is the former name of Config, kept so external consumers keep compiling.
Deprecated: use Config.
type PurchaseReconciler ¶
type PurchaseReconciler interface {
ReconcilePurchase(ctx context.Context, req common.ReconcileRequest) common.ReconcileResult
}
PurchaseReconciler is optionally implemented by a ServiceClient whose purchase API has no idempotency token (AWS EC2, Redshift). Read-only. Not on ServiceClient, so no implementer or mock breaks. A client that does not implement it is treated by callers as Unknown.
type RecommendationsClient ¶
type RecommendationsClient interface {
// Get recommendations with filtering
GetRecommendations(ctx context.Context, params *common.RecommendationParams) ([]common.Recommendation, error)
// Get recommendations for a specific service
GetRecommendationsForService(ctx context.Context, service common.ServiceType) ([]common.Recommendation, error)
// Get recommendations for all supported services
GetAllRecommendations(ctx context.Context) ([]common.Recommendation, error)
}
RecommendationsClient provides centralized recommendations across all services.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages registered cloud providers.
func (*Registry) GetAllProviders ¶
GetAllProviders returns instances of all registered providers. Factory failures are logged and the provider is omitted; use GetAllProvidersWithErrors to receive them.
func (*Registry) GetAllProvidersWithErrors ¶
GetAllProvidersWithErrors returns instances of all registered providers whose factory succeeded, plus one error per provider whose factory failed. Each error wraps the factory's error and names the provider. Both results are ordered by provider name.
func (*Registry) GetProvider ¶
GetProvider creates a provider instance by name with default config.
Returns:
- "provider %s not registered" when no factory has been registered for that name
- "provider %s factory failed: %w" when the factory itself returned an error
Callers can distinguish the two cases via the returned error message; previously both cases returned nil and callers had no way to surface the factory failure.
func (*Registry) GetProviderNames ¶
GetProviderNames returns the names of all registered providers.
func (*Registry) GetProviderWithConfig ¶
GetProviderWithConfig creates a provider instance with custom config.
func (*Registry) IsRegistered ¶
IsRegistered checks if a provider is registered.
func (*Registry) Unregister ¶
Unregister removes a provider from the registry.
type ServiceClient ¶
type ServiceClient interface {
// Service identity
GetServiceType() common.ServiceType
GetRegion() string
// Recommendations
GetRecommendations(ctx context.Context, params *common.RecommendationParams) ([]common.Recommendation, error)
// Commitments (RI/SP/CUD/etc)
GetExistingCommitments(ctx context.Context) ([]common.Commitment, error)
PurchaseCommitment(ctx context.Context, rec common.Recommendation, opts common.PurchaseOptions) (common.PurchaseResult, error)
}
ServiceClient handles operations for a specific service in a specific region.