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

Commit5bd1392

Browse files
committed
chore: Implement enterprise endpoints for moons
1 parent243f837 commit5bd1392

File tree

12 files changed

+205
-12
lines changed

12 files changed

+205
-12
lines changed

‎coderd/audit/diff.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type Auditable interface {
1616
database.GitSSHKey|
1717
database.WorkspaceBuild|
1818
database.AuditableGroup|
19-
database.License
19+
database.License|
20+
database.WorkspaceProxy
2021
}
2122

2223
// Map is a map of changed fields in an audited resource. It maps field names to

‎coderd/database/dbauthz/querier.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,10 +1647,8 @@ func (q *querier) GetWorkspaceByWorkspaceAppID(ctx context.Context, workspaceApp
16471647
returnfetch(q.log,q.auth,q.db.GetWorkspaceByWorkspaceAppID)(ctx,workspaceAppID)
16481648
}
16491649

1650-
func (q*querier)GetWorkspaceProxies(ctx context.Context) ([]database.WorkspaceProxy,error) {
1651-
returnfetchWithPostFilter(q.auth,func(ctx context.Context,_any) ([]database.WorkspaceProxy,error) {
1652-
returnq.db.GetWorkspaceProxies(ctx)
1653-
})(ctx,nil)
1650+
func (q*querier)GetWorkspaceProxies(ctx context.Context,organizationID uuid.UUID) ([]database.WorkspaceProxy,error) {
1651+
returnfetchWithPostFilter(q.auth,q.GetWorkspaceProxies)(ctx,organizationID)
16541652
}
16551653

16561654
func (q*querier)GetWorkspaceProxyByID(ctx context.Context,id uuid.UUID) (database.WorkspaceProxy,error) {

‎coderd/database/dbfake/databasefake.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4896,12 +4896,16 @@ func (q *fakeQuerier) UpdateWorkspaceAgentStartupLogOverflowByID(_ context.Conte
48964896
returnsql.ErrNoRows
48974897
}
48984898

4899-
func (q*fakeQuerier)GetWorkspaceProxies(ctx context.Context) ([]database.WorkspaceProxy,error) {
4899+
func (q*fakeQuerier)GetWorkspaceProxies(ctx context.Context,organizationID uuid.UUID) ([]database.WorkspaceProxy,error) {
49004900
q.mutex.Lock()
49014901
deferq.mutex.Unlock()
49024902

4903-
cpy:=make([]database.WorkspaceProxy,len(q.workspaceProxies))
4904-
copy(cpy,q.workspaceProxies)
4903+
cpy:=make([]database.WorkspaceProxy,0,len(q.workspaceProxies))
4904+
for_,p:=rangeq.workspaceProxies {
4905+
ifp.OrganizationID==organizationID&&!p.Deleted {
4906+
cpy=append(cpy,p)
4907+
}
4908+
}
49054909
returncpy,nil
49064910
}
49074911

‎coderd/database/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/proxies.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ SELECT
5252
FROM
5353
workspace_proxies
5454
WHERE
55-
deleted= false;
55+
deleted= false
56+
AND organization_id= @organization_id;

‎codersdk/deployment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,10 @@ const (
15701570
// for all users.
15711571
ExperimentTemplateEditorExperiment="template_editor"
15721572

1573+
// ExperimentMoons enabled the workspace proxy endpoints and CRUD. This
1574+
// feature is not yet complete in functionality.
1575+
ExperimentMoonsExperiment="moons"
1576+
15731577
// Add new experiments here!
15741578
// ExperimentExample Experiment = "example"
15751579
)

‎codersdk/workspaceproxy.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package codersdk
2+
3+
import (
4+
"time"
5+
6+
"github.com/google/uuid"
7+
)
8+
9+
typeCreateWorkspaceProxyRequeststruct {
10+
Namestring`json:"name"`
11+
Iconstring`json:"icon"`
12+
URLstring`json:"url"`
13+
WildcardURLstring`json:"wildcard_url"`
14+
}
15+
16+
typeWorkspaceProxystruct {
17+
ID uuid.UUID`db:"id" json:"id"`
18+
OrganizationID uuid.UUID`db:"organization_id" json:"organization_id"`
19+
Namestring`db:"name" json:"name"`
20+
Iconstring`db:"icon" json:"icon"`
21+
// Full url including scheme of the proxy api url: https://us.example.com
22+
Urlstring`db:"url" json:"url"`
23+
// URL with the wildcard for subdomain based app hosting: https://*.us.example.com
24+
WildcardUrlstring`db:"wildcard_url" json:"wildcard_url"`
25+
CreatedAt time.Time`db:"created_at" json:"created_at"`
26+
UpdatedAt time.Time`db:"updated_at" json:"updated_at"`
27+
Deletedbool`db:"deleted" json:"deleted"`
28+
}

‎enterprise/audit/table.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ var auditableResourcesTypes = map[any]map[string]Action{
160160
"exp":ActionTrack,
161161
"uuid":ActionTrack,
162162
},
163+
&database.WorkspaceProxy{}: {
164+
"id":ActionTrack,
165+
"organization_id":ActionTrack,
166+
"name":ActionTrack,
167+
"icon":ActionTrack,
168+
"url":ActionTrack,
169+
"wildcard_url":ActionTrack,
170+
"created_at":ActionTrack,
171+
"updated_at":ActionTrack,
172+
"deleted":ActionTrack,
173+
},
163174
}
164175

165176
// auditMap converts a map of struct pointers to a map of struct names as

‎enterprise/coderd/coderd.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ func New(ctx context.Context, options *Options) (*API, error) {
8181
r.Get("/",api.licenses)
8282
r.Delete("/{id}",api.deleteLicense)
8383
})
84+
r.Route("/organizations/{organization}/workspaceproxys",func(r chi.Router) {
85+
r.Use(
86+
apiKeyMiddleware,
87+
api.moonsEnabledMW,
88+
httpmw.ExtractOrganizationParam(api.Database),
89+
)
90+
r.Post("/",api.postWorkspaceProxyByOrganization)
91+
r.Get("/",api.workspaceProxiesByOrganization)
92+
// TODO: Add specific workspace proxy endpoints.
93+
//r.Route("/{proxyName}", func(r chi.Router) {
94+
//r.Use(
95+
//httpmw.ExtractWorkspaceProxyByNameParam(api.Database),
96+
//)
97+
//
98+
//r.Get("/", api.workspaceProxyByName)
99+
//})
100+
})
84101
r.Route("/organizations/{organization}/groups",func(r chi.Router) {
85102
r.Use(
86103
apiKeyMiddleware,

‎enterprise/coderd/templates.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,13 @@ func (api *API) templateRBACEnabledMW(next http.Handler) http.Handler {
279279
next.ServeHTTP(rw,r)
280280
})
281281
}
282+
283+
func (api*API)moonsEnabledMW(next http.Handler) http.Handler {
284+
returnhttp.HandlerFunc(func(rw http.ResponseWriter,r*http.Request) {
285+
if!api.AGPL.Experiments.Enabled(codersdk.ExperimentMoons) {
286+
httpapi.RouteNotFound(rw)
287+
return
288+
}
289+
next.ServeHTTP(rw,r)
290+
})
291+
}

‎enterprise/coderd/workspaceproxy.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package coderd
2+
3+
import (
4+
"database/sql"
5+
"fmt"
6+
"net/http"
7+
8+
"golang.org/x/xerrors"
9+
10+
"github.com/coder/coder/coderd/audit"
11+
"github.com/coder/coder/coderd/database"
12+
"github.com/coder/coder/coderd/httpapi"
13+
"github.com/coder/coder/coderd/httpmw"
14+
"github.com/coder/coder/codersdk"
15+
"github.com/google/uuid"
16+
)
17+
18+
// @Summary Create workspace proxy for organization
19+
// @ID create-workspace-proxy-for-organization
20+
// @Security CoderSessionToken
21+
// @Accept json
22+
// @Produce json
23+
// @Tags Templates
24+
// @Param request body codersdk.CreateWorkspaceProxyRequest true "Create workspace proxy request"
25+
// @Param organization path string true "Organization ID"
26+
// @Success 201 {object} codersdk.WorkspaceProxy
27+
// @Router /organizations/{organization}/workspaceproxys [post]
28+
func (api*API)postWorkspaceProxyByOrganization(rw http.ResponseWriter,r*http.Request) {
29+
var (
30+
ctx=r.Context()
31+
org=httpmw.OrganizationParam(r)
32+
auditor=api.AGPL.Auditor.Load()
33+
aReq,commitAudit=audit.InitRequest[database.WorkspaceProxy](rw,&audit.RequestParams{
34+
Audit:*auditor,
35+
Log:api.Logger,
36+
Request:r,
37+
Action:database.AuditActionCreate,
38+
})
39+
)
40+
defercommitAudit()
41+
42+
varreq codersdk.CreateWorkspaceProxyRequest
43+
if!httpapi.Read(ctx,rw,r,&req) {
44+
return
45+
}
46+
47+
proxy,err:=api.Database.InsertWorkspaceProxy(ctx, database.InsertWorkspaceProxyParams{
48+
ID:uuid.New(),
49+
OrganizationID:org.ID,
50+
Name:req.Name,
51+
Icon:req.Icon,
52+
// TODO: validate URLs
53+
Url:req.URL,
54+
WildcardUrl:req.WildcardURL,
55+
CreatedAt:database.Now(),
56+
UpdatedAt:database.Now(),
57+
})
58+
ifdatabase.IsUniqueViolation(err) {
59+
httpapi.Write(ctx,rw,http.StatusConflict, codersdk.Response{
60+
Message:fmt.Sprintf("Workspace proxy with name %q already exists.",req.Name),
61+
})
62+
return
63+
}
64+
iferr!=nil {
65+
httpapi.InternalServerError(rw,err)
66+
return
67+
}
68+
69+
aReq.New=proxy
70+
httpapi.Write(ctx,rw,http.StatusCreated,convertProxy(proxy))
71+
}
72+
73+
// @Summary Get workspace proxies
74+
// @ID get-workspace-proxies
75+
// @Security CoderSessionToken
76+
// @Produce json
77+
// @Tags Enterprise
78+
// @Param organization path string true "Organization ID" format(uuid)
79+
// @Success 200 {array} codersdk.WorkspaceProxy
80+
// @Router /organizations/{organization}/workspaceproxys [get]
81+
func (api*API)workspaceProxiesByOrganization(rw http.ResponseWriter,r*http.Request) {
82+
var (
83+
ctx=r.Context()
84+
org=httpmw.OrganizationParam(r)
85+
)
86+
87+
proxies,err:=api.Database.GetWorkspaceProxies(ctx,org.ID)
88+
iferr!=nil&&!xerrors.Is(err,sql.ErrNoRows) {
89+
httpapi.InternalServerError(rw,err)
90+
return
91+
}
92+
93+
httpapi.Write(ctx,rw,http.StatusOK,convertProxies(proxies))
94+
}
95+
96+
97+
98+
funcconvertProxies(p []database.WorkspaceProxy) []codersdk.WorkspaceProxy {
99+
resp:=make([]codersdk.WorkspaceProxy,0,len(p))
100+
for_,proxy:=rangep {
101+
resp=append(resp,convertProxy(proxy))
102+
}
103+
returnresp
104+
}
105+
106+
funcconvertProxy(p database.WorkspaceProxy) codersdk.WorkspaceProxy {
107+
return codersdk.WorkspaceProxy{
108+
ID:p.ID,
109+
OrganizationID:p.OrganizationID,
110+
Name:p.Name,
111+
Icon:p.Icon,
112+
Url:p.Url,
113+
WildcardUrl:p.WildcardUrl,
114+
CreatedAt:p.CreatedAt,
115+
UpdatedAt:p.UpdatedAt,
116+
Deleted:p.Deleted,
117+
}
118+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp