-
Notifications
You must be signed in to change notification settings - Fork 32
Add argus grafana describe command
#221
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
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fb69919
Add `argus grafana config describe` command
7e275f2
Extend command to also show dashboard URL
3c1fa25
Generate docs
f409125
Improve command descriptions
33aa1fc
Adjust function names
11f3e2c
Show initial Grafana credentials in output
8f21948
Add example for showing password
92e5f10
Change to hide-password flag
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| ## stackit argus grafana | ||
|
|
||
| Provides functionality for the Grafana configuration of Argus instances | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Provides functionality for the Grafana configuration of Argus instances. | ||
|
|
||
| ``` | ||
| stackit argus grafana [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit argus grafana" | ||
| ``` | ||
|
|
||
| ### 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 | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit argus](./stackit_argus.md) - Provides functionality for Argus | ||
| * [stackit argus grafana describe](./stackit_argus_grafana_describe.md) - Shows details of the Grafana configuration of an Argus instance | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ## stackit argus grafana describe | ||
|
|
||
| Shows details of the Grafana configuration of an Argus instance | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Shows details of the Grafana configuration of an Argus instance. | ||
|
|
||
| ``` | ||
| stackit argus grafana describe [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| Get details of the Grafana configuration of an Argus instance with ID "xxx" | ||
| $ stackit argus credentials describe --instance-id xxx | ||
|
|
||
| Get details of of the Grafana configuration of an Argus instance with ID "xxx" in a table format | ||
| $ stackit argus credentials describe --instance-id xxx --output-format pretty | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit argus grafana describe" | ||
| --instance-id string Instance ID | ||
| ``` | ||
|
|
||
| ### 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 | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit argus grafana](./stackit_argus_grafana.md) - Provides functionality for the Grafana configuration of Argus instances | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package describe | ||
|
|
||
| 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/print" | ||
| "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 ( | ||
| instanceIdFlag = "instance-id" | ||
| ) | ||
|
|
||
| type inputModel struct { | ||
| *globalflags.GlobalFlagModel | ||
| InstanceId string | ||
| } | ||
|
|
||
| func NewCmd(p *print.Printer) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "describe", | ||
| Short: "Shows details of the Grafana configuration of an Argus instance", | ||
| Long: "Shows details of the Grafana configuration of an Argus instance.", | ||
| Args: args.NoArgs, | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `Get details of the Grafana configuration of an Argus instance with ID "xxx"`, | ||
| "$ stackit argus credentials describe --instance-id xxx"), | ||
| examples.NewExample( | ||
| `Get details of of the Grafana configuration of an Argus instance with ID "xxx" in a table format`, | ||
| "$ stackit argus credentials describe --instance-id xxx --output-format pretty"), | ||
| ), | ||
| 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(p) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Call API | ||
| grafanaConfigsReq := buildGrafanaConfigRequest(ctx, model, apiClient) | ||
| grafanaConfigsResp, err := grafanaConfigsReq.Execute() | ||
| if err != nil { | ||
| return fmt.Errorf("get Grafana configs: %w", err) | ||
| } | ||
| instanceReq := buildInstanceRequest(ctx, model, apiClient) | ||
| instanceResp, err := instanceReq.Execute() | ||
| if err != nil { | ||
| return fmt.Errorf("get instance: %w", err) | ||
| } | ||
|
|
||
| return outputResult(p, model.OutputFormat, grafanaConfigsResp, instanceResp) | ||
| }, | ||
| } | ||
| configureFlags(cmd) | ||
| return cmd | ||
| } | ||
|
|
||
| func configureFlags(cmd *cobra.Command) { | ||
| cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") | ||
|
|
||
| err := flags.MarkFlagsRequired(cmd, instanceIdFlag) | ||
| cobra.CheckErr(err) | ||
| } | ||
|
|
||
| func parseInput(cmd *cobra.Command) (*inputModel, error) { | ||
| globalFlags := globalflags.Parse(cmd) | ||
| if globalFlags.ProjectId == "" { | ||
| return nil, &errors.ProjectIdError{} | ||
| } | ||
|
|
||
| return &inputModel{ | ||
| GlobalFlagModel: globalFlags, | ||
| InstanceId: flags.FlagToStringValue(cmd, instanceIdFlag), | ||
| }, nil | ||
| } | ||
|
|
||
| func buildGrafanaConfigRequest(ctx context.Context, model *inputModel, apiClient *argus.APIClient) argus.ApiGetGrafanaConfigsRequest { | ||
| req := apiClient.GetGrafanaConfigs(ctx, model.InstanceId, model.ProjectId) | ||
| return req | ||
| } | ||
|
|
||
| func buildInstanceRequest(ctx context.Context, model *inputModel, apiClient *argus.APIClient) argus.ApiGetInstanceRequest { | ||
joaopalet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| req := apiClient.GetInstance(ctx, model.InstanceId, model.ProjectId) | ||
| return req | ||
| } | ||
|
|
||
| func outputResult(p *print.Printer, outputFormat string, grafanaConfigs *argus.GrafanaConfigs, instance *argus.GetInstanceResponse) error { | ||
| switch outputFormat { | ||
| case globalflags.PrettyOutputFormat: | ||
|
|
||
| table := tables.NewTable() | ||
| table.AddRow("GRAFANA DASHBOARD", *instance.Instance.GrafanaUrl) | ||
| table.AddSeparator() | ||
| table.AddRow("PUBLIC READ ACCESS", *grafanaConfigs.PublicReadAccess) | ||
| table.AddSeparator() | ||
| table.AddRow("SINGLE SIGN-ON", *grafanaConfigs.UseStackitSso) | ||
DiogoFerrao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| err := table.Display(p) | ||
| if err != nil { | ||
| return fmt.Errorf("render table: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| default: | ||
| details, err := json.MarshalIndent(grafanaConfigs, "", " ") | ||
| if err != nil { | ||
| return fmt.Errorf("marshal Grafana configs: %w", err) | ||
| } | ||
| p.Outputln(string(details)) | ||
|
|
||
| return nil | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.