Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/cmd/config/profile/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
Expand Down Expand Up @@ -49,6 +50,14 @@ func NewCmd(p *print.Printer) *cobra.Command {
return fmt.Errorf("set profile: %w", err)
}

flow, err := auth.GetAuthFlow()
if err != nil {
p.Debug(print.WarningLevel, "both keyring and text file storage failed to find a valid authentication flow for the active profile")
p.Warn("Failed to find a valid authentication flow for the active profile. Please login using the 'stackit auth login' command.\n")
} else {
p.Debug(print.InfoLevel, "found valid authentication flow for active profile: %s", auth.GetPrettyAuthFlow(flow))
}

p.Info("Successfully set active profile to %q\n", model.Profile)
return nil
},
Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/config/profile/unset/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
Expand Down Expand Up @@ -31,6 +32,14 @@ func NewCmd(p *print.Printer) *cobra.Command {
return fmt.Errorf("unset profile: %w", err)
}

flow, err := auth.GetAuthFlow()
if err != nil {
p.Debug(print.WarningLevel, "both keyring and text file storage failed to find a valid authentication flow for the active profile")
p.Warn("Failed to find a valid authentication flow for the active profile. Please login using the 'stackit auth login' command.\n")
} else {
p.Debug(print.InfoLevel, "found valid authentication flow for active profile: %s", auth.GetPrettyAuthFlow(flow))
}

p.Info("Profile unset successfully. The default profile will be used.\n")
return nil
},
Expand Down
13 changes: 13 additions & 0 deletions internal/pkg/auth/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,16 @@ func createEncodedTextFile() error {

return nil
}

func GetPrettyAuthFlow(flow AuthFlow) string {
switch flow {
case AUTH_FLOW_USER_TOKEN:
return "User Token"
case AUTH_FLOW_SERVICE_ACCOUNT_TOKEN:
return "Service Account Token"
case AUTH_FLOW_SERVICE_ACCOUNT_KEY:
return "Service Account Key"
default:
return "Unknown"
}
}