Skip to content

Commit 6ebadab

Browse files
authored
feat: Add basic support for rich parameters to coderd and provisionerd (#5710)
1 parent 70fd786 commit 6ebadab

39 files changed

+2581
-789
lines changed

coderd/apidoc/docs.go

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

+1
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ func New(options *Options) *API {
435435
r.Patch("/cancel", api.patchCancelTemplateVersion)
436436
r.Get("/schema", api.templateVersionSchema)
437437
r.Get("/parameters", api.templateVersionParameters)
438+
r.Get("/rich-parameters", api.templateVersionRichParameters)
438439
r.Get("/resources", api.templateVersionResources)
439440
r.Get("/logs", api.templateVersionLogs)
440441
r.Route("/dry-run", func(r chi.Router) {

coderd/coderdtest/authorize.go

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
177177
AssertAction: rbac.ActionRead,
178178
AssertObject: rbac.ResourceTemplate.InOrg(a.Template.OrganizationID),
179179
},
180+
"GET:/api/v2/templateversions/{templateversion}/rich-parameters": {
181+
AssertAction: rbac.ActionRead,
182+
AssertObject: rbac.ResourceTemplate.InOrg(a.Template.OrganizationID),
183+
},
180184
"GET:/api/v2/templateversions/{templateversion}/resources": {
181185
AssertAction: rbac.ActionRead,
182186
AssertObject: rbac.ResourceTemplate.InOrg(a.Template.OrganizationID),

coderd/database/databasefake/databasefake.go

+66
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ type data struct {
111111
provisionerJobs []database.ProvisionerJob
112112
replicas []database.Replica
113113
templateVersions []database.TemplateVersion
114+
templateVersionParameters []database.TemplateVersionParameter
114115
templates []database.Template
115116
workspaceAgents []database.WorkspaceAgent
116117
workspaceApps []database.WorkspaceApp
117118
workspaceBuilds []database.WorkspaceBuild
119+
workspaceBuildParameters []database.WorkspaceBuildParameter
118120
workspaceResourceMetadata []database.WorkspaceResourceMetadatum
119121
workspaceResources []database.WorkspaceResource
120122
workspaces []database.Workspace
@@ -1365,6 +1367,20 @@ func (q *fakeQuerier) GetWorkspaceBuildByWorkspaceIDAndBuildNumber(_ context.Con
13651367
return database.WorkspaceBuild{}, sql.ErrNoRows
13661368
}
13671369

1370+
func (q *fakeQuerier) GetWorkspaceBuildParameters(_ context.Context, workspaceBuildID uuid.UUID) ([]database.WorkspaceBuildParameter, error) {
1371+
q.mutex.RLock()
1372+
defer q.mutex.RUnlock()
1373+
1374+
params := make([]database.WorkspaceBuildParameter, 0)
1375+
for _, param := range params {
1376+
if param.WorkspaceBuildID != workspaceBuildID {
1377+
continue
1378+
}
1379+
params = append(params, param)
1380+
}
1381+
return params, nil
1382+
}
1383+
13681384
func (q *fakeQuerier) GetWorkspaceBuildsCreatedAfter(_ context.Context, after time.Time) ([]database.WorkspaceBuild, error) {
13691385
q.mutex.RLock()
13701386
defer q.mutex.RUnlock()
@@ -1656,6 +1672,20 @@ func (q *fakeQuerier) GetTemplateVersionByTemplateIDAndName(_ context.Context, a
16561672
return database.TemplateVersion{}, sql.ErrNoRows
16571673
}
16581674

1675+
func (q *fakeQuerier) GetTemplateVersionParameters(_ context.Context, templateVersionID uuid.UUID) ([]database.TemplateVersionParameter, error) {
1676+
q.mutex.RLock()
1677+
defer q.mutex.RUnlock()
1678+
1679+
parameters := make([]database.TemplateVersionParameter, 0)
1680+
for _, param := range q.templateVersionParameters {
1681+
if param.TemplateVersionID != templateVersionID {
1682+
continue
1683+
}
1684+
parameters = append(parameters, param)
1685+
}
1686+
return parameters, nil
1687+
}
1688+
16591689
func (q *fakeQuerier) GetTemplateVersionByOrganizationAndName(_ context.Context, arg database.GetTemplateVersionByOrganizationAndNameParams) (database.TemplateVersion, error) {
16601690
q.mutex.RLock()
16611691
defer q.mutex.RUnlock()
@@ -2398,6 +2428,28 @@ func (q *fakeQuerier) InsertTemplateVersion(_ context.Context, arg database.Inse
23982428
return version, nil
23992429
}
24002430

2431+
func (q *fakeQuerier) InsertTemplateVersionParameter(_ context.Context, arg database.InsertTemplateVersionParameterParams) (database.TemplateVersionParameter, error) {
2432+
q.mutex.Lock()
2433+
defer q.mutex.Unlock()
2434+
2435+
//nolint:gosimple
2436+
param := database.TemplateVersionParameter{
2437+
TemplateVersionID: arg.TemplateVersionID,
2438+
Name: arg.Name,
2439+
Description: arg.Description,
2440+
Type: arg.Type,
2441+
Mutable: arg.Mutable,
2442+
DefaultValue: arg.DefaultValue,
2443+
Icon: arg.Icon,
2444+
Options: arg.Options,
2445+
ValidationRegex: arg.ValidationRegex,
2446+
ValidationMin: arg.ValidationMin,
2447+
ValidationMax: arg.ValidationMax,
2448+
}
2449+
q.templateVersionParameters = append(q.templateVersionParameters, param)
2450+
return param, nil
2451+
}
2452+
24012453
func (q *fakeQuerier) InsertProvisionerJobLogs(_ context.Context, arg database.InsertProvisionerJobLogsParams) ([]database.ProvisionerJobLog, error) {
24022454
q.mutex.Lock()
24032455
defer q.mutex.Unlock()
@@ -2723,6 +2775,20 @@ func (q *fakeQuerier) InsertWorkspaceBuild(_ context.Context, arg database.Inser
27232775
return workspaceBuild, nil
27242776
}
27252777

2778+
func (q *fakeQuerier) InsertWorkspaceBuildParameters(_ context.Context, arg database.InsertWorkspaceBuildParametersParams) error {
2779+
q.mutex.Lock()
2780+
defer q.mutex.Unlock()
2781+
2782+
for index, name := range arg.Name {
2783+
q.workspaceBuildParameters = append(q.workspaceBuildParameters, database.WorkspaceBuildParameter{
2784+
WorkspaceBuildID: arg.WorkspaceBuildID,
2785+
Name: name,
2786+
Value: arg.Value[index],
2787+
})
2788+
}
2789+
return nil
2790+
}
2791+
27262792
func (q *fakeQuerier) InsertWorkspaceApp(_ context.Context, arg database.InsertWorkspaceAppParams) (database.WorkspaceApp, error) {
27272793
q.mutex.Lock()
27282794
defer q.mutex.Unlock()

coderd/database/dump.sql

+56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DROP TABLE template_version_parameters;
2+
3+
DROP TABLE workspace_build_parameters;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
CREATE TABLE IF NOT EXISTS template_version_parameters (
2+
template_version_id uuid not null references template_versions (id) on delete cascade,
3+
name text not null,
4+
description text not null,
5+
type text not null,
6+
mutable boolean not null,
7+
default_value text not null,
8+
icon text not null,
9+
options jsonb not null default '[]'::jsonb,
10+
validation_regex text not null,
11+
validation_min integer not null,
12+
validation_max integer not null,
13+
unique (template_version_id, name)
14+
);
15+
16+
COMMENT ON COLUMN template_version_parameters.name IS 'Parameter name';
17+
COMMENT ON COLUMN template_version_parameters.description IS 'Parameter description';
18+
COMMENT ON COLUMN template_version_parameters.type IS 'Parameter type';
19+
COMMENT ON COLUMN template_version_parameters.mutable IS 'Is parameter mutable?';
20+
COMMENT ON COLUMN template_version_parameters.default_value IS 'Default value';
21+
COMMENT ON COLUMN template_version_parameters.icon IS 'Icon';
22+
COMMENT ON COLUMN template_version_parameters.options IS 'Additional options';
23+
COMMENT ON COLUMN template_version_parameters.validation_regex IS 'Validation: regex pattern';
24+
COMMENT ON COLUMN template_version_parameters.validation_min IS 'Validation: minimum length of value';
25+
COMMENT ON COLUMN template_version_parameters.validation_max IS 'Validation: maximum length of value';
26+
27+
CREATE TABLE IF NOT EXISTS workspace_build_parameters (
28+
workspace_build_id uuid not null references workspace_builds (id) on delete cascade,
29+
name text not null,
30+
value text not null,
31+
unique (workspace_build_id, name)
32+
);
33+
34+
COMMENT ON COLUMN workspace_build_parameters.name IS 'Parameter name';
35+
COMMENT ON COLUMN workspace_build_parameters.value IS 'Parameter value';

coderd/database/migrations/migrate_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ func TestMigrateUpWithFixtures(t *testing.T) {
239239
"group_members",
240240
"licenses",
241241
"replicas",
242+
"template_version_parameters",
243+
"workspace_build_parameters",
242244
}
243245
s := &tableStats{s: make(map[string]int)}
244246

0 commit comments

Comments
 (0)