-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathlogin.go
More file actions
39 lines (34 loc) · 1.4 KB
/
login.go
File metadata and controls
39 lines (34 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package login
import (
"fmt"
"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
)
func NewCmd(p *types.CmdParams) *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Short: "Logs in for the STACKIT Terraform Provider and SDK",
Long: fmt.Sprintf("%s\n%s\n%s",
"Logs in for the STACKIT Terraform Provider and SDK using a user account.",
"The authentication is done via a web-based authorization flow, where the command will open a browser window in which you can login to your STACKIT account.",
"The credentials are stored separately from the CLI authentication and will be used by the STACKIT Terraform Provider and SDK."),
Args: args.NoArgs,
Example: examples.Build(
examples.NewExample(
`Login for the STACKIT Terraform Provider and SDK. This command will open a browser window where you can login to your STACKIT account`,
"$ stackit auth api login"),
),
RunE: func(_ *cobra.Command, _ []string) error {
err := auth.AuthorizeUser(p.Printer, auth.StorageContextAPI, false)
if err != nil {
return fmt.Errorf("authorization failed: %w", err)
}
p.Printer.Outputln("Successfully logged in for STACKIT Terraform Provider and SDK.\n")
return nil
},
}
return cmd
}