11package plugin
22
33import (
4+ "encoding/json"
45 "fmt"
56 "os"
67 "path/filepath"
@@ -9,7 +10,6 @@ import (
910 "github.com/sirupsen/logrus"
1011 "github.com/urfave/cli/v2"
1112 "golang.org/x/sys/execabs"
12- "gopkg.in/yaml.v3"
1313)
1414
1515// Daemon defines Docker daemon parameters.
@@ -33,8 +33,9 @@ type Daemon struct {
3333// Login defines Docker login parameters.
3434type Login struct {
3535 RegistryData
36- Config string // Docker Auth Config
37- RegistriesYaml string // Docker Auth with YAML config
36+ Config string
37+ Registries []RegistryData
38+ RegistriesRaw string
3839}
3940
4041type RegistryData struct {
@@ -44,10 +45,6 @@ type RegistryData struct {
4445 Email string // Docker registry email
4546}
4647
47- type RegistriesYaml struct {
48- Registries []RegistryData `yaml:"registries"`
49- }
50-
5148// Build defines Docker build parameters.
5249type Build struct {
5350 Ref string // Git commit ref
@@ -86,7 +83,10 @@ type Settings struct {
8683 Dryrun bool
8784}
8885
89- const strictFilePerm = 0o600
86+ const (
87+ strictFilePerm = 0o600
88+ DefaultRegistry = "https://index.docker.io/v1/"
89+ )
9090
9191// Validate handles the settings validation of the plugin.
9292func (p * Plugin ) Validate () error {
@@ -118,6 +118,16 @@ func (p *Plugin) Validate() error {
118118 }
119119 }
120120
121+ if err := json .Unmarshal ([]byte (p .settings .Login .RegistriesRaw ), & p .settings .Login .Registries ); err != nil {
122+ return fmt .Errorf ("error unmarshal registries: %w" , err )
123+ }
124+
125+ for i , registryData := range p .settings .Login .Registries {
126+ if registryData .Registry == "" {
127+ p .settings .Login .Registries [i ].Registry = DefaultRegistry
128+ }
129+ }
130+
121131 return nil
122132}
123133
@@ -185,25 +195,12 @@ func (p *Plugin) Execute() error {
185195 }
186196 }
187197
188- if p .settings .Login .RegistriesYaml != "" {
189- var t RegistriesYaml
198+ for _ , registryData := range p .settings .Login .Registries {
199+ cmd := commandLogin ( registryData )
190200
191- err := yaml . Unmarshal ([] byte ( p . settings . Login . RegistriesYaml ), & t )
201+ err := cmd . Run ( )
192202 if err != nil {
193- return fmt .Errorf ("error unmarshal registries: %w" , err )
194- }
195-
196- for _ , registryData := range t .Registries {
197- if registryData .Registry == "" {
198- registryData .Registry = "https://index.docker.io/v1/"
199- }
200-
201- cmd := commandLogin (registryData )
202-
203- err := cmd .Run ()
204- if err != nil {
205- return fmt .Errorf ("error authenticating: %w" , err )
206- }
203+ return fmt .Errorf ("error authenticating: %w" , err )
207204 }
208205 }
209206
@@ -217,7 +214,7 @@ func (p *Plugin) Execute() error {
217214 switch {
218215 case p .settings .Login .Password != "" :
219216 logrus .Info ("Detected registry credentials" )
220- case p .settings .Login .RegistriesYaml != "" :
217+ case len ( p .settings .Login .Registries ) > 0 :
221218 logrus .Info ("Detected multiple registry credentials" )
222219 case p .settings .Login .Config != "" :
223220 logrus .Info ("Detected registry credentials file" )
0 commit comments