Skip to content

Commit bb032c3

Browse files
committed
Renames and formatting
1 parent b7f3b86 commit bb032c3

File tree

9 files changed

+30
-38
lines changed

9 files changed

+30
-38
lines changed

coderd/workspaceagents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ func (api *API) workspaceAgentCoordinate(rw http.ResponseWriter, r *http.Request
10051005
func (api *API) workspaceAgentClientCoordinate(rw http.ResponseWriter, r *http.Request) {
10061006
ctx := r.Context()
10071007

1008-
// This route accepts user API key auth and moon auth. The moon actor has
1008+
// This route accepts user API key auth and workspace proxy auth. The moon actor has
10091009
// full permissions so should be able to pass this authz check.
10101010
workspace := httpmw.WorkspaceParam(r)
10111011
if !api.Authorize(r, rbac.ActionCreate, workspace.ExecutionRBAC()) {

codersdk/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ type Client struct {
7979
HTTPClient *http.Client
8080
URL *url.URL
8181

82-
// TokenHeader is an optional custom header to use for setting tokens. By
83-
// default SessionTokenHeader is used.
84-
TokenHeader string
82+
// SessionTokenHeader is an optional custom header to use for setting tokens. By
83+
// default 'Coder-Session-Token' is used.
84+
SessionTokenHeader string
8585

8686
// Logger is optionally provided to log requests.
8787
// Method, URL, and response code will be logged by default.
@@ -155,7 +155,7 @@ func (c *Client) Request(ctx context.Context, method, path string, body interfac
155155
return nil, xerrors.Errorf("create request: %w", err)
156156
}
157157

158-
tokenHeader := c.TokenHeader
158+
tokenHeader := c.SessionTokenHeader
159159
if tokenHeader == "" {
160160
tokenHeader = SessionTokenHeader
161161
}

codersdk/workspaceagents.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ func (c *Client) DialWorkspaceAgent(ctx context.Context, agentID uuid.UUID, opti
202202
}
203203
coordinateHeaders := make(http.Header)
204204
tokenHeader := SessionTokenHeader
205-
if c.TokenHeader != "" {
206-
tokenHeader = c.TokenHeader
205+
if c.SessionTokenHeader != "" {
206+
tokenHeader = c.SessionTokenHeader
207207
}
208208
coordinateHeaders.Set(tokenHeader, c.SessionToken())
209209
ctx, cancel := context.WithCancel(ctx)

enterprise/coderd/coderd.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ func New(ctx context.Context, options *Options) (*API, error) {
8888
)
8989
r.Post("/", api.postWorkspaceProxy)
9090
r.Get("/", api.workspaceProxies)
91+
r.Route("/me", func(r chi.Router) {
92+
r.Use(
93+
httpmw.ExtractExternalProxy(httpmw.ExtractExternalProxyConfig{
94+
DB: options.Database,
95+
Optional: false,
96+
}),
97+
)
98+
r.Post("/issue-signed-app-token", api.workspaceProxyIssueSignedAppToken)
99+
})
91100
// TODO: Add specific workspace proxy endpoints.
92101
// r.Route("/{proxyName}", func(r chi.Router) {
93102
// r.Use(
@@ -97,17 +106,6 @@ func New(ctx context.Context, options *Options) (*API, error) {
97106
// r.Get("/", api.workspaceProxyByName)
98107
// })
99108
})
100-
r.Route("/proxy-internal", func(r chi.Router) {
101-
r.Use(
102-
api.moonsEnabledMW,
103-
httpmw.ExtractExternalProxy(httpmw.ExtractExternalProxyConfig{
104-
DB: options.Database,
105-
Optional: false,
106-
}),
107-
)
108-
109-
r.Post("/issue-signed-app-token", api.issueSignedAppToken)
110-
})
111109
r.Route("/organizations/{organization}/groups", func(r chi.Router) {
112110
r.Use(
113111
apiKeyMiddleware,

enterprise/coderd/coderdenttest/proxytest.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,15 @@ import (
1313
"testing"
1414

1515
"github.com/moby/moby/pkg/namesgenerator"
16-
17-
"github.com/coder/coder/codersdk"
18-
19-
"github.com/coder/coder/enterprise/coderd"
20-
21-
"github.com/coder/coder/enterprise/wsproxy"
22-
23-
"github.com/stretchr/testify/require"
24-
25-
"github.com/coder/coder/coderd/httpapi"
26-
2716
"github.com/prometheus/client_golang/prometheus"
17+
"github.com/stretchr/testify/require"
2818

2919
"cdr.dev/slog"
3020
"cdr.dev/slog/sloggers/slogtest"
21+
"github.com/coder/coder/coderd/httpapi"
22+
"github.com/coder/coder/codersdk"
23+
"github.com/coder/coder/enterprise/coderd"
24+
"github.com/coder/coder/enterprise/wsproxy"
3125
)
3226

3327
type ProxyOptions struct {

enterprise/coderd/workspaceproxy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
// @Security CoderSessionToken
2525
// @Accept json
2626
// @Produce json
27-
// @Tags Templates
27+
// @Tags Enterprise
2828
// @Param request body codersdk.CreateWorkspaceProxyRequest true "Create workspace proxy request"
2929
// @Success 201 {object} codersdk.WorkspaceProxy
3030
// @Router /workspaceproxies [post]
@@ -165,9 +165,9 @@ func convertProxy(p database.WorkspaceProxy) codersdk.WorkspaceProxy {
165165
// @Tags Enterprise
166166
// @Param request body workspaceapps.IssueTokenRequest true "Issue signed app token request"
167167
// @Success 201 {object} wsproxysdk.IssueSignedAppTokenResponse
168-
// @Router /proxy-internal/issue-signed-app-token [post]
168+
// @Router /workspaceproxies/me/issue-signed-app-token [post]
169169
// @x-apidocgen {"skip": true}
170-
func (api *API) issueSignedAppToken(rw http.ResponseWriter, r *http.Request) {
170+
func (api *API) workspaceProxyIssueSignedAppToken(rw http.ResponseWriter, r *http.Request) {
171171
ctx := r.Context()
172172

173173
// NOTE: this endpoint will return JSON on success, but will (usually)

enterprise/wsproxy/wsproxysdk/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ type Client struct {
2323
// URL.
2424
func New(serverURL *url.URL) *Client {
2525
coderSDKClient := codersdk.New(serverURL)
26-
coderSDKClient.TokenHeader = httpmw.ExternalProxyAuthTokenHeader
26+
coderSDKClient.SessionTokenHeader = httpmw.ExternalProxyAuthTokenHeader
2727

2828
coderSDKClientIgnoreRedirects := codersdk.New(serverURL)
2929
coderSDKClientIgnoreRedirects.HTTPClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
3030
return http.ErrUseLastResponse
3131
}
32-
coderSDKClientIgnoreRedirects.TokenHeader = httpmw.ExternalProxyAuthTokenHeader
32+
coderSDKClientIgnoreRedirects.SessionTokenHeader = httpmw.ExternalProxyAuthTokenHeader
3333

3434
return &Client{
3535
CoderSDKClient: coderSDKClient,

enterprise/wsproxy/wsproxysdk/proxyinternal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type IssueSignedAppTokenResponse struct {
2121
// request. The error page will be returned as JSON. For use in external
2222
// proxies, use IssueSignedAppTokenHTML instead.
2323
func (c *Client) IssueSignedAppToken(ctx context.Context, req workspaceapps.IssueTokenRequest) (IssueSignedAppTokenResponse, error) {
24-
resp, err := c.RequestIgnoreRedirects(ctx, http.MethodPost, "/api/v2/proxy-internal/issue-signed-app-token", req, func(r *http.Request) {
24+
resp, err := c.RequestIgnoreRedirects(ctx, http.MethodPost, "/api/v2/workspaceproxies/me/issue-signed-app-token", req, func(r *http.Request) {
2525
// This forces any HTML error pages to be returned as JSON instead.
2626
r.Header.Set("Accept", "application/json")
2727
})
@@ -51,7 +51,7 @@ func (c *Client) IssueSignedAppTokenHTML(ctx context.Context, rw http.ResponseWr
5151
_ = json.NewEncoder(rw).Encode(res)
5252
}
5353

54-
resp, err := c.RequestIgnoreRedirects(ctx, http.MethodPost, "/api/v2/proxy-internal/issue-signed-app-token", req, func(r *http.Request) {
54+
resp, err := c.RequestIgnoreRedirects(ctx, http.MethodPost, "/api/v2/workspaceproxies/me/issue-signed-app-token", req, func(r *http.Request) {
5555
r.Header.Set("Accept", "text/html")
5656
})
5757
if err != nil {

enterprise/wsproxy/wsproxysdk/proxyinternal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func Test_IssueSignedAppTokenHTML(t *testing.T) {
4242
atomic.AddInt64(&called, 1)
4343

4444
assert.Equal(t, r.Method, http.MethodPost)
45-
assert.Equal(t, r.URL.Path, "/api/v2/proxy-internal/issue-signed-app-token")
45+
assert.Equal(t, r.URL.Path, "/api/v2/workspaceproxies/me/issue-signed-app-token")
4646
assert.Equal(t, r.Header.Get(httpmw.ExternalProxyAuthTokenHeader), expectedProxyToken)
4747

4848
var req workspaceapps.IssueTokenRequest
@@ -102,7 +102,7 @@ func Test_IssueSignedAppTokenHTML(t *testing.T) {
102102
atomic.AddInt64(&called, 1)
103103

104104
assert.Equal(t, r.Method, http.MethodPost)
105-
assert.Equal(t, r.URL.Path, "/api/v2/proxy-internal/issue-signed-app-token")
105+
assert.Equal(t, r.URL.Path, "/api/v2/workspaceproxies/me/issue-signed-app-token")
106106
assert.Equal(t, r.Header.Get(httpmw.ExternalProxyAuthTokenHeader), expectedProxyToken)
107107

108108
rw.WriteHeader(expectedResponseStatus)

0 commit comments

Comments
 (0)