provider

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectCloudFromInstances

func DetectCloudFromInstances(instances []*cloud.Instance) (string, error)

DetectCloudFromInstances detects the cloud provider from a list of instances. Returns the most common cloud provider or error if instances use different clouds.

This is useful when CSV contains instances from multiple clouds - validates that all instances are from the same cloud provider.

Parameters:

  • instances: List of cloud instances

Returns:

  • string: Detected cloud type ("aws", "gcp", "azure")
  • error: Error if no instances, or multiple different clouds detected

Example usage:

cloudType, err := provider.DetectCloudFromInstances(instances)
if err != nil {
    return fmt.Errorf("cloud detection failed: %w", err)
}
p, err := provider.NewProvider(cloudType)

func GetSupportedProviders

func GetSupportedProviders() []string

GetSupportedProviders returns list of supported cloud provider types. Useful for CLI help text and validation.

Example usage:

supportedProviders := provider.GetSupportedProviders()
fmt.Printf("Supported clouds: %v\n", supportedProviders)
// Output: Supported clouds: [aws gcp azure]

func IsProviderSupported

func IsProviderSupported(cloudType string) bool

IsProviderSupported checks if a cloud provider type is supported. Case-insensitive comparison.

Example usage:

if !provider.IsProviderSupported(userInput) {
    return fmt.Errorf("unsupported cloud: %s", userInput)
}

func NewProvider

func NewProvider(cloudType string, options ...Option) (cloud.CloudProvider, error)

NewProvider creates a new cloud provider based on the provider type. Uses Factory Pattern to abstract provider creation logic from CLI layer.

Supported providers:

  • "aws": Amazon Web Services (implemented)
  • "gcp": Google Cloud Platform (not yet implemented)
  • "azure": Microsoft Azure (not yet implemented)

Parameters:

  • cloudType: Provider type ("aws", "gcp", "azure")
  • options: Functional options for provider configuration

Returns:

  • cloud.CloudProvider: Initialized provider instance
  • error: Error if provider type is unsupported or initialization fails

Example usage:

// Create AWS provider with default config
provider, err := provider.NewProvider("aws")

// Create AWS provider with custom profile
provider, err := provider.NewProvider("aws", provider.WithProfile("production"))

// Create AWS provider with profile and region
provider, err := provider.NewProvider("aws",
    provider.WithProfile("production"),
    provider.WithRegion("us-east-1"),
)

Multi-cloud support:

// Detect cloud from CSV and create appropriate provider
cloudType := instances[0].Cloud  // "aws", "gcp", "azure"
provider, err := provider.NewProvider(cloudType)

func NewProviderFromInstances

func NewProviderFromInstances(instances []*cloud.Instance, options ...Option) (cloud.CloudProvider, error)

NewProviderFromInstances detects cloud type from instances and creates provider. Convenience wrapper around DetectCloudFromInstances + NewProvider.

Parameters:

  • instances: List of cloud instances
  • options: Functional options for provider configuration

Returns:

  • cloud.CloudProvider: Initialized provider instance
  • error: Error if detection fails or provider creation fails

Example usage:

// Detect cloud and create provider automatically
p, err := provider.NewProviderFromInstances(instances,
    provider.WithProfile("production"),
)

Types

type Config

type Config struct {
	// Profile is the cloud provider profile/credential to use
	// For AWS: ~/.aws/credentials profile name
	// For GCP: service account key file path
	// For Azure: subscription ID
	Profile string

	// Region is the default region for cloud operations
	// Optional: can be overridden per-instance from CSV
	Region string
}

Config holds configuration for cloud provider initialization. Used with functional options pattern for flexible provider creation.

type Option

type Option func(*Config)

Option is a functional option for configuring Config

func WithProfile

func WithProfile(profile string) Option

WithProfile sets the cloud provider profile/credential

func WithRegion

func WithRegion(region string) Option

WithRegion sets the default region for cloud operations

type ProviderType

type ProviderType string

ProviderType represents supported cloud provider types

const (
	// ProviderAWS represents Amazon Web Services
	ProviderAWS ProviderType = "aws"

	// ProviderGCP represents Google Cloud Platform
	// Currently not implemented, reserved for future use
	ProviderGCP ProviderType = "gcp"

	// ProviderAzure represents Microsoft Azure
	// Currently not implemented, reserved for future use
	ProviderAzure ProviderType = "azure"
)

Jump to

Keyboard shortcuts

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