Skip to content

Commit

Permalink
Merge branch 'master' into fix-update-to-specific-version-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored May 2, 2024
2 parents 49bebea + eda262c commit a7ef8e0
Show file tree
Hide file tree
Showing 23 changed files with 335 additions and 340 deletions.
9 changes: 4 additions & 5 deletions cmd/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/fi-ts/cloud-go/api/models"
"github.com/fi-ts/cloudctl/cmd/output"
"github.com/go-openapi/strfmt"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -27,21 +28,19 @@ func newAuditCmd(c *config) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
return c.auditList()
},
PreRun: bindPFlags,
}
auditDescribeCmd := &cobra.Command{
Use: "describe <rqid>",
Short: "describe an audit trace",
RunE: func(cmd *cobra.Command, args []string) error {
return c.auditDescribe(args)
},
PreRun: bindPFlags,
}

auditDescribeCmd.Flags().String("phase", "response", "phase of the audit trace. One of [request, response, single, error, opened, closed]")
auditDescribeCmd.Flags().Bool("prettify-body", false, "attempts to interpret the body as json and prettifies it")

must(auditDescribeCmd.RegisterFlagCompletionFunc("phase", c.comp.AuditPhaseCompletion))
genericcli.Must(auditDescribeCmd.RegisterFlagCompletionFunc("phase", c.comp.AuditPhaseCompletion))

auditListCmd.Flags().StringP("query", "q", "", "filters audit trace body payloads for the given text.")

Expand All @@ -67,8 +66,8 @@ func newAuditCmd(c *config) *cobra.Command {

auditListCmd.Flags().Int64("limit", 100, "limit the number of audit traces.")

must(auditListCmd.RegisterFlagCompletionFunc("type", c.comp.AuditTypeCompletion))
must(auditListCmd.RegisterFlagCompletionFunc("phase", c.comp.AuditPhaseCompletion))
genericcli.Must(auditListCmd.RegisterFlagCompletionFunc("type", c.comp.AuditTypeCompletion))
genericcli.Must(auditListCmd.RegisterFlagCompletionFunc("phase", c.comp.AuditPhaseCompletion))

auditCmd.AddCommand(auditDescribeCmd)
auditCmd.AddCommand(auditListCmd)
Expand Down
85 changes: 38 additions & 47 deletions cmd/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/go-openapi/strfmt"
"github.com/go-playground/validator/v10"
"github.com/jinzhu/now"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -49,7 +50,6 @@ func newBillingCmd(c *config) *cobra.Command {
}
return c.projectsBilling()
},
PreRun: bindPFlags,
}
containerBillingCmd := &cobra.Command{
Use: "container",
Expand All @@ -69,7 +69,6 @@ export CLOUDCTL_COSTS_MEMORY_GI_HOUR=0.01 # costs per memory hour
}
return c.containerUsage()
},
PreRun: bindPFlags,
}
clusterBillingCmd := &cobra.Command{
Use: "cluster",
Expand All @@ -88,7 +87,6 @@ export CLOUDCTL_COSTS_HOUR=0.01 # costs per hour
}
return c.clusterUsage()
},
PreRun: bindPFlags,
}
ipBillingCmd := &cobra.Command{
Use: "ip",
Expand All @@ -107,7 +105,6 @@ export CLOUDCTL_COSTS_HOUR=0.01 # costs per hour
}
return c.ipUsage()
},
PreRun: bindPFlags,
}
machineBillingCmd := &cobra.Command{
Use: "machine",
Expand All @@ -126,7 +123,6 @@ export CLOUDCTL_COSTS_HOUR=0.01 # costs per hour
}
return c.machineUsage()
},
PreRun: bindPFlags,
}
productOptionBillingCmd := &cobra.Command{
Use: "product-option",
Expand All @@ -145,7 +141,6 @@ export CLOUDCTL_COSTS_HOUR=0.01 # costs per hour
}
return c.productOptionUsage()
},
PreRun: bindPFlags,
}
networkTrafficBillingCmd := &cobra.Command{
Use: "network-traffic",
Expand All @@ -166,7 +161,6 @@ export CLOUDCTL_COSTS_TOTAL_NETWORK_TRAFFIC_GI=0.01 # costs per gi
}
return c.networkTrafficUsage()
},
PreRun: bindPFlags,
}
s3BillingCmd := &cobra.Command{
Use: "s3",
Expand All @@ -185,7 +179,6 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # costs per storage hour
}
return c.s3Usage()
},
PreRun: bindPFlags,
}
volumeBillingCmd := &cobra.Command{
Use: "volume",
Expand All @@ -204,7 +197,6 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # costs per capacity hour
}
return c.volumeUsage()
},
PreRun: bindPFlags,
}
postgresBillingCmd := &cobra.Command{
Use: "postgres",
Expand All @@ -225,7 +217,6 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
}
return c.postgresUsage()
},
PreRun: bindPFlags,
}

billingCmd.AddCommand(projectBillingCmd)
Expand Down Expand Up @@ -254,11 +245,11 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
containerBillingCmd.Flags().StringSliceVar(&billingOpts.Annotations, "annotations", nil, "annotations filtering")
containerBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file")

must(containerBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
must(containerBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
must(containerBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))
genericcli.Must(containerBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
genericcli.Must(containerBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
genericcli.Must(containerBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))

must(viper.BindPFlags(containerBillingCmd.Flags()))
genericcli.Must(viper.BindPFlags(containerBillingCmd.Flags()))

clusterBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account")
clusterBillingCmd.Flags().StringP("time-format", "", "2006-01-02", "the time format used to parse the arguments 'from' and 'to'")
Expand All @@ -268,11 +259,11 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
clusterBillingCmd.Flags().StringVarP(&billingOpts.ClusterID, "cluster-id", "c", "", "the cluster to account")
clusterBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file")

must(clusterBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
must(clusterBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
must(clusterBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))
genericcli.Must(clusterBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
genericcli.Must(clusterBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
genericcli.Must(clusterBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))

must(viper.BindPFlags(clusterBillingCmd.Flags()))
genericcli.Must(viper.BindPFlags(clusterBillingCmd.Flags()))

machineBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account")
machineBillingCmd.Flags().StringP("time-format", "", "2006-01-02", "the time format used to parse the arguments 'from' and 'to'")
Expand All @@ -284,13 +275,13 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
machineBillingCmd.Flags().String("size-id", "", "the size-id to account")
machineBillingCmd.Flags().String("partition-id", "", "the partition-id to account")

must(machineBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
must(machineBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
must(machineBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))
must(machineBillingCmd.RegisterFlagCompletionFunc("partition-id", c.comp.PartitionListCompletion))
must(machineBillingCmd.RegisterFlagCompletionFunc("size-id", c.comp.SizeListCompletion))
genericcli.Must(machineBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
genericcli.Must(machineBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
genericcli.Must(machineBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))
genericcli.Must(machineBillingCmd.RegisterFlagCompletionFunc("partition-id", c.comp.PartitionListCompletion))
genericcli.Must(machineBillingCmd.RegisterFlagCompletionFunc("size-id", c.comp.SizeListCompletion))

must(viper.BindPFlags(machineBillingCmd.Flags()))
genericcli.Must(viper.BindPFlags(machineBillingCmd.Flags()))

productOptionBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account")
productOptionBillingCmd.Flags().StringP("time-format", "", "2006-01-02", "the time format used to parse the arguments 'from' and 'to'")
Expand All @@ -300,12 +291,12 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
productOptionBillingCmd.Flags().StringVarP(&billingOpts.ClusterID, "cluster-id", "c", "", "the cluster to account")
productOptionBillingCmd.Flags().String("id", "", "the id of the product option to account")

must(productOptionBillingCmd.RegisterFlagCompletionFunc("id", c.comp.ProductOptionsCompletion))
must(productOptionBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
must(productOptionBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
must(productOptionBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))
genericcli.Must(productOptionBillingCmd.RegisterFlagCompletionFunc("id", c.comp.ProductOptionsCompletion))
genericcli.Must(productOptionBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
genericcli.Must(productOptionBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
genericcli.Must(productOptionBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))

must(viper.BindPFlags(productOptionBillingCmd.Flags()))
genericcli.Must(viper.BindPFlags(productOptionBillingCmd.Flags()))

ipBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account")
ipBillingCmd.Flags().StringP("time-format", "", "2006-01-02", "the time format used to parse the arguments 'from' and 'to'")
Expand All @@ -315,10 +306,10 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
ipBillingCmd.Flags().StringSliceVar(&billingOpts.Annotations, "annotations", nil, "annotations filtering")
ipBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file")

must(ipBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
must(ipBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
genericcli.Must(ipBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
genericcli.Must(ipBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))

must(viper.BindPFlags(ipBillingCmd.Flags()))
genericcli.Must(viper.BindPFlags(ipBillingCmd.Flags()))

networkTrafficBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account")
networkTrafficBillingCmd.Flags().StringP("time-format", "", "2006-01-02", "the time format used to parse the arguments 'from' and 'to'")
Expand All @@ -329,11 +320,11 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
networkTrafficBillingCmd.Flags().StringVarP(&billingOpts.Device, "device", "", "", "the device to account")
networkTrafficBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file")

must(networkTrafficBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
must(networkTrafficBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
must(networkTrafficBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))
genericcli.Must(networkTrafficBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
genericcli.Must(networkTrafficBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
genericcli.Must(networkTrafficBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))

must(viper.BindPFlags(networkTrafficBillingCmd.Flags()))
genericcli.Must(viper.BindPFlags(networkTrafficBillingCmd.Flags()))

s3BillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account")
s3BillingCmd.Flags().StringP("time-format", "", "2006-01-02", "the time format used to parse the arguments 'from' and 'to'")
Expand All @@ -342,10 +333,10 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
s3BillingCmd.Flags().StringVarP(&billingOpts.ProjectID, "project-id", "p", "", "the project to account")
s3BillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file")

must(s3BillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
must(s3BillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
genericcli.Must(s3BillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
genericcli.Must(s3BillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))

must(viper.BindPFlags(s3BillingCmd.Flags()))
genericcli.Must(viper.BindPFlags(s3BillingCmd.Flags()))

volumeBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account")
volumeBillingCmd.Flags().StringP("time-format", "", "2006-01-02", "the time format used to parse the arguments 'from' and 'to'")
Expand All @@ -357,11 +348,11 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
volumeBillingCmd.Flags().StringSliceVar(&billingOpts.Annotations, "annotations", nil, "annotations filtering")
volumeBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file")

must(volumeBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
must(volumeBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
must(volumeBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))
genericcli.Must(volumeBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
genericcli.Must(volumeBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
genericcli.Must(volumeBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion))

must(viper.BindPFlags(volumeBillingCmd.Flags()))
genericcli.Must(viper.BindPFlags(volumeBillingCmd.Flags()))

postgresBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account")
postgresBillingCmd.Flags().StringP("time-format", "", "2006-01-02", "the time format used to parse the arguments 'from' and 'to'")
Expand All @@ -372,11 +363,11 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour
postgresBillingCmd.Flags().StringSliceVar(&billingOpts.Annotations, "annotations", nil, "annotations filtering")
postgresBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file")

must(postgresBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
must(postgresBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
must(postgresBillingCmd.RegisterFlagCompletionFunc("uuid", c.comp.PostgresListCompletion))
genericcli.Must(postgresBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion))
genericcli.Must(postgresBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion))
genericcli.Must(postgresBillingCmd.RegisterFlagCompletionFunc("uuid", c.comp.PostgresListCompletion))

must(viper.BindPFlags(postgresBillingCmd.Flags()))
genericcli.Must(viper.BindPFlags(postgresBillingCmd.Flags()))

return billingCmd
}
Expand Down
Loading

0 comments on commit a7ef8e0

Please sign in to comment.