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
48 changes: 48 additions & 0 deletions api/v1alpha1/azure/azure_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package azure

// AzureConfig represents the Azure configuration
type AzureConfig struct {
// Enabled indicates whether Azure integration is enabled.
Enabled *bool `yaml:"enabled,omitempty"`

// SubscriptionID is the Azure subscription identifier
SubscriptionID *string `yaml:"subscription_id,omitempty"`

// TenantID is the Azure tenant identifier
TenantID *string `yaml:"tenant_id,omitempty"`

// Environment specifies the Azure cloud environment (e.g. "public", "usgovernment")
Environment *string `yaml:"environment,omitempty"`
}

// Merge performs a deep merge of the current AzureConfig with another AzureConfig.
func (base *AzureConfig) Merge(overlay *AzureConfig) {
if overlay == nil {
return
}
if overlay.Enabled != nil {
base.Enabled = overlay.Enabled
}
if overlay.SubscriptionID != nil {
base.SubscriptionID = overlay.SubscriptionID
}
if overlay.TenantID != nil {
base.TenantID = overlay.TenantID
}
if overlay.Environment != nil {
base.Environment = overlay.Environment
}
}

// Copy creates a deep copy of the AzureConfig object
func (c *AzureConfig) Copy() *AzureConfig {
if c == nil {
return nil
}
return &AzureConfig{
Enabled: c.Enabled,
SubscriptionID: c.SubscriptionID,
TenantID: c.TenantID,
Environment: c.Environment,
}
}
46 changes: 46 additions & 0 deletions api/v1alpha1/azure/azure_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package azure

import (
"testing"
)

func TestAzureConfig(t *testing.T) {
t.Run("Merge", func(t *testing.T) {
base := &AzureConfig{
Enabled: boolPtr(false),
}
overlay := &AzureConfig{
Enabled: boolPtr(true),
}

base.Merge(overlay)

if *base.Enabled != true {
t.Errorf("Expected Enabled to be true, got %v", *base.Enabled)
}
})

t.Run("Copy", func(t *testing.T) {
original := &AzureConfig{
Enabled: boolPtr(true),
}

copy := original.Copy()

if copy == nil {
t.Fatal("Expected non-nil copy")
}

if copy == original {
t.Error("Expected copy to be a new instance")
}

if *copy.Enabled != *original.Enabled {
t.Errorf("Expected Enabled to be %v, got %v", *original.Enabled, *copy.Enabled)
}
})
}

func boolPtr(b bool) *bool {
return &b
}
9 changes: 9 additions & 0 deletions api/v1alpha1/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
"github.com/windsorcli/cli/api/v1alpha1/aws"
"github.com/windsorcli/cli/api/v1alpha1/azure"
"github.com/windsorcli/cli/api/v1alpha1/cluster"
"github.com/windsorcli/cli/api/v1alpha1/dns"
"github.com/windsorcli/cli/api/v1alpha1/docker"
Expand All @@ -27,6 +28,7 @@ type Context struct {
Environment map[string]string `yaml:"environment,omitempty"`
Secrets *secrets.SecretsConfig `yaml:"secrets,omitempty"`
AWS *aws.AWSConfig `yaml:"aws,omitempty"`
Azure *azure.AzureConfig `yaml:"azure,omitempty"`
Docker *docker.DockerConfig `yaml:"docker,omitempty"`
Git *git.GitConfig `yaml:"git,omitempty"`
Terraform *terraform.TerraformConfig `yaml:"terraform,omitempty"`
Expand Down Expand Up @@ -67,6 +69,12 @@ func (base *Context) Merge(overlay *Context) {
}
base.AWS.Merge(overlay.AWS)
}
if overlay.Azure != nil {
if base.Azure == nil {
base.Azure = &azure.AzureConfig{}
}
base.Azure.Merge(overlay.Azure)
}
if overlay.Docker != nil {
if base.Docker == nil {
base.Docker = &docker.DockerConfig{}
Expand Down Expand Up @@ -133,6 +141,7 @@ func (c *Context) DeepCopy() *Context {
Environment: environmentCopy,
Secrets: c.Secrets.Copy(),
AWS: c.AWS.Copy(),
Azure: c.Azure.Copy(),
Docker: c.Docker.Copy(),
Git: c.Git.Copy(),
Terraform: c.Terraform.Copy(),
Expand Down
101 changes: 88 additions & 13 deletions api/v1alpha1/config_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/windsorcli/cli/api/v1alpha1/aws"
"github.com/windsorcli/cli/api/v1alpha1/azure"
"github.com/windsorcli/cli/api/v1alpha1/cluster"
"github.com/windsorcli/cli/api/v1alpha1/dns"
"github.com/windsorcli/cli/api/v1alpha1/docker"
Expand All @@ -21,6 +22,12 @@ func TestConfig_Merge(t *testing.T) {
Enabled: ptrBool(true),
AWSEndpointURL: ptrString("https://base.aws.endpoint"),
},
Azure: &azure.AzureConfig{
Enabled: ptrBool(true),
SubscriptionID: ptrString("base-sub"),
TenantID: ptrString("base-tenant"),
Environment: ptrString("base-cloud"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(true),
},
Expand Down Expand Up @@ -61,6 +68,12 @@ func TestConfig_Merge(t *testing.T) {
AWS: &aws.AWSConfig{
AWSEndpointURL: ptrString("https://overlay.aws.endpoint"),
},
Azure: &azure.AzureConfig{
Enabled: ptrBool(false),
SubscriptionID: ptrString("overlay-sub"),
TenantID: ptrString("overlay-tenant"),
Environment: ptrString("overlay-cloud"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(false),
},
Expand Down Expand Up @@ -102,6 +115,18 @@ func TestConfig_Merge(t *testing.T) {
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.Azure.Enabled == nil || *base.Azure.Enabled != false {
t.Errorf("Azure Enabled mismatch: expected false, got %v", *base.Azure.Enabled)
}
if base.Azure.SubscriptionID == nil || *base.Azure.SubscriptionID != "overlay-sub" {
t.Errorf("Azure SubscriptionID mismatch: expected 'overlay-sub', got '%s'", *base.Azure.SubscriptionID)
}
if base.Azure.TenantID == nil || *base.Azure.TenantID != "overlay-tenant" {
t.Errorf("Azure TenantID mismatch: expected 'overlay-tenant', got '%s'", *base.Azure.TenantID)
}
if base.Azure.Environment == nil || *base.Azure.Environment != "overlay-cloud" {
t.Errorf("Azure Environment mismatch: expected 'overlay-cloud', got '%s'", *base.Azure.Environment)
}
if base.Docker.Enabled == nil || *base.Docker.Enabled != false {
t.Errorf("Docker Enabled mismatch: expected false, got %v", *base.Docker.Enabled)
}
Expand All @@ -123,8 +148,8 @@ func TestConfig_Merge(t *testing.T) {
if base.Secrets.OnePasswordConfig.Vaults["vault1"].URL != "https://url.com" {
t.Errorf("Secrets Vault URL mismatch: expected 'https://url.com', got '%s'", base.Secrets.OnePasswordConfig.Vaults["vault1"].URL)
}
if len(base.Environment) != 2 || base.Environment["KEY1"] != "value1" || base.Environment["KEY2"] != "value2" {
t.Errorf("Environment merge mismatch: expected map with 'KEY1' and 'KEY2', got %v", base.Environment)
if len(base.Environment) != 2 || base.Environment["KEY2"] != "value2" {
t.Errorf("Environment mismatch: expected map with 'KEY2', got %v", base.Environment)
}
if base.Network.CIDRBlock == nil || *base.Network.CIDRBlock != "10.0.0.0/8" {
t.Errorf("Network CIDRBlock mismatch: expected '10.0.0.0/8', got '%s'", *base.Network.CIDRBlock)
Expand All @@ -140,6 +165,12 @@ func TestConfig_Merge(t *testing.T) {
Enabled: ptrBool(true),
AWSEndpointURL: ptrString("https://base.aws.endpoint"),
},
Azure: &azure.AzureConfig{
Enabled: ptrBool(true),
SubscriptionID: ptrString("base-sub"),
TenantID: ptrString("base-tenant"),
Environment: ptrString("base-cloud"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(true),
},
Expand Down Expand Up @@ -182,6 +213,18 @@ func TestConfig_Merge(t *testing.T) {
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.Azure.Enabled == nil || *base.Azure.Enabled != true {
t.Errorf("Azure Enabled mismatch: expected true, got %v", *base.Azure.Enabled)
}
if base.Azure.SubscriptionID == nil || *base.Azure.SubscriptionID != "base-sub" {
t.Errorf("Azure SubscriptionID mismatch: expected 'base-sub', got '%s'", *base.Azure.SubscriptionID)
}
if base.Azure.TenantID == nil || *base.Azure.TenantID != "base-tenant" {
t.Errorf("Azure TenantID mismatch: expected 'base-tenant', got '%s'", *base.Azure.TenantID)
}
if base.Azure.Environment == nil || *base.Azure.Environment != "base-cloud" {
t.Errorf("Azure Environment mismatch: expected 'base-cloud', got '%s'", *base.Azure.Environment)
}
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 @@ -221,6 +264,12 @@ func TestConfig_Merge(t *testing.T) {
AWS: &aws.AWSConfig{
AWSEndpointURL: ptrString("https://overlay.aws.endpoint"),
},
Azure: &azure.AzureConfig{
Enabled: ptrBool(false),
SubscriptionID: ptrString("overlay-sub"),
TenantID: ptrString("overlay-tenant"),
Environment: ptrString("overlay-cloud"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(false),
},
Expand Down Expand Up @@ -262,6 +311,18 @@ func TestConfig_Merge(t *testing.T) {
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.Azure.Enabled == nil || *base.Azure.Enabled != false {
t.Errorf("Azure Enabled mismatch: expected false, got %v", *base.Azure.Enabled)
}
if base.Azure.SubscriptionID == nil || *base.Azure.SubscriptionID != "overlay-sub" {
t.Errorf("Azure SubscriptionID mismatch: expected 'overlay-sub', got '%s'", *base.Azure.SubscriptionID)
}
if base.Azure.TenantID == nil || *base.Azure.TenantID != "overlay-tenant" {
t.Errorf("Azure TenantID mismatch: expected 'overlay-tenant', got '%s'", *base.Azure.TenantID)
}
if base.Azure.Environment == nil || *base.Azure.Environment != "overlay-cloud" {
t.Errorf("Azure Environment mismatch: expected 'overlay-cloud', got '%s'", *base.Azure.Environment)
}
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 @@ -337,6 +398,12 @@ func TestConfig_Copy(t *testing.T) {
Enabled: ptrBool(true),
AWSEndpointURL: ptrString("https://original.aws.endpoint"),
},
Azure: &azure.AzureConfig{
Enabled: ptrBool(true),
SubscriptionID: ptrString("original-sub"),
TenantID: ptrString("original-tenant"),
Environment: ptrString("original-cloud"),
},
Docker: &docker.DockerConfig{
Enabled: ptrBool(true),
},
Expand Down Expand Up @@ -379,6 +446,18 @@ func TestConfig_Copy(t *testing.T) {
if original.AWS.Enabled == nil || copy.AWS.Enabled == nil || *original.AWS.Enabled != *copy.AWS.Enabled {
t.Errorf("AWS Enabled mismatch: expected %v, got %v", *original.AWS.Enabled, *copy.AWS.Enabled)
}
if original.Azure.Enabled == nil || copy.Azure.Enabled == nil || *original.Azure.Enabled != *copy.Azure.Enabled {
t.Errorf("Azure Enabled mismatch: expected %v, got %v", *original.Azure.Enabled, *copy.Azure.Enabled)
}
if original.Azure.SubscriptionID == nil || copy.Azure.SubscriptionID == nil || *original.Azure.SubscriptionID != *copy.Azure.SubscriptionID {
t.Errorf("Azure SubscriptionID mismatch: expected %v, got %v", *original.Azure.SubscriptionID, *copy.Azure.SubscriptionID)
}
if original.Azure.TenantID == nil || copy.Azure.TenantID == nil || *original.Azure.TenantID != *copy.Azure.TenantID {
t.Errorf("Azure TenantID mismatch: expected %v, got %v", *original.Azure.TenantID, *copy.Azure.TenantID)
}
if original.Azure.Environment == nil || copy.Azure.Environment == nil || *original.Azure.Environment != *copy.Azure.Environment {
t.Errorf("Azure Environment mismatch: expected %v, got %v", *original.Azure.Environment, *copy.Azure.Environment)
}
if original.Docker.Enabled == nil || copy.Docker.Enabled == nil || *original.Docker.Enabled != *copy.Docker.Enabled {
t.Errorf("Docker Enabled mismatch: expected %v, got %v", *original.Docker.Enabled, *copy.Docker.Enabled)
}
Expand All @@ -397,26 +476,19 @@ func TestConfig_Copy(t *testing.T) {
if original.DNS.Enabled == nil || copy.DNS.Enabled == nil || *original.DNS.Enabled != *copy.DNS.Enabled {
t.Errorf("DNS Enabled mismatch: expected %v, got %v", *original.DNS.Enabled, *copy.DNS.Enabled)
}
if original.Network.CIDRBlock == nil || copy.Network.CIDRBlock == nil || *original.Network.CIDRBlock != *copy.Network.CIDRBlock {
t.Errorf("Network CIDRBlock mismatch: expected %v, got %v", *original.Network.CIDRBlock, *copy.Network.CIDRBlock)
}
if original.Blueprint == nil || copy.Blueprint == nil || *original.Blueprint != *copy.Blueprint {
t.Errorf("Blueprint mismatch: expected %v, got %v", *original.Blueprint, *copy.Blueprint)
}

// Modify the copy and ensure original is unchanged
copy.Docker.Enabled = ptrBool(false)
if original.Docker.Enabled == nil || *original.Docker.Enabled == *copy.Docker.Enabled {
t.Errorf("Original Docker Enabled was modified: expected %v, got %v", true, *copy.Docker.Enabled)
}

copy.Cluster.Enabled = ptrBool(false)
if original.Cluster.Enabled == nil || *original.Cluster.Enabled == *copy.Cluster.Enabled {
t.Errorf("Original Cluster Enabled was modified: expected %v, got %v", true, *copy.Cluster.Enabled)
}
})

t.Run("CopyWithNilValues", func(t *testing.T) {
original := &Context{
Environment: nil,
AWS: nil,
Azure: nil,
Docker: nil,
Git: nil,
Terraform: nil,
Expand All @@ -433,6 +505,9 @@ func TestConfig_Copy(t *testing.T) {
if copy.AWS != nil {
t.Errorf("AWS should be nil, got %v", copy.AWS)
}
if copy.Azure != nil {
t.Errorf("Azure should be nil, got %v", copy.Azure)
}
if copy.Docker != nil {
t.Errorf("Docker should be nil, got %v", copy.Docker)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type ComponentConstructors struct {
NewToolsManager func(di.Injector) tools.ToolsManager

NewAwsEnvPrinter func(di.Injector) env.EnvPrinter
NewAzureEnvPrinter func(di.Injector) env.EnvPrinter
NewDockerEnvPrinter func(di.Injector) env.EnvPrinter
NewKubeEnvPrinter func(di.Injector) env.EnvPrinter
NewOmniEnvPrinter func(di.Injector) env.EnvPrinter
Expand Down Expand Up @@ -186,6 +187,9 @@ func NewDefaultConstructors() ComponentConstructors {
NewAwsEnvPrinter: func(injector di.Injector) env.EnvPrinter {
return env.NewAwsEnvPrinter(injector)
},
NewAzureEnvPrinter: func(injector di.Injector) env.EnvPrinter {
return env.NewAzureEnvPrinter(injector)
},
NewDockerEnvPrinter: func(injector di.Injector) env.EnvPrinter {
return env.NewDockerEnvPrinter(injector)
},
Expand Down Expand Up @@ -906,6 +910,7 @@ func (c *BaseController) createEnvComponents(req Requirements) error {

envPrinters := map[string]func(di.Injector) env.EnvPrinter{
"awsEnv": c.constructors.NewAwsEnvPrinter,
"azureEnv": c.constructors.NewAzureEnvPrinter,
"dockerEnv": c.constructors.NewDockerEnvPrinter,
"kubeEnv": c.constructors.NewKubeEnvPrinter,
"omniEnv": c.constructors.NewOmniEnvPrinter,
Expand All @@ -918,6 +923,9 @@ func (c *BaseController) createEnvComponents(req Requirements) error {
if key == "awsEnv" && !configHandler.GetBool("aws.enabled") {
continue
}
if key == "azureEnv" && !configHandler.GetBool("azure.enabled") {
continue
}
if key == "dockerEnv" && !configHandler.GetBool("docker.enabled") {
continue
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/mock_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func NewMockConstructors() ComponentConstructors {
NewAwsEnvPrinter: func(injector di.Injector) env.EnvPrinter {
return env.NewMockEnvPrinter()
},
NewAzureEnvPrinter: func(injector di.Injector) env.EnvPrinter {
return env.NewMockEnvPrinter()
},
NewDockerEnvPrinter: func(injector di.Injector) env.EnvPrinter {
return env.NewMockEnvPrinter()
},
Expand Down
Loading
Loading