Skip to content

Commit 644a7b5

Browse files
committed
refactor(api): introduce map of registryURL -> ociCredentials as suggested by @majst01
1 parent 380592a commit 644a7b5

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

api/api.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type MetalConfig struct {
1313
NTPServers []string `json:"ntp_servers,omitempty"`
1414
Partition string `json:"partition"`
1515
// Logging contains logging configurations passed to metal-hammer
16-
Logging *Logging `json:"logging,omitempty"`
17-
OciConfig []*OciConfig `json:"oci_config,omitempty"`
16+
Logging *Logging `json:"logging,omitempty"`
17+
OciConfig map[string]*OciCredentials `json:"oci_config,omitempty"`
1818
}
1919

2020
type Logging struct {
@@ -46,9 +46,7 @@ type CertificateAuth struct {
4646
InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty"`
4747
}
4848

49-
type OciConfig struct {
50-
// URL pointing to the oci registry
51-
RegistryURL string `json:"registry_url,omitempty"`
49+
type OciCredentials struct {
5250
// Username that is capable of logging in to the registry
5351
Username string `json:"username,omitempty"`
5452
// Password for the user

pixiecore/cli/grpccmd.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,13 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
227227
return nil, fmt.Errorf("error reading flag: %w", err)
228228
}
229229

230-
var ociConfigs []*api.OciConfig
230+
ociConfigs := make(map[string]*api.OciCredentials)
231231

232232
for _, c := range metalHammerOciConfigs {
233-
var ociConfig *api.OciConfig
233+
var (
234+
ociCredentials *api.OciCredentials
235+
registryURL string
236+
)
234237

235238
parts := strings.SplitSeq(c, ",")
236239
for p := range parts {
@@ -246,17 +249,17 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
246249
if v == "" {
247250
return nil, fmt.Errorf("no registry url specified for oci config: %s", c)
248251
}
249-
ociConfig.RegistryURL = v
252+
registryURL = v
250253
case "username":
251-
ociConfig.Username = v
254+
ociCredentials.Username = v
252255
case "password":
253-
ociConfig.Password = v
256+
ociCredentials.Password = v
254257
default:
255258
return nil, fmt.Errorf("unknown key %q in OCI config", k)
256259
}
257260
}
258261

259-
ociConfigs = append(ociConfigs, ociConfig)
262+
ociConfigs[registryURL] = ociCredentials
260263
}
261264

262265
return &api.MetalConfig{

0 commit comments

Comments
 (0)