Allow registry auth config without authority value (#420)

* Allow registry auth config without authority value

Signed-off-by: Dan Luhring <dan.luhring@anchore.com>

* Update CLI tests for new stereoscope log output

Signed-off-by: Dan Luhring <dan.luhring@anchore.com>
This commit is contained in:
Dan Luhring
2021-05-24 16:05:56 -04:00
committed by GitHub
parent 2ca2f03501
commit 17bbf840cf
5 changed files with 20 additions and 21 deletions
+3 -3
View File
@@ -37,7 +37,7 @@ func (cfg *registry) parseConfigValues() error {
os.Getenv("SYFT_REGISTRY_AUTH_PASSWORD"),
os.Getenv("SYFT_REGISTRY_AUTH_TOKEN")
if hasNonEmptyCredentials(authority, username, password, token) {
if hasNonEmptyCredentials(username, password, token) {
// note: we prepend the credentials such that the environment variables take precedence over on-disk configuration.
cfg.Auth = append([]RegistryCredentials{
{
@@ -51,8 +51,8 @@ func (cfg *registry) parseConfigValues() error {
return nil
}
func hasNonEmptyCredentials(authority, username, password, token string) bool {
return authority != "" && password != "" && username != "" || authority != "" && token != ""
func hasNonEmptyCredentials(username, password, token string) bool {
return password != "" && username != "" || token != ""
}
func (cfg *registry) ToOptions() *image.RegistryOptions {
+12 -15
View File
@@ -9,51 +9,48 @@ import (
func TestHasNonEmptyCredentials(t *testing.T) {
tests := []struct {
auth, username, password, token string
expected bool
username, password, token string
expected bool
}{
{
"", "", "", "",
"", "", "",
false,
},
{
"auth", "", "", "",
"user", "", "",
false,
},
{
"auth", "user", "", "",
"", "pass", "",
false,
},
{
"auth", "", "pass", "",
false,
},
{
"auth", "", "pass", "tok",
"", "pass", "tok",
true,
},
{
"auth", "user", "", "tok",
"user", "", "tok",
true,
},
{
"auth", "", "", "tok",
"", "", "tok",
true,
},
{
"auth", "user", "pass", "tok",
"user", "pass", "tok",
true,
},
{
"auth", "user", "pass", "",
"user", "pass", "",
true,
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%+v", test), func(t *testing.T) {
assert.Equal(t, test.expected, hasNonEmptyCredentials(test.auth, test.username, test.password, test.token))
assert.Equal(t, test.expected, hasNonEmptyCredentials(test.username, test.password, test.token))
})
}
}