Skip to content

Commit f930b48

Browse files
Merge branch 'master' into master
2 parents a251a9b + e7f266b commit f930b48

File tree

14 files changed

+65
-29
lines changed

14 files changed

+65
-29
lines changed

functional_tests/helpers.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package functests
88
import (
99
"encoding/json"
1010
"fmt"
11-
"io/ioutil"
1211
"os"
1312
"strings"
1413

@@ -49,10 +48,10 @@ func check(cbCtx *appgw.ConfigBuilderContext, expectedFilename string, stopChan
4948

5049
// Repair tests
5150
if os.Getenv("RENDER_SNAPSHOTS") != "" {
52-
ioutil.WriteFile(expectedFilename, []byte(actualJSONTxt), 0644)
51+
os.WriteFile(expectedFilename, []byte(actualJSONTxt), 0644)
5352
}
5453

55-
expectedBytes, err := ioutil.ReadFile(expectedFilename)
54+
expectedBytes, err := os.ReadFile(expectedFilename)
5655
expectedJSON := strings.Trim(string(expectedBytes), "\n")
5756
gomega.Expect(err).ToNot(gomega.HaveOccurred())
5857

helm/ingress-azure/templates/crds.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ metadata:
2424
{{- end }}
2525
spec:
2626
{{- if .hostname }}
27-
hostname: {{ .hostname }}
27+
hostname: {{ .hostname | quote }}
2828
{{- end }}
2929
{{- if .paths }}
3030
paths:
@@ -35,4 +35,4 @@ spec:
3535
---
3636
{{- end }}
3737
{{- end -}}
38-
{{- end -}}
38+
{{- end -}}

helm/ingress-azure/tests/snapshots.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"bufio"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"os"
1413
"os/exec"
1514
"path/filepath"
@@ -73,7 +72,7 @@ func RenderChart(chart, values, dir string) error {
7372

7473
// CaptureSnapshot renders a new snapshot from a given Helm chart and values file.
7574
func CaptureSnapshot(chart, values string) (*Snapshot, error) {
76-
dir, err := ioutil.TempDir("", "")
75+
dir, err := os.MkdirTemp("", "")
7776
if err != nil {
7877
return nil, fmt.Errorf("creating tempdir: %v", err)
7978
}
@@ -163,7 +162,7 @@ func StripNonDeterministic(path string) error {
163162
lines = append(lines, text)
164163
}
165164

166-
return ioutil.WriteFile(path, []byte(strings.Join(lines, "\n")), 0644)
165+
return os.WriteFile(path, []byte(strings.Join(lines, "\n")), 0644)
167166
})
168167
}
169168

pkg/appgw/appgw_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package appgw
88
import (
99
"context"
1010
"fmt"
11-
"io/ioutil"
11+
"os"
1212
"time"
1313

1414
n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-03-01/network"
@@ -606,11 +606,11 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
606606
Data: make(map[string][]byte),
607607
}
608608

609-
key, err := ioutil.ReadFile("../../tests/data/k8s.cert.key")
609+
key, err := os.ReadFile("../../tests/data/k8s.cert.key")
610610
Ω(err).ToNot(HaveOccurred(), "Unable to read the cert key: %v", err)
611611
ingressSecret.Data["tls.key"] = key
612612

613-
cert, err := ioutil.ReadFile("../../tests/data/k8s.x509.cert")
613+
cert, err := os.ReadFile("../../tests/data/k8s.x509.cert")
614614
Ω(err).ToNot(HaveOccurred(), "Unable to read the cert key: %v", err)
615615
ingressSecret.Data["tls.crt"] = cert
616616

pkg/azure/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (az *azClient) WaitForGetAccessOnGateway(maxRetryCount int) (err error) {
174174
)
175175

176176
e.Message += fmt.Sprintf(" You can use '%s' to assign permissions."+
177-
" AGIC Identity needs atleast has 'Contributor' access to Application Gateway '%s' and 'Reader' access to Application Gateway's Resource Group '%s'.",
177+
" AGIC Identity needs at least 'Contributor' access to Application Gateway '%s' and 'Reader' access to Application Gateway's Resource Group '%s'.",
178178
roleAssignmentCmd,
179179
string(az.appGwName),
180180
string(az.resourceGroupName),

pkg/azure/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"errors"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"time"
1010

@@ -29,7 +29,7 @@ func (fs *FakeSender) Do(request *http.Request) (response *http.Response, err er
2929
if fs.body != nil {
3030
b, err := json.Marshal(fs.body)
3131
if err == nil {
32-
response.Body = ioutil.NopCloser(bytes.NewReader(b))
32+
response.Body = io.NopCloser(bytes.NewReader(b))
3333
}
3434
}
3535
}

pkg/azure/cloudproviderconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package azure
88
import (
99
"encoding/json"
1010
"fmt"
11-
"io/ioutil"
11+
"os"
1212
)
1313

1414
// CloudProviderConfig represent the CloudProvider Context file such as Azure
@@ -29,7 +29,7 @@ type CloudProviderConfig struct {
2929

3030
// NewCloudProviderConfig returns an CloudProviderConfig struct from file path
3131
func NewCloudProviderConfig(path string) (*CloudProviderConfig, error) {
32-
b, err := ioutil.ReadFile(path)
32+
b, err := os.ReadFile(path)
3333
if err != nil {
3434
return nil, fmt.Errorf("Reading Az Context file %q failed: %v", path, err)
3535
}

pkg/azure/defaultazurecredential/authorizer.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package defaultazurecredential
22

33
import (
44
"context"
5+
"fmt"
6+
"os"
57

68
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
79
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
810
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
911
"github.com/Azure/go-autorest/autorest"
12+
"github.com/Azure/go-autorest/autorest/azure"
1013
"k8s.io/klog/v2"
1114
)
1215

@@ -26,20 +29,34 @@ func NewAuthorizer() (autorest.Authorizer, error) {
2629
return nil, err
2730
}
2831

32+
scope := tokenScopeFromEnvironment()
33+
klog.V(7).Infof("Fetching token with scope %s", scope)
2934
return autorest.NewBearerAuthorizer(&tokenCredentialWrapper{
30-
cred: cred,
35+
cred: cred,
36+
scope: scope,
3137
}), nil
3238
}
3339

40+
func tokenScopeFromEnvironment() string {
41+
cloud := os.Getenv("AZURE_ENVIRONMENT")
42+
env, err := azure.EnvironmentFromName(cloud)
43+
if err != nil {
44+
env = azure.PublicCloud
45+
}
46+
47+
return fmt.Sprintf("%s.default", env.TokenAudience)
48+
}
49+
3450
type tokenCredentialWrapper struct {
35-
cred azcore.TokenCredential
51+
cred azcore.TokenCredential
52+
scope string
3653
}
3754

3855
func (w *tokenCredentialWrapper) OAuthToken() string {
3956
klog.V(7).Info("Getting Azure token using DefaultAzureCredential")
4057

4158
token, err := w.cred.GetToken(context.Background(), policy.TokenRequestOptions{
42-
Scopes: []string{"https://management.azure.com/.default"},
59+
Scopes: []string{w.scope},
4360
})
4461

4562
if err != nil {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package defaultazurecredential
2+
3+
import (
4+
"os"
5+
"testing"
6+
)
7+
8+
func TestTokenScopeFromEnvironment(t *testing.T) {
9+
scope := map[string]string{
10+
"AZUREPUBLICCLOUD": "https://management.azure.com/.default",
11+
"AZURECHINACLOUD": "https://management.chinacloudapi.cn/.default",
12+
"AZUREUSGOVERNMENTCLOUD": "https://management.usgovcloudapi.net/.default",
13+
}
14+
15+
for env, expectedScope := range scope {
16+
os.Setenv("AZURE_ENVIRONMENT", env)
17+
scope := tokenScopeFromEnvironment()
18+
if scope != expectedScope {
19+
t.Errorf("Expected scope %s, got %s", expectedScope, scope)
20+
}
21+
}
22+
}

pkg/brownfield/targets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (t Target) IsBlacklisted(blacklist TargetBlacklist) bool {
3434
// An empty blacklist hostname indicates that any hostname would be blacklisted.
3535
// If host names match - this target is in the blacklist.
3636
// AGIC is allowed to create and modify App Gwy config for blank host.
37-
hostIsBlacklisted := blTarget.Hostname == "" || strings.ToLower(t.Hostname) == strings.ToLower(blTarget.Hostname)
37+
hostIsBlacklisted := blTarget.Hostname == "" || strings.EqualFold(t.Hostname, blTarget.Hostname)
3838

3939
pathIsBlacklisted := blTarget.Path == "" || blTarget.Path == "/*" || t.Path.lower() == blTarget.Path.lower() || blTarget.Path.contains(t.Path) // TODO(draychev): || t.Path.contains(blTarget.Path)
4040

0 commit comments

Comments
 (0)