Skip to content

Commit e400797

Browse files
authored
Improvements for argus grafana commands (#230)
1 parent f7cc6ea commit e400797

File tree

4 files changed

+51
-40
lines changed

4 files changed

+51
-40
lines changed

docs/stackit_argus_grafana_describe.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,27 @@ The Grafana dashboard URL and initial credentials (admin user and password) will
99
The initial password is shown by default, if you want to hide it use the "--hide-password" flag.
1010

1111
```
12-
stackit argus grafana describe [flags]
12+
stackit argus grafana describe INSTANCE_ID [flags]
1313
```
1414

1515
### Examples
1616

1717
```
1818
Get details of the Grafana configuration of an Argus instance with ID "xxx"
19-
$ stackit argus credentials describe --instance-id xxx
19+
$ stackit argus credentials describe xxx
2020
2121
Get details of the Grafana configuration of an Argus instance with ID "xxx" in a table format
22-
$ stackit argus credentials describe --instance-id xxx --output-format pretty
22+
$ stackit argus credentials describe xxx --output-format pretty
2323
2424
Get details of the Grafana configuration of an Argus instance with ID "xxx" and hide the initial admin password
25-
$ stackit argus credentials describe --instance-id xxx --output-format pretty --hide-password
25+
$ stackit argus credentials describe xxx --output-format pretty --hide-password
2626
```
2727

2828
### Options
2929

3030
```
31-
-h, --help Help for "stackit argus grafana describe"
32-
--hide-password Show the initial admin password in the "pretty" output format
33-
--instance-id string Instance ID
31+
-h, --help Help for "stackit argus grafana describe"
32+
--hide-password Show the initial admin password in the "pretty" output format
3433
```
3534

3635
### Options inherited from parent commands

internal/cmd/argus/grafana/describe/describe.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import (
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
1515
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1617

1718
"github.com/spf13/cobra"
1819
"github.com/stackitcloud/stackit-sdk-go/services/argus"
1920
)
2021

2122
const (
22-
instanceIdFlag = "instance-id"
23+
instanceIdArg = "INSTANCE_ID"
2324
hidePasswordFlag = "hide-password"
2425
)
2526

@@ -31,28 +32,28 @@ type inputModel struct {
3132

3233
func NewCmd(p *print.Printer) *cobra.Command {
3334
cmd := &cobra.Command{
34-
Use: "describe",
35+
Use: fmt.Sprintf("describe %s", instanceIdArg),
3536
Short: "Shows details of the Grafana configuration of an Argus instance",
3637
Long: fmt.Sprintf("%s\n%s\n%s",
3738
"Shows details of the Grafana configuration of an Argus instance.",
3839
`The Grafana dashboard URL and initial credentials (admin user and password) will be shown in the "pretty" output format. These credentials are only valid for first login. Please change the password after first login. After changing, the initial password is no longer valid.`,
3940
`The initial password is shown by default, if you want to hide it use the "--hide-password" flag.`,
4041
),
41-
Args: args.NoArgs,
42+
Args: args.SingleArg(instanceIdArg, utils.ValidateUUID),
4243
Example: examples.Build(
4344
examples.NewExample(
4445
`Get details of the Grafana configuration of an Argus instance with ID "xxx"`,
45-
"$ stackit argus credentials describe --instance-id xxx"),
46+
"$ stackit argus credentials describe xxx"),
4647
examples.NewExample(
4748
`Get details of the Grafana configuration of an Argus instance with ID "xxx" in a table format`,
48-
"$ stackit argus credentials describe --instance-id xxx --output-format pretty"),
49+
"$ stackit argus credentials describe xxx --output-format pretty"),
4950
examples.NewExample(
5051
`Get details of the Grafana configuration of an Argus instance with ID "xxx" and hide the initial admin password`,
51-
"$ stackit argus credentials describe --instance-id xxx --output-format pretty --hide-password"),
52+
"$ stackit argus credentials describe xxx --output-format pretty --hide-password"),
5253
),
5354
RunE: func(cmd *cobra.Command, args []string) error {
5455
ctx := context.Background()
55-
model, err := parseInput(cmd)
56+
model, err := parseInput(cmd, args)
5657
if err != nil {
5758
return err
5859
}
@@ -82,22 +83,20 @@ func NewCmd(p *print.Printer) *cobra.Command {
8283
}
8384

8485
func configureFlags(cmd *cobra.Command) {
85-
cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID")
8686
cmd.Flags().Bool(hidePasswordFlag, false, `Show the initial admin password in the "pretty" output format`)
87-
88-
err := flags.MarkFlagsRequired(cmd, instanceIdFlag)
89-
cobra.CheckErr(err)
9087
}
9188

92-
func parseInput(cmd *cobra.Command) (*inputModel, error) {
89+
func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
90+
instanceId := inputArgs[0]
91+
9392
globalFlags := globalflags.Parse(cmd)
9493
if globalFlags.ProjectId == "" {
9594
return nil, &errors.ProjectIdError{}
9695
}
9796

9897
return &inputModel{
9998
GlobalFlagModel: globalFlags,
100-
InstanceId: flags.FlagToStringValue(cmd, instanceIdFlag),
99+
InstanceId: instanceId,
101100
HidePassword: flags.FlagToBoolValue(cmd, hidePasswordFlag),
102101
}, nil
103102
}

internal/cmd/argus/grafana/describe/describe_test.go

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@ var testClient = &argus.APIClient{}
2121
var testProjectId = uuid.NewString()
2222
var testInstanceId = uuid.NewString()
2323

24+
func fixtureArgValues(mods ...func(argValues []string)) []string {
25+
argValues := []string{
26+
testInstanceId,
27+
}
28+
for _, mod := range mods {
29+
mod(argValues)
30+
}
31+
return argValues
32+
}
33+
2434
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2535
flagValues := map[string]string{
26-
projectIdFlag: testProjectId,
27-
instanceIdFlag: testInstanceId,
36+
projectIdFlag: testProjectId,
2837
}
2938
for _, mod := range mods {
3039
mod(flagValues)
@@ -72,12 +81,20 @@ func TestParseInput(t *testing.T) {
7281
}{
7382
{
7483
description: "base",
84+
argValues: fixtureArgValues(),
7585
flagValues: fixtureFlagValues(),
7686
isValid: true,
7787
expectedModel: fixtureInputModel(),
7888
},
89+
{
90+
description: "no arg values",
91+
argValues: []string{},
92+
flagValues: fixtureFlagValues(),
93+
isValid: false,
94+
},
7995
{
8096
description: "hide password",
97+
argValues: fixtureArgValues(),
8198
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
8299
flagValues[hidePasswordFlag] = "true"
83100
}),
@@ -94,50 +111,45 @@ func TestParseInput(t *testing.T) {
94111
},
95112
{
96113
description: "no flag values",
114+
argValues: fixtureArgValues(),
97115
flagValues: map[string]string{},
98116
isValid: false,
99117
},
100118
{
101119
description: "project id missing",
120+
argValues: fixtureArgValues(),
102121
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
103122
delete(flagValues, projectIdFlag)
104123
}),
105124
isValid: false,
106125
},
107126
{
108127
description: "project id invalid 1",
128+
argValues: fixtureArgValues(),
109129
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
110130
flagValues[projectIdFlag] = ""
111131
}),
112132
isValid: false,
113133
},
114134
{
115135
description: "project id invalid 2",
136+
argValues: fixtureArgValues(),
116137
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
117138
flagValues[projectIdFlag] = "invalid-uuid"
118139
}),
119140
isValid: false,
120141
},
121-
{
122-
description: "instance id missing",
123-
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
124-
delete(flagValues, instanceIdFlag)
125-
}),
126-
isValid: false,
127-
},
128142
{
129143
description: "instance id invalid 1",
130-
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
131-
flagValues[instanceIdFlag] = ""
132-
}),
133-
isValid: false,
144+
argValues: []string{""},
145+
flagValues: fixtureFlagValues(),
146+
isValid: false,
134147
},
135148
{
136149
description: "instance id invalid 2",
137-
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
138-
flagValues[instanceIdFlag] = "invalid-uuid"
139-
}),
140-
isValid: false,
150+
argValues: []string{"invalid-uuid"},
151+
flagValues: fixtureFlagValues(),
152+
isValid: false,
141153
},
142154
{
143155
description: "credentials id invalid 1",
@@ -187,7 +199,7 @@ func TestParseInput(t *testing.T) {
187199
t.Fatalf("error validating flags: %v", err)
188200
}
189201

190-
model, err := parseInput(cmd)
202+
model, err := parseInput(cmd, tt.argValues)
191203
if err != nil {
192204
if !tt.isValid {
193205
return

internal/cmd/argus/grafana/single-sign-on/single_sign_on.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import (
1414

1515
func NewCmd(p *print.Printer) *cobra.Command {
1616
cmd := &cobra.Command{
17-
Use: "single-sign-on",
18-
Short: "Enable or disable single sign-on for Grafana in Argus instances",
17+
Use: "single-sign-on",
18+
Aliases: []string{"sso"},
19+
Short: "Enable or disable single sign-on for Grafana in Argus instances",
1920
Long: fmt.Sprintf("%s\n%s",
2021
"Enable or disable single sign-on for Grafana in Argus instances.",
2122
"When enabled for an instance, overwrites the generic OAuth2 authentication and configures STACKIT single sign-on for that instance.",

0 commit comments

Comments
 (0)