diff --git a/cmd/cluster.go b/cmd/cluster.go index 7ce4f61b..75b0acd4 100644 --- a/cmd/cluster.go +++ b/cmd/cluster.go @@ -449,6 +449,7 @@ func newClusterCmd(c *config) *cobra.Command { clusterCmd.AddCommand(clusterMonitoringSecretCmd) clusterCmd.AddCommand(newClusterAuditCmd(c)) clusterCmd.AddCommand(newClusterXdrCmd(c)) + clusterCmd.AddCommand(newClusterQCACmd(c)) return clusterCmd } diff --git a/cmd/cluster_qca.go b/cmd/cluster_qca.go new file mode 100644 index 00000000..c16c718e --- /dev/null +++ b/cmd/cluster_qca.go @@ -0,0 +1,81 @@ +package cmd + +import ( + "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" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +type qcaCmd struct { + c *config +} + +func newClusterQCACmd(c *config) *cobra.Command { + w := qcaCmd{ + c: c, + } + + clusterQCACmd := &cobra.Command{ + Use: "qca", + Short: "configure a cluster's qualys cloud agent configuration", + Long: `qualys cloud agent scans and monitors the nodes of a cluster`, + } + + configureCmd := &cobra.Command{ + Use: "configure --cluster-id=", + Short: "configure the qca settings for this cluster (only allowed for provider tenant)", + RunE: func(cmd *cobra.Command, args []string) error { + return w.configure() + }, + } + + showCmd := &cobra.Command{ + Use: "show --cluster-id=", + Short: "show the current qca configuration for this cluster", + RunE: func(cmd *cobra.Command, args []string) error { + return w.show() + }, + } + + clusterQCACmd.PersistentFlags().String("cluster-id", "", "the id of the cluster to apply the xdr configuration to") + genericcli.Must(clusterQCACmd.MarkPersistentFlagRequired("cluster-id")) + genericcli.Must(clusterQCACmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion)) + + configureCmd.Flags().Bool("disabled", false, "disables the entire xdr functionality") + + clusterQCACmd.AddCommand(configureCmd, showCmd) + + return clusterQCACmd +} + +func (c *qcaCmd) configure() error { + + qcaConfiguration := &models.V1QualysCloudAgent{} + + if viper.IsSet("disabled") { + qcaConfiguration.Disabled = new(viper.GetBool("disabled")) + } + + _, err := c.c.cloud.Cluster.UpdateCluster(cluster.NewUpdateClusterParams().WithBody(&models.V1ClusterUpdateRequest{ + ID: new(viper.GetString("cluster-id")), + QCAConfig: qcaConfiguration, + }), nil) + if err != nil { + return err + } + + return nil +} + +func (c *qcaCmd) show() error { + findRequest := cluster.NewFindClusterParams() + findRequest.SetID(viper.GetString("cluster-id")) + shoot, err := c.c.cloud.Cluster.FindCluster(findRequest, nil) + if err != nil { + return err + } + + return c.c.describePrinter.Print(shoot.Payload.QCAConfig) +} diff --git a/go.mod b/go.mod index a684a4f8..44553c12 100644 --- a/go.mod +++ b/go.mod @@ -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.1 - github.com/fi-ts/cloud-go v0.33.0 + github.com/fi-ts/cloud-go v0.34.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 diff --git a/go.sum b/go.sum index 18b5ab57..a4414fb0 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,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.1 h1:F4rFua+Q8wF03ASNPTgiUNEQ4vTgnZ1B/ac3B+ssiT8= github.com/fi-ts/accounting-go v0.11.1/go.mod h1:yX9yqzX+i23O/Bj9Gn22oM+/nd2QtjMsvVIWab9UAU4= -github.com/fi-ts/cloud-go v0.33.0 h1:GMU+dUnJVGAjSORB9Sqkxg62SdOwQ+1hOXdx+MaUK4g= -github.com/fi-ts/cloud-go v0.33.0/go.mod h1:gwsY2TQzq4DIu8pevHUZXI11uE1zePOnpYXkPtLYlsw= +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/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.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=