|
4 | 4 | package boxcli
|
5 | 5 |
|
6 | 6 | import (
|
| 7 | + "encoding/json" |
| 8 | + |
7 | 9 | "github.com/MakeNowJust/heredoc/v2"
|
8 | 10 | "github.com/pkg/errors"
|
9 | 11 | "github.com/spf13/cobra"
|
10 | 12 | "go.jetpack.io/devbox/internal/devbox"
|
11 | 13 | "go.jetpack.io/devbox/internal/devbox/devopt"
|
| 14 | + "go.jetpack.io/devbox/internal/devbox/providers/nixcache" |
12 | 15 | )
|
13 | 16 |
|
14 | 17 | type cacheFlags struct {
|
@@ -58,7 +61,41 @@ func cacheCmd() *cobra.Command {
|
58 | 61 | &flags.to, "to", "", "URI of the cache to copy to")
|
59 | 62 |
|
60 | 63 | cacheCommand.AddCommand(uploadCommand)
|
| 64 | + cacheCommand.AddCommand(cacheCredentialsCmd()) |
61 | 65 | cacheCommand.Hidden = true
|
62 | 66 |
|
63 | 67 | return cacheCommand
|
64 | 68 | }
|
| 69 | + |
| 70 | +func cacheCredentialsCmd() *cobra.Command { |
| 71 | + return &cobra.Command{ |
| 72 | + Use: "credentials", |
| 73 | + Short: "Output S3 cache credentials", |
| 74 | + Hidden: true, |
| 75 | + Args: cobra.ExactArgs(0), |
| 76 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 77 | + cfg, err := nixcache.Get().Config(cmd.Context()) |
| 78 | + if err != nil { |
| 79 | + return err |
| 80 | + } |
| 81 | + |
| 82 | + creds := struct { |
| 83 | + Version int `json:"Version"` |
| 84 | + AccessKeyID string `json:"AccessKeyId"` |
| 85 | + SecretAccessKey string `json:"SecretAccessKey"` |
| 86 | + SessionToken string `json:"SessionToken"` |
| 87 | + }{ |
| 88 | + Version: 1, |
| 89 | + AccessKeyID: *cfg.Credentials.AccessKeyId, |
| 90 | + SecretAccessKey: *cfg.Credentials.SecretKey, |
| 91 | + SessionToken: *cfg.Credentials.SessionToken, |
| 92 | + } |
| 93 | + out, err := json.Marshal(creds) |
| 94 | + if err != nil { |
| 95 | + return err |
| 96 | + } |
| 97 | + _, _ = cmd.OutOrStdout().Write(out) |
| 98 | + return nil |
| 99 | + }, |
| 100 | + } |
| 101 | +} |
0 commit comments