Skip to content

Commit e2705a5

Browse files
Merge branch 'main' into dependabot/go_modules/github.com/stackitcloud/stackit-sdk-go/services/serviceaccount-0.21.1
2 parents 216d578 + 538e0ac commit e2705a5

5 files changed

Lines changed: 39 additions & 18 deletions

File tree

‎docs/stackit_auth_login.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ stackit auth login [flags]
2121
### Options
2222

2323
```
24-
-h, --help Help for "stackit auth login"
25-
--port int The port on which the callback server will listen to. By default, it tries to bind a port between 8000 and 8020.
26-
When a value is specified, it will only try to use the specified port. Valid values are within the range of 8000 to 8020.
24+
-h, --help Help for "stackit auth login"
25+
--no-browser-open If set, does not open the browser automatically but only prints the URL to the terminal
26+
--port int The port on which the callback server will listen to. By default, it tries to bind a port between 8000 and 8020.
27+
When a value is specified, it will only try to use the specified port. Valid values are within the range of 8000 to 8020.
2728
```
2829

2930
### Options inherited from parent commands

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/stackitcloud/stackit-sdk-go/services/dns v0.25.0
2525
github.com/stackitcloud/stackit-sdk-go/services/edge v0.13.2
2626
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.1
27-
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.0
27+
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.1
2828
github.com/stackitcloud/stackit-sdk-go/services/intake v0.12.0
2929
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.2
3030
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.13.0

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ github.com/stackitcloud/stackit-sdk-go/services/edge v0.13.2 h1:UDkXmgOAlP3y/u7F
626626
github.com/stackitcloud/stackit-sdk-go/services/edge v0.13.2/go.mod h1:hlUcPvOgH/CzZqH7u4SwV81qiismCVAtvw5pTAf6si4=
627627
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.1 h1:7R5peSRer3Y83mfB6wcdCP0vhEjsq4myUdVhl24q6to=
628628
github.com/stackitcloud/stackit-sdk-go/services/git v0.14.1/go.mod h1:kz2pl17t9MNQx0+fNXg10ZAVfjmvOtsHB7VlAzu/Io8=
629-
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.0 h1:DZEd4ORWEAu3/t92xLD7ah5gCshP+n5mOYxdOzdiZLc=
630-
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.0/go.mod h1:o6Mt/ZUB/3qvIwtu4B57m9IlyaUxAFS2Tu5XImiZxCE=
629+
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.1 h1:5D0ABveu3SZyB7DBkVJcCSS4fr1TiMmfdJA98TgDn/o=
630+
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.15.1/go.mod h1:o6Mt/ZUB/3qvIwtu4B57m9IlyaUxAFS2Tu5XImiZxCE=
631631
github.com/stackitcloud/stackit-sdk-go/services/intake v0.12.0 h1:1RDIGabA3U/kWrV0vkbkTof075liEHMdn39BsNwDI4k=
632632
github.com/stackitcloud/stackit-sdk-go/services/intake v0.12.0/go.mod h1:+v3VG6bXopAB2/uRz5yDXNFUwMSw0qJVRPxb3SDsACM=
633633
github.com/stackitcloud/stackit-sdk-go/services/kms v1.14.0 h1:6vZhGEIEqXUcs6pzpVNsHRAcskAVuKRq9lNMCMlYn+Q=

‎internal/cmd/auth/login/login.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import (
1414
)
1515

1616
const (
17-
portFlag = "port"
17+
portFlag = "port"
18+
noBrowserOpenFlag = "no-browser-open"
1819
)
1920

2021
type inputModel struct {
21-
Port *int
22+
Port *int
23+
NoBrowserOpen bool
2224
}
2325

2426
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -43,6 +45,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
4345
err = auth.AuthorizeUser(params.Printer, auth.UserAuthConfig{
4446
IsReauthentication: false,
4547
Port: model.Port,
48+
NoBrowserOpen: model.NoBrowserOpen,
4649
})
4750
if err != nil {
4851
return fmt.Errorf("authorization failed: %w", err)
@@ -62,6 +65,9 @@ func configureFlags(cmd *cobra.Command) {
6265
"The port on which the callback server will listen to. By default, it tries to bind a port between 8000 and 8020.\n"+
6366
"When a value is specified, it will only try to use the specified port. Valid values are within the range of 8000 to 8020.",
6467
)
68+
cmd.Flags().Bool(noBrowserOpenFlag, false,
69+
"If set, does not open the browser automatically but only prints the URL to the terminal",
70+
)
6571
}
6672

6773
func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
@@ -71,8 +77,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
7177
return nil, fmt.Errorf("port must be between 8000 and 8020")
7278
}
7379

80+
noBrowserOpen := flags.FlagToBoolValue(p, cmd, noBrowserOpenFlag)
81+
7482
model := inputModel{
75-
Port: port,
83+
Port: port,
84+
NoBrowserOpen: noBrowserOpen,
7685
}
7786

7887
p.DebugInputModel(model)

‎internal/pkg/auth/user_login.go‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type UserAuthConfig struct {
5151
IsReauthentication bool
5252
// Port defines which port should be used for the UserAuthFlow callback
5353
Port *int
54+
// NoBrowserOpen stops the browser from opening automatically during the login flow
55+
NoBrowserOpen bool
5456
}
5557

5658
type apiClient interface {
@@ -250,19 +252,28 @@ func AuthorizeUser(p *print.Printer, authConfig UserAuthConfig) error {
250252
}
251253
})
252254

253-
p.Debug(print.DebugLevel, "opening browser for authentication: %s", authorizationURL)
254255
p.Debug(print.DebugLevel, "using authentication server on %s", idpWellKnownConfig.Issuer)
255256
p.Debug(print.DebugLevel, "using client ID %s for authentication ", idpClientID)
256257

257-
// Open a browser window to the authorizationURL
258-
err = openBrowser(authorizationURL)
259-
if err != nil {
260-
return fmt.Errorf("open browser to URL %s: %w", authorizationURL, err)
261-
}
258+
if authConfig.NoBrowserOpen {
259+
p.Debug(print.DebugLevel, "skipping browser opening since the commandline flag was passed")
262260

263-
// Print the link
264-
p.Info("Your browser has been opened to visit:\n\n")
265-
p.Info("%s\n\n", authorizationURL)
261+
// Print the link in terminal
262+
p.Noticeln("Open the following URL in your browser:\n")
263+
p.Outputf("%s\n\n", authorizationURL)
264+
} else {
265+
p.Debug(print.DebugLevel, "opening browser for authentication: %s", authorizationURL)
266+
267+
// Open a browser window to the authorizationURL
268+
err = openBrowser(authorizationURL)
269+
if err != nil {
270+
return fmt.Errorf("open browser to URL %s: %w", authorizationURL, err)
271+
}
272+
273+
// Print the link
274+
p.Info("Your browser has been opened to visit:\n\n")
275+
p.Info("%s\n\n", authorizationURL)
276+
}
266277

267278
// Start the blocking web server loop
268279
// It will exit when the handlers get fired and call server.Close()

0 commit comments

Comments
 (0)