Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit059ac4e

Browse files
committed
Move type def to codersdk
Signed-off-by: Danny Kopping <danny@coder.com>
1 parentec3bac6 commit059ac4e

File tree

6 files changed

+31
-20
lines changed

6 files changed

+31
-20
lines changed

‎coderd/workspaceapps/apptest/setup.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/coder/coder/v2/coderd/coderdtest"
2323
"github.com/coder/coder/v2/coderd/workspaceapps"
2424
"github.com/coder/coder/v2/coderd/workspaceapps/appurl"
25-
"github.com/coder/coder/v2/coderd/workspaceapps/cors"
2625
"github.com/coder/coder/v2/codersdk"
2726
"github.com/coder/coder/v2/codersdk/agentsdk"
2827
"github.com/coder/coder/v2/cryptorand"
@@ -102,7 +101,7 @@ type App struct {
102101
Pathstring
103102

104103
// Control the behavior of CORS handling.
105-
CORSBehaviorcors.AppCORSBehavior
104+
CORSBehaviorcodersdk.AppCORSBehavior
106105
}
107106

108107
// Details are the full test details returned from setupProxyTestWithFactory.
@@ -271,15 +270,15 @@ func setupProxyTestWithFactory(t *testing.T, factory DeploymentFactory, opts *De
271270
WorkspaceName:workspace.Name,
272271
AgentName:agnt.Name,
273272
AppSlugOrPort:proxyTestAppNamePublicCORSPassthru,
274-
CORSBehavior:cors.AppCORSBehaviorPassthru,
273+
CORSBehavior:codersdk.AppCORSBehaviorPassthru,
275274
Query:proxyTestAppQuery,
276275
}
277276
details.Apps.AuthenticatedCORSPassthru=App{
278277
Username:me.Username,
279278
WorkspaceName:workspace.Name,
280279
AgentName:agnt.Name,
281280
AppSlugOrPort:proxyTestAppNameAuthenticatedCORSPassthru,
282-
CORSBehavior:cors.AppCORSBehaviorPassthru,
281+
CORSBehavior:codersdk.AppCORSBehaviorPassthru,
283282
Query:proxyTestAppQuery,
284283
}
285284
details.Apps.PublicCORSDefault=App{

‎coderd/workspaceapps/cors/cors.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package cors
22

3-
import"context"
3+
import (
4+
"context"
45

5-
typeAppCORSBehaviorstring
6-
7-
const (
8-
AppCORSBehaviorSimpleAppCORSBehavior="simple"
9-
AppCORSBehaviorPassthruAppCORSBehavior="passthru"
6+
"github.com/coder/coder/v2/codersdk"
107
)
118

129
typecontextKeyBehaviorstruct{}
1310

1411
// WithBehavior sets the CORS behavior for the given context.
15-
funcWithBehavior(ctx context.Context,behaviorAppCORSBehavior) context.Context {
12+
funcWithBehavior(ctx context.Context,behaviorcodersdk.AppCORSBehavior) context.Context {
1613
returncontext.WithValue(ctx,contextKeyBehavior{},behavior)
1714
}
1815

1916
// HasBehavior returns true if the given context has the specified CORS behavior.
20-
funcHasBehavior(ctx context.Context,behaviorAppCORSBehavior)bool {
17+
funcHasBehavior(ctx context.Context,behaviorcodersdk.AppCORSBehavior)bool {
2118
val:=ctx.Value(contextKeyBehavior{})
22-
b,ok:=val.(AppCORSBehavior)
19+
b,ok:=val.(codersdk.AppCORSBehavior)
2320
returnok&&b==behavior
2421
}

‎coderd/workspaceapps/db.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/coder/coder/v2/coderd/jwtutils"
2626
"github.com/coder/coder/v2/coderd/rbac"
2727
"github.com/coder/coder/v2/coderd/rbac/policy"
28-
"github.com/coder/coder/v2/coderd/workspaceapps/cors"
2928
"github.com/coder/coder/v2/codersdk"
3029
)
3130

@@ -132,7 +131,7 @@ func (p *DBTokenProvider) Issue(ctx context.Context, rw http.ResponseWriter, r *
132131
ifdbReq.AppURL!=nil {
133132
token.AppURL=dbReq.AppURL.String()
134133
}
135-
token.CORSBehavior=cors.AppCORSBehavior(dbReq.AppCORSBehavior)
134+
token.CORSBehavior=codersdk.AppCORSBehavior(dbReq.AppCORSBehavior)
136135

137136
// Verify the user has access to the app.
138137
authed,warnings,err:=p.authorizeRequest(r.Context(),authz,dbReq)

‎coderd/workspaceapps/proxy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func (s *Server) determineCORSBehavior(token *SignedToken, app appurl.Applicatio
441441
corsHandler:=httpmw.WorkspaceAppCors(s.HostnameRegex,app)(next)
442442

443443
returnhttp.HandlerFunc(func(rw http.ResponseWriter,r*http.Request) {
444-
varbehaviorcors.AppCORSBehavior
444+
varbehaviorcodersdk.AppCORSBehavior
445445
iftoken!=nil {
446446
behavior=token.CORSBehavior
447447
}
@@ -452,7 +452,7 @@ func (s *Server) determineCORSBehavior(token *SignedToken, app appurl.Applicatio
452452
r=r.WithContext(cors.WithBehavior(r.Context(),behavior))
453453

454454
switchbehavior {
455-
casecors.AppCORSBehaviorPassthru:
455+
casecodersdk.AppCORSBehaviorPassthru:
456456
// Bypass the CORS middleware.
457457
next.ServeHTTP(rw,r)
458458
return
@@ -595,7 +595,7 @@ func (s *Server) proxyWorkspaceApp(rw http.ResponseWriter, r *http.Request, appT
595595

596596
proxy.ModifyResponse=func(r*http.Response)error {
597597
// If passthru behavior is set, disable our CORS header stripping.
598-
ifcors.HasBehavior(r.Request.Context(),cors.AppCORSBehaviorPassthru) {
598+
ifcors.HasBehavior(r.Request.Context(),codersdk.AppCORSBehaviorPassthru) {
599599
returnnil
600600
}
601601

‎coderd/workspaceapps/token.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/coder/coder/v2/coderd/cryptokeys"
1313
"github.com/coder/coder/v2/coderd/jwtutils"
14-
"github.com/coder/coder/v2/coderd/workspaceapps/cors"
1514
"github.com/coder/coder/v2/codersdk"
1615
)
1716

@@ -27,7 +26,7 @@ type SignedToken struct {
2726
WorkspaceID uuid.UUID`json:"workspace_id"`
2827
AgentID uuid.UUID`json:"agent_id"`
2928
AppURLstring`json:"app_url"`
30-
CORSBehaviorcors.AppCORSBehavior`json:"cors_behavior"`
29+
CORSBehaviorcodersdk.AppCORSBehavior`json:"cors_behavior"`
3130
}
3231

3332
// MatchesRequest returns true if the token matches the request. Any token that

‎codersdk/cors_behavior.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package codersdk
2+
3+
import"golang.org/x/xerrors"
4+
5+
typeAppCORSBehaviorstring
6+
7+
const (
8+
AppCORSBehaviorSimpleAppCORSBehavior="simple"
9+
AppCORSBehaviorPassthruAppCORSBehavior="passthru"
10+
)
11+
12+
func (cAppCORSBehavior)Validate()error {
13+
ifc!=AppCORSBehaviorSimple&&c!=AppCORSBehaviorPassthru {
14+
returnxerrors.New("Invalid CORS behavior.")
15+
}
16+
returnnil
17+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp