provider

package
v0.0.0-...-519451a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: OSL-3.0 Imports: 8 Imported by: 5 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterProvider

func RegisterProvider(name string, factory Factory) error

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 Factory

type Factory func(config *Config) (Provider, error)

Factory is a function that creates a new provider instance.

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

func CreateAndValidateProvider(ctx context.Context, name string, config *Config) (Provider, error)

CreateAndValidateProvider creates and validates a provider.

func CreateProvider

func CreateProvider(name string, config *Config) (Provider, error)

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

func CreateProviders(names []string) ([]Provider, error)

CreateProviders creates multiple provider instances.

func DetectAvailableProviders

func DetectAvailableProviders(ctx context.Context) ([]Provider, error)

DetectAvailableProviders scans for configured cloud credentials It checks all registered providers and returns those with valid credentials.

func DetectProvider

func DetectProvider(ctx context.Context, name string) (Provider, error)

DetectProvider detects a specific provider by name.

func GetOrDetectProviders

func GetOrDetectProviders(ctx context.Context, names []string) ([]Provider, error)

GetOrDetectProviders gets specified providers or auto-detects available ones.

func GetProvidersByNames

func GetProvidersByNames(ctx context.Context, names []string) ([]Provider, error)

GetProvidersByNames gets providers by their names.

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 GetRegistry

func GetRegistry() *Registry

GetRegistry returns the global provider registry.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new provider registry.

func (*Registry) GetAllProviders

func (r *Registry) GetAllProviders() []Provider

GetAllProviders returns instances of all registered providers. Factory failures are logged and the provider is omitted; use GetAllProvidersWithErrors to receive them.

func (*Registry) GetAllProvidersWithErrors

func (r *Registry) GetAllProvidersWithErrors() ([]Provider, []error)

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

func (r *Registry) GetProvider(name string) (Provider, error)

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

func (r *Registry) GetProviderNames() []string

GetProviderNames returns the names of all registered providers.

func (*Registry) GetProviderWithConfig

func (r *Registry) GetProviderWithConfig(name string, config *Config) (Provider, error)

GetProviderWithConfig creates a provider instance with custom config.

func (*Registry) IsRegistered

func (r *Registry) IsRegistered(name string) bool

IsRegistered checks if a provider is registered.

func (*Registry) Register

func (r *Registry) Register(name string, factory Factory) error

Register registers a provider factory with the registry.

func (*Registry) Unregister

func (r *Registry) Unregister(name string)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL