File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -91,3 +91,10 @@ func SuccessRedirect() string {
91
91
func Audience () []string {
92
92
return []string {"https://api.jetpack.io" }
93
93
}
94
+
95
+ func DashboardHostname () string {
96
+ if IsDev {
97
+ return "http://localhost:8080"
98
+ }
99
+ return "https://cloud.jetify.com"
100
+ }
Original file line number Diff line number Diff line change 6
6
"io"
7
7
8
8
"go.jetpack.io/devbox/internal/boxcli/usererr"
9
+ "go.jetpack.io/devbox/internal/build"
9
10
"go.jetpack.io/devbox/internal/devbox/providers/identity"
10
11
"go.jetpack.io/devbox/internal/devbox/providers/nixcache"
11
12
"go.jetpack.io/devbox/internal/nix"
@@ -77,9 +78,19 @@ func getWriteCacheURI(
77
78
if err != nil {
78
79
return "" , err
79
80
}
81
+
80
82
if len (caches ) == 0 {
83
+ slug , err := identity .GetOrgSlug (ctx )
84
+ if err != nil {
85
+ return "" , err
86
+ }
81
87
return "" ,
82
- usererr .New ("You don't have permission to write to any Nix caches." )
88
+ usererr .New (
89
+ "You don't have permission to write to any Nix caches. To configure cache, go to " +
90
+ "%s/teams/%s/devbox" ,
91
+ build .DashboardHostname (),
92
+ slug ,
93
+ )
83
94
}
84
95
if len (caches ) > 1 {
85
96
ux .Fwarning (w , "Multiple caches available, using %s.\n " , caches [0 ].GetUri ())
Original file line number Diff line number Diff line change @@ -2,8 +2,11 @@ package identity
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"os"
6
7
8
+ "github.com/go-jose/go-jose/v4"
9
+ "github.com/go-jose/go-jose/v4/jwt"
7
10
"go.jetify.com/typeid"
8
11
"go.jetpack.io/devbox/internal/build"
9
12
"go.jetpack.io/pkg/api"
@@ -91,3 +94,26 @@ func getAccessTokenFromAPIToken(
91
94
92
95
return cachedAccessTokenFromAPIToken , nil
93
96
}
97
+
98
+ func GetOrgSlug (ctx context.Context ) (string , error ) {
99
+ tok , err := GenSession (ctx )
100
+ if err != nil {
101
+ return "" , err
102
+ }
103
+
104
+ if tok .IDToken == "" {
105
+ return "" , errors .New ("ID token is not present" )
106
+ }
107
+
108
+ jwt , err := jwt .ParseSigned (tok .IDToken , []jose.SignatureAlgorithm {jose .RS256 })
109
+ if err != nil {
110
+ return "" , err
111
+ }
112
+
113
+ claims := map [string ]any {}
114
+ if err = jwt .UnsafeClaimsWithoutVerification (& claims ); err != nil {
115
+ return "" , err
116
+ }
117
+
118
+ return claims ["org_trusted_metadata" ].(map [string ]any )["slug" ].(string ), nil
119
+ }
You can’t perform that action at this time.
0 commit comments