provider

package
v0.0.0-...-16b5795 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: OSL-3.0 Imports: 8 Imported by: 0

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 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 *ProviderConfig) (Provider, error)

CreateAndValidateProvider creates and validates a provider using the real factory.

type Factory

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

Factory is a function that creates a new provider instance.

type FactoryInterface

type FactoryInterface interface {
	CreateAndValidateProvider(ctx context.Context, name string, cfg *ProviderConfig) (Provider, error)
}

FactoryInterface allows creating cloud providers (enables testing).

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 *ProviderConfig) (Provider, error)

CreateAndValidateProvider creates and validates a provider.

func CreateProvider

func CreateProvider(name string, config *ProviderConfig) (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

type ProviderConfig struct {
	Name string

	// Deprecated: Profile is overloaded with provider-specific semantics
	// (AWS: named profile, Azure: subscription ID, GCP: project ID). Prefer
	// the typed AWSProfile/AzureSubscriptionID/GCPProjectID fields below;
	// when both are set, the typed field wins.
	Profile string

	// Typed per-provider identity fields. When set, these take precedence
	// over Profile. Each provider only reads its own field and ignores the
	// others, so a single ProviderConfig 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

	// Optional pre-resolved credentials. Each field is typed as `any` to
	// keep this module free of Azure/GCP SDK dependencies; providers
	// type-assert to their expected concrete type and ignore mismatches:
	//   - 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
}

ProviderConfig represents configuration for a provider.

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 *ProviderConfig) (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)
	ValidateOffering(ctx context.Context, rec common.Recommendation) error
	GetOfferingDetails(ctx context.Context, rec common.Recommendation) (*common.OfferingDetails, error)

	// Resource validation
	GetValidResourceTypes(ctx context.Context) ([]string, 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