Documentation
¶
Index ¶
- type AWSProvider
- func (p *AWSProvider) ExecuteCommand(ctx context.Context, instance *cloud.Instance, commands []string, ...) (*cloud.CommandResult, error)
- func (p *AWSProvider) HasTag(ctx context.Context, instance *cloud.Instance, key, value string) (bool, error)
- func (*AWSProvider) Name() string
- func (p *AWSProvider) TagInstance(ctx context.Context, instance *cloud.Instance, tags map[string]string) error
- func (p *AWSProvider) TestConnectivity(ctx context.Context, instance *cloud.Instance, host string, port int) error
- func (p *AWSProvider) ValidateInstance(ctx context.Context, instance *cloud.Instance) error
- type SessionManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AWSProvider ¶
type AWSProvider struct {
// contains filtered or unexported fields
}
AWSProvider implements cloud.CloudProvider interface for AWS. Uses AWS Systems Manager (SSM) for remote command execution and EC2 API for instance tagging.
This is the concrete implementation of the CloudProvider abstraction, allowing the rest of the codebase to work with AWS without knowing AWS-specific details.
func NewAWSProvider ¶
func NewAWSProvider() *AWSProvider
NewAWSProvider creates a new AWS provider with connection pooling
func (*AWSProvider) ExecuteCommand ¶
func (p *AWSProvider) ExecuteCommand(ctx context.Context, instance *cloud.Instance, commands []string, timeout time.Duration) (*cloud.CommandResult, error)
ExecuteCommand executes shell commands remotely on the instance via SSM. Uses AWS-RunShellScript document to execute commands.
Parameters:
- ctx: context for timeout/cancellation
- instance: target instance
- commands: slice of shell commands to execute
- timeout: maximum execution time
Returns CommandResult with stdout, stderr, exit code, and duration.
func (*AWSProvider) HasTag ¶
func (p *AWSProvider) HasTag(ctx context.Context, instance *cloud.Instance, key, value string) (bool, error)
HasTag checks if instance already has a specific tag with given value. Useful for idempotency - skip processing if instance already tagged.
Example: Check if instance has "puppet=true" before reinstalling Puppet.
Returns true if tag exists with exact key and value, false otherwise.
func (*AWSProvider) TagInstance ¶
func (p *AWSProvider) TagInstance(ctx context.Context, instance *cloud.Instance, tags map[string]string) error
TagInstance adds tags to an EC2 instance. Tags are used to mark instances after successful installation.
Common use cases:
- Mark instances as "puppet=true" after Puppet installation
- Add timestamp tags for audit trail
- Tag with installer metadata
Note: Tags are applied at EC2 level, not SSM. Requires ec2:CreateTags permission.
func (*AWSProvider) TestConnectivity ¶
func (p *AWSProvider) TestConnectivity(ctx context.Context, instance *cloud.Instance, host string, port int) error
TestConnectivity tests network connectivity from instance to a host:port. Uses multiple methods for better compatibility across different OS distributions.
Methods tried in order: 1. nc (netcat) - most reliable 2. telnet - fallback 3. /dev/tcp - bash built-in (limited compatibility)
This is useful for validating prerequisites, e.g., checking if instance can reach Puppet Server before attempting installation.
func (*AWSProvider) ValidateInstance ¶
ValidateInstance checks if instance is accessible via SSM. An instance must be: 1. Registered in SSM 2. Online (ping status = Online) 3. SSM agent running and healthy
Returns error if instance is not reachable via SSM.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages AWS client connections using connection pooling. This implements the Pool Pattern - reusing connections instead of creating new ones for each request, which significantly improves performance.
Thread-safe for concurrent access using RWMutex.
func NewSessionManager ¶
func NewSessionManager() *SessionManager
NewSessionManager creates a new session manager with empty pools
func (*SessionManager) Close ¶
func (sm *SessionManager) Close()
Close closes all cached clients and clears pools Should be called when shutting down the application
func (*SessionManager) GetEC2Client ¶
func (sm *SessionManager) GetEC2Client(ctx context.Context, profile, region string) (*ec2.Client, error)
GetEC2Client returns a cached EC2 client or creates a new one if needed. Used for tagging instances after successful installation.
Parameters:
- ctx: context for timeout/cancellation
- profile: AWS profile name from ~/.aws/credentials
- region: AWS region (e.g., us-east-1)
Returns cached client if exists, creates new one otherwise. Thread-safe using RWMutex with double-check locking pattern.
func (*SessionManager) GetSSMClient ¶
func (sm *SessionManager) GetSSMClient(ctx context.Context, profile, region string) (*ssm.Client, error)
GetSSMClient returns a cached SSM client or creates a new one if needed. Uses connection pooling for performance - reuses existing clients when possible.
Parameters:
- ctx: context for timeout/cancellation
- profile: AWS profile name from ~/.aws/credentials
- region: AWS region (e.g., us-east-1)
Returns cached client if exists, creates new one otherwise. Thread-safe using RWMutex with double-check locking pattern.
func (*SessionManager) GetStats ¶
func (sm *SessionManager) GetStats() map[string]int
GetStats returns statistics about cached clients Useful for monitoring and debugging