mirror of
https://github.com/anchore/syft
synced 2024-11-10 14:24:12 +00:00
dont append registry auth if potentially empty
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
2a5207ec88
commit
9fb79bfa2e
2 changed files with 62 additions and 3 deletions
|
@ -37,7 +37,7 @@ func (cfg *registry) parseConfigValues() error {
|
||||||
os.Getenv("SYFT_REGISTRY_AUTH_PASSWORD"),
|
os.Getenv("SYFT_REGISTRY_AUTH_PASSWORD"),
|
||||||
os.Getenv("SYFT_REGISTRY_AUTH_TOKEN")
|
os.Getenv("SYFT_REGISTRY_AUTH_TOKEN")
|
||||||
|
|
||||||
if hasNonEmptyCredentials(authority, password, token) {
|
if hasNonEmptyCredentials(authority, username, password, token) {
|
||||||
// note: we prepend the credentials such that the environment variables take precedence over on-disk configuration.
|
// note: we prepend the credentials such that the environment variables take precedence over on-disk configuration.
|
||||||
cfg.Auth = append([]RegistryCredentials{
|
cfg.Auth = append([]RegistryCredentials{
|
||||||
{
|
{
|
||||||
|
@ -51,8 +51,8 @@ func (cfg *registry) parseConfigValues() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasNonEmptyCredentials(authority, password, token string) bool {
|
func hasNonEmptyCredentials(authority, username, password, token string) bool {
|
||||||
return authority != "" && password != "" || authority != "" && token != ""
|
return authority != "" && password != "" && username != "" || authority != "" && token != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *registry) ToOptions() *image.RegistryOptions {
|
func (cfg *registry) ToOptions() *image.RegistryOptions {
|
||||||
|
|
59
internal/config/registry_test.go
Normal file
59
internal/config/registry_test.go
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHasNonEmptyCredentials(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
auth, username, password, token string
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"", "", "", "",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"auth", "", "", "",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"auth", "user", "", "",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"auth", "", "pass", "",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"auth", "", "pass", "tok",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"auth", "user", "", "tok",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"auth", "", "", "tok",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"auth", "user", "pass", "tok",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"auth", "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))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue