@@ -20,6 +20,7 @@ import (
2020 "os"
2121 "strings"
2222
23+ yaml "github.com/goccy/go-yaml"
2324 "github.com/metal-stack/pixie/api"
2425 "github.com/metal-stack/pixie/pixiecore"
2526 "github.com/spf13/cobra"
@@ -222,44 +223,38 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
222223 }
223224 }
224225
225- metalHammerOciConfigs , err := cmd .Flags ().GetStringSlice ("metal-hammer-oci-configs " )
226+ metalHammerOciConfigFilePath , err := cmd .Flags ().GetString ("metal-hammer-oci-config-file-path " )
226227 if err != nil {
227228 return nil , fmt .Errorf ("error reading flag: %w" , err )
228229 }
229230
230231 ociConfigs := make (map [string ]* api.OciCredentials )
232+ if metalHammerOciConfigFilePath != "" {
233+ metalHammerOciConfigFileContent , err := os .ReadFile (metalHammerOciConfigFilePath )
234+ if err != nil {
235+ return nil , fmt .Errorf ("error retrieving oci configs file: %w" , err )
236+ }
231237
232- for _ , c := range metalHammerOciConfigs {
233- var (
234- ociCredentials * api.OciCredentials
235- registryURL string
236- )
238+ type MetalHammerOciConfig struct {
239+ RegistryURL string `yaml:"registry-url"`
240+ Credentials * api.OciCredentials
241+ }
242+ type MetalHammerOciConfigs struct {
243+ OciConfigs []MetalHammerOciConfig `yaml:"oci-configs"`
244+ }
245+ var metalHammerOciConfigs MetalHammerOciConfigs
246+ err = yaml .Unmarshal (metalHammerOciConfigFileContent , & metalHammerOciConfigs )
247+ if err != nil {
248+ return nil , fmt .Errorf ("error parsing oci configs: %w" , err )
249+ }
237250
238- parts := strings .SplitSeq (c , "," )
239- for p := range parts {
240- kv := strings .SplitN (strings .TrimSpace (p ), "=" , 2 )
241- if len (kv ) != 2 {
242- return nil , fmt .Errorf ("invalid key-value pair in OCI config: %q" , p )
251+ for _ , config := range metalHammerOciConfigs .OciConfigs {
252+ if config .RegistryURL == "" {
253+ return nil , fmt .Errorf ("no registry url specified for oci config: %+v" , config )
243254 }
244255
245- k := strings .ToLower (strings .TrimSpace (kv [0 ]))
246- v := strings .TrimSpace (kv [1 ])
247- switch k {
248- case "registry_url" :
249- if v == "" {
250- return nil , fmt .Errorf ("no registry url specified for oci config: %s" , c )
251- }
252- registryURL = v
253- case "username" :
254- ociCredentials .Username = v
255- case "password" :
256- ociCredentials .Password = v
257- default :
258- return nil , fmt .Errorf ("unknown key %q in OCI config" , k )
259- }
256+ ociConfigs [config .RegistryURL ] = config .Credentials
260257 }
261-
262- ociConfigs [registryURL ] = ociCredentials
263258 }
264259
265260 return & api.MetalConfig {
0 commit comments