Skip to content

Commit e053648

Browse files
committed
fix(cli): wire oci-configs to grpccmd as requested by @majst01
1 parent 85e7881 commit e053648

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

pixiecore/cli/grpccmd.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package cli
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"net/url"
2021
"os"
@@ -85,6 +86,9 @@ func init() {
8586
grpcCmd.Flags().String("metal-hammer-logging-key", "", "set metal-hammer to send logs to a remote endpoint and authenticate with this key")
8687
grpcCmd.Flags().Bool("metal-hammer-logging-tls-insecure", false, "set metal-hammer to send logs to a remote endpoint without verifying the tls certificate")
8788
grpcCmd.Flags().String("metal-hammer-logging-type", "loki", "set metal-hammer to send logs to a remote endpoint with this logging type")
89+
90+
// metal-hammer oci configs
91+
grpcCmd.Flags().StringSlice("metal-hammer-oci-configs", nil, "multiple metal-hammer oci configs. comma-separated key-value pairs (registry_url=...,username=...,password=...). registry URL is mandatory, login credentials are optional depending on whether the oci image is public.")
8892
}
8993

9094
func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
@@ -219,6 +223,43 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
219223
}
220224
}
221225

226+
metalHammerOciConfigs, err := cmd.Flags().GetStringSlice("metal-hammer-oci-configs")
227+
if err != nil {
228+
return nil, fmt.Errorf("error reading flag: %w", err)
229+
}
230+
231+
var ociConfigs []*api.OciConfig
232+
233+
for _, c := range metalHammerOciConfigs {
234+
var ociConfig *api.OciConfig
235+
236+
parts := strings.SplitSeq(c, ",")
237+
for p := range parts {
238+
kv := strings.SplitN(strings.TrimSpace(p), "=", 2)
239+
if len(kv) != 2 {
240+
return nil, fmt.Errorf("invalid key-value pair in OCI config: %q", p)
241+
}
242+
243+
k := strings.ToLower(strings.TrimSpace(kv[0]))
244+
v := strings.TrimSpace(kv[1])
245+
switch k {
246+
case "registry_url":
247+
if v == "" {
248+
return nil, fmt.Errorf("no registry url specified for oci config: %s", c)
249+
}
250+
ociConfig.RegistryURL = v
251+
case "username":
252+
ociConfig.Username = v
253+
case "password":
254+
ociConfig.Password = v
255+
default:
256+
return nil, fmt.Errorf("unknown key %q in OCI config", k)
257+
}
258+
}
259+
260+
ociConfigs = append(ociConfigs, ociConfig)
261+
}
262+
222263
return &api.MetalConfig{
223264
Debug: metalHammerDebug,
224265
GRPCAddress: grpcAddress,
@@ -231,5 +272,6 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
231272
NTPServers: ntpServers,
232273
Logging: logging,
233274
Partition: partition,
275+
OciConfig: ociConfigs,
234276
}, nil
235277
}

0 commit comments

Comments
 (0)