From e53b3d32943d0346c25e075d2607fec0fe3ebcbb Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Mon, 17 Apr 2023 15:27:00 +0200 Subject: [PATCH] Remove Apps and first run logic from Tenant struct (#742) --- internal/cli/cli.go | 64 +++++----------------------------------- internal/cli/test.go | 27 ++--------------- internal/display/test.go | 14 +++++++-- 3 files changed, 20 insertions(+), 85 deletions(-) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index ca8698c2c..55bba46e2 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -46,18 +46,13 @@ type config struct { // The fields are tailor fit specifically for // interacting with the management API. type Tenant struct { - Name string `json:"name"` - Domain string `json:"domain"` - AccessToken string `json:"access_token,omitempty"` - Scopes []string `json:"scopes,omitempty"` - ExpiresAt time.Time `json:"expires_at"` - Apps map[string]app `json:"apps,omitempty"` - DefaultAppID string `json:"default_app_id,omitempty"` - ClientID string `json:"client_id"` -} - -type app struct { - FirstRuns map[string]bool `json:"first_runs"` + Name string `json:"name"` + Domain string `json:"domain"` + AccessToken string `json:"access_token,omitempty"` + Scopes []string `json:"scopes,omitempty"` + ExpiresAt time.Time `json:"expires_at"` + DefaultAppID string `json:"default_app_id,omitempty"` + ClientID string `json:"client_id"` } var errUnauthenticated = errors.New("Not logged in. Try 'auth0 login'.") @@ -301,10 +296,6 @@ func (c *cli) getTenant() (Tenant, error) { return Tenant{}, fmt.Errorf("Unable to find tenant: %s; run 'auth0 tenants use' to see your configured tenants or run 'auth0 login' to configure a new tenant", c.tenant) } - if t.Apps == nil { - t.Apps = map[string]app{} - } - return t, nil } @@ -390,22 +381,6 @@ func (c *cli) removeTenant(ten string) error { return nil } -func (c *cli) isFirstCommandRun(clientID string, command string) (bool, error) { - tenant, err := c.getTenant() - - if err != nil { - return false, err - } - - if a, found := tenant.Apps[clientID]; found { - if a.FirstRuns[command] { - return false, nil - } - } - - return true, nil -} - func (c *cli) setDefaultAppID(id string) error { tenant, err := c.getTenant() if err != nil { @@ -422,31 +397,6 @@ func (c *cli) setDefaultAppID(id string) error { return nil } -func (c *cli) setFirstCommandRun(clientID string, command string) error { - tenant, err := c.getTenant() - if err != nil { - return err - } - - if a, found := tenant.Apps[clientID]; found { - if a.FirstRuns == nil { - a.FirstRuns = map[string]bool{} - } - a.FirstRuns[command] = true - tenant.Apps[clientID] = a - } else { - tenant.Apps[clientID] = app{ - FirstRuns: map[string]bool{ - command: true, - }, - } - } - - c.config.Tenants[tenant.Domain] = tenant - - return nil -} - func checkInstallID(c *cli) error { if c.config.InstallID == "" { c.config.InstallID = uuid.NewString() diff --git a/internal/cli/test.go b/internal/cli/test.go index 314ef3877..7f8c41ea6 100644 --- a/internal/cli/test.go +++ b/internal/cli/test.go @@ -152,37 +152,14 @@ func testLoginCmd(cli *cli) *cobra.Command { } var userInfo *authutil.UserInfo - if err := ansi.Spinner("Fetching user metadata", func() error { - // Use the access token to fetch user information from the /userinfo endpoint. + if err := ansi.Spinner("Fetching user metadata", func() (err error) { userInfo, err = authutil.FetchUserInfo(http.DefaultClient, tenant.Domain, tokenResponse.AccessToken) return err }); err != nil { return fmt.Errorf("failed to fetch user info: %w", err) } - cli.renderer.Newline() - cli.renderer.TestLogin(userInfo, tokenResponse) - cli.renderer.Newline() - - const commandKey = "test_login" - isFirstRun, err := cli.isFirstCommandRun(inputs.ClientID, commandKey) - if err != nil { - return err - } - - if isFirstRun { - cli.renderer.Infof("Login flow is working!") - cli.renderer.Infof( - "%s Consider downloading and running a quickstart next by running `auth0 quickstarts download %s`", - ansi.Faint("Hint:"), - inputs.ClientID, - ) - - if err := cli.setFirstCommandRun(inputs.ClientID, commandKey); err != nil { - return err - } - } - + cli.renderer.TestLogin(userInfo, tokenResponse, inputs.ClientID) return nil }, } diff --git a/internal/display/test.go b/internal/display/test.go index 315ff1457..690c21f15 100644 --- a/internal/display/test.go +++ b/internal/display/test.go @@ -15,12 +15,20 @@ type userInfoAndTokens struct { Tokens *authutil.TokenResponse `json:"tokens"` } -func (r *Renderer) TestLogin(u *authutil.UserInfo, t *authutil.TokenResponse) { - r.Heading("/userinfo") +func (r *Renderer) TestLogin(u *authutil.UserInfo, t *authutil.TokenResponse, clientID string) { + r.Heading("user metadata and token") data := &userInfoAndTokens{UserInfo: u, Tokens: t} - r.JSONResult(data) + + r.Newline() + r.Newline() + r.Infof( + "%s Login flow is working! If this is the first time you are testing the login flow for this "+ + "application, consider downloading and running a quickstart next by running %s", + ansi.Faint("Hint:"), + fmt.Sprintf("`auth0 quickstarts download %s`", clientID), + ) } func (r *Renderer) TestToken(client *management.Client, t *authutil.TokenResponse) {