Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type MetalConfig struct {
NTPServers []string `json:"ntp_servers,omitempty"`
Partition string `json:"partition"`
// Logging contains logging configurations passed to metal-hammer
Logging *Logging `json:"logging,omitempty"`
Logging *Logging `json:"logging,omitempty"`
OciConfig []*OciConfig `json:"oci_config,omitempty"`
}

type Logging struct {
Expand Down Expand Up @@ -45,6 +46,15 @@ type CertificateAuth struct {
InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty"`
}

type OciConfig struct {
// URL pointing to the oci registry
RegistryURL string `json:"registry_url,omitempty"`
// Username that is capable of logging in to the registry
Username string `json:"username,omitempty"`
// Password for the user
Password string `json:"password,omitempty"`
}

// LogType defines which logging backend should be used
type LogType string

Expand Down
41 changes: 41 additions & 0 deletions pixiecore/cli/grpccmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func init() {
grpcCmd.Flags().String("metal-hammer-logging-key", "", "set metal-hammer to send logs to a remote endpoint and authenticate with this key")
grpcCmd.Flags().Bool("metal-hammer-logging-tls-insecure", false, "set metal-hammer to send logs to a remote endpoint without verifying the tls certificate")
grpcCmd.Flags().String("metal-hammer-logging-type", "loki", "set metal-hammer to send logs to a remote endpoint with this logging type")

// metal-hammer oci configs
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.")
}

func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
Expand Down Expand Up @@ -219,6 +222,43 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
}
}

metalHammerOciConfigs, err := cmd.Flags().GetStringSlice("metal-hammer-oci-configs")
if err != nil {
return nil, fmt.Errorf("error reading flag: %w", err)
}

var ociConfigs []*api.OciConfig

for _, c := range metalHammerOciConfigs {
var ociConfig *api.OciConfig

parts := strings.SplitSeq(c, ",")
for p := range parts {
kv := strings.SplitN(strings.TrimSpace(p), "=", 2)
if len(kv) != 2 {
return nil, fmt.Errorf("invalid key-value pair in OCI config: %q", p)
}

k := strings.ToLower(strings.TrimSpace(kv[0]))
v := strings.TrimSpace(kv[1])
switch k {
case "registry_url":
if v == "" {
return nil, fmt.Errorf("no registry url specified for oci config: %s", c)
}
ociConfig.RegistryURL = v
case "username":
ociConfig.Username = v
case "password":
ociConfig.Password = v
default:
return nil, fmt.Errorf("unknown key %q in OCI config", k)
}
}

ociConfigs = append(ociConfigs, ociConfig)
}

return &api.MetalConfig{
Debug: metalHammerDebug,
GRPCAddress: grpcAddress,
Expand All @@ -231,5 +271,6 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
NTPServers: ntpServers,
Logging: logging,
Partition: partition,
OciConfig: ociConfigs,
}, nil
}