Skip to content
Merged
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
37 changes: 37 additions & 0 deletions cmd/cluster_qca.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package cmd

import (
"fmt"
"net"
"net/url"
"strings"

"github.com/fi-ts/cloud-go/api/client/cluster"
"github.com/fi-ts/cloud-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
Expand Down Expand Up @@ -44,6 +49,7 @@ func newClusterQCACmd(c *config) *cobra.Command {
genericcli.Must(clusterQCACmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))

configureCmd.Flags().Bool("disabled", false, "disables the entire xdr functionality")
configureCmd.Flags().String("proxy", "", "the proxy for the qca configuration, either in the form ip:port or as a parseable url")

clusterQCACmd.AddCommand(configureCmd, showCmd)

Expand All @@ -58,6 +64,14 @@ func (c *qcaCmd) configure() error {
qcaConfiguration.Disabled = new(viper.GetBool("disabled"))
}

if viper.IsSet("proxy") {
proxy, err := parseQCAProxy(viper.GetString("proxy"))
if err != nil {
return err
}
qcaConfiguration.Proxy = proxy
}

_, err := c.c.cloud.Cluster.UpdateCluster(cluster.NewUpdateClusterParams().WithBody(&models.V1ClusterUpdateRequest{
ID: new(viper.GetString("cluster-id")),
QCAConfig: qcaConfiguration,
Expand All @@ -69,6 +83,29 @@ func (c *qcaCmd) configure() error {
return nil
}

func parseQCAProxy(proxy string) (string, error) {
if proxy == "" {
return "", fmt.Errorf("proxy must not be empty")
}

if strings.Contains(proxy, "://") {
u, err := url.Parse(proxy)
if err != nil {
return "", fmt.Errorf("unable to parse proxy url %q: %w", proxy, err)
}
if u.Host == "" {
return "", fmt.Errorf("invalid proxy url %q: missing host", proxy)
}
return proxy, nil
}

if _, _, err := net.SplitHostPort(proxy); err != nil {
return "", fmt.Errorf("invalid proxy %q, must be in the form ip:port or a parseable url", proxy)
}

return proxy, nil
}

func (c *qcaCmd) show() error {
findRequest := cluster.NewFindClusterParams()
findRequest.SetID(viper.GetString("cluster-id"))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.19.0
github.com/fi-ts/accounting-go v0.11.2
github.com/fi-ts/cloud-go v0.34.0
github.com/fi-ts/cloud-go v0.35.0
github.com/gardener/gardener/pkg/apis v1.140.0
github.com/gardener/machine-controller-manager v0.62.1
github.com/gizak/termui/v3 v3.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
github.com/fi-ts/accounting-go v0.11.2 h1:bCDMeUiz+mJB+sH/XKU/FEFK24MTlZ6qNWGoHZcSI0U=
github.com/fi-ts/accounting-go v0.11.2/go.mod h1:HIbq56OpPJILxHnZ8bXJcOmCPnhhMJdbBJPJLXmcYNQ=
github.com/fi-ts/cloud-go v0.34.0 h1:qVbVlXvpeZEk1KDxVpNvAaHMqz4q+dpLThpd4M8dUeI=
github.com/fi-ts/cloud-go v0.34.0/go.mod h1:gwsY2TQzq4DIu8pevHUZXI11uE1zePOnpYXkPtLYlsw=
github.com/fi-ts/cloud-go v0.35.0 h1:f6m8SRvEYYC+RIjQqSDchkg77XR3JYO0036tgbddoRA=
github.com/fi-ts/cloud-go v0.35.0/go.mod h1:gwsY2TQzq4DIu8pevHUZXI11uE1zePOnpYXkPtLYlsw=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho=
Expand Down
Loading