Skip to content

Commit 6e075b2

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

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

pixiecore/cli/grpccmd.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func init() {
8585
grpcCmd.Flags().String("metal-hammer-logging-key", "", "set metal-hammer to send logs to a remote endpoint and authenticate with this key")
8686
grpcCmd.Flags().Bool("metal-hammer-logging-tls-insecure", false, "set metal-hammer to send logs to a remote endpoint without verifying the tls certificate")
8787
grpcCmd.Flags().String("metal-hammer-logging-type", "loki", "set metal-hammer to send logs to a remote endpoint with this logging type")
88+
89+
// metal-hammer oci configs
90+
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.")
8891
}
8992

9093
func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
@@ -219,6 +222,40 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
219222
}
220223
}
221224

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

0 commit comments

Comments
 (0)