Merge pull request #13 from Area128/master

Allow reading password from file so that docker secrets can be used
This commit is contained in:
Roman Vynar 2018-08-14 14:29:02 +03:00 committed by GitHub
commit 7525e87c1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -12,8 +12,11 @@ verify_tls: true
# They need to have a full access to the registry. # They need to have a full access to the registry.
# If token authentication service is enabled, it will be auto-discovered and those credentials # If token authentication service is enabled, it will be auto-discovered and those credentials
# will be used to obtain access tokens. # will be used to obtain access tokens.
# When the registry_password_file entry is used, the password can be passed as a docker secret
# and read from file. This overides the registry_password entry.
registry_username: user registry_username: user
registry_password: pass registry_password: pass
# registry_password_file: /run/secrets/registry_password_file
# Event listener token. # Event listener token.
# The same one should be configured on Docker registry as Authorization Bearer token. # The same one should be configured on Docker registry as Authorization Bearer token.

12
main.go
View File

@ -26,6 +26,7 @@ type configData struct {
VerifyTLS bool `yaml:"verify_tls"` VerifyTLS bool `yaml:"verify_tls"`
Username string `yaml:"registry_username"` Username string `yaml:"registry_username"`
Password string `yaml:"registry_password"` Password string `yaml:"registry_password"`
PasswordFile string `yaml:"registry_password_file"`
EventListenerToken string `yaml:"event_listener_token"` EventListenerToken string `yaml:"event_listener_token"`
EventRetentionDays int `yaml:"event_retention_days"` EventRetentionDays int `yaml:"event_retention_days"`
EventDatabaseDriver string `yaml:"event_database_driver"` EventDatabaseDriver string `yaml:"event_database_driver"`
@ -86,6 +87,17 @@ func main() {
a.config.BasePath = a.config.BasePath[0 : len(a.config.BasePath)-1] a.config.BasePath = a.config.BasePath[0 : len(a.config.BasePath)-1]
} }
} }
// Read password from file.
if a.config.PasswordFile != "" {
if _, err := os.Stat(a.config.PasswordFile); os.IsNotExist(err) {
panic(err)
}
passwordBytes, err := ioutil.ReadFile(a.config.PasswordFile)
if err != nil {
panic(err)
}
a.config.Password = string(passwordBytes[:])
}
// Init registry API client. // Init registry API client.
a.client = registry.NewClient(a.config.RegistryURL, a.config.VerifyTLS, a.config.Username, a.config.Password) a.client = registry.NewClient(a.config.RegistryURL, a.config.VerifyTLS, a.config.Username, a.config.Password)