Skip to content

Improvements to profiles functionality #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 13, 2024
25 changes: 24 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ brews:
email: [email protected]
homepage: "https://github.com/stackitcloud/stackit-cli"
description: "A command-line interface to manage STACKIT resources.\nThis CLI is in a BETA state. More services and functionality will be supported soon."
folder: Formula
directory: Formula
license: "Apache-2.0"
# If set to auto, the release will not be uploaded to the homebrew tap repo
# if the tag has a prerelease indicator (e.g. v0.0.1-alpha1)
Expand All @@ -125,3 +125,26 @@ snapcrafts:
grade: devel
# Whether to publish the Snap to the store
publish: true

winget:
- name: stackit
publisher: stackitcloud
short_description: A command-line interface to manage STACKIT resources.
license: Apache-2.0
publisher_support_url: "https://github.com/stackitcloud/stackit-cli/issues"
package_identifier: stackitcloud.stackit
homepage: "https://github.com/stackitcloud/stackit-cli"
# If set to auto, the release will not be uploaded to the homebrew tap repo
# if the tag has a prerelease indicator (e.g. v0.0.1-alpha1)
# Temporarily not skipping prereleases to test integration with Winget
# skip_upload: auto
repository:
owner: stackitcloud
name: winget-pkgs
pull_request:
enabled: true
draft: true
base:
owner: microsoft
name: winget-pkgs
branch: master
13 changes: 7 additions & 6 deletions docs/stackit_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Provides functionality for CLI configuration options

### Synopsis

Provides functionality for CLI configuration options
The configuration is stored in a file in the user's config directory, which is OS dependent.
Windows: %APPDATA%\stackit
Linux: $XDG_CONFIG_HOME/stackit
macOS: $HOME/Library/Application Support/stackit
The configuration file is named `cli-config.json` and is created automatically in your first CLI run.
Provides functionality for CLI configuration options.
You can set and unset different configuration options via the "stackit config set" and "stackit config unset" commands.

Additionally, you can configure the CLI to use different profiles, each with its own configuration.
Additional profiles can be configured via the "STACKIT_CLI_PROFILE" environment variable or using the "stackit config profile set PROFILE" and "stackit config profile unset" commands.
The environment variable takes precedence over what is set via the commands.

```
stackit config [flags]
Expand All @@ -35,6 +35,7 @@ stackit config [flags]

* [stackit](./stackit.md) - Manage STACKIT resources using the command line
* [stackit config list](./stackit_config_list.md) - Lists the current CLI configuration values
* [stackit config profile](./stackit_config_profile.md) - Manage the CLI configuration profiles
* [stackit config set](./stackit_config_set.md) - Sets CLI configuration options
* [stackit config unset](./stackit_config_unset.md) - Unsets CLI configuration options

37 changes: 37 additions & 0 deletions docs/stackit_config_profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## stackit config profile

Manage the CLI configuration profiles

### Synopsis

Manage the CLI configuration profiles.
The profile to be used can be managed via the "STACKIT_CLI_PROFILE" environment variable or using the "stackit config profile set PROFILE" and "stackit config profile unset" commands.
The environment variable takes precedence over what is set via the commands.
When no profile is set, the default profile is used.

```
stackit config profile [flags]
```

### Options

```
-h, --help Help for "stackit config profile"
```

### 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" "none"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options
* [stackit config profile set](./stackit_config_profile_set.md) - Set a CLI configuration profile
* [stackit config profile unset](./stackit_config_profile_unset.md) - Unset the current active CLI configuration profile

43 changes: 43 additions & 0 deletions docs/stackit_config_profile_set.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## stackit config profile set

Set a CLI configuration profile

### Synopsis

Set a CLI configuration profile as the active profile.
The profile to be used can be managed via the STACKIT_CLI_PROFILE environment variable or using the "stackit config profile set PROFILE" and "stackit config profile unset" commands.
The environment variable takes precedence over what is set via the commands.
A new profile is created automatically if it does not exist.
When no profile is set, the default profile is used.

```
stackit config profile set PROFILE [flags]
```

### Examples

```
Set the configuration profile "my-profile" as the active profile
$ stackit config profile set my-profile
```

### Options

```
-h, --help Help for "stackit config profile set"
```

### 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" "none"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit config profile](./stackit_config_profile.md) - Manage the CLI configuration profiles

40 changes: 40 additions & 0 deletions docs/stackit_config_profile_unset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit config profile unset

Unset the current active CLI configuration profile

### Synopsis

Unset the current active CLI configuration profile.
When no profile is set, the default profile will be used.

```
stackit config profile unset [flags]
```

### Examples

```
Unset the currently active configuration profile. The default profile will be used.
$ stackit config profile unset
```

### Options

```
-h, --help Help for "stackit config profile unset"
```

### 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" "none"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit config profile](./stackit_config_profile.md) - Manage the CLI configuration profiles

3 changes: 2 additions & 1 deletion docs/stackit_load-balancer_observability-credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ stackit load-balancer observability-credentials [flags]

* [stackit load-balancer](./stackit_load-balancer.md) - Provides functionality for Load Balancer
* [stackit load-balancer observability-credentials add](./stackit_load-balancer_observability-credentials_add.md) - Adds observability credentials to Load Balancer
* [stackit load-balancer observability-credentials cleanup](./stackit_load-balancer_observability-credentials_cleanup.md) - Deletes observability credentials unused by any Load Balancer
* [stackit load-balancer observability-credentials delete](./stackit_load-balancer_observability-credentials_delete.md) - Deletes observability credentials for Load Balancer
* [stackit load-balancer observability-credentials describe](./stackit_load-balancer_observability-credentials_describe.md) - Shows details of observability credentials for Load Balancer
* [stackit load-balancer observability-credentials list](./stackit_load-balancer_observability-credentials_list.md) - Lists all observability credentials for Load Balancer
* [stackit load-balancer observability-credentials list](./stackit_load-balancer_observability-credentials_list.md) - Lists observability credentials for Load Balancer
* [stackit load-balancer observability-credentials update](./stackit_load-balancer_observability-credentials_update.md) - Updates observability credentials for Load Balancer

39 changes: 39 additions & 0 deletions docs/stackit_load-balancer_observability-credentials_cleanup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## stackit load-balancer observability-credentials cleanup

Deletes observability credentials unused by any Load Balancer

### Synopsis

Deletes observability credentials unused by any Load Balancer.

```
stackit load-balancer observability-credentials cleanup [flags]
```

### Examples

```
Delete observability credentials unused by any Load Balancer
$ stackit load-balancer observability-credentials cleanup
```

### Options

```
-h, --help Help for "stackit load-balancer observability-credentials cleanup"
```

### 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" "none"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit load-balancer observability-credentials](./stackit_load-balancer_observability-credentials.md) - Provides functionality for Load Balancer observability credentials

18 changes: 13 additions & 5 deletions docs/stackit_load-balancer_observability-credentials_list.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## stackit load-balancer observability-credentials list

Lists all observability credentials for Load Balancer
Lists observability credentials for Load Balancer

### Synopsis

Lists all observability credentials for Load Balancer.
Lists observability credentials for Load Balancer.

```
stackit load-balancer observability-credentials list [flags]
Expand All @@ -13,13 +13,19 @@ stackit load-balancer observability-credentials list [flags]
### Examples

```
List all observability credentials for Load Balancer
List all Load Balancer observability credentials
$ stackit load-balancer observability-credentials list

List all observability credentials for Load Balancer in JSON format
List all observability credentials being used by Load Balancer
$ stackit load-balancer observability-credentials list --used

List all observability credentials not being used by Load Balancer
$ stackit load-balancer observability-credentials list --unused

List all Load Balancer observability credentials in JSON format
$ stackit load-balancer observability-credentials list --output-format json

List up to 10 observability credentials for Load Balancer
List up to 10 Load Balancer observability credentials
$ stackit load-balancer observability-credentials list --limit 10
```

Expand All @@ -28,6 +34,8 @@ stackit load-balancer observability-credentials list [flags]
```
-h, --help Help for "stackit load-balancer observability-credentials list"
--limit int Maximum number of entries to list
--unused List only credentials not being used by a Load Balancer
--used List only credentials being used by a Load Balancer
```

### Options inherited from parent commands
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/config/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func outputResult(p *print.Printer, outputFormat string, configData map[string]a
switch outputFormat {
case print.JSONOutputFormat:
if activeProfile != "" {
configData["active_profile"] = activeProfile
configData["profile"] = activeProfile
}
details, err := json.MarshalIndent(configData, "", " ")
if err != nil {
Expand All @@ -83,9 +83,6 @@ func outputResult(p *print.Printer, outputFormat string, configData map[string]a
p.Outputln(string(details))
return nil
default:
if activeProfile != "" {
p.Outputf("\n ACTIVE PROFILE: %s\n", activeProfile)
}

// Sort the config options by key
configKeys := make([]string, 0, len(configData))
Expand All @@ -95,6 +92,9 @@ func outputResult(p *print.Printer, outputFormat string, configData map[string]a
sort.Strings(configKeys)

table := tables.NewTable()
if activeProfile != "" {
table.SetTitle(fmt.Sprintf("Profile: %q", activeProfile))
}
table.SetHeader("NAME", "VALUE")
for _, key := range configKeys {
value := configData[key]
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/config/profile/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("set %s", profileArg),
Short: "Set a CLI configuration profile",
Long: fmt.Sprintf("%s\n%s\n%s\n%s",
Long: fmt.Sprintf("%s\n%s\n%s\n%s\n%s",
"Set a CLI configuration profile as the active profile.",
`The profile to be used can be managed via the STACKIT_CLI_PROFILE environment variable or using the "stackit config profile set PROFILE" and "stackit config profile unset" commands.`,
"The environment variable takes precedence over what is set via the commands.",
"A new profile is created automatically if it does not exist.",
"When no profile is set, the default profile is used.",
),
Args: args.SingleArg(profileArg, nil),
Expand All @@ -43,12 +44,12 @@ func NewCmd(p *print.Printer) *cobra.Command {
return err
}

err = config.SetProfile(model.Profile)
err = config.SetProfile(p, model.Profile)
if err != nil {
return fmt.Errorf("set profile: %w", err)
}

p.Info("Profile %q set successfully as the active profile\n", model.Profile)
p.Info("Successfully set active profile to %q\n", model.Profile)
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/config/profile/unset/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
"$ stackit config profile unset"),
),
RunE: func(cmd *cobra.Command, args []string) error {
err := config.UnsetProfile()
err := config.UnsetProfile(p)
if err != nil {
return fmt.Errorf("unset profile: %w", err)
}
Expand Down
7 changes: 5 additions & 2 deletions internal/cmd/load-balancer/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func renderLoadBalancer(loadBalancer *loadbalancer.LoadBalancer) string {
}

table := tables.NewTable()
table.SetTitle("Load Balancer")
table.AddRow("NAME", *loadBalancer.Name)
table.AddSeparator()
table.AddRow("STATE", *loadBalancer.Status)
Expand All @@ -182,7 +183,8 @@ func renderLoadBalancer(loadBalancer *loadbalancer.LoadBalancer) string {

func renderListeners(listeners []loadbalancer.Listener) string {
table := tables.NewTable()
table.SetHeader("LISTENER NAME", "PORT", "PROTOCOL", "TARGET POOL")
table.SetTitle("Listeners")
table.SetHeader("NAME", "PORT", "PROTOCOL", "TARGET POOL")
for i := range listeners {
listener := listeners[i]
table.AddRow(*listener.Name, *listener.Port, *listener.Protocol, *listener.TargetPool)
Expand All @@ -192,7 +194,8 @@ func renderListeners(listeners []loadbalancer.Listener) string {

func renderTargetPools(targetPools []loadbalancer.TargetPool) string {
table := tables.NewTable()
table.SetHeader("TARGET POOL NAME", "PORT", "TARGETS")
table.SetTitle("Target Pools")
table.SetHeader("NAME", "PORT", "TARGETS")
for _, targetPool := range targetPools {
table.AddRow(*targetPool.Name, *targetPool.TargetPort, len(*targetPool.Targets))
}
Expand Down
Loading