Skip to content

Commit c1c591e

Browse files
authored
Merge pull request #376 from depot/luke/support-jit-token
feat: support JIT tokens from Depot environments
2 parents 117231a + 1b305d3 commit c1c591e

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

pkg/cmd/cargo/cargo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ func NewCmdCargo() *cobra.Command {
5353
}
5454

5555
// Get authentication token
56-
token := os.Getenv("DEPOT_CACHE_TOKEN")
57-
token, err = helpers.ResolveToken(ctx, token)
56+
token, err := helpers.ResolveToken(ctx, "")
5857
if err != nil {
5958
return fmt.Errorf("failed to resolve token: %w", err)
6059
}

pkg/cmd/gocache/gocache.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func NewCmdGoCache() *cobra.Command {
4949
return err
5050
}
5151

52-
token := os.Getenv("DEPOT_CACHE_TOKEN")
5352
token, err = helpers.ResolveToken(ctx, token)
5453
if err != nil {
5554
return err

pkg/helpers/token.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func ResolveToken(ctx context.Context, token string) (string, error) {
4040
}
4141
}
4242

43+
if token == "" {
44+
token = resolveJITToken()
45+
}
46+
4347
if token == "" && IsTerminal() {
4448
return AuthorizeDevice(ctx)
4549
}
@@ -61,3 +65,15 @@ func AuthorizeDevice(ctx context.Context) (string, error) {
6165
}
6266
return tokenResponse.Token, nil
6367
}
68+
69+
func resolveJITToken() string {
70+
if token := os.Getenv("DEPOT_JIT_TOKEN"); token != "" {
71+
return token
72+
}
73+
74+
if token := os.Getenv("DEPOT_CACHE_TOKEN"); token != "" {
75+
return token
76+
}
77+
78+
return ""
79+
}

0 commit comments

Comments
 (0)