diff --git a/internal/cmd/local/docker/secret.go b/internal/cmd/local/docker/secret.go index bbf6283..5dcc86b 100644 --- a/internal/cmd/local/docker/secret.go +++ b/internal/cmd/local/docker/secret.go @@ -22,28 +22,14 @@ import ( // } func Secret(server, user, pass, email string) ([]byte, error) { // map of the server to the credentials - servers := map[string]credential{ - server: newCredential(user, pass, email), - } - auths := map[string]map[string]credential{ - "auths": servers, - } - - return json.Marshal(auths) -} - -type credential struct { - Username string `json:"username"` - Password string `json:"password"` - Email string `json:"email"` - Auth string `json:"auth"` -} - -func newCredential(user, pass, email string) credential { - return credential{ - Username: user, - Password: pass, - Email: email, - Auth: base64.StdEncoding.EncodeToString([]byte(user + ":" + pass)), - } -} + return json.Marshal(map[string]any{ + "auths": map[string]any { + server: map[string]any { + "username": user, + "password": pass, + "email": email, + "auth": base64.StdEncoding.EncodeToString([]byte(user + ":" + pass)), + }, + }, + }) +} \ No newline at end of file diff --git a/internal/cmd/local/docker/secret_test.go b/internal/cmd/local/docker/secret_test.go index 282f8a6..cfe9f01 100644 --- a/internal/cmd/local/docker/secret_test.go +++ b/internal/cmd/local/docker/secret_test.go @@ -2,17 +2,15 @@ package docker import ( "testing" - - "github.com/google/go-cmp/cmp" ) func Test_Secret(t *testing.T) { - exp := `{"auths":{"my-registry.example:5000":{"username":"tiger","password":"pass1234","email":"tiger@acme.example","auth":"dGlnZXI6cGFzczEyMzQ="}}}` + exp := `{"auths":{"my-registry.example:5000":{"auth":"dGlnZXI6cGFzczEyMzQ=","email":"tiger@acme.example","password":"pass1234","username":"tiger"}}}` act, err := Secret("my-registry.example:5000", "tiger", "pass1234", "tiger@acme.example") if err != nil { t.Fatal(err) } - if d := cmp.Diff(exp, string(act)); d != "" { - t.Errorf("Secret mismatch (-want +got):\n%s", d) + if exp != string(act) { + t.Errorf("Secret mismatch:\nwant: %s\ngot: %s", exp, act) } }