Skip to content

Commit 2d1b914

Browse files
DiogoFerraojoaopaletGokceGKKumm-Kaistackit-pipeline
authored
Onboard Argus credentials (#251)
* Onboard Argus credentials: create command (#216) * argus credentials create command implementation * improve documentation, add test cases for hide-password * Onboard Argus credentials: delete and list commands (#222) * argus credentials delete command implementation * add documentation * update examples * argus credentials list command implementation * remove hide password flag from create * Improve info messages * improve create help * Argus Credentials: Merge main and add error level debug logs (#245) * Add `argus grafana describe` command (#221) * Add `argus grafana config describe` command * Extend command to also show dashboard URL * Generate docs * Improve command descriptions * Adjust function names * Show initial Grafana credentials in output * Add example for showing password * Change to hide-password flag * Update GitHub actions (#223) * Implemnt util for Argus grafana configuration commands (#224) * Add `argus grafana single-sign-on` commands (#228) * Add argus grafana single-sign-on enable command * Add argus grafana single-sign-on disable command * Update docs * Register disable command and update docs * Improvements after review * Add repology packaging status badge to INSTALLATION docs (#215) * Add argus grafana `public-read-access` commands (#229) * Copy files from single sign-on * Adaptations for the public-read-access commands * Update docs * Improvements after review * Move instance ID to argument * Adapt examples * Change config handling: only create config file & directory if needed (#214) * Change config handling: only create config file & directory if needed * Changes from code review * Fix config read * correctly handle f.Close error * chore(deps): update renovatebot/github-action action to v40.1.9 (#225) Co-authored-by: Renovate Bot <[email protected]> * fix(deps): update module github.com/stackitcloud/stackit-sdk-go/services/ske to v0.13.0 (#226) Co-authored-by: Renovate Bot <[email protected]> * Improvements for argus grafana commands (#230) * Add debug error logs (#217) * add error debug logs to clients * add error debug logs to refreshToken * add error debug logs to label fetching * Update internal/pkg/services/argus/client/client.go Co-authored-by: Vicente Pinto <[email protected]> * Update internal/pkg/services/argus/client/client.go Co-authored-by: Vicente Pinto <[email protected]> * add error debug logs to flag conversions * add printer to argus grafana commands * add debug log to getBearerToken function * fix debug messages on clients * Update internal/pkg/flags/flag_to_value.go Co-authored-by: Vicente Pinto <[email protected]> * remove obsolete err from the debug messages * make printer first parameter * add printer to new argus commands * Update internal/pkg/auth/user_token_flow.go Co-authored-by: Vicente Pinto <[email protected]> * Update internal/cmd/root.go Co-authored-by: Vicente Pinto <[email protected]> * fix linting problem * add string formatting to the printer debug function * set source in log handler to false --------- Co-authored-by: Vicente Pinto <[email protected]> * change order of debug and error logs (#232) * Output format none (#234) * Output format none * Add unit test, move const to print pkg * Switch usage of const * Signature (#237) * update docs for output format none addition (#239) * Add json output format (#238) * fix typo in error message * remove unused flag * add json output format for the responses * fix linting * adapt some parameters in Contribution file * change globalflags to print to use json format * Update internal/cmd/opensearch/credentials/create/create.go Co-authored-by: Vicente Pinto <[email protected]> * remove redundant error from return values of config list * shift switch case in the outputResult function --------- Co-authored-by: Vicente Pinto <[email protected]> * Update docs (#244) * Onboard Argus scrape configurations (#242) * Onboard Argus Scrape Configs: generate-payload command (#231) * Initial implementation * add utils, testing and make command work * implement function to create default create config * update help, improve testing and remove verification when job name is not provided * Improve testing * address PR comments * improve variable names * update command help * address PR comments * fix utils testing * Onboard Argus Scrape Config: create command (#233) * implement command and testing * remove TODO * address PR comments * address PR comments * Onboard Argus Scrape Config: delete command (#235) * delete command implementation and testing * improve help and log messages * update help * address PR comments * generate docs * Onboard Argus Scrape Configs: update command (#236) * delete command implementation and testing * initial implementation * finish implementation * generate docs * cleanup * remove json files * Address PR comments * generate docs * add comment about async method * Onboard Argus scrape config: list and describe commands (#240) * delete command implementation and testing * initial implementation * finish implementation * remove json files * list command implementation and testing * describe command implementation and testing * verify pointer before dereference * add config name to confirmation prompt in create cmd * generate docs * improve describe output * improve describe output * address PR comments * Merge main (#241) * Add `argus grafana describe` command (#221) * Add `argus grafana config describe` command * Extend command to also show dashboard URL * Generate docs * Improve command descriptions * Adjust function names * Show initial Grafana credentials in output * Add example for showing password * Change to hide-password flag * Update GitHub actions (#223) * Implemnt util for Argus grafana configuration commands (#224) * Add `argus grafana single-sign-on` commands (#228) * Add argus grafana single-sign-on enable command * Add argus grafana single-sign-on disable command * Update docs * Register disable command and update docs * Improvements after review * Add repology packaging status badge to INSTALLATION docs (#215) * Add argus grafana `public-read-access` commands (#229) * Copy files from single sign-on * Adaptations for the public-read-access commands * Update docs * Improvements after review * Move instance ID to argument * Adapt examples * Change config handling: only create config file & directory if needed (#214) * Change config handling: only create config file & directory if needed * Changes from code review * Fix config read * correctly handle f.Close error * chore(deps): update renovatebot/github-action action to v40.1.9 (#225) Co-authored-by: Renovate Bot <[email protected]> * fix(deps): update module github.com/stackitcloud/stackit-sdk-go/services/ske to v0.13.0 (#226) Co-authored-by: Renovate Bot <[email protected]> * Improvements for argus grafana commands (#230) * Add debug error logs (#217) * add error debug logs to clients * add error debug logs to refreshToken * add error debug logs to label fetching * Update internal/pkg/services/argus/client/client.go Co-authored-by: Vicente Pinto <[email protected]> * Update internal/pkg/services/argus/client/client.go Co-authored-by: Vicente Pinto <[email protected]> * add error debug logs to flag conversions * add printer to argus grafana commands * add debug log to getBearerToken function * fix debug messages on clients * Update internal/pkg/flags/flag_to_value.go Co-authored-by: Vicente Pinto <[email protected]> * remove obsolete err from the debug messages * make printer first parameter * add printer to new argus commands * Update internal/pkg/auth/user_token_flow.go Co-authored-by: Vicente Pinto <[email protected]> * Update internal/cmd/root.go Co-authored-by: Vicente Pinto <[email protected]> * fix linting problem * add string formatting to the printer debug function * set source in log handler to false --------- Co-authored-by: Vicente Pinto <[email protected]> * change order of debug and error logs (#232) * Output format none (#234) * Output format none * Add unit test, move const to print pkg * Switch usage of const * Signature (#237) * update docs for output format none addition (#239) * merge main * add error level debug logs to scrape config commands --------- Co-authored-by: João Palet <[email protected]> Co-authored-by: GokceGK <[email protected]> Co-authored-by: Kumm-Kai <[email protected]> Co-authored-by: stackit-pipeline <[email protected]> Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Vicente Pinto <[email protected]> * fix seg fault on create with no payload (#243) --------- Co-authored-by: João Palet <[email protected]> Co-authored-by: GokceGK <[email protected]> Co-authored-by: Kumm-Kai <[email protected]> Co-authored-by: stackit-pipeline <[email protected]> Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Vicente Pinto <[email protected]> * Add error level debug logs to commands --------- Co-authored-by: João Palet <[email protected]> Co-authored-by: GokceGK <[email protected]> Co-authored-by: Kumm-Kai <[email protected]> Co-authored-by: stackit-pipeline <[email protected]> Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Vicente Pinto <[email protected]> --------- Co-authored-by: João Palet <[email protected]> Co-authored-by: GokceGK <[email protected]> Co-authored-by: Kumm-Kai <[email protected]> Co-authored-by: stackit-pipeline <[email protected]> Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Vicente Pinto <[email protected]>
1 parent 7e4b958 commit 2d1b914

13 files changed

+1207
-0
lines changed

docs/stackit_argus.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ stackit argus [flags]
2929
### SEE ALSO
3030

3131
* [stackit](./stackit.md) - Manage STACKIT resources using the command line
32+
* [stackit argus credentials](./stackit_argus_credentials.md) - Provides functionality for Argus credentials
3233
* [stackit argus grafana](./stackit_argus_grafana.md) - Provides functionality for the Grafana configuration of Argus instances
3334
* [stackit argus instance](./stackit_argus_instance.md) - Provides functionality for Argus instances
3435
* [stackit argus plans](./stackit_argus_plans.md) - Lists all Argus service plans

docs/stackit_argus_credentials.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## stackit argus credentials
2+
3+
Provides functionality for Argus credentials
4+
5+
### Synopsis
6+
7+
Provides functionality for Argus credentials.
8+
9+
```
10+
stackit argus credentials [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help Help for "stackit argus credentials"
17+
```
18+
19+
### Options inherited from parent commands
20+
21+
```
22+
-y, --assume-yes If set, skips all confirmation prompts
23+
--async If set, runs the command asynchronously
24+
-o, --output-format string Output format, one of ["json" "pretty" "none"]
25+
-p, --project-id string Project ID
26+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
27+
```
28+
29+
### SEE ALSO
30+
31+
* [stackit argus](./stackit_argus.md) - Provides functionality for Argus
32+
* [stackit argus credentials create](./stackit_argus_credentials_create.md) - Creates credentials for an Argus instance.
33+
* [stackit argus credentials delete](./stackit_argus_credentials_delete.md) - Deletes credentials of an Argus instance
34+
* [stackit argus credentials list](./stackit_argus_credentials_list.md) - Lists the usernames of all credentials for an Argus instance
35+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## stackit argus credentials create
2+
3+
Creates credentials for an Argus instance.
4+
5+
### Synopsis
6+
7+
Creates credentials (username and password) for an Argus instance.
8+
The credentials will be generated and included in the response. You won't be able to retrieve the password later.
9+
10+
```
11+
stackit argus credentials create [flags]
12+
```
13+
14+
### Examples
15+
16+
```
17+
Create credentials for Argus instance with ID "xxx"
18+
$ stackit argus credentials create --instance-id xxx
19+
```
20+
21+
### Options
22+
23+
```
24+
-h, --help Help for "stackit argus credentials create"
25+
--instance-id string Instance ID
26+
```
27+
28+
### Options inherited from parent commands
29+
30+
```
31+
-y, --assume-yes If set, skips all confirmation prompts
32+
--async If set, runs the command asynchronously
33+
-o, --output-format string Output format, one of ["json" "pretty" "none"]
34+
-p, --project-id string Project ID
35+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
36+
```
37+
38+
### SEE ALSO
39+
40+
* [stackit argus credentials](./stackit_argus_credentials.md) - Provides functionality for Argus credentials
41+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit argus credentials delete
2+
3+
Deletes credentials of an Argus instance
4+
5+
### Synopsis
6+
7+
Deletes credentials of an Argus instance.
8+
9+
```
10+
stackit argus credentials delete USERNAME [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Delete credentials of username "xxx" for Argus instance with ID "yyy"
17+
$ stackit argus credentials delete xxx --instance-id yyy
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit argus credentials delete"
24+
--instance-id string Instance ID
25+
```
26+
27+
### Options inherited from parent commands
28+
29+
```
30+
-y, --assume-yes If set, skips all confirmation prompts
31+
--async If set, runs the command asynchronously
32+
-o, --output-format string Output format, one of ["json" "pretty" "none"]
33+
-p, --project-id string Project ID
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit argus credentials](./stackit_argus_credentials.md) - Provides functionality for Argus credentials
40+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## stackit argus credentials list
2+
3+
Lists the usernames of all credentials for an Argus instance
4+
5+
### Synopsis
6+
7+
Lists the usernames of all credentials for an Argus instance.
8+
9+
```
10+
stackit argus credentials list [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List the usernames of all credentials for an Argus instance with ID "xxx"
17+
$ stackit argus credentials list --instance-id xxx
18+
19+
List the usernames of all credentials for an Argus instance in JSON format
20+
$ stackit argus credentials list --instance-id xxx --output-format json
21+
22+
List the usernames of up to 10 credentials for an Argus instance
23+
$ stackit argus credentials list --instance-id xxx --limit 10
24+
```
25+
26+
### Options
27+
28+
```
29+
-h, --help Help for "stackit argus credentials list"
30+
--instance-id string Instance ID
31+
--limit int Maximum number of entries to list
32+
```
33+
34+
### Options inherited from parent commands
35+
36+
```
37+
-y, --assume-yes If set, skips all confirmation prompts
38+
--async If set, runs the command asynchronously
39+
-o, --output-format string Output format, one of ["json" "pretty" "none"]
40+
-p, --project-id string Project ID
41+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
42+
```
43+
44+
### SEE ALSO
45+
46+
* [stackit argus credentials](./stackit_argus_credentials.md) - Provides functionality for Argus credentials
47+

internal/cmd/argus/argus.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package argus
22

33
import (
4+
"github.com/stackitcloud/stackit-cli/internal/cmd/argus/credentials"
45
"github.com/stackitcloud/stackit-cli/internal/cmd/argus/grafana"
56
"github.com/stackitcloud/stackit-cli/internal/cmd/argus/instance"
67
"github.com/stackitcloud/stackit-cli/internal/cmd/argus/plans"
@@ -27,6 +28,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
2728
func addSubcommands(cmd *cobra.Command, p *print.Printer) {
2829
cmd.AddCommand(grafana.NewCmd(p))
2930
cmd.AddCommand(instance.NewCmd(p))
31+
cmd.AddCommand(credentials.NewCmd(p))
3032
cmd.AddCommand(scrapeconfig.NewCmd(p))
3133
cmd.AddCommand(plans.NewCmd(p))
3234
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package create
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
8+
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
14+
argusUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/utils"
15+
16+
"github.com/spf13/cobra"
17+
"github.com/stackitcloud/stackit-sdk-go/services/argus"
18+
)
19+
20+
const (
21+
instanceIdFlag = "instance-id"
22+
)
23+
24+
type inputModel struct {
25+
*globalflags.GlobalFlagModel
26+
27+
InstanceId string
28+
}
29+
30+
func NewCmd(p *print.Printer) *cobra.Command {
31+
cmd := &cobra.Command{
32+
Use: "create",
33+
Short: "Creates credentials for an Argus instance.",
34+
Long: fmt.Sprintf("%s\n%s",
35+
"Creates credentials (username and password) for an Argus instance.",
36+
"The credentials will be generated and included in the response. You won't be able to retrieve the password later."),
37+
Args: args.NoArgs,
38+
Example: examples.Build(
39+
examples.NewExample(
40+
`Create credentials for Argus instance with ID "xxx"`,
41+
"$ stackit argus credentials create --instance-id xxx"),
42+
),
43+
RunE: func(cmd *cobra.Command, args []string) error {
44+
ctx := context.Background()
45+
model, err := parseInput(p, cmd)
46+
if err != nil {
47+
return err
48+
}
49+
50+
// Configure API client
51+
apiClient, err := client.ConfigureClient(p)
52+
if err != nil {
53+
return err
54+
}
55+
56+
instanceLabel, err := argusUtils.GetInstanceName(ctx, apiClient, model.InstanceId, model.ProjectId)
57+
if err != nil {
58+
p.Debug(print.ErrorLevel, "get instance name: %v", err)
59+
instanceLabel = model.InstanceId
60+
}
61+
62+
if !model.AssumeYes {
63+
prompt := fmt.Sprintf("Are you sure you want to create credentials for instance %q?", instanceLabel)
64+
err = p.PromptForConfirmation(prompt)
65+
if err != nil {
66+
return err
67+
}
68+
}
69+
70+
// Call API
71+
req := buildRequest(ctx, model, apiClient)
72+
if err != nil {
73+
return err
74+
}
75+
resp, err := req.Execute()
76+
if err != nil {
77+
return fmt.Errorf("create credentials for Argus instance: %w", err)
78+
}
79+
80+
p.Outputf("Created credentials for instance %q.\n\n", instanceLabel)
81+
// The username field cannot be set by the user so we only display it if it's not returned empty
82+
username := *resp.Credentials.Username
83+
if username != "" {
84+
p.Outputf("Username: %s\n", username)
85+
}
86+
87+
p.Outputf("Password: %s\n", *resp.Credentials.Password)
88+
return nil
89+
},
90+
}
91+
configureFlags(cmd)
92+
return cmd
93+
}
94+
95+
func configureFlags(cmd *cobra.Command) {
96+
cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID")
97+
98+
err := flags.MarkFlagsRequired(cmd, instanceIdFlag)
99+
cobra.CheckErr(err)
100+
}
101+
102+
func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
103+
globalFlags := globalflags.Parse(p, cmd)
104+
if globalFlags.ProjectId == "" {
105+
return nil, &cliErr.ProjectIdError{}
106+
}
107+
108+
return &inputModel{
109+
GlobalFlagModel: globalFlags,
110+
InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag),
111+
}, nil
112+
}
113+
114+
func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APIClient) argus.ApiCreateCredentialsRequest {
115+
req := apiClient.CreateCredentials(ctx, model.InstanceId, model.ProjectId)
116+
return req
117+
}

0 commit comments

Comments
 (0)