From 610dfc89bdf61dc6be5eae78949002f3991aba72 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Mon, 13 Dec 2021 14:48:10 -0500 Subject: [PATCH 1/5] Fix remote cache config detection to support just slug --- cli/internal/cache/cache.go | 2 +- cli/internal/config/config.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/internal/cache/cache.go b/cli/internal/cache/cache.go index 51df1b7e6246a..7c56dcbf80264 100644 --- a/cli/internal/cache/cache.go +++ b/cli/internal/cache/cache.go @@ -34,7 +34,7 @@ func newSyncCache(config *config.Config, remoteOnly bool) Cache { if config.Cache.Dir != "" && !remoteOnly { mplex.caches = append(mplex.caches, newFsCache(config)) } - if config.Token != "" && config.TeamId != "" { + if (config.Token != "" && config.TeamId != "") || (config.Token != "" && config.TeamSlug != "") { fmt.Println(ui.Dim("• Remote computation caching enabled (experimental)")) mplex.caches = append(mplex.caches, newHTTPCache(config)) } diff --git a/cli/internal/config/config.go b/cli/internal/config/config.go index 05617ff1d1576..6bf0de0f4fe96 100644 --- a/cli/internal/config/config.go +++ b/cli/internal/config/config.go @@ -92,7 +92,8 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, } partialConfig.Token = userConfig.Token - enverr := envconfig.Process("turbo", partialConfig) + enverr := envconfig.Process("TURBO", partialConfig) + fmt.Printf("TURBO_TEAM: %v, %v\n", partialConfig.TeamSlug, os.Getenv("TURBO_TEAM")) if enverr != nil { return nil, fmt.Errorf("invalid environment variable: %w", err) } From e2fb4f28168d1719a7b7adb17365657a0bc94cd8 Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Mon, 13 Dec 2021 14:52:06 -0500 Subject: [PATCH 2/5] Remove fmt.printf --- cli/internal/config/config.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/internal/config/config.go b/cli/internal/config/config.go index 6bf0de0f4fe96..0a1299c22e73a 100644 --- a/cli/internal/config/config.go +++ b/cli/internal/config/config.go @@ -93,7 +93,6 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, partialConfig.Token = userConfig.Token enverr := envconfig.Process("TURBO", partialConfig) - fmt.Printf("TURBO_TEAM: %v, %v\n", partialConfig.TeamSlug, os.Getenv("TURBO_TEAM")) if enverr != nil { return nil, fmt.Errorf("invalid environment variable: %w", err) } From 1204c970e3878350aeefcd97afbfcac7362f132f Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Mon, 13 Dec 2021 14:52:56 -0500 Subject: [PATCH 3/5] Remove ensureTeam (pre-acq legacy) --- cli/internal/config/config.go | 38 ----------------------------------- 1 file changed, 38 deletions(-) diff --git a/cli/internal/config/config.go b/cli/internal/config/config.go index 0a1299c22e73a..5ea911060ae17 100644 --- a/cli/internal/config/config.go +++ b/cli/internal/config/config.go @@ -113,7 +113,6 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, } } - shouldEnsureTeam := false // Process arguments looking for `-v` flags to control the log level. // This overrides whatever the env var set. var outArgs []string @@ -151,7 +150,6 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, partialConfig.Token = arg[len("--token="):] case strings.HasPrefix(arg, "--team="): partialConfig.TeamSlug = arg[len("--team="):] - shouldEnsureTeam = true default: outArgs = append(outArgs, arg) } @@ -191,45 +189,9 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, c.ApiClient.SetToken(partialConfig.Token) - if shouldEnsureTeam || partialConfig.TeamSlug != "" { - if err := c.ensureTeam(); err != nil { - return c, err - } - } - return c, nil } -func (c *Config) ensureTeam() error { - // if c.Token == "" { - // if IsCI() { - // fmt.Println(ui.Warn("no token has been provided, but you specified a Turborepo team and project. If this is intended (e.g. a pull request on an open source GitHub project from an outside contributor triggered this), you can ignore this warning. Otherwise, please run `turbo login`, pass `--token` flag, or set `TURBO_TOKEN` environment variable to enable remote caching. In the meantime, turbo will attempt to continue with local caching.")) - // return nil - // } - // return fmt.Errorf("no credentials found. Please run `turbo login`, pass `--token` flag, or set TURBO_TOKEN environment variable") - // } - // req, err := graphql.NewGetTeamRequest(c.ApiUrl, &graphql.GetTeamVariables{ - // Slug: (*graphql.String)(&c.TeamSlug), - // }) - // if err != nil { - // return fmt.Errorf("could not fetch team information: %w", err) - // } - // req.Header.Set("Authorization", "Bearer "+c.Token) - // res, resErr := req.Execute(c.GraphQLClient.Client) - // if resErr != nil { - // return fmt.Errorf("could not fetch team information: %w", resErr) - // } - - // if res.Team.ID == "" { - // return fmt.Errorf("could not fetch team information. Check the spelling of `%v` and make sure that the %v team exists on turborepo.com and that you have access to it", c.TeamSlug, c.TeamSlug) - // } - - // c.TeamId = res.Team.ID - // c.TeamSlug = res.Team.Slug - - return nil -} - // IsLogged returns true if the user is logged into turborepo.com func (c *Config) IsLoggedIn() bool { return c.Token != "" From de634943ae3fe0401ba288d0d673917886505a1a Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Mon, 13 Dec 2021 14:53:33 -0500 Subject: [PATCH 4/5] Change comment --- cli/internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/internal/config/config.go b/cli/internal/config/config.go index 5ea911060ae17..f558b82c64686 100644 --- a/cli/internal/config/config.go +++ b/cli/internal/config/config.go @@ -192,7 +192,7 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, return c, nil } -// IsLogged returns true if the user is logged into turborepo.com +// IsLogged returns true if the user is logged into a Remote Cache func (c *Config) IsLoggedIn() bool { return c.Token != "" } From a418750f46cfaf8b1ac0920163c822f2148f27aa Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Mon, 13 Dec 2021 14:53:51 -0500 Subject: [PATCH 5/5] Fix comment --- cli/internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/internal/config/config.go b/cli/internal/config/config.go index f558b82c64686..c62c6145e5886 100644 --- a/cli/internal/config/config.go +++ b/cli/internal/config/config.go @@ -192,7 +192,7 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, return c, nil } -// IsLogged returns true if the user is logged into a Remote Cache +// IsLoggedIn returns true if the user is logged into a Remote Cache func (c *Config) IsLoggedIn() bool { return c.Token != "" }