Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Showing 2 changed files with 30 additions and 30 deletions.
56 changes: 28 additions & 28 deletions registry/azure.go
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@ import (
)

const (
// Mount volume from hostpath.
azureCloudConfigJsonFile = "/etc/kubernetes/azure.json"
// Mount volume from hostpath.
azureCloudConfigJsonFile = "/etc/kubernetes/azure.json"
)

type azureCloudConfig struct {
AADClientId string `json:"aadClientId"`
AADClientSecret string `json:"aadClientSecret"`
AADClientId string `json:"aadClientId"`
AADClientSecret string `json:"aadClientSecret"`
}

// Fetch Azure Active Directory clientid/secret pair from azure.json, usable for container registry authentication.
@@ -23,31 +23,31 @@ type azureCloudConfig struct {
// https://github.com/kubernetes/kubernetes/issues/58034 seeks to deprecate this kubelet command-line argument, possibly
// replacing it with managed identity for the Node VMs. See https://github.com/Azure/acr/blob/master/docs/AAD-OAuth.md
func GetAzureCloudConfigAADToken(host string) (creds, error) {
jsonFile, err := ioutil.ReadFile(azureCloudConfigJsonFile)
if err != nil {
return creds{}, err
}

var token azureCloudConfig

err = json.Unmarshal(jsonFile, &token)
if err != nil {
return creds{}, err
}

return creds{
registry: host,
provenance: "azure.json",
username: token.AADClientId,
password: token.AADClientSecret}, nil
jsonFile, err := ioutil.ReadFile(azureCloudConfigJsonFile)
if err != nil {
return creds{}, err
}

var token azureCloudConfig

err = json.Unmarshal(jsonFile, &token)
if err != nil {
return creds{}, err
}

return creds{
registry: host,
provenance: "azure.json",
username: token.AADClientId,
password: token.AADClientSecret}, nil
}

// List from https://github.com/kubernetes/kubernetes/blob/master/pkg/credentialprovider/azure/azure_credentials.go
func HostIsAzureContainerRegistry(host string) (bool) {
for _, v := range []string{".azurecr.io", ".azurecr.cn", ".azurecr.de", ".azurecr.us"} {
if strings.HasSuffix(host, v) {
return true
}
}
return false
func HostIsAzureContainerRegistry(host string) bool {
for _, v := range []string{".azurecr.io", ".azurecr.cn", ".azurecr.de", ".azurecr.us"} {
if strings.HasSuffix(host, v) {
return true
}
}
return false
}
4 changes: 2 additions & 2 deletions registry/azure_test.go
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ import (

func Test_HostIsAzureContainerRegistry(t *testing.T) {
for _, v := range []struct {
host string
isACR bool
host string
isACR bool
}{
{
host: "azurecr.io",

0 comments on commit 3cb2179

Please sign in to comment.