mygithub.libinneed.workers.dev/stackitcloud/stackit-cli
Advanced tools
+6
-0
@@ -29,2 +29,8 @@ { | ||
| "endpoint": "object.storage.eu01.onstackit.cloud" | ||
| }, | ||
| "distribution": { | ||
| "region": "eu01", | ||
| "bucket": "distribution", | ||
| "acl":"public-read", | ||
| "endpoint": "object.storage.eu01.onstackit.cloud" | ||
| } | ||
@@ -31,0 +37,0 @@ }, |
@@ -32,3 +32,2 @@ ## stackit config set | ||
| ``` | ||
| --argus-custom-endpoint string Argus API base URL, used in calls to this API | ||
| --authorization-custom-endpoint string Authorization API base URL, used in calls to this API | ||
@@ -35,0 +34,0 @@ --dns-custom-endpoint string DNS API base URL, used in calls to this API |
@@ -29,3 +29,2 @@ ## stackit config unset | ||
| ``` | ||
| --argus-custom-endpoint Argus API base URL. If unset, uses the default base URL | ||
| --async Configuration option to run commands asynchronously | ||
@@ -32,0 +31,0 @@ --authorization-custom-endpoint Authorization API base URL. If unset, uses the default base URL |
| ## stackit rabbitmq credentials create | ||
| Creates credentials for an RabbitMQ instance | ||
| Creates credentials for a RabbitMQ instance | ||
| ### Synopsis | ||
| Creates credentials (username and password) for an RabbitMQ instance. | ||
| Creates credentials (username and password) for a RabbitMQ instance. | ||
@@ -16,6 +16,6 @@ ``` | ||
| ``` | ||
| Create credentials for an RabbitMQ instance | ||
| Create credentials for a RabbitMQ instance | ||
| $ stackit rabbitmq credentials create --instance-id xxx | ||
| Create credentials for an RabbitMQ instance and hide the password in the output | ||
| Create credentials for a RabbitMQ instance and hide the password in the output | ||
| $ stackit rabbitmq credentials create --instance-id xxx --hide-password | ||
@@ -22,0 +22,0 @@ ``` |
| ## stackit rabbitmq credentials delete | ||
| Deletes credentials of an RabbitMQ instance | ||
| Deletes credentials of a RabbitMQ instance | ||
| ### Synopsis | ||
| Deletes credentials of an RabbitMQ instance. | ||
| Deletes credentials of a RabbitMQ instance. | ||
@@ -9,0 +9,0 @@ ``` |
| ## stackit rabbitmq credentials describe | ||
| Shows details of credentials of an RabbitMQ instance | ||
| Shows details of credentials of a RabbitMQ instance | ||
| ### Synopsis | ||
| Shows details of credentials of an RabbitMQ instance. The password will be shown in plain text in the output. | ||
| Shows details of credentials of a RabbitMQ instance. The password will be shown in plain text in the output. | ||
@@ -9,0 +9,0 @@ ``` |
| ## stackit rabbitmq credentials list | ||
| Lists all credentials' IDs for an RabbitMQ instance | ||
| Lists all credentials' IDs for a RabbitMQ instance | ||
| ### Synopsis | ||
| Lists all credentials' IDs for an RabbitMQ instance. | ||
| Lists all credentials' IDs for a RabbitMQ instance. | ||
@@ -16,9 +16,9 @@ ``` | ||
| ``` | ||
| List all credentials' IDs for an RabbitMQ instance | ||
| List all credentials' IDs for a RabbitMQ instance | ||
| $ stackit rabbitmq credentials list --instance-id xxx | ||
| List all credentials' IDs for an RabbitMQ instance in JSON format | ||
| List all credentials' IDs for a RabbitMQ instance in JSON format | ||
| $ stackit rabbitmq credentials list --instance-id xxx --output-format json | ||
| List up to 10 credentials' IDs for an RabbitMQ instance | ||
| List up to 10 credentials' IDs for a RabbitMQ instance | ||
| $ stackit rabbitmq credentials list --instance-id xxx --limit 10 | ||
@@ -25,0 +25,0 @@ ``` |
@@ -31,6 +31,6 @@ ## stackit rabbitmq credentials | ||
| * [stackit rabbitmq](./stackit_rabbitmq.md) - Provides functionality for RabbitMQ | ||
| * [stackit rabbitmq credentials create](./stackit_rabbitmq_credentials_create.md) - Creates credentials for an RabbitMQ instance | ||
| * [stackit rabbitmq credentials delete](./stackit_rabbitmq_credentials_delete.md) - Deletes credentials of an RabbitMQ instance | ||
| * [stackit rabbitmq credentials describe](./stackit_rabbitmq_credentials_describe.md) - Shows details of credentials of an RabbitMQ instance | ||
| * [stackit rabbitmq credentials list](./stackit_rabbitmq_credentials_list.md) - Lists all credentials' IDs for an RabbitMQ instance | ||
| * [stackit rabbitmq credentials create](./stackit_rabbitmq_credentials_create.md) - Creates credentials for a RabbitMQ instance | ||
| * [stackit rabbitmq credentials delete](./stackit_rabbitmq_credentials_delete.md) - Deletes credentials of a RabbitMQ instance | ||
| * [stackit rabbitmq credentials describe](./stackit_rabbitmq_credentials_describe.md) - Shows details of credentials of a RabbitMQ instance | ||
| * [stackit rabbitmq credentials list](./stackit_rabbitmq_credentials_list.md) - Lists all credentials' IDs for a RabbitMQ instance | ||
| ## stackit rabbitmq instance create | ||
| Creates an RabbitMQ instance | ||
| Creates a RabbitMQ instance | ||
| ### Synopsis | ||
| Creates an RabbitMQ instance. | ||
| Creates a RabbitMQ instance. | ||
@@ -16,9 +16,9 @@ ``` | ||
| ``` | ||
| Create an RabbitMQ instance with name "my-instance" and specify plan by name and version | ||
| Create a RabbitMQ instance with name "my-instance" and specify plan by name and version | ||
| $ stackit rabbitmq instance create --name my-instance --plan-name stackit-rabbitmq-1.2.10-replica --version 3.10 | ||
| Create an RabbitMQ instance with name "my-instance" and specify plan by ID | ||
| Create a RabbitMQ instance with name "my-instance" and specify plan by ID | ||
| $ stackit rabbitmq instance create --name my-instance --plan-id xxx | ||
| Create an RabbitMQ instance with name "my-instance" and specify IP range which is allowed to access it | ||
| Create a RabbitMQ instance with name "my-instance" and specify IP range which is allowed to access it | ||
| $ stackit rabbitmq instance create --name my-instance --plan-id xxx --acl 1.2.3.0/24 | ||
@@ -25,0 +25,0 @@ ``` |
| ## stackit rabbitmq instance delete | ||
| Deletes an RabbitMQ instance | ||
| Deletes a RabbitMQ instance | ||
| ### Synopsis | ||
| Deletes an RabbitMQ instance. | ||
| Deletes a RabbitMQ instance. | ||
@@ -16,3 +16,3 @@ ``` | ||
| ``` | ||
| Delete an RabbitMQ instance with ID "xxx" | ||
| Delete a RabbitMQ instance with ID "xxx" | ||
| $ stackit rabbitmq instance delete xxx | ||
@@ -19,0 +19,0 @@ ``` |
| ## stackit rabbitmq instance describe | ||
| Shows details of an RabbitMQ instance | ||
| Shows details of a RabbitMQ instance | ||
| ### Synopsis | ||
| Shows details of an RabbitMQ instance. | ||
| Shows details of a RabbitMQ instance. | ||
@@ -16,6 +16,6 @@ ``` | ||
| ``` | ||
| Get details of an RabbitMQ instance with ID "xxx" | ||
| Get details of a RabbitMQ instance with ID "xxx" | ||
| $ stackit rabbitmq instance describe xxx | ||
| Get details of an RabbitMQ instance with ID "xxx" in a table format | ||
| Get details of a RabbitMQ instance with ID "xxx" in a table format | ||
| $ stackit rabbitmq instance describe xxx --output-format pretty | ||
@@ -22,0 +22,0 @@ ``` |
| ## stackit rabbitmq instance update | ||
| Updates an RabbitMQ instance | ||
| Updates a RabbitMQ instance | ||
| ### Synopsis | ||
| Updates an RabbitMQ instance. | ||
| Updates a RabbitMQ instance. | ||
@@ -16,6 +16,6 @@ ``` | ||
| ``` | ||
| Update the plan of an RabbitMQ instance with ID "xxx" | ||
| Update the plan of a RabbitMQ instance with ID "xxx" | ||
| $ stackit rabbitmq instance update xxx --plan-id yyy | ||
| Update the range of IPs allowed to access an RabbitMQ instance with ID "xxx" | ||
| Update the range of IPs allowed to access a RabbitMQ instance with ID "xxx" | ||
| $ stackit rabbitmq instance update xxx --acl 1.2.3.0/24 | ||
@@ -22,0 +22,0 @@ ``` |
@@ -31,7 +31,7 @@ ## stackit rabbitmq instance | ||
| * [stackit rabbitmq](./stackit_rabbitmq.md) - Provides functionality for RabbitMQ | ||
| * [stackit rabbitmq instance create](./stackit_rabbitmq_instance_create.md) - Creates an RabbitMQ instance | ||
| * [stackit rabbitmq instance delete](./stackit_rabbitmq_instance_delete.md) - Deletes an RabbitMQ instance | ||
| * [stackit rabbitmq instance describe](./stackit_rabbitmq_instance_describe.md) - Shows details of an RabbitMQ instance | ||
| * [stackit rabbitmq instance create](./stackit_rabbitmq_instance_create.md) - Creates a RabbitMQ instance | ||
| * [stackit rabbitmq instance delete](./stackit_rabbitmq_instance_delete.md) - Deletes a RabbitMQ instance | ||
| * [stackit rabbitmq instance describe](./stackit_rabbitmq_instance_describe.md) - Shows details of a RabbitMQ instance | ||
| * [stackit rabbitmq instance list](./stackit_rabbitmq_instance_list.md) - Lists all RabbitMQ instances | ||
| * [stackit rabbitmq instance update](./stackit_rabbitmq_instance_update.md) - Updates an RabbitMQ instance | ||
| * [stackit rabbitmq instance update](./stackit_rabbitmq_instance_update.md) - Updates a RabbitMQ instance | ||
@@ -16,6 +16,6 @@ ## stackit secrets-manager user list | ||
| ``` | ||
| List all Secrets Manager users of instance with ID "xxx | ||
| List all Secrets Manager users of instance with ID "xxx" | ||
| $ stackit secrets-manager user list --instance-id xxx | ||
| List all Secrets Manager users in JSON format with ID "xxx | ||
| List all Secrets Manager users in JSON format with ID "xxx" | ||
| $ stackit secrets-manager user list --instance-id xxx --output-format json | ||
@@ -22,0 +22,0 @@ |
+0
-1
@@ -28,3 +28,2 @@ ## stackit | ||
| * [stackit argus](./stackit_argus.md) - Provides functionality for Argus | ||
| * [stackit auth](./stackit_auth.md) - Provides authentication functionality | ||
@@ -31,0 +30,0 @@ * [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options |
+2
-3
@@ -9,3 +9,3 @@ module github.com/stackitcloud/stackit-cli | ||
| github.com/google/uuid v1.6.0 | ||
| github.com/jedib0t/go-pretty/v6 v6.5.4 | ||
| github.com/jedib0t/go-pretty/v6 v6.5.5 | ||
| github.com/spf13/cobra v1.8.0 | ||
@@ -24,3 +24,3 @@ github.com/spf13/pflag v1.0.5 | ||
| github.com/stackitcloud/stackit-sdk-go/services/ske v0.10.1 | ||
| github.com/zalando/go-keyring v0.2.3 | ||
| github.com/zalando/go-keyring v0.2.4 | ||
| golang.org/x/mod v0.16.0 | ||
@@ -53,3 +53,2 @@ golang.org/x/oauth2 v0.18.0 | ||
| github.com/spf13/cast v1.6.0 // indirect | ||
| github.com/stackitcloud/stackit-sdk-go/services/argus v0.9.5 | ||
| github.com/stackitcloud/stackit-sdk-go/services/logme v0.10.1 | ||
@@ -56,0 +55,0 @@ github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.10.1 |
+4
-6
@@ -32,4 +32,4 @@ github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0= | ||
| github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
| github.com/jedib0t/go-pretty/v6 v6.5.4 h1:gOGo0613MoqUcf0xCj+h/V3sHDaZasfv152G6/5l91s= | ||
| github.com/jedib0t/go-pretty/v6 v6.5.4/go.mod h1:5LQIxa52oJ/DlDSLv0HEkWOFMDGoWkJb9ss5KqPpJBg= | ||
| github.com/jedib0t/go-pretty/v6 v6.5.5 h1:PpIU8lOjxvVYGGKule0QxxJfNysUSbC9lggQU2cpZJc= | ||
| github.com/jedib0t/go-pretty/v6 v6.5.5/go.mod h1:5LQIxa52oJ/DlDSLv0HEkWOFMDGoWkJb9ss5KqPpJBg= | ||
| github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= | ||
@@ -79,4 +79,2 @@ github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.10.0/go.mod h1:B5dkVm2HlBRG7liBVIFNqncDb6TUHnJ7t0GsKhAFuRk= | ||
| github.com/stackitcloud/stackit-sdk-go/services/argus v0.9.5 h1:RLsA2jO9sMNpn7NYdtFyumY5Vj4n4WtBm2J2NBKlsnw= | ||
| github.com/stackitcloud/stackit-sdk-go/services/argus v0.9.5/go.mod h1:lzGbqwV0hqeX/kUvaaFTgjOJRxUlsZ911TX1YAcKwqc= | ||
| github.com/stackitcloud/stackit-sdk-go/services/authorization v0.1.1 h1:h7dCaBlbU34WSGuEXREmCdCzQafZgdXDZuairAzeuo8= | ||
@@ -121,4 +119,4 @@ github.com/stackitcloud/stackit-sdk-go/services/authorization v0.1.1/go.mod h1:V+wTIfuJRV8PiSOfMX6GCTaHWltGaLCz8ImOKeHIaIA= | ||
| github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | ||
| github.com/zalando/go-keyring v0.2.3 h1:v9CUu9phlABObO4LPWycf+zwMG7nlbb3t/B5wa97yms= | ||
| github.com/zalando/go-keyring v0.2.3/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk= | ||
| github.com/zalando/go-keyring v0.2.4 h1:wi2xxTqdiwMKbM6TWwi+uJCG/Tum2UV0jqaQhCa9/68= | ||
| github.com/zalando/go-keyring v0.2.4/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk= | ||
| go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= | ||
@@ -125,0 +123,0 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= |
+2
-27
@@ -23,31 +23,6 @@ # Installation | ||
| #### Debian/Ubuntu (`APT`) | ||
| Currently, you can install via [Homebrew](https://brew.sh/) or refer to one of the installation methods below. | ||
| The STACKIT CLI can be installed through the [`APT`](https://ubuntu.com/server/docs/package-management) package manager. | ||
| > We are currently working on distributing the CLI on package managers for Linux. | ||
| 1. Import the STACKIT public key: | ||
| ```shell | ||
| curl https://object.storage.eu01.onstackit.cloud/stackit-public-key/key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/stackit.gpg | ||
| ``` | ||
| 2. Add the STACKIT CLI package repository as a package source: | ||
| ```shell | ||
| echo "deb [signed-by=/usr/share/keyrings/stackit.gpg] https://object.storage.eu01.onstackit.cloud/stackit-cli-apt stackit main" | sudo tee -a /etc/apt/sources.list.d/stackit.list | ||
| ``` | ||
| 3. Update repository information and install the `stackit` package: | ||
| ```shell | ||
| sudo apt-get update | ||
| sudo apt-get install stackit | ||
| ``` | ||
| #### Any distribution | ||
| Alternatively, you can install via [Homebrew](https://brew.sh/) or refer to one of the installation methods below. | ||
| > We are currently working on distributing the CLI on more package managers for Linux. | ||
| ### Windows | ||
@@ -54,0 +29,0 @@ |
@@ -21,3 +21,2 @@ package set | ||
| argusCustomEndpointFlag = "argus-custom-endpoint" | ||
| authorizationCustomEndpointFlag = "authorization-custom-endpoint" | ||
@@ -97,3 +96,2 @@ dnsCustomEndpointFlag = "dns-custom-endpoint" | ||
| cmd.Flags().String(argusCustomEndpointFlag, "", "Argus API base URL, used in calls to this API") | ||
| cmd.Flags().String(authorizationCustomEndpointFlag, "", "Authorization API base URL, used in calls to this API") | ||
@@ -114,6 +112,4 @@ cmd.Flags().String(dnsCustomEndpointFlag, "", "DNS API base URL, used in calls to this API") | ||
| err := viper.BindPFlag(config.ArgusCustomEndpointKey, cmd.Flags().Lookup(argusCustomEndpointFlag)) | ||
| err := viper.BindPFlag(config.AuthorizationCustomEndpointKey, cmd.Flags().Lookup(authorizationCustomEndpointFlag)) | ||
| cobra.CheckErr(err) | ||
| err = viper.BindPFlag(config.AuthorizationCustomEndpointKey, cmd.Flags().Lookup(authorizationCustomEndpointFlag)) | ||
| cobra.CheckErr(err) | ||
| err = viper.BindPFlag(config.DNSCustomEndpointKey, cmd.Flags().Lookup(dnsCustomEndpointFlag)) | ||
@@ -120,0 +116,0 @@ cobra.CheckErr(err) |
@@ -15,3 +15,2 @@ package unset | ||
| argusCustomEndpointFlag: true, | ||
| authorizationCustomEndpointFlag: true, | ||
@@ -41,3 +40,2 @@ dnsCustomEndpointFlag: true, | ||
| ArgusCustomEndpoint: true, | ||
| AuthorizationCustomEndpoint: true, | ||
@@ -83,3 +81,2 @@ DNSCustomEndpoint: true, | ||
| model.ArgusCustomEndpoint = false | ||
| model.AuthorizationCustomEndpoint = false | ||
@@ -120,12 +117,2 @@ model.DNSCustomEndpoint = false | ||
| { | ||
| description: "argus custom endpoint empty", | ||
| flagValues: fixtureFlagValues(func(flagValues map[string]bool) { | ||
| flagValues[argusCustomEndpointFlag] = false | ||
| }), | ||
| isValid: true, | ||
| expectedModel: fixtureInputModel(func(model *inputModel) { | ||
| model.ArgusCustomEndpoint = false | ||
| }), | ||
| }, | ||
| { | ||
| description: "dns custom endpoint empty", | ||
@@ -132,0 +119,0 @@ flagValues: fixtureFlagValues(func(flagValues map[string]bool) { |
@@ -23,3 +23,2 @@ package unset | ||
| argusCustomEndpointFlag = "argus-custom-endpoint" | ||
| authorizationCustomEndpointFlag = "authorization-custom-endpoint" | ||
@@ -48,3 +47,2 @@ dnsCustomEndpointFlag = "dns-custom-endpoint" | ||
| ArgusCustomEndpoint bool | ||
| AuthorizationCustomEndpoint bool | ||
@@ -100,5 +98,2 @@ DNSCustomEndpoint bool | ||
| if model.ArgusCustomEndpoint { | ||
| viper.Set(config.ArgusCustomEndpointKey, "") | ||
| } | ||
| if model.AuthorizationCustomEndpoint { | ||
@@ -165,3 +160,2 @@ viper.Set(config.AuthorizationCustomEndpointKey, "") | ||
| cmd.Flags().Bool(argusCustomEndpointFlag, false, "Argus API base URL. If unset, uses the default base URL") | ||
| cmd.Flags().Bool(authorizationCustomEndpointFlag, false, "Authorization API base URL. If unset, uses the default base URL") | ||
@@ -190,3 +184,2 @@ cmd.Flags().Bool(dnsCustomEndpointFlag, false, "DNS API base URL. If unset, uses the default base URL") | ||
| SessionTimeLimit: flags.FlagToBoolValue(cmd, sessionTimeLimitFlag), | ||
| ArgusCustomEndpoint: flags.FlagToBoolValue(cmd, argusCustomEndpointFlag), | ||
| AuthorizationCustomEndpoint: flags.FlagToBoolValue(cmd, authorizationCustomEndpointFlag), | ||
@@ -193,0 +186,0 @@ DNSCustomEndpoint: flags.FlagToBoolValue(cmd, dnsCustomEndpointFlag), |
@@ -66,3 +66,3 @@ package list | ||
| if err != nil { | ||
| return fmt.Errorf("list LogMe credentialss: %w", err) | ||
| return fmt.Errorf("list LogMe credentials: %w", err) | ||
| } | ||
@@ -69,0 +69,0 @@ credentials := *resp.CredentialsList |
@@ -66,3 +66,3 @@ package list | ||
| if err != nil { | ||
| return fmt.Errorf("list MariaDB credentialss: %w", err) | ||
| return fmt.Errorf("list MariaDB credentials: %w", err) | ||
| } | ||
@@ -69,0 +69,0 @@ credentials := *resp.CredentialsList |
@@ -153,9 +153,2 @@ package update | ||
| { | ||
| description: "base", | ||
| argValues: fixtureArgValues(), | ||
| flagValues: fixtureRequiredFlagValues(), | ||
| isValid: true, | ||
| expectedModel: fixtureRequiredInputModel(), | ||
| }, | ||
| { | ||
| description: "no values", | ||
@@ -179,2 +172,9 @@ argValues: []string{}, | ||
| { | ||
| description: "only instance and project ids", | ||
| argValues: fixtureArgValues(), | ||
| flagValues: fixtureRequiredFlagValues(), | ||
| isValid: false, | ||
| }, | ||
| { | ||
| description: "all values with flavor id", | ||
@@ -181,0 +181,0 @@ argValues: fixtureArgValues(), |
@@ -153,6 +153,18 @@ package update | ||
| instanceName := flags.FlagToStringPointer(cmd, instanceNameFlag) | ||
| flavorId := flags.FlagToStringPointer(cmd, flavorIdFlag) | ||
| cpu := flags.FlagToInt64Pointer(cmd, cpuFlag) | ||
| ram := flags.FlagToInt64Pointer(cmd, ramFlag) | ||
| acl := flags.FlagToStringSlicePointer(cmd, aclFlag) | ||
| backupSchedule := flags.FlagToStringPointer(cmd, backupScheduleFlag) | ||
| storageClass := flags.FlagToStringPointer(cmd, storageClassFlag) | ||
| storageSize := flags.FlagToInt64Pointer(cmd, storageSizeFlag) | ||
| version := flags.FlagToStringPointer(cmd, versionFlag) | ||
| instanceType := flags.FlagToStringPointer(cmd, typeFlag) | ||
| if instanceName == nil && flavorId == nil && cpu == nil && ram == nil && acl == nil && | ||
| backupSchedule == nil && storageClass == nil && storageSize == nil && version == nil && instanceType == nil { | ||
| return nil, &cliErr.EmptyUpdateError{} | ||
| } | ||
| if flavorId != nil && (cpu != nil || ram != nil) { | ||
@@ -168,12 +180,12 @@ return nil, &cliErr.DatabaseInputFlavorError{ | ||
| InstanceId: instanceId, | ||
| InstanceName: flags.FlagToStringPointer(cmd, instanceNameFlag), | ||
| ACL: flags.FlagToStringSlicePointer(cmd, aclFlag), | ||
| BackupSchedule: flags.FlagToStringPointer(cmd, backupScheduleFlag), | ||
| InstanceName: instanceName, | ||
| ACL: acl, | ||
| BackupSchedule: backupSchedule, | ||
| FlavorId: flavorId, | ||
| CPU: cpu, | ||
| RAM: ram, | ||
| StorageClass: flags.FlagToStringPointer(cmd, storageClassFlag), | ||
| StorageSize: flags.FlagToInt64Pointer(cmd, storageSizeFlag), | ||
| Version: flags.FlagToStringPointer(cmd, versionFlag), | ||
| Type: flags.FlagToStringPointer(cmd, typeFlag), | ||
| StorageClass: storageClass, | ||
| StorageSize: storageSize, | ||
| Version: version, | ||
| Type: instanceType, | ||
| }, nil | ||
@@ -180,0 +192,0 @@ } |
@@ -66,3 +66,3 @@ package list | ||
| if err != nil { | ||
| return fmt.Errorf("list OpenSearch credentialss: %w", err) | ||
| return fmt.Errorf("list OpenSearch credentials: %w", err) | ||
| } | ||
@@ -69,0 +69,0 @@ credentials := *resp.CredentialsList |
@@ -153,9 +153,2 @@ package update | ||
| { | ||
| description: "base", | ||
| argValues: fixtureArgValues(), | ||
| flagValues: fixtureRequiredFlagValues(), | ||
| isValid: true, | ||
| expectedModel: fixtureRequiredInputModel(), | ||
| }, | ||
| { | ||
| description: "no values", | ||
@@ -179,2 +172,9 @@ argValues: []string{}, | ||
| { | ||
| description: "only instance and project ids", | ||
| argValues: fixtureArgValues(), | ||
| flagValues: fixtureRequiredFlagValues(), | ||
| isValid: false, | ||
| }, | ||
| { | ||
| description: "all values with flavor id", | ||
@@ -181,0 +181,0 @@ argValues: fixtureArgValues(), |
@@ -153,6 +153,18 @@ package update | ||
| instanceName := flags.FlagToStringPointer(cmd, instanceNameFlag) | ||
| flavorId := flags.FlagToStringPointer(cmd, flavorIdFlag) | ||
| cpu := flags.FlagToInt64Pointer(cmd, cpuFlag) | ||
| ram := flags.FlagToInt64Pointer(cmd, ramFlag) | ||
| acl := flags.FlagToStringSlicePointer(cmd, aclFlag) | ||
| backupSchedule := flags.FlagToStringPointer(cmd, backupScheduleFlag) | ||
| storageClass := flags.FlagToStringPointer(cmd, storageClassFlag) | ||
| storageSize := flags.FlagToInt64Pointer(cmd, storageSizeFlag) | ||
| version := flags.FlagToStringPointer(cmd, versionFlag) | ||
| instanceType := flags.FlagToStringPointer(cmd, typeFlag) | ||
| if instanceName == nil && flavorId == nil && cpu == nil && ram == nil && acl == nil && | ||
| backupSchedule == nil && storageClass == nil && storageSize == nil && version == nil && instanceType == nil { | ||
| return nil, &cliErr.EmptyUpdateError{} | ||
| } | ||
| if flavorId != nil && (cpu != nil || ram != nil) { | ||
@@ -168,12 +180,12 @@ return nil, &cliErr.DatabaseInputFlavorError{ | ||
| InstanceId: instanceId, | ||
| InstanceName: flags.FlagToStringPointer(cmd, instanceNameFlag), | ||
| ACL: flags.FlagToStringSlicePointer(cmd, aclFlag), | ||
| BackupSchedule: flags.FlagToStringPointer(cmd, backupScheduleFlag), | ||
| InstanceName: instanceName, | ||
| ACL: acl, | ||
| BackupSchedule: backupSchedule, | ||
| FlavorId: flavorId, | ||
| CPU: cpu, | ||
| RAM: ram, | ||
| StorageClass: flags.FlagToStringPointer(cmd, storageClassFlag), | ||
| StorageSize: flags.FlagToInt64Pointer(cmd, storageSizeFlag), | ||
| Version: flags.FlagToStringPointer(cmd, versionFlag), | ||
| Type: flags.FlagToStringPointer(cmd, typeFlag), | ||
| StorageClass: storageClass, | ||
| StorageSize: storageSize, | ||
| Version: version, | ||
| Type: instanceType, | ||
| }, nil | ||
@@ -180,0 +192,0 @@ } |
@@ -34,11 +34,11 @@ package create | ||
| Use: "create", | ||
| Short: "Creates credentials for an RabbitMQ instance", | ||
| Long: "Creates credentials (username and password) for an RabbitMQ instance.", | ||
| Short: "Creates credentials for a RabbitMQ instance", | ||
| Long: "Creates credentials (username and password) for a RabbitMQ instance.", | ||
| Args: args.NoArgs, | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `Create credentials for an RabbitMQ instance`, | ||
| `Create credentials for a RabbitMQ instance`, | ||
| "$ stackit rabbitmq credentials create --instance-id xxx"), | ||
| examples.NewExample( | ||
| `Create credentials for an RabbitMQ instance and hide the password in the output`, | ||
| `Create credentials for a RabbitMQ instance and hide the password in the output`, | ||
| "$ stackit rabbitmq credentials create --instance-id xxx --hide-password"), | ||
@@ -45,0 +45,0 @@ ), |
@@ -36,4 +36,4 @@ package delete | ||
| Use: fmt.Sprintf("delete %s", credentialsIdArg), | ||
| Short: "Deletes credentials of an RabbitMQ instance", | ||
| Long: "Deletes credentials of an RabbitMQ instance.", | ||
| Short: "Deletes credentials of a RabbitMQ instance", | ||
| Long: "Deletes credentials of a RabbitMQ instance.", | ||
| Args: args.SingleArg(credentialsIdArg, utils.ValidateUUID), | ||
@@ -40,0 +40,0 @@ Example: examples.Build( |
@@ -36,4 +36,4 @@ package describe | ||
| Use: fmt.Sprintf("describe %s", credentialsIdArg), | ||
| Short: "Shows details of credentials of an RabbitMQ instance", | ||
| Long: "Shows details of credentials of an RabbitMQ instance. The password will be shown in plain text in the output.", | ||
| Short: "Shows details of credentials of a RabbitMQ instance", | ||
| Long: "Shows details of credentials of a RabbitMQ instance. The password will be shown in plain text in the output.", | ||
| Args: args.SingleArg(credentialsIdArg, utils.ValidateUUID), | ||
@@ -40,0 +40,0 @@ Example: examples.Build( |
@@ -35,14 +35,14 @@ package list | ||
| Use: "list", | ||
| Short: "Lists all credentials' IDs for an RabbitMQ instance", | ||
| Long: "Lists all credentials' IDs for an RabbitMQ instance.", | ||
| Short: "Lists all credentials' IDs for a RabbitMQ instance", | ||
| Long: "Lists all credentials' IDs for a RabbitMQ instance.", | ||
| Args: args.NoArgs, | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `List all credentials' IDs for an RabbitMQ instance`, | ||
| `List all credentials' IDs for a RabbitMQ instance`, | ||
| "$ stackit rabbitmq credentials list --instance-id xxx"), | ||
| examples.NewExample( | ||
| `List all credentials' IDs for an RabbitMQ instance in JSON format`, | ||
| `List all credentials' IDs for a RabbitMQ instance in JSON format`, | ||
| "$ stackit rabbitmq credentials list --instance-id xxx --output-format json"), | ||
| examples.NewExample( | ||
| `List up to 10 credentials' IDs for an RabbitMQ instance`, | ||
| `List up to 10 credentials' IDs for a RabbitMQ instance`, | ||
| "$ stackit rabbitmq credentials list --instance-id xxx --limit 10"), | ||
@@ -67,3 +67,3 @@ ), | ||
| if err != nil { | ||
| return fmt.Errorf("list RabbitMQ credentialss: %w", err) | ||
| return fmt.Errorf("list RabbitMQ credentials: %w", err) | ||
| } | ||
@@ -70,0 +70,0 @@ credentials := *resp.CredentialsList |
@@ -61,14 +61,14 @@ package create | ||
| Use: "create", | ||
| Short: "Creates an RabbitMQ instance", | ||
| Long: "Creates an RabbitMQ instance.", | ||
| Short: "Creates a RabbitMQ instance", | ||
| Long: "Creates a RabbitMQ instance.", | ||
| Args: args.NoArgs, | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `Create an RabbitMQ instance with name "my-instance" and specify plan by name and version`, | ||
| `Create a RabbitMQ instance with name "my-instance" and specify plan by name and version`, | ||
| "$ stackit rabbitmq instance create --name my-instance --plan-name stackit-rabbitmq-1.2.10-replica --version 3.10"), | ||
| examples.NewExample( | ||
| `Create an RabbitMQ instance with name "my-instance" and specify plan by ID`, | ||
| `Create a RabbitMQ instance with name "my-instance" and specify plan by ID`, | ||
| "$ stackit rabbitmq instance create --name my-instance --plan-id xxx"), | ||
| examples.NewExample( | ||
| `Create an RabbitMQ instance with name "my-instance" and specify IP range which is allowed to access it`, | ||
| `Create a RabbitMQ instance with name "my-instance" and specify IP range which is allowed to access it`, | ||
| "$ stackit rabbitmq instance create --name my-instance --plan-id xxx --acl 1.2.3.0/24"), | ||
@@ -75,0 +75,0 @@ ), |
@@ -34,8 +34,8 @@ package delete | ||
| Use: fmt.Sprintf("delete %s", instanceIdArg), | ||
| Short: "Deletes an RabbitMQ instance", | ||
| Long: "Deletes an RabbitMQ instance.", | ||
| Short: "Deletes a RabbitMQ instance", | ||
| Long: "Deletes a RabbitMQ instance.", | ||
| Args: args.SingleArg(instanceIdArg, utils.ValidateUUID), | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `Delete an RabbitMQ instance with ID "xxx"`, | ||
| `Delete a RabbitMQ instance with ID "xxx"`, | ||
| "$ stackit rabbitmq instance delete xxx"), | ||
@@ -42,0 +42,0 @@ ), |
@@ -34,11 +34,11 @@ package describe | ||
| Use: fmt.Sprintf("describe %s", instanceIdArg), | ||
| Short: "Shows details of an RabbitMQ instance", | ||
| Long: "Shows details of an RabbitMQ instance.", | ||
| Short: "Shows details of a RabbitMQ instance", | ||
| Long: "Shows details of a RabbitMQ instance.", | ||
| Args: args.SingleArg(instanceIdArg, utils.ValidateUUID), | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `Get details of an RabbitMQ instance with ID "xxx"`, | ||
| `Get details of a RabbitMQ instance with ID "xxx"`, | ||
| "$ stackit rabbitmq instance describe xxx"), | ||
| examples.NewExample( | ||
| `Get details of an RabbitMQ instance with ID "xxx" in a table format`, | ||
| `Get details of a RabbitMQ instance with ID "xxx" in a table format`, | ||
| "$ stackit rabbitmq instance describe xxx --output-format pretty"), | ||
@@ -45,0 +45,0 @@ ), |
@@ -62,11 +62,11 @@ package update | ||
| Use: fmt.Sprintf("update %s", instanceIdArg), | ||
| Short: "Updates an RabbitMQ instance", | ||
| Long: "Updates an RabbitMQ instance.", | ||
| Short: "Updates a RabbitMQ instance", | ||
| Long: "Updates a RabbitMQ instance.", | ||
| Args: args.SingleArg(instanceIdArg, utils.ValidateUUID), | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `Update the plan of an RabbitMQ instance with ID "xxx"`, | ||
| `Update the plan of a RabbitMQ instance with ID "xxx"`, | ||
| "$ stackit rabbitmq instance update xxx --plan-id yyy"), | ||
| examples.NewExample( | ||
| `Update the range of IPs allowed to access an RabbitMQ instance with ID "xxx"`, | ||
| `Update the range of IPs allowed to access a RabbitMQ instance with ID "xxx"`, | ||
| "$ stackit rabbitmq instance update xxx --acl 1.2.3.0/24"), | ||
@@ -73,0 +73,0 @@ ), |
@@ -66,3 +66,3 @@ package list | ||
| if err != nil { | ||
| return fmt.Errorf("list Redis credentialss: %w", err) | ||
| return fmt.Errorf("list Redis credentials: %w", err) | ||
| } | ||
@@ -69,0 +69,0 @@ credentials := *resp.CredentialsList |
@@ -9,3 +9,2 @@ package cmd | ||
| "github.com/stackitcloud/stackit-cli/internal/cmd/argus" | ||
| "github.com/stackitcloud/stackit-cli/internal/cmd/auth" | ||
@@ -89,3 +88,2 @@ "github.com/stackitcloud/stackit-cli/internal/cmd/config" | ||
| func addSubcommands(cmd *cobra.Command) { | ||
| cmd.AddCommand(argus.NewCmd()) | ||
| cmd.AddCommand(auth.NewCmd()) | ||
@@ -92,0 +90,0 @@ cmd.AddCommand(config.NewCmd()) |
@@ -111,8 +111,10 @@ package describe | ||
| table.AddSeparator() | ||
| table.AddRow("DESCRIPTION", *user.Description) | ||
| if user.Description != nil && *user.Description != "" { | ||
| table.AddRow("DESCRIPTION", *user.Description) | ||
| table.AddSeparator() | ||
| } | ||
| if user.Password != nil && *user.Password != "" { | ||
| table.AddRow("PASSWORD", *user.Password) | ||
| table.AddSeparator() | ||
| table.AddRow("PASSWORD", *user.Password) | ||
| } | ||
| table.AddSeparator() | ||
| table.AddRow("WRITE ACCESS", *user.Write) | ||
@@ -119,0 +121,0 @@ |
@@ -41,6 +41,6 @@ package list | ||
| examples.NewExample( | ||
| `List all Secrets Manager users of instance with ID "xxx`, | ||
| `List all Secrets Manager users of instance with ID "xxx"`, | ||
| "$ stackit secrets-manager user list --instance-id xxx"), | ||
| examples.NewExample( | ||
| `List all Secrets Manager users in JSON format with ID "xxx`, | ||
| `List all Secrets Manager users in JSON format with ID "xxx"`, | ||
| "$ stackit secrets-manager user list --instance-id xxx --output-format json"), | ||
@@ -47,0 +47,0 @@ examples.NewExample( |
@@ -19,3 +19,2 @@ package config | ||
| ArgusCustomEndpointKey = "argus_custom_endpoint" | ||
| AuthorizationCustomEndpointKey = "authorization_custom_endpoint" | ||
@@ -61,3 +60,2 @@ DNSCustomEndpointKey = "dns_custom_endpoint" | ||
| ResourceManagerEndpointKey, | ||
| ArgusCustomEndpointKey, | ||
| AuthorizationCustomEndpointKey, | ||
@@ -135,3 +133,2 @@ MongoDBFlexCustomEndpointKey, | ||
| viper.SetDefault(DNSCustomEndpointKey, "") | ||
| viper.SetDefault(ArgusCustomEndpointKey, "") | ||
| viper.SetDefault(AuthorizationCustomEndpointKey, "") | ||
@@ -138,0 +135,0 @@ viper.SetDefault(MongoDBFlexCustomEndpointKey, "") |
+4
-4
| # STACKIT CLI (BETA) | ||
| Welcome to the STACKIT CLI, a command-line interface for the STACKIT services. | ||
| Welcome to the [STACKIT](https://www.stackit.de/en) CLI, a command-line interface for the STACKIT services. | ||
@@ -51,3 +51,3 @@ This CLI is in a BETA state. More services and functionality will be supported soon. | ||
| | Service | CLI Commands | Status | | ||
| | ----------------------- | ------------------------- | ----------------------- | | ||
| | ----------------------- | ------------------------- |-------------------------| | ||
| | Argus | | Will be integrated soon | | ||
@@ -61,3 +61,3 @@ | Authorization | `project`, `organization` | :white_check_mark: | | ||
| | MongoDB Flex | `mongodbflex` | :white_check_mark: | | ||
| | Object Storage | | Will be integrated soon | | ||
| | Object Storage | `object-storage` | :white_check_mark: | | ||
| | OpenSearch | `opensearch` | :white_check_mark: | | ||
@@ -68,3 +68,3 @@ | PostgreSQL Flex | `postgresflex` | :white_check_mark: | | ||
| | Resource Manager | `project` | :white_check_mark: | | ||
| | Secrets Manager | | Will be integrated soon | | ||
| | Secrets Manager | `secrets-manager` | :white_check_mark: | | ||
| | Service Account | `service-account` | :white_check_mark: | | ||
@@ -71,0 +71,0 @@ |
@@ -11,2 +11,3 @@ #!/bin/bash | ||
| APT_BUCKET_NAME="stackit-cli-apt" | ||
| APT_NEW_BUCKET_NAME="distribution" | ||
| PUBLIC_KEY_BUCKET_NAME="stackit-public-key" | ||
@@ -55,2 +56,2 @@ PUBLIC_KEY_FILE="key.gpg" | ||
| printf "\n>>> Publishing updated snapshot \n" | ||
| aptly publish snapshot -keyring="${CUSTOM_KEYRING_FILE}" -gpg-key="${GPG_PRIVATE_KEY_FINGERPRINT}" -passphrase "${GPG_PASSPHRASE}" -config "${APTLY_CONFIG_FILE_PATH}" updated-snapshot "s3:${APT_BUCKET_NAME}:" | ||
| aptly publish snapshot -keyring="${CUSTOM_KEYRING_FILE}" -gpg-key="${GPG_PRIVATE_KEY_FINGERPRINT}" -passphrase "${GPG_PASSPHRASE}" -config "${APTLY_CONFIG_FILE_PATH}" updated-snapshot "s3:${APT_NEW_BUCKET_NAME}:apt/cli" |
| ## stackit argus plans | ||
| Lists all Argus service plans | ||
| ### Synopsis | ||
| Lists all Argus service plans. | ||
| ``` | ||
| stackit argus plans [flags] | ||
| ``` | ||
| ### Examples | ||
| ``` | ||
| List all Argus service plans | ||
| $ stackit argus plans | ||
| List all Argus service plans in JSON format | ||
| $ stackit argus plans --output-format json | ||
| List up to 10 Argus service plans | ||
| $ stackit argus plans --limit 10 | ||
| ``` | ||
| ### Options | ||
| ``` | ||
| -h, --help Help for "stackit argus plans" | ||
| --limit int Maximum number of entries to list | ||
| ``` | ||
| ### Options inherited from parent commands | ||
| ``` | ||
| -y, --assume-yes If set, skips all confirmation prompts | ||
| --async If set, runs the command asynchronously | ||
| -o, --output-format string Output format, one of ["json" "pretty"] | ||
| -p, --project-id string Project ID | ||
| ``` | ||
| ### SEE ALSO | ||
| * [stackit argus](./stackit_argus.md) - Provides functionality for Argus | ||
| ## stackit argus | ||
| Provides functionality for Argus | ||
| ### Synopsis | ||
| Provides functionality for Argus. | ||
| ``` | ||
| stackit argus [flags] | ||
| ``` | ||
| ### Options | ||
| ``` | ||
| -h, --help Help for "stackit argus" | ||
| ``` | ||
| ### Options inherited from parent commands | ||
| ``` | ||
| -y, --assume-yes If set, skips all confirmation prompts | ||
| --async If set, runs the command asynchronously | ||
| -o, --output-format string Output format, one of ["json" "pretty"] | ||
| -p, --project-id string Project ID | ||
| ``` | ||
| ### SEE ALSO | ||
| * [stackit](./stackit.md) - Manage STACKIT resources using the command line | ||
| * [stackit argus plans](./stackit_argus_plans.md) - Lists all Argus service plans | ||
| package argus | ||
| import ( | ||
| "github.com/stackitcloud/stackit-cli/internal/cmd/argus/plans" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/args" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/utils" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
| func NewCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "argus", | ||
| Short: "Provides functionality for Argus", | ||
| Long: "Provides functionality for Argus.", | ||
| Args: args.NoArgs, | ||
| Run: utils.CmdHelp, | ||
| } | ||
| addSubcommands(cmd) | ||
| return cmd | ||
| } | ||
| func addSubcommands(cmd *cobra.Command) { | ||
| cmd.AddCommand(plans.NewCmd()) | ||
| } |
| package plans | ||
| import ( | ||
| "context" | ||
| "testing" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/utils" | ||
| "github.com/google/go-cmp/cmp" | ||
| "github.com/google/go-cmp/cmp/cmpopts" | ||
| "github.com/google/uuid" | ||
| "github.com/spf13/cobra" | ||
| "github.com/stackitcloud/stackit-sdk-go/services/argus" | ||
| ) | ||
| var projectIdFlag = globalflags.ProjectIdFlag | ||
| type testCtxKey struct{} | ||
| var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") | ||
| var testClient = &argus.APIClient{} | ||
| var testProjectId = uuid.NewString() | ||
| func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { | ||
| flagValues := map[string]string{ | ||
| projectIdFlag: testProjectId, | ||
| limitFlag: "10", | ||
| } | ||
| for _, mod := range mods { | ||
| mod(flagValues) | ||
| } | ||
| return flagValues | ||
| } | ||
| func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { | ||
| model := &inputModel{ | ||
| GlobalFlagModel: &globalflags.GlobalFlagModel{ | ||
| ProjectId: testProjectId, | ||
| }, | ||
| Limit: utils.Ptr(int64(10)), | ||
| } | ||
| for _, mod := range mods { | ||
| mod(model) | ||
| } | ||
| return model | ||
| } | ||
| func fixtureRequest(mods ...func(request *argus.ApiListPlansRequest)) argus.ApiListPlansRequest { | ||
| request := testClient.ListPlans(testCtx, testProjectId) | ||
| for _, mod := range mods { | ||
| mod(&request) | ||
| } | ||
| return request | ||
| } | ||
| func TestParseInput(t *testing.T) { | ||
| tests := []struct { | ||
| description string | ||
| flagValues map[string]string | ||
| isValid bool | ||
| expectedModel *inputModel | ||
| }{ | ||
| { | ||
| description: "base", | ||
| flagValues: fixtureFlagValues(), | ||
| isValid: true, | ||
| expectedModel: fixtureInputModel(), | ||
| }, | ||
| { | ||
| description: "no values", | ||
| flagValues: map[string]string{}, | ||
| isValid: false, | ||
| }, | ||
| { | ||
| description: "project id missing", | ||
| flagValues: fixtureFlagValues(func(flagValues map[string]string) { | ||
| delete(flagValues, projectIdFlag) | ||
| }), | ||
| isValid: false, | ||
| }, | ||
| { | ||
| description: "project id invalid 1", | ||
| flagValues: fixtureFlagValues(func(flagValues map[string]string) { | ||
| flagValues[projectIdFlag] = "" | ||
| }), | ||
| isValid: false, | ||
| }, | ||
| { | ||
| description: "project id invalid 2", | ||
| flagValues: fixtureFlagValues(func(flagValues map[string]string) { | ||
| flagValues[projectIdFlag] = "invalid-uuid" | ||
| }), | ||
| isValid: false, | ||
| }, | ||
| { | ||
| description: "limit invalid", | ||
| flagValues: fixtureFlagValues(func(flagValues map[string]string) { | ||
| flagValues[limitFlag] = "invalid" | ||
| }), | ||
| isValid: false, | ||
| }, | ||
| { | ||
| description: "limit invalid 2", | ||
| flagValues: fixtureFlagValues(func(flagValues map[string]string) { | ||
| flagValues[limitFlag] = "0" | ||
| }), | ||
| isValid: false, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.description, func(t *testing.T) { | ||
| cmd := &cobra.Command{} | ||
| err := globalflags.Configure(cmd.Flags()) | ||
| if err != nil { | ||
| t.Fatalf("configure global flags: %v", err) | ||
| } | ||
| configureFlags(cmd) | ||
| for flag, value := range tt.flagValues { | ||
| err := cmd.Flags().Set(flag, value) | ||
| if err != nil { | ||
| if !tt.isValid { | ||
| return | ||
| } | ||
| t.Fatalf("setting flag --%s=%s: %v", flag, value, err) | ||
| } | ||
| } | ||
| err = cmd.ValidateRequiredFlags() | ||
| if err != nil { | ||
| if !tt.isValid { | ||
| return | ||
| } | ||
| t.Fatalf("error validating flags: %v", err) | ||
| } | ||
| model, err := parseInput(cmd) | ||
| if err != nil { | ||
| if !tt.isValid { | ||
| return | ||
| } | ||
| t.Fatalf("error parsing flags: %v", err) | ||
| } | ||
| if !tt.isValid { | ||
| t.Fatalf("did not fail on invalid input") | ||
| } | ||
| diff := cmp.Diff(model, tt.expectedModel) | ||
| if diff != "" { | ||
| t.Fatalf("Data does not match: %s", diff) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| func TestBuildRequest(t *testing.T) { | ||
| tests := []struct { | ||
| description string | ||
| model *inputModel | ||
| expectedRequest argus.ApiListPlansRequest | ||
| }{ | ||
| { | ||
| description: "base", | ||
| model: fixtureInputModel(), | ||
| expectedRequest: fixtureRequest(), | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.description, func(t *testing.T) { | ||
| request := buildRequest(testCtx, tt.model, testClient) | ||
| diff := cmp.Diff(request, tt.expectedRequest, | ||
| cmp.AllowUnexported(tt.expectedRequest), | ||
| cmpopts.EquateComparable(testCtx), | ||
| ) | ||
| if diff != "" { | ||
| t.Fatalf("Data does not match: %s", diff) | ||
| } | ||
| }) | ||
| } | ||
| } |
| package plans | ||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/args" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/errors" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/examples" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/flags" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/tables" | ||
| "github.com/spf13/cobra" | ||
| "github.com/stackitcloud/stackit-sdk-go/services/argus" | ||
| ) | ||
| const ( | ||
| limitFlag = "limit" | ||
| ) | ||
| type inputModel struct { | ||
| *globalflags.GlobalFlagModel | ||
| Limit *int64 | ||
| } | ||
| func NewCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "plans", | ||
| Short: "Lists all Argus service plans", | ||
| Long: "Lists all Argus service plans.", | ||
| Args: args.NoArgs, | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `List all Argus service plans`, | ||
| "$ stackit argus plans"), | ||
| examples.NewExample( | ||
| `List all Argus service plans in JSON format`, | ||
| "$ stackit argus plans --output-format json"), | ||
| examples.NewExample( | ||
| `List up to 10 Argus service plans`, | ||
| "$ stackit argus plans --limit 10"), | ||
| ), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := context.Background() | ||
| model, err := parseInput(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| // Configure API client | ||
| apiClient, err := client.ConfigureClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| // Call API | ||
| req := buildRequest(ctx, model, apiClient) | ||
| resp, err := req.Execute() | ||
| if err != nil { | ||
| return fmt.Errorf("get Argus service plans: %w", err) | ||
| } | ||
| plans := *resp.Plans | ||
| if len(plans) == 0 { | ||
| projectLabel, err := projectname.GetProjectName(ctx, cmd) | ||
| if err != nil { | ||
| projectLabel = model.ProjectId | ||
| } | ||
| cmd.Printf("No plans found for project %q\n", projectLabel) | ||
| return nil | ||
| } | ||
| // Truncate output | ||
| if model.Limit != nil && len(plans) > int(*model.Limit) { | ||
| plans = plans[:*model.Limit] | ||
| } | ||
| return outputResult(cmd, model.OutputFormat, plans) | ||
| }, | ||
| } | ||
| configureFlags(cmd) | ||
| return cmd | ||
| } | ||
| func configureFlags(cmd *cobra.Command) { | ||
| cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") | ||
| } | ||
| func parseInput(cmd *cobra.Command) (*inputModel, error) { | ||
| globalFlags := globalflags.Parse(cmd) | ||
| if globalFlags.ProjectId == "" { | ||
| return nil, &errors.ProjectIdError{} | ||
| } | ||
| limit := flags.FlagToInt64Pointer(cmd, limitFlag) | ||
| if limit != nil && *limit < 1 { | ||
| return nil, &errors.FlagValidationError{ | ||
| Flag: limitFlag, | ||
| Details: "must be greater than 0", | ||
| } | ||
| } | ||
| return &inputModel{ | ||
| GlobalFlagModel: globalFlags, | ||
| Limit: limit, | ||
| }, nil | ||
| } | ||
| func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APIClient) argus.ApiListPlansRequest { | ||
| req := apiClient.ListPlans(ctx, model.ProjectId) | ||
| return req | ||
| } | ||
| func outputResult(cmd *cobra.Command, outputFormat string, plans []argus.Plan) error { | ||
| switch outputFormat { | ||
| case globalflags.JSONOutputFormat: | ||
| details, err := json.MarshalIndent(plans, "", " ") | ||
| if err != nil { | ||
| return fmt.Errorf("marshal Argus plans: %w", err) | ||
| } | ||
| cmd.Println(string(details)) | ||
| return nil | ||
| default: | ||
| table := tables.NewTable() | ||
| table.SetHeader("ID", "PLAN NAME", "DESCRIPTION") | ||
| for i := range plans { | ||
| o := plans[i] | ||
| table.AddRow(*o.Id, *o.Name, *o.Description) | ||
| table.AddSeparator() | ||
| } | ||
| table.EnableAutoMergeOnColumns(1) | ||
| err := table.Display(cmd) | ||
| if err != nil { | ||
| return fmt.Errorf("render table: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
| } |
| package client | ||
| import ( | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/auth" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/config" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/errors" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" | ||
| "github.com/stackitcloud/stackit-sdk-go/services/argus" | ||
| ) | ||
| func ConfigureClient(cmd *cobra.Command) (*argus.APIClient, error) { | ||
| var err error | ||
| var apiClient *argus.APIClient | ||
| var cfgOptions []sdkConfig.ConfigurationOption | ||
| authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) | ||
| if err != nil { | ||
| return nil, &errors.AuthError{} | ||
| } | ||
| cfgOptions = append(cfgOptions, authCfgOption, sdkConfig.WithRegion("eu01")) | ||
| customEndpoint := viper.GetString(config.ArgusCustomEndpointKey) | ||
| if customEndpoint != "" { | ||
| cfgOptions = append(cfgOptions, sdkConfig.WithEndpoint(customEndpoint)) | ||
| } | ||
| apiClient, err = argus.NewAPIClient(cfgOptions...) | ||
| if err != nil { | ||
| return nil, &errors.AuthError{} | ||
| } | ||
| return apiClient, nil | ||
| } |