Skip to content

Commit a5a5c4d

Browse files
authored
chore: Add workspace proxy enterprise cli commands (#7176)
* feat: Add workspace proxy enterprise cli commands * chore: Handle custom workspace proxy options. Remove excess * chore: Add endpoint to register workspace proxies
1 parent 8926c10 commit a5a5c4d

30 files changed

+1558
-107
lines changed

cli/clibase/option.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ func (s *OptionSet) Add(opts ...Option) {
8080
*s = append(*s, opts...)
8181
}
8282

83+
// Filter will only return options that match the given filter. (return true)
84+
func (s OptionSet) Filter(filter func(opt Option) bool) OptionSet {
85+
cpy := make(OptionSet, 0)
86+
for _, opt := range s {
87+
if filter(opt) {
88+
cpy = append(cpy, opt)
89+
}
90+
}
91+
return cpy
92+
}
93+
8394
// FlagSet returns a pflag.FlagSet for the OptionSet.
8495
func (s *OptionSet) FlagSet() *pflag.FlagSet {
8596
if s == nil {

cli/cliui/output.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,35 @@ func (textFormat) AttachOptions(_ *clibase.OptionSet) {}
192192
func (textFormat) Format(_ context.Context, data any) (string, error) {
193193
return fmt.Sprintf("%s", data), nil
194194
}
195+
196+
// DataChangeFormat allows manipulating the data passed to an output format.
197+
// This is because sometimes the data needs to be manipulated before it can be
198+
// passed to the output format.
199+
// For example, you may want to pass something different to the text formatter
200+
// than what you pass to the json formatter.
201+
type DataChangeFormat struct {
202+
format OutputFormat
203+
change func(data any) (any, error)
204+
}
205+
206+
// ChangeFormatterData allows manipulating the data passed to an output
207+
// format.
208+
func ChangeFormatterData(format OutputFormat, change func(data any) (any, error)) *DataChangeFormat {
209+
return &DataChangeFormat{format: format, change: change}
210+
}
211+
212+
func (d *DataChangeFormat) ID() string {
213+
return d.format.ID()
214+
}
215+
216+
func (d *DataChangeFormat) AttachOptions(opts *clibase.OptionSet) {
217+
d.format.AttachOptions(opts)
218+
}
219+
220+
func (d *DataChangeFormat) Format(ctx context.Context, data any) (string, error) {
221+
newData, err := d.change(data)
222+
if err != nil {
223+
return "", err
224+
}
225+
return d.format.Format(ctx, newData)
226+
}

coderd/apidoc/docs.go

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbauthz/dbauthz.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ var (
181181
rbac.ResourceUserData.Type: {rbac.ActionCreate, rbac.ActionUpdate},
182182
rbac.ResourceWorkspace.Type: {rbac.ActionUpdate},
183183
rbac.ResourceWorkspaceExecution.Type: {rbac.ActionCreate},
184+
rbac.ResourceWorkspaceProxy.Type: {rbac.ActionCreate, rbac.ActionUpdate, rbac.ActionDelete},
184185
}),
185186
Org: map[string][]rbac.Permission{},
186187
User: []rbac.Permission{},

coderd/database/dbauthz/querier.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,10 @@ func (q *querier) GetWorkspaceProxyByID(ctx context.Context, id uuid.UUID) (data
16971697
return fetch(q.log, q.auth, q.db.GetWorkspaceProxyByID)(ctx, id)
16981698
}
16991699

1700+
func (q *querier) GetWorkspaceProxyByName(ctx context.Context, name string) (database.WorkspaceProxy, error) {
1701+
return fetch(q.log, q.auth, q.db.GetWorkspaceProxyByName)(ctx, name)
1702+
}
1703+
17001704
func (q *querier) GetWorkspaceProxyByHostname(ctx context.Context, hostname string) (database.WorkspaceProxy, error) {
17011705
return fetch(q.log, q.auth, q.db.GetWorkspaceProxyByHostname)(ctx, hostname)
17021706
}
@@ -1705,11 +1709,11 @@ func (q *querier) InsertWorkspaceProxy(ctx context.Context, arg database.InsertW
17051709
return insert(q.log, q.auth, rbac.ResourceWorkspaceProxy, q.db.InsertWorkspaceProxy)(ctx, arg)
17061710
}
17071711

1708-
func (q *querier) UpdateWorkspaceProxy(ctx context.Context, arg database.UpdateWorkspaceProxyParams) (database.WorkspaceProxy, error) {
1709-
fetch := func(ctx context.Context, arg database.UpdateWorkspaceProxyParams) (database.WorkspaceProxy, error) {
1712+
func (q *querier) RegisterWorkspaceProxy(ctx context.Context, arg database.RegisterWorkspaceProxyParams) (database.WorkspaceProxy, error) {
1713+
fetch := func(ctx context.Context, arg database.RegisterWorkspaceProxyParams) (database.WorkspaceProxy, error) {
17101714
return q.db.GetWorkspaceProxyByID(ctx, arg.ID)
17111715
}
1712-
return updateWithReturn(q.log, q.auth, fetch, q.db.UpdateWorkspaceProxy)(ctx, arg)
1716+
return updateWithReturn(q.log, q.auth, fetch, q.db.RegisterWorkspaceProxy)(ctx, arg)
17131717
}
17141718

17151719
func (q *querier) UpdateWorkspaceProxyDeleted(ctx context.Context, arg database.UpdateWorkspaceProxyDeletedParams) error {

coderd/database/dbauthz/querier_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ func (s *MethodTestSuite) TestWorkspaceProxy() {
444444
ID: uuid.New(),
445445
}).Asserts(rbac.ResourceWorkspaceProxy, rbac.ActionCreate)
446446
}))
447-
s.Run("UpdateWorkspaceProxy", s.Subtest(func(db database.Store, check *expects) {
447+
s.Run("RegisterWorkspaceProxy", s.Subtest(func(db database.Store, check *expects) {
448448
p, _ := dbgen.WorkspaceProxy(s.T(), db, database.WorkspaceProxy{})
449-
check.Args(database.UpdateWorkspaceProxyParams{
449+
check.Args(database.RegisterWorkspaceProxyParams{
450450
ID: p.ID,
451451
}).Asserts(p, rbac.ActionUpdate)
452452
}))

coderd/database/dbfake/databasefake.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5127,6 +5127,21 @@ func (q *fakeQuerier) GetWorkspaceProxyByID(_ context.Context, id uuid.UUID) (da
51275127
return database.WorkspaceProxy{}, sql.ErrNoRows
51285128
}
51295129

5130+
func (q *fakeQuerier) GetWorkspaceProxyByName(_ context.Context, name string) (database.WorkspaceProxy, error) {
5131+
q.mutex.Lock()
5132+
defer q.mutex.Unlock()
5133+
5134+
for _, proxy := range q.workspaceProxies {
5135+
if proxy.Deleted {
5136+
continue
5137+
}
5138+
if proxy.Name == name {
5139+
return proxy, nil
5140+
}
5141+
}
5142+
return database.WorkspaceProxy{}, sql.ErrNoRows
5143+
}
5144+
51305145
func (q *fakeQuerier) GetWorkspaceProxyByHostname(_ context.Context, hostname string) (database.WorkspaceProxy, error) {
51315146
q.mutex.RLock()
51325147
defer q.mutex.RUnlock()
@@ -5187,14 +5202,12 @@ func (q *fakeQuerier) InsertWorkspaceProxy(_ context.Context, arg database.Inser
51875202
return p, nil
51885203
}
51895204

5190-
func (q *fakeQuerier) UpdateWorkspaceProxy(_ context.Context, arg database.UpdateWorkspaceProxyParams) (database.WorkspaceProxy, error) {
5205+
func (q *fakeQuerier) RegisterWorkspaceProxy(_ context.Context, arg database.RegisterWorkspaceProxyParams) (database.WorkspaceProxy, error) {
51915206
q.mutex.Lock()
51925207
defer q.mutex.Unlock()
51935208

51945209
for i, p := range q.workspaceProxies {
51955210
if p.ID == arg.ID {
5196-
p.Name = arg.Name
5197-
p.Icon = arg.Icon
51985211
p.Url = arg.Url
51995212
p.WildcardHostname = arg.WildcardHostname
52005213
p.UpdatedAt = database.Now()

coderd/database/querier.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy