Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow storing the registry password in a file #360

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/backend/registrybackend/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -15,6 +15,7 @@ package security

import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"sync"
Expand Down Expand Up @@ -47,6 +48,7 @@ var v2Version = auth.APIVersion{
type Config struct {
TLS httputil.TLSConfig `yaml:"tls"`
BasicAuth *types.AuthConfig `yaml:"basic"`
PasswordFile string `yaml:"passwordFile"`
RemoteCredentialsStore string `yaml:"credsStore"`
EnableHTTPFallback bool `yaml:"enableHTTPFallback"`
}
Expand Down Expand Up @@ -173,6 +175,12 @@ func (c credentialStore) Basic(*url.URL) (string, string) {
if basic == nil {
return "", ""
}
if c.config.PasswordFile != "" {
passwordBytes, err := ioutil.ReadFile(c.config.PasswordFile)
if err == nil {
return basic.Username, (string)(passwordBytes)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Go, it's preferred to typecast by calling T(v), where T is the new type and v is the value:
return basic.Username, string(passwordBytes)

}
}
return basic.Username, basic.Password
}

Expand Down