Skip to content

Commit

Permalink
fix(profile/create): support sso (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Jan 15, 2024
1 parent 680e9aa commit c01669c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ func Exec(data *global.Data) error {
displayAPIEndpoint(apiEndpoint, endpointSource, data.Output)
}

// NOTE: Some commands need just the auth server to be running.
// But not necessarily need to process an existing token.
// e.g. `profile create example_sso_user --sso`
// Which needs the auth server so it can start up an OAuth flow.
if !commandRequiresToken(commandName) && commandRequiresAuthServer(commandName) {
// NOTE: Checking for nil allows our test suite to mock the server.
// i.e. it'll be nil whenever the CLI is run by a user but not `go test`.
if data.AuthServer == nil {
authServer, err := configureAuth(apiEndpoint, data.Args, data.Config, data.HTTPClient, data.Env)
if err != nil {
return fmt.Errorf("failed to configure authentication processes: %w", err)
}
data.AuthServer = authServer
}
}

if commandRequiresToken(commandName) {
// NOTE: Checking for nil allows our test suite to mock the server.
// i.e. it'll be nil whenever the CLI is run by a user but not `go test`.
Expand Down Expand Up @@ -624,6 +640,12 @@ func commandCollectsData(command string) bool {
return false
}

// commandRequiresAuthServer determines if the command to be executed is one that
// requires just the authentication server to be running.
func commandRequiresAuthServer(command string) bool {
return command == "profile create"
}

// commandRequiresToken determines if the command to be executed is one that
// requires an API token.
func commandRequiresToken(command string) bool {
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/profile/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (c *CreateCommand) Exec(in io.Reader, out io.Writer) (err error) {
if err != nil {
return err
}
text.Break(out)
}

if c.sso {
Expand Down

0 comments on commit c01669c

Please sign in to comment.