Skip to content

Commit

Permalink
Adding feature for #4209
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy-Boyle <9406398+Jeremy-Boyle@users.noreply.github.com>
  • Loading branch information
Jeremy-Boyle committed Jan 25, 2024
1 parent 8dd49cc commit 3ca267a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 11 additions & 0 deletions provider/azure/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ func getCloudConfiguration(name string) (cloud.Configuration, error) {
return cloud.AzureGovernment, nil
case "AZURECHINACLOUD":
return cloud.AzureChina, nil
case "AZURECUSTOMCLOUD":
azureAdEndpoint := os.Getenv("AZURE_AD_ENDPOINT")

if azureAdEndpoint == "" {
return cloud.Configuration{}, fmt.Errorf("AD Endpoint Not set: %s", name)
} else {
customCloud := cloud.Configuration{
ActiveDirectoryAuthorityHost: os.Getenv("AZURE_AD_ENDPOINT"),
}
return customCloud, nil
}
}
return cloud.Configuration{}, fmt.Errorf("unknown cloud name: %s", name)
}
16 changes: 13 additions & 3 deletions provider/azure/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package azure

import (
"os"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
Expand All @@ -26,14 +27,23 @@ func TestGetCloudConfiguration(t *testing.T) {
tests := map[string]struct {
cloudName string
expected cloud.Configuration
setEnv map[string]string
}{
"AzureChinaCloud": {"AzureChinaCloud", cloud.AzureChina},
"AzurePublicCloud": {"", cloud.AzurePublic},
"AzureUSGovernment": {"AzureUSGovernmentCloud", cloud.AzureGovernment},
"AzureChinaCloud": {"AzureChinaCloud", cloud.AzureChina, nil},
"AzurePublicCloud": {"", cloud.AzurePublic, nil},
"AzureUSGovernment": {"AzureUSGovernmentCloud", cloud.AzureGovernment, nil},
"AzureCustomCloud": {"AzureCustomCloud", cloud.Configuration{ActiveDirectoryAuthorityHost: "https://custom.microsoftonline.com/"}, map[string]string{"AZURE_AD_ENDPOINT": "https://custom.microsoftonline.com/"}},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
if test.setEnv != nil {
for key, value := range test.setEnv {
os.Setenv(key, value)
defer os.Unsetenv(key)
}
}

cloudCfg, err := getCloudConfiguration(test.cloudName)
if err != nil {
t.Errorf("got unexpected err %v", err)
Expand Down

0 comments on commit 3ca267a

Please sign in to comment.