Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions api/v1alpha1/aws/aws_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ type AWSConfig struct {
// Enabled indicates whether AWS integration is enabled.
Enabled *bool `yaml:"enabled,omitempty"`

// AWSEndpointURL specifies the custom endpoint URL for AWS services.
AWSEndpointURL *string `yaml:"aws_endpoint_url,omitempty"`
// EndpointURL specifies the custom endpoint URL for AWS services.
EndpointURL *string `yaml:"endpoint_url,omitempty"`

// AWSProfile defines the AWS CLI profile to use for authentication.
AWSProfile *string `yaml:"aws_profile,omitempty"`
// Profile defines the AWS CLI profile to use for authentication.
Profile *string `yaml:"profile,omitempty"`

// S3Hostname sets the custom hostname for the S3 service.
S3Hostname *string `yaml:"s3_hostname,omitempty"`
Expand All @@ -19,6 +19,9 @@ type AWSConfig struct {

// Localstack contains the configuration for Localstack, a local AWS cloud emulator.
Localstack *LocalstackConfig `yaml:"localstack,omitempty"`

// Region specifies the AWS region to use.
Region *string `yaml:"region,omitempty"`
}

// LocalstackConfig represents the Localstack configuration
Expand All @@ -32,11 +35,11 @@ func (base *AWSConfig) Merge(overlay *AWSConfig) {
if overlay.Enabled != nil {
base.Enabled = overlay.Enabled
}
if overlay.AWSEndpointURL != nil {
base.AWSEndpointURL = overlay.AWSEndpointURL
if overlay.EndpointURL != nil {
base.EndpointURL = overlay.EndpointURL
}
if overlay.AWSProfile != nil {
base.AWSProfile = overlay.AWSProfile
if overlay.Profile != nil {
base.Profile = overlay.Profile
}
if overlay.S3Hostname != nil {
base.S3Hostname = overlay.S3Hostname
Expand All @@ -55,6 +58,9 @@ func (base *AWSConfig) Merge(overlay *AWSConfig) {
base.Localstack.Services = overlay.Localstack.Services
}
}
if overlay.Region != nil {
base.Region = overlay.Region
}
}

// Copy creates a deep copy of the AWSConfig object
Expand All @@ -66,11 +72,11 @@ func (c *AWSConfig) Copy() *AWSConfig {
if c.Enabled != nil {
copy.Enabled = c.Enabled
}
if c.AWSEndpointURL != nil {
copy.AWSEndpointURL = c.AWSEndpointURL
if c.EndpointURL != nil {
copy.EndpointURL = c.EndpointURL
}
if c.AWSProfile != nil {
copy.AWSProfile = c.AWSProfile
if c.Profile != nil {
copy.Profile = c.Profile
}
if c.S3Hostname != nil {
copy.S3Hostname = c.S3Hostname
Expand All @@ -87,5 +93,8 @@ func (c *AWSConfig) Copy() *AWSConfig {
copy.Localstack.Services = c.Localstack.Services
}
}
if c.Region != nil {
copy.Region = c.Region
}
return copy
}
91 changes: 53 additions & 38 deletions api/v1alpha1/aws/aws_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,41 @@ import (
func TestAWSConfig_Merge(t *testing.T) {
t.Run("MergeWithNoNils", func(t *testing.T) {
base := &AWSConfig{
Enabled: ptrBool(true),
AWSEndpointURL: ptrString("https://base.aws.endpoint"),
AWSProfile: ptrString("base-profile"),
S3Hostname: ptrString("base-s3-hostname"),
MWAAEndpoint: ptrString("base-mwaa-endpoint"),
Enabled: ptrBool(true),
EndpointURL: ptrString("https://base.aws.endpoint"),
Profile: ptrString("base-profile"),
S3Hostname: ptrString("base-s3-hostname"),
MWAAEndpoint: ptrString("base-mwaa-endpoint"),
Localstack: &LocalstackConfig{
Enabled: ptrBool(true),
Services: []string{"s3", "lambda"},
},
Region: ptrString("base-region"),
}

overlay := &AWSConfig{
Enabled: ptrBool(false),
AWSEndpointURL: ptrString("https://overlay.aws.endpoint"),
AWSProfile: ptrString("overlay-profile"),
S3Hostname: ptrString("overlay-s3-hostname"),
MWAAEndpoint: ptrString("overlay-mwaa-endpoint"),
Enabled: ptrBool(false),
EndpointURL: ptrString("https://overlay.aws.endpoint"),
Profile: ptrString("overlay-profile"),
S3Hostname: ptrString("overlay-s3-hostname"),
MWAAEndpoint: ptrString("overlay-mwaa-endpoint"),
Localstack: &LocalstackConfig{
Enabled: ptrBool(false),
Services: []string{"dynamodb"},
},
Region: ptrString("overlay-region"),
}

base.Merge(overlay)

if base.Enabled == nil || *base.Enabled != false {
t.Errorf("Enabled mismatch: expected false, got %v", *base.Enabled)
}
if base.AWSEndpointURL == nil || *base.AWSEndpointURL != "https://overlay.aws.endpoint" {
t.Errorf("AWSEndpointURL mismatch: expected 'https://overlay.aws.endpoint', got '%s'", *base.AWSEndpointURL)
if base.EndpointURL == nil || *base.EndpointURL != "https://overlay.aws.endpoint" {
t.Errorf("EndpointURL mismatch: expected 'https://overlay.aws.endpoint', got '%s'", *base.EndpointURL)
}
if base.AWSProfile == nil || *base.AWSProfile != "overlay-profile" {
t.Errorf("AWSProfile mismatch: expected 'overlay-profile', got '%s'", *base.AWSProfile)
if base.Profile == nil || *base.Profile != "overlay-profile" {
t.Errorf("Profile mismatch: expected 'overlay-profile', got '%s'", *base.Profile)
}
if base.S3Hostname == nil || *base.S3Hostname != "overlay-s3-hostname" {
t.Errorf("S3Hostname mismatch: expected 'overlay-s3-hostname', got '%s'", *base.S3Hostname)
Expand All @@ -53,40 +55,45 @@ func TestAWSConfig_Merge(t *testing.T) {
if len(base.Localstack.Services) != 1 || base.Localstack.Services[0] != "dynamodb" {
t.Errorf("Localstack Services mismatch: expected ['dynamodb'], got %v", base.Localstack.Services)
}
if base.Region == nil || *base.Region != "overlay-region" {
t.Errorf("Region mismatch: expected 'overlay-region', got '%s'", *base.Region)
}
})

t.Run("MergeWithAllNils", func(t *testing.T) {
base := &AWSConfig{
Enabled: nil,
AWSEndpointURL: nil,
AWSProfile: nil,
S3Hostname: nil,
MWAAEndpoint: nil,
Localstack: nil,
Enabled: nil,
EndpointURL: nil,
Profile: nil,
S3Hostname: nil,
MWAAEndpoint: nil,
Localstack: nil,
Region: nil,
}

overlay := &AWSConfig{
Enabled: nil,
AWSEndpointURL: nil,
AWSProfile: nil,
S3Hostname: nil,
MWAAEndpoint: nil,
Enabled: nil,
EndpointURL: nil,
Profile: nil,
S3Hostname: nil,
MWAAEndpoint: nil,
Localstack: &LocalstackConfig{
Enabled: nil,
Services: nil,
},
Region: nil,
}

base.Merge(overlay)

if base.Enabled != nil {
t.Errorf("Enabled mismatch: expected nil, got %v", base.Enabled)
}
if base.AWSEndpointURL != nil {
t.Errorf("AWSEndpointURL mismatch: expected nil, got '%s'", *base.AWSEndpointURL)
if base.EndpointURL != nil {
t.Errorf("EndpointURL mismatch: expected nil, got '%s'", *base.EndpointURL)
}
if base.AWSProfile != nil {
t.Errorf("AWSProfile mismatch: expected nil, got '%s'", *base.AWSProfile)
if base.Profile != nil {
t.Errorf("Profile mismatch: expected nil, got '%s'", *base.Profile)
}
if base.S3Hostname != nil {
t.Errorf("S3Hostname mismatch: expected nil, got '%s'", *base.S3Hostname)
Expand All @@ -97,33 +104,37 @@ func TestAWSConfig_Merge(t *testing.T) {
if base.Localstack != nil && (base.Localstack.Enabled != nil || base.Localstack.Services != nil) {
t.Errorf("Localstack mismatch: expected nil, got %v", base.Localstack)
}
if base.Region != nil {
t.Errorf("Region mismatch: expected nil, got '%s'", *base.Region)
}
})
}

func TestAWSConfig_Copy(t *testing.T) {
t.Run("CopyWithNonNilValues", func(t *testing.T) {
original := &AWSConfig{
Enabled: ptrBool(true),
AWSEndpointURL: ptrString("https://original.aws.endpoint"),
AWSProfile: ptrString("original-profile"),
S3Hostname: ptrString("original-s3-hostname"),
MWAAEndpoint: ptrString("original-mwaa-endpoint"),
Enabled: ptrBool(true),
EndpointURL: ptrString("https://original.aws.endpoint"),
Profile: ptrString("original-profile"),
S3Hostname: ptrString("original-s3-hostname"),
MWAAEndpoint: ptrString("original-mwaa-endpoint"),
Localstack: &LocalstackConfig{
Enabled: ptrBool(true),
Services: []string{"s3", "lambda"},
},
Region: ptrString("original-region"),
}

copy := original.Copy()

if original.Enabled == nil || copy.Enabled == nil || *original.Enabled != *copy.Enabled {
t.Errorf("Enabled mismatch: expected %v, got %v", *original.Enabled, *copy.Enabled)
}
if original.AWSEndpointURL == nil || copy.AWSEndpointURL == nil || *original.AWSEndpointURL != *copy.AWSEndpointURL {
t.Errorf("AWSEndpointURL mismatch: expected %v, got %v", *original.AWSEndpointURL, *copy.AWSEndpointURL)
if original.EndpointURL == nil || copy.EndpointURL == nil || *original.EndpointURL != *copy.EndpointURL {
t.Errorf("EndpointURL mismatch: expected %v, got %v", *original.EndpointURL, *copy.EndpointURL)
}
if original.AWSProfile == nil || copy.AWSProfile == nil || *original.AWSProfile != *copy.AWSProfile {
t.Errorf("AWSProfile mismatch: expected %v, got %v", *original.AWSProfile, *copy.AWSProfile)
if original.Profile == nil || copy.Profile == nil || *original.Profile != *copy.Profile {
t.Errorf("Profile mismatch: expected %v, got %v", *original.Profile, *copy.Profile)
}
if original.S3Hostname == nil || copy.S3Hostname == nil || *original.S3Hostname != *copy.S3Hostname {
t.Errorf("S3Hostname mismatch: expected %v, got %v", *original.S3Hostname, *copy.S3Hostname)
Expand Down Expand Up @@ -154,6 +165,10 @@ func TestAWSConfig_Copy(t *testing.T) {
if original.Localstack.Services[0] == copy.Localstack.Services[0] {
t.Errorf("Original Localstack Services was modified: expected %v, got %v", "s3", copy.Localstack.Services[0])
}

if original.Region == nil || copy.Region == nil || *original.Region != *copy.Region {
t.Errorf("Region mismatch: expected %v, got %v", *original.Region, *copy.Region)
}
})

t.Run("CopyNil", func(t *testing.T) {
Expand Down
28 changes: 14 additions & 14 deletions api/v1alpha1/config_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func TestConfig_Merge(t *testing.T) {
t.Run("MergeWithNonNilValues", func(t *testing.T) {
base := &Context{
AWS: &aws.AWSConfig{
Enabled: ptrBool(true),
AWSEndpointURL: ptrString("https://base.aws.endpoint"),
Enabled: ptrBool(true),
EndpointURL: ptrString("https://base.aws.endpoint"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(true),
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestConfig_Merge(t *testing.T) {

overlay := &Context{
AWS: &aws.AWSConfig{
AWSEndpointURL: ptrString("https://overlay.aws.endpoint"),
EndpointURL: ptrString("https://overlay.aws.endpoint"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(false),
Expand Down Expand Up @@ -97,8 +97,8 @@ func TestConfig_Merge(t *testing.T) {

base.Merge(overlay)

if base.AWS.AWSEndpointURL == nil || *base.AWS.AWSEndpointURL != "https://overlay.aws.endpoint" {
t.Errorf("AWS AWSEndpointURL mismatch: expected 'https://overlay.aws.endpoint', got '%s'", *base.AWS.AWSEndpointURL)
if base.AWS.EndpointURL == nil || *base.AWS.EndpointURL != "https://overlay.aws.endpoint" {
t.Errorf("AWS EndpointURL mismatch: expected 'https://overlay.aws.endpoint', got '%s'", *base.AWS.EndpointURL)
}
if base.Docker.Enabled == nil || *base.Docker.Enabled != false {
t.Errorf("Docker Enabled mismatch: expected false, got %v", *base.Docker.Enabled)
Expand Down Expand Up @@ -132,8 +132,8 @@ func TestConfig_Merge(t *testing.T) {
t.Run("MergeWithNilOverlay", func(t *testing.T) {
base := &Context{
AWS: &aws.AWSConfig{
Enabled: ptrBool(true),
AWSEndpointURL: ptrString("https://base.aws.endpoint"),
Enabled: ptrBool(true),
EndpointURL: ptrString("https://base.aws.endpoint"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(true),
Expand Down Expand Up @@ -173,8 +173,8 @@ func TestConfig_Merge(t *testing.T) {
var overlay *Context = nil
base.Merge(overlay)

if base.AWS.AWSEndpointURL == nil || *base.AWS.AWSEndpointURL != "https://base.aws.endpoint" {
t.Errorf("AWS AWSEndpointURL mismatch: expected 'https://base.aws.endpoint', got '%s'", *base.AWS.AWSEndpointURL)
if base.AWS.EndpointURL == nil || *base.AWS.EndpointURL != "https://base.aws.endpoint" {
t.Errorf("AWS EndpointURL mismatch: expected 'https://base.aws.endpoint', got '%s'", *base.AWS.EndpointURL)
}
if base.Docker.Enabled == nil || *base.Docker.Enabled != true {
t.Errorf("Docker Enabled mismatch: expected true, got %v", *base.Docker.Enabled)
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestConfig_Merge(t *testing.T) {

overlay := &Context{
AWS: &aws.AWSConfig{
AWSEndpointURL: ptrString("https://overlay.aws.endpoint"),
EndpointURL: ptrString("https://overlay.aws.endpoint"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(false),
Expand Down Expand Up @@ -249,8 +249,8 @@ func TestConfig_Merge(t *testing.T) {

base.Merge(overlay)

if base.AWS.AWSEndpointURL == nil || *base.AWS.AWSEndpointURL != "https://overlay.aws.endpoint" {
t.Errorf("AWS AWSEndpointURL mismatch: expected 'https://overlay.aws.endpoint', got '%s'", *base.AWS.AWSEndpointURL)
if base.AWS.EndpointURL == nil || *base.AWS.EndpointURL != "https://overlay.aws.endpoint" {
t.Errorf("AWS EndpointURL mismatch: expected 'https://overlay.aws.endpoint', got '%s'", *base.AWS.EndpointURL)
}
if base.Docker.Enabled == nil || *base.Docker.Enabled != false {
t.Errorf("Docker Enabled mismatch: expected false, got %v", *base.Docker.Enabled)
Expand Down Expand Up @@ -305,8 +305,8 @@ func TestConfig_Copy(t *testing.T) {
"KEY": "value",
},
AWS: &aws.AWSConfig{
Enabled: ptrBool(true),
AWSEndpointURL: ptrString("https://original.aws.endpoint"),
Enabled: ptrBool(true),
EndpointURL: ptrString("https://original.aws.endpoint"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(true),
Expand Down
1 change: 1 addition & 0 deletions aqua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ packages:
- name: helm/helm@v3.17.1
- name: 1password/cli@v2.30.3
- name: fluxcd/flux2@v2.5.0
- name: aws/aws-cli@2.24.10
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/zclconf/go-cty v1.16.2
golang.org/x/crypto v0.34.0
golang.org/x/sys v0.30.0
gopkg.in/ini.v1 v1.67.0
k8s.io/api v0.32.2
k8s.io/apimachinery v0.32.2
k8s.io/client-go v0.32.2
Expand Down Expand Up @@ -169,7 +170,6 @@ require (
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.32.2 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions pkg/config/yaml_config_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestYamlConfigHandler_Get(t *testing.T) {
// When setting the default context (should not be used)
defaultContext := v1alpha1.Context{
AWS: &aws.AWSConfig{
AWSEndpointURL: ptrString("http://default.aws.endpoint"),
EndpointURL: ptrString("http://default.aws.endpoint"),
},
}
handler.SetDefault(defaultContext)
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestYamlConfigHandler_SaveConfig(t *testing.T) {
"email": "john.doe@example.com",
},
AWS: &aws.AWSConfig{
AWSEndpointURL: nil,
EndpointURL: nil,
},
},
},
Expand Down Expand Up @@ -487,7 +487,7 @@ func TestYamlConfigHandler_GetInt(t *testing.T) {
Contexts: map[string]*v1alpha1.Context{
"default": {
AWS: &aws.AWSConfig{
AWSEndpointURL: ptrString("notAnInt"),
EndpointURL: ptrString("notAnInt"),
},
},
},
Expand Down Expand Up @@ -1040,7 +1040,7 @@ func TestSetValueByPath(t *testing.T) {
"level2": "value2",
},
AWS: &aws.AWSConfig{
AWSEndpointURL: ptrString("http://aws.test:4566"),
EndpointURL: ptrString("http://aws.test:4566"),
},
},
},
Expand Down
Loading
Loading