5
5
package main
6
6
7
7
import (
8
+ "bytes"
8
9
"context"
9
10
"errors"
10
11
"io"
36
37
Version = ""
37
38
)
38
39
39
- const Code = "/ide/bin/gitpod-code"
40
+ const (
41
+ Code = "/ide/bin/gitpod-code"
42
+ ProductJsonLocation = "/ide/product.json"
43
+ )
40
44
41
45
func main () {
42
46
enableDebug := os .Getenv ("SUPERVISOR_DEBUG_ENABLE" ) == "true"
@@ -45,6 +49,10 @@ func main() {
45
49
log .Info ("codehelper started" )
46
50
startTime := time .Now ()
47
51
52
+ if err := replaceOpenVSXUrl (); err != nil {
53
+ log .WithError (err ).Error ("failed to replace OpenVSX URL" )
54
+ }
55
+
48
56
phaseDone := phaseLogging ("ResolveWsInfo" )
49
57
wsInfo , err := resolveWorkspaceInfo (context .Background ())
50
58
if err != nil || wsInfo == nil {
@@ -258,3 +266,22 @@ func phaseLogging(phase string) context.CancelFunc {
258
266
}()
259
267
return cancel
260
268
}
269
+
270
+ func replaceOpenVSXUrl () error {
271
+ phase := phaseLogging ("ReplaceOpenVSXUrl" )
272
+ defer phase ()
273
+ b , err := os .ReadFile (ProductJsonLocation )
274
+ if err != nil {
275
+ return errors .New ("failed to read product.json: " + err .Error ())
276
+ }
277
+ registryUrl := os .Getenv ("VSX_REGISTRY_URL" )
278
+ if registryUrl != "" {
279
+ b = bytes .ReplaceAll (b , []byte ("https://open-vsx.org" ), []byte (registryUrl ))
280
+ }
281
+ b = bytes .ReplaceAll (b , []byte ("{{extensionsGalleryItemUrl}}" ), []byte ("https://open-vsx.org/vscode/item" ))
282
+ b = bytes .ReplaceAll (b , []byte ("{{trustedDomain}}" ), []byte ("https://open-vsx.org" ))
283
+ if err := os .WriteFile (ProductJsonLocation , b , 0644 ); err != nil {
284
+ return errors .New ("failed to write product.json: " + err .Error ())
285
+ }
286
+ return nil
287
+ }
0 commit comments