Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v24.3.x] [UX-33] rpk: migrate login + profile creation flow to the Public API. #24995

Open
wants to merge 3 commits into
base: v24.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion src/go/rpk/pkg/cli/cloud/byoc/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func loginAndEnsurePluginVersion(ctx context.Context, fs afero.Fs, cfg *config.C
token = overrides.CloudToken
} else {
priorProfile := cfg.ActualProfile()
_, authVir, clearedProfile, _, err := oauth.LoadFlow(ctx, fs, cfg, auth0.NewClient(cfg.DevOverrides()), false, false, cfg.DevOverrides().CloudAPIURL)
_, authVir, clearedProfile, _, err := oauth.LoadFlow(ctx, fs, cfg, auth0.NewClient(cfg.DevOverrides()), false, false)
if err != nil {
return "", "", false, fmt.Errorf("unable to load the cloud token: %w. You may need to logout with 'rpk cloud logout --clear-credentials' and try again", err)
}
Expand Down Expand Up @@ -107,6 +107,8 @@ func loginAndEnsurePluginVersion(ctx context.Context, fs afero.Fs, cfg *config.C
return "", "", false, fmt.Errorf("unable to get latest installpack: %v", err)
}
} else {
// We can't use the PublicAPI client here as the Public API response
// does not include the Cluster's installpack version.
cluster, err := cl.Cluster(ctx, redpandaID)
if err != nil {
return "", "", false, fmt.Errorf("unable to request cluster details for %q: %w", redpandaID, err)
Expand Down
2 changes: 1 addition & 1 deletion src/go/rpk/pkg/cli/cloud/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ token and client ID is always synced.
out.MaybeDie(err, "rpk unable to load config: %v", err)

p := yAct.Profile(yAct.CurrentProfile)
authAct, authVir, clearedProfile, _, err := oauth.LoadFlow(cmd.Context(), fs, cfg, auth0.NewClient(cfg.DevOverrides()), noBrowser, true, cfg.DevOverrides().CloudAPIURL)
authAct, authVir, clearedProfile, _, err := oauth.LoadFlow(cmd.Context(), fs, cfg, auth0.NewClient(cfg.DevOverrides()), noBrowser, true)
if err != nil {
fmt.Printf("Unable to login to Redpanda Cloud (%v).\n", err)
if e := (*oauth.BadClientTokenError)(nil); errors.As(err, &e) && authVir != nil && authVir.HasClientCredentials() {
Expand Down
5 changes: 2 additions & 3 deletions src/go/rpk/pkg/cli/cloud/resourcegroup/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ func createCommand(fs afero.Fs, p *config.Params) *cobra.Command {
cfg, err := p.Load(fs)
out.MaybeDie(err, "rpk unable to load config: %v", err)
priorProfile := cfg.ActualProfile()
_, authVir, clearedProfile, _, err := oauth.LoadFlow(cmd.Context(), fs, cfg, auth0.NewClient(cfg.DevOverrides()), false, false, cfg.DevOverrides().CloudAPIURL)
_, authVir, clearedProfile, _, err := oauth.LoadFlow(cmd.Context(), fs, cfg, auth0.NewClient(cfg.DevOverrides()), false, false)
out.MaybeDie(err, "unable to authenticate with Redpanda Cloud: %v", err)
oauth.MaybePrintSwapMessage(clearedProfile, priorProfile, authVir)
authToken := authVir.AuthToken
cl, err := publicapi.NewControlPlaneClientSet(cfg.DevOverrides().PublicAPIURL, authToken)
out.MaybeDie(err, "unable to create the public api client: %v", err)
cl := publicapi.NewCloudClientSet(cfg.DevOverrides().PublicAPIURL, authToken)

var (
res []createResponse
Expand Down
6 changes: 2 additions & 4 deletions src/go/rpk/pkg/cli/cloud/resourcegroup/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ func deleteCommand(fs afero.Fs, p *config.Params) *cobra.Command {
cfg, err := p.Load(fs)
out.MaybeDie(err, "rpk unable to load config: %v", err)
priorProfile := cfg.ActualProfile()
_, authVir, clearedProfile, _, err := oauth.LoadFlow(cmd.Context(), fs, cfg, auth0.NewClient(cfg.DevOverrides()), false, false, cfg.DevOverrides().CloudAPIURL)
_, authVir, clearedProfile, _, err := oauth.LoadFlow(cmd.Context(), fs, cfg, auth0.NewClient(cfg.DevOverrides()), false, false)
out.MaybeDie(err, "unable to authenticate with Redpanda Cloud: %v", err)

oauth.MaybePrintSwapMessage(clearedProfile, priorProfile, authVir)
authToken := authVir.AuthToken

cl, err := publicapi.NewControlPlaneClientSet(cfg.DevOverrides().PublicAPIURL, authToken)
out.MaybeDie(err, "unable to create the public api client: %v", err)

cl := publicapi.NewCloudClientSet(cfg.DevOverrides().PublicAPIURL, authToken)
name := args[0]
listed, err := cl.ResourceGroup.ListResourceGroups(cmd.Context(), connect.NewRequest(&controlplanev1beta2.ListResourceGroupsRequest{
Filter: &controlplanev1beta2.ListResourceGroupsRequest_Filter{Name: name},
Expand Down
8 changes: 3 additions & 5 deletions src/go/rpk/pkg/cli/cloud/resourcegroup/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ func listCommand(fs afero.Fs, p *config.Params) *cobra.Command {
cfg, err := p.Load(fs)
out.MaybeDie(err, "rpk unable to load config: %v", err)
priorProfile := cfg.ActualProfile()
_, authVir, clearedProfile, _, err := oauth.LoadFlow(cmd.Context(), fs, cfg, auth0.NewClient(cfg.DevOverrides()), false, false, cfg.DevOverrides().CloudAPIURL)
_, authVir, clearedProfile, _, err := oauth.LoadFlow(cmd.Context(), fs, cfg, auth0.NewClient(cfg.DevOverrides()), false, false)
out.MaybeDie(err, "unable to authenticate with Redpanda Cloud: %v", err)

oauth.MaybePrintSwapMessage(clearedProfile, priorProfile, authVir)
authToken := authVir.AuthToken
cl, err := publicapi.NewControlPlaneClientSet(cfg.DevOverrides().PublicAPIURL, authToken)

out.MaybeDie(err, "unable to create the public api client: %v", err)
cl := publicapi.NewCloudClientSet(cfg.DevOverrides().PublicAPIURL, authToken)

resourceGroups, err := listAllResourceGroups(cmd.Context(), cl)
out.MaybeDie(err, "unable to list resource groups: %v", err)
Expand All @@ -73,7 +71,7 @@ func listCommand(fs afero.Fs, p *config.Params) *cobra.Command {

// listAllResourceGroups uses the pagination feature to traverse all pages of the
// list request and return all resource groups.
func listAllResourceGroups(ctx context.Context, cl *publicapi.ControlPlaneClientSet) ([]listResponse, error) {
func listAllResourceGroups(ctx context.Context, cl *publicapi.CloudClientSet) ([]listResponse, error) {
var (
pageToken string
listed []*controlplanev1beta2.ResourceGroup
Expand Down
13 changes: 9 additions & 4 deletions src/go/rpk/pkg/cli/profile/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ go_library(
deps = [
"//src/go/rpk/pkg/adminapi",
"//src/go/rpk/pkg/cli/container/common",
"//src/go/rpk/pkg/cloudapi",
"//src/go/rpk/pkg/config",
"//src/go/rpk/pkg/httpapi",
"//src/go/rpk/pkg/oauth",
"//src/go/rpk/pkg/oauth/providers/auth0",
"//src/go/rpk/pkg/os",
Expand All @@ -44,7 +42,14 @@ go_library(
go_test(
name = "profile_test",
size = "small",
srcs = ["prompt_test.go"],
srcs = [
"create_test.go",
"prompt_test.go",
],
embed = [":profile"],
deps = ["@com_github_fatih_color//:color"],
deps = [
"@build_buf_gen_go_redpandadata_cloud_protocolbuffers_go//redpanda/api/controlplane/v1beta2",
"@com_github_fatih_color//:color",
"@com_github_stretchr_testify//require",
],
)
Loading