Skip to content

Commit af04f29

Browse files
authored
Merge pull request #25 from tmax-cloud/fix/secret-error
[fix] Fix secret parse error
2 parents b230890 + 386d00b commit af04f29

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

internal/utils/secret.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package utils
22

33
import (
4+
"encoding/base64"
45
"encoding/json"
56
"fmt"
67
corev1 "k8s.io/api/core/v1"
@@ -69,7 +70,7 @@ func (s *ImagePullSecret) GetHostBasicAuth(host string) (string, error) {
6970
username, isUserPresent := loginAuth[DockerConfigUserKey]
7071
password, isPasswordPresent := loginAuth[DockerConfigPasswordKey]
7172
if isUserPresent && isPasswordPresent {
72-
return fmt.Sprintf("%s:%s", username, password), nil
73+
return base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", username, password))), nil
7374
}
7475
return "", fmt.Errorf("there is neither basic auth nor id/pw in docker config json for host %s", host)
7576
}

internal/utils/secret_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package utils
22

33
import (
4+
"encoding/base64"
45
"github.com/bmizerany/assert"
56
corev1 "k8s.io/api/core/v1"
67
"reflect"
@@ -143,7 +144,7 @@ func TestImagePullSecret_GetHostBasicAuth(t *testing.T) {
143144
auths: map[string]DockerLoginCredential{
144145
"https://found-host": {"user": "testID", "password": "testPW"},
145146
},
146-
expectedAuth: "testID:testPW",
147+
expectedAuth: base64.StdEncoding.EncodeToString([]byte("testID:testPW")),
147148
expectedErrorOccurs: false,
148149
expectedErrorString: "",
149150
},

pkg/server/validator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package server
22

33
import (
44
"context"
5-
"encoding/base64"
65
"fmt"
76
"github.com/tmax-cloud/image-validating-webhook/internal/utils"
87
"github.com/tmax-cloud/registry-operator/pkg/image"
@@ -191,7 +190,7 @@ func (h *validator) getBasicAuthForRegistry(host string) (string, error) {
191190
continue
192191
}
193192

194-
return base64.StdEncoding.EncodeToString([]byte(basicAuth)), nil
193+
return basicAuth, nil
195194
}
196195

197196
// DO NOT return error - the image may be public

0 commit comments

Comments
 (0)