1
+ //go:build !slim
2
+
1
3
package cli
2
4
3
5
import (
7
9
"log"
8
10
"net"
9
11
"net/http"
12
+ "net/url"
10
13
"runtime/pprof"
11
14
"time"
12
15
@@ -34,12 +37,44 @@ func (r *RootCmd) workspaceProxy() *clibase.Cmd {
34
37
},
35
38
Children : []* clibase.Cmd {
36
39
r .proxyServer (),
40
+ r .registerProxy (),
37
41
},
38
42
}
39
43
40
44
return cmd
41
45
}
42
46
47
+ func (r * RootCmd ) registerProxy () * clibase.Cmd {
48
+ client := new (codersdk.Client )
49
+ cmd := & clibase.Cmd {
50
+ Use : "register" ,
51
+ Short : "Register a workspace proxy" ,
52
+ Middleware : clibase .Chain (
53
+ clibase .RequireNArgs (1 ),
54
+ r .InitClient (client ),
55
+ ),
56
+ Handler : func (i * clibase.Invocation ) error {
57
+ ctx := i .Context ()
58
+ name := i .Args [0 ]
59
+ // TODO: Fix all this
60
+ resp , err := client .CreateWorkspaceProxy (ctx , codersdk.CreateWorkspaceProxyRequest {
61
+ Name : name ,
62
+ DisplayName : name ,
63
+ Icon : "whocares.png" ,
64
+ URL : "http://localhost:6005" ,
65
+ WildcardHostname : "" ,
66
+ })
67
+ if err != nil {
68
+ return xerrors .Errorf ("create workspace proxy: %w" , err )
69
+ }
70
+
71
+ fmt .Println (resp .ProxyToken )
72
+ return nil
73
+ },
74
+ }
75
+ return cmd
76
+ }
77
+
43
78
func (r * RootCmd ) proxyServer () * clibase.Cmd {
44
79
var (
45
80
// TODO: Remove options that we do not need
@@ -50,8 +85,9 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
50
85
51
86
client := new (codersdk.Client )
52
87
cmd := & clibase.Cmd {
53
- Use : "server" ,
54
- Short : "Start a workspace proxy server" ,
88
+ Use : "server" ,
89
+ Short : "Start a workspace proxy server" ,
90
+ Options : opts ,
55
91
Middleware : clibase .Chain (
56
92
cli .WriteConfigMW (cfg ),
57
93
cli .PrintDeprecatedOptions (),
@@ -67,14 +103,16 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
67
103
defer scd .Close ()
68
104
ctx := scd .Ctx
69
105
106
+ pu , _ := url .Parse ("http://localhost:3000" )
70
107
proxy , err := wsproxy .New (& wsproxy.Options {
71
108
Logger : scd .Logger ,
72
109
// TODO: PrimaryAccessURL
73
- PrimaryAccessURL : nil ,
74
- AccessURL : cfg .AccessURL .Value (),
75
- AppHostname : scd .AppHostname ,
76
- AppHostnameRegex : scd .AppHostnameRegex ,
77
- RealIPConfig : scd .RealIPConfig ,
110
+ PrimaryAccessURL : pu ,
111
+ AccessURL : cfg .AccessURL .Value (),
112
+ AppHostname : scd .AppHostname ,
113
+ AppHostnameRegex : scd .AppHostnameRegex ,
114
+ RealIPConfig : scd .RealIPConfig ,
115
+ // TODO: AppSecurityKey
78
116
AppSecurityKey : workspaceapps.SecurityKey {},
79
117
Tracing : scd .Tracer ,
80
118
PrometheusRegistry : scd .PrometheusRegistry ,
@@ -85,6 +123,9 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
85
123
// TODO: ProxySessionToken
86
124
ProxySessionToken : "" ,
87
125
})
126
+ if err != nil {
127
+ return xerrors .Errorf ("create workspace proxy: %w" , err )
128
+ }
88
129
89
130
shutdownConnsCtx , shutdownConns := context .WithCancel (ctx )
90
131
defer shutdownConns ()
@@ -110,7 +151,7 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
110
151
111
152
// TODO: So this obviously is not going to work well.
112
153
errCh := make (chan error , 1 )
113
- pprof .Do (ctx , pprof .Labels ("service" , "workspace-proxy" ), func (ctx context.Context ) {
154
+ go pprof .Do (ctx , pprof .Labels ("service" , "workspace-proxy" ), func (ctx context.Context ) {
114
155
errCh <- scd .HTTPServers .Serve (httpServer )
115
156
})
116
157
@@ -128,7 +169,6 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
128
169
var exitErr error
129
170
select {
130
171
case exitErr = <- errCh :
131
- fmt .Println ("As" )
132
172
case <- scd .NotifyCtx .Done ():
133
173
exitErr = scd .NotifyCtx .Err ()
134
174
_ , _ = fmt .Fprintln (inv .Stdout , cliui .Styles .Bold .Render (
0 commit comments