Skip to content

Commit 1f6189f

Browse files
Merge pull request #113 from spectrocloud/PEM-7501
PEM-7501: Loaded custom azure environment from file
2 parents 23953c3 + 34c9590 commit 1f6189f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

azure/scope/azure_secret_cloud.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package scope
2+
3+
import (
4+
"context"
5+
"os"
6+
"path/filepath"
7+
"strings"
8+
9+
"github.com/Azure/go-autorest/autorest/azure"
10+
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
11+
)
12+
13+
const (
14+
AzureEnvironentFolderEnvName = "AZURE_ENVIRONMENT_FOLDER"
15+
)
16+
17+
func init() {
18+
19+
_, log, done := tele.StartSpanWithLogger(context.Background(), "scope.AzureScope.init")
20+
log.Info("AzureSecretCloud initializing")
21+
defer done()
22+
path := os.Getenv(AzureEnvironentFolderEnvName)
23+
log.Info("Path is", path)
24+
if path == "" {
25+
return
26+
}
27+
files, err := os.ReadDir(path)
28+
if err != nil {
29+
log.Error(err, "error reading folder", "path", path)
30+
return
31+
}
32+
33+
for _, file := range files {
34+
if !file.IsDir() && strings.EqualFold(filepath.Ext(file.Name()), ".json") {
35+
if env, err := azure.EnvironmentFromFile(filepath.Join(path, file.Name())); err == nil {
36+
azure.SetEnvironment(env.Name, env)
37+
log.Info("loaded Azure environment from file", "EnvName", env.Name)
38+
log.Info("loaded Azure environment from file", "filename", file.Name())
39+
} else {
40+
log.Error(err, "failed to load Azure environment from file", "filename", file.Name())
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)