• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Azure / aks-tls-bootstrap-client / 6934250924

20 Nov 2023 06:22PM UTC coverage: 86.311% (-0.2%) from 86.534%
6934250924

push

github

web-flow
feat: add multicloud support, refactor unit tests (#37)

* feat: add multicloud support, refactor unit tests

* chore: fix lint

---------

Co-authored-by: Cameron Meissner <cameissner@microsoft.com>

68 of 82 new or added lines in 4 files covered. (82.93%)

2 existing lines in 1 file now uncovered.

372 of 431 relevant lines covered (86.31%)

4.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
/pkg/client/cloud.go
1
// Copyright (c) Microsoft Corporation.
2
// Licensed under the MIT license.
3

4
package client
5

6
import (
7
        "encoding/json"
8
        "fmt"
9
        "strings"
10

11
        "github.com/Azure/aks-tls-bootstrap-client/pkg/datamodel"
12
        "github.com/Azure/go-autorest/autorest/azure"
13
)
14

15
const (
16
        azureConfigPathLinux         = "/etc/kubernetes/azure.json"
17
        azureConfigPathWindows       = "c:\\k\\azure.json"
18
        customCloudConfigPathLinux   = "/etc/kubernetes/akscustom.json"
19
        customCloudConfigPathWindows = "c:\\k\\azurestackcloud.json"
20

21
        azurePublicCloud = "AzurePublicCloud"
22
        azureUSGovCloud  = "AzureUSGovernmentCloud"
23
        azureChinaCloud  = "AzureChinaCloud"
24
)
25

26
func getAADAuthorityURL(reader fileReader, azureConfig *datamodel.AzureConfig) (string, error) {
5✔
27
        cloudName := azureConfig.Cloud
5✔
28

5✔
29
        if strings.EqualFold(cloudName, azurePublicCloud) || strings.EqualFold(cloudName, azureUSGovCloud) || strings.EqualFold(cloudName, azureChinaCloud) {
8✔
30
                env, err := azure.EnvironmentFromName(cloudName)
3✔
31
                if err != nil {
3✔
NEW
32
                        return "", fmt.Errorf("unable to determine cloud environment config from cloud name %s: %w", cloudName, err)
×
NEW
33
                }
×
34
                return env.ActiveDirectoryEndpoint, nil
3✔
35
        }
36

37
        // azure.EnvironmnetFromName does something similar for stack, but that relies on AZURE_ENVIRONMENT_FILENAME being set
38
        // which isn't always the case on Windows.
39
        var (
2✔
40
                customEnv = &azure.Environment{}
2✔
41
                err       error
2✔
42
        )
2✔
43
        if isWindows() {
2✔
NEW
44
                err = loadJSONFromPath(reader, customCloudConfigPathWindows, customEnv)
×
45
        } else {
2✔
46
                err = loadJSONFromPath(reader, customCloudConfigPathLinux, customEnv)
2✔
47
        }
2✔
48
        if err != nil {
3✔
49
                return "", fmt.Errorf("unable to load custom cloud environment config: %w", err)
1✔
50
        }
1✔
51

52
        return customEnv.ActiveDirectoryEndpoint, nil
1✔
53
}
54

55
func (c *tlsBootstrapClientImpl) loadAzureConfig() error {
9✔
56
        var (
9✔
57
                azureConfig = &datamodel.AzureConfig{}
9✔
58
                err         error
9✔
59
        )
9✔
60
        if isWindows() {
9✔
NEW
61
                err = loadJSONFromPath(c.reader, azureConfigPathWindows, azureConfig)
×
62
        } else {
9✔
63
                err = loadJSONFromPath(c.reader, azureConfigPathLinux, azureConfig)
9✔
64
        }
9✔
65
        if err != nil {
11✔
66
                return fmt.Errorf("unable to load azure config: %w", err)
2✔
67
        }
2✔
68
        c.azureConfig = azureConfig
7✔
69
        return nil
7✔
70
}
71

72
func loadJSONFromPath(reader fileReader, path string, out interface{}) error {
11✔
73
        jsonBytes, err := reader.ReadFile(path)
11✔
74
        if err != nil {
13✔
75
                return fmt.Errorf("failed to parse %s: %w", path, err)
2✔
76
        }
2✔
77
        if err = json.Unmarshal(jsonBytes, out); err != nil {
10✔
78
                return fmt.Errorf("failed to unmarshal %s: %w", path, err)
1✔
79
        }
1✔
80
        return nil
8✔
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc