- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: Add workspace application support#1773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
bdfa61a8b2f6c4e3cf488e3ff8adb6e1ea6430cfe76ef781cf70dd170805250934b1ff866eeed4b73034b4f9615c88df46d327df7f84f5eacec2de3c57f8dd8e61cacb6e6d7b46b24f74d8b257e9b746380b56008b81c3560ad8810a63becd3b9ab57a1ae155b9194fcd2d12eb056400fe3aecc2018cdc2d5261f856f17d1a21f94ad90bcb38abbb54f89642637be3e50da4fbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -27,6 +27,7 @@ import ( | ||
| "github.com/coder/coder/coderd/rbac" | ||
| "github.com/coder/coder/coderd/tracing" | ||
| "github.com/coder/coder/coderd/turnconn" | ||
| "github.com/coder/coder/coderd/wsconncache" | ||
| "github.com/coder/coder/codersdk" | ||
| "github.com/coder/coder/site" | ||
| ) | ||
| @@ -44,14 +45,14 @@ type Options struct { | ||
| // app. Specific routes may have their own limiters. | ||
| APIRateLimit int | ||
| AWSCertificates awsidentity.Certificates | ||
| Authorizer rbac.Authorizer | ||
| AzureCertificates x509.VerifyOptions | ||
| GoogleTokenValidator *idtoken.Validator | ||
| GithubOAuth2Config *GithubOAuth2Config | ||
| ICEServers []webrtc.ICEServer | ||
| SecureAuthCookie bool | ||
| SSHKeygenAlgorithm gitsshkey.Algorithm | ||
| TURNServer *turnconn.Server | ||
| TracerProvider *sdktrace.TracerProvider | ||
| } | ||
| @@ -75,9 +76,11 @@ func New(options *Options) *API { | ||
| r := chi.NewRouter() | ||
| api := &API{ | ||
| Options: options, | ||
| Handler: r, | ||
| siteHandler: site.Handler(site.FS()), | ||
| } | ||
| api.workspaceAgentCache = wsconncache.New(api.dialWorkspaceAgent, 0) | ||
| apiKeyMiddleware := httpmw.ExtractAPIKey(options.Database, &httpmw.OAuth2Configs{ | ||
| Github: options.GithubOAuth2Config, | ||
| @@ -93,6 +96,20 @@ func New(options *Options) *API { | ||
| tracing.HTTPMW(api.TracerProvider, "coderd.http"), | ||
| ) | ||
| apps := func(r chi.Router) { | ||
| r.Use( | ||
| httpmw.RateLimitPerMinute(options.APIRateLimit), | ||
| apiKeyMiddleware, | ||
| httpmw.ExtractUserParam(api.Database), | ||
| ) | ||
| r.Get("/*", api.workspaceAppsProxyPath) | ||
| } | ||
| // %40 is the encoded character of the @ symbol. VS Code Web does | ||
| // not handle character encoding properly, so it's safe to assume | ||
| // other applications might not as well. | ||
| r.Route("/%40{user}/{workspacename}/apps/{workspaceapp}", apps) | ||
Contributor
| ||
| r.Route("/@{user}/{workspacename}/apps/{workspaceapp}", apps) | ||
greyscaled marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| r.Route("/api/v2", func(r chi.Router) { | ||
| r.NotFound(func(rw http.ResponseWriter, r *http.Request) { | ||
| httpapi.Write(rw, http.StatusNotFound, httpapi.Response{ | ||
| @@ -327,24 +344,27 @@ func New(options *Options) *API { | ||
| r.Get("/state", api.workspaceBuildState) | ||
| }) | ||
| }) | ||
| r.NotFound(api.siteHandler.ServeHTTP) | ||
| return api | ||
| } | ||
| type API struct { | ||
| *Options | ||
| Handler chi.Router | ||
| siteHandler http.Handler | ||
| websocketWaitMutex sync.Mutex | ||
| websocketWaitGroup sync.WaitGroup | ||
| workspaceAgentCache *wsconncache.Cache | ||
| } | ||
| // Close waits for all WebSocket connections to drain before returning. | ||
| func (api *API) Close()error{ | ||
| api.websocketWaitMutex.Lock() | ||
| api.websocketWaitGroup.Wait() | ||
| api.websocketWaitMutex.Unlock() | ||
| return api.workspaceAgentCache.Close() | ||
| } | ||
| func debugLogRequest(log slog.Logger) func(http.Handler) http.Handler { | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| DROP TABLE workspace_apps; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| CREATE TABLE workspace_apps ( | ||
| id uuid NOT NULL, | ||
| created_at timestamp with time zone NOT NULL, | ||
| agent_id uuid NOT NULL REFERENCES workspace_agents (id) ON DELETE CASCADE, | ||
| name varchar(64) NOT NULL, | ||
| icon varchar(256) NOT NULL, | ||
| command varchar(65534), | ||
| url varchar(65534), | ||
| relative_path boolean NOT NULL DEFAULT false, | ||
| PRIMARY KEY (id), | ||
| UNIQUE(agent_id, name) | ||
| ); |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.