Skip to content
18 changes: 18 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 97 additions & 8 deletions coderd/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,19 @@ func (api *API) templateVersion(rw http.ResponseWriter, r *http.Request) {
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(job), user))
schemas, err := api.Database.GetParameterSchemasByJobID(ctx, job.ID)
if errors.Is(err, sql.ErrNoRows) {
err = nil
}
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error listing parameter schemas.",
Detail: err.Error(),
})
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(job), user, schemas))
}

// @Summary Patch template version by ID
Expand Down Expand Up @@ -156,7 +168,19 @@ func (api *API) patchTemplateVersion(rw http.ResponseWriter, r *http.Request) {
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(updatedTemplateVersion, convertProvisionerJob(job), user))
schemas, err := api.Database.GetParameterSchemasByJobID(ctx, job.ID)
if errors.Is(err, sql.ErrNoRows) {
err = nil
}
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error listing parameter schemas.",
Detail: err.Error(),
})
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(updatedTemplateVersion, convertProvisionerJob(job), user, schemas))
}

// @Summary Cancel template version by ID
Expand Down Expand Up @@ -887,7 +911,18 @@ func (api *API) templateVersionsByTemplate(rw http.ResponseWriter, r *http.Reque
})
return err
}
apiVersions = append(apiVersions, convertTemplateVersion(version, convertProvisionerJob(job), user))
schemas, err := api.Database.GetParameterSchemasByJobID(ctx, job.ID)
if errors.Is(err, sql.ErrNoRows) {
err = nil
}
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error listing parameter schemas.",
Detail: err.Error(),
})
return err
}
apiVersions = append(apiVersions, convertTemplateVersion(version, convertProvisionerJob(job), user, schemas))
}

return nil
Expand Down Expand Up @@ -951,7 +986,19 @@ func (api *API) templateVersionByName(rw http.ResponseWriter, r *http.Request) {
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(job), user))
schemas, err := api.Database.GetParameterSchemasByJobID(ctx, job.ID)
if errors.Is(err, sql.ErrNoRows) {
err = nil
}
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error listing parameter schemas.",
Detail: err.Error(),
})
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(job), user, schemas))
}

// @Summary Get template version by organization, template, and name
Expand Down Expand Up @@ -1025,7 +1072,19 @@ func (api *API) templateVersionByOrganizationTemplateAndName(rw http.ResponseWri
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(job), user))
schemas, err := api.Database.GetParameterSchemasByJobID(ctx, job.ID)
if errors.Is(err, sql.ErrNoRows) {
err = nil
}
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error listing parameter schemas.",
Detail: err.Error(),
})
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(job), user, schemas))
}

// @Summary Get previous template version by organization, template, and name
Expand Down Expand Up @@ -1120,7 +1179,19 @@ func (api *API) previousTemplateVersionByOrganizationTemplateAndName(rw http.Res
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(previousTemplateVersion, convertProvisionerJob(job), user))
schemas, err := api.Database.GetParameterSchemasByJobID(ctx, job.ID)
if errors.Is(err, sql.ErrNoRows) {
err = nil
}
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error listing parameter schemas.",
Detail: err.Error(),
})
return
}

httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(previousTemplateVersion, convertProvisionerJob(job), user, schemas))
}

// @Summary Update active template version by template ID
Expand Down Expand Up @@ -1494,7 +1565,19 @@ func (api *API) postTemplateVersionsByOrganization(rw http.ResponseWriter, r *ht
return
}

httpapi.Write(ctx, rw, http.StatusCreated, convertTemplateVersion(templateVersion, convertProvisionerJob(provisionerJob), user))
schemas, err := api.Database.GetParameterSchemasByJobID(ctx, provisionerJob.ID)
if errors.Is(err, sql.ErrNoRows) {
err = nil
}
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error listing parameter schemas.",
Detail: err.Error(),
})
return
}

httpapi.Write(ctx, rw, http.StatusCreated, convertTemplateVersion(templateVersion, convertProvisionerJob(provisionerJob), user, schemas))
}

// templateVersionResources returns the workspace agent resources associated
Expand Down Expand Up @@ -1561,7 +1644,7 @@ func (api *API) templateVersionLogs(rw http.ResponseWriter, r *http.Request) {
api.provisionerJobLogs(rw, r, job)
}

func convertTemplateVersion(version database.TemplateVersion, job codersdk.ProvisionerJob, user database.User) codersdk.TemplateVersion {
func convertTemplateVersion(version database.TemplateVersion, job codersdk.ProvisionerJob, user database.User, schemas []database.ParameterSchema) codersdk.TemplateVersion {
createdBy := codersdk.User{
ID: user.ID,
Username: user.Username,
Expand All @@ -1572,6 +1655,11 @@ func convertTemplateVersion(version database.TemplateVersion, job codersdk.Provi
AvatarURL: user.AvatarURL.String,
}

var warnings []codersdk.TemplateVersionWarning
if len(schemas) > 0 {
warnings = append(warnings, codersdk.TemplateVersionWarningDeprecatedParameters)
}

return codersdk.TemplateVersion{
ID: version.ID,
TemplateID: &version.TemplateID.UUID,
Expand All @@ -1582,6 +1670,7 @@ func convertTemplateVersion(version database.TemplateVersion, job codersdk.Provi
Job: job,
Readme: version.Readme,
CreatedBy: createdBy,
Warnings: warnings,
}
}

Expand Down
43 changes: 43 additions & 0 deletions coderd/templateversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
require.Len(t, auditor.AuditLogs(), 2)
assert.Equal(t, database.AuditActionCreate, auditor.AuditLogs()[1].Action)
})

t.Run("Example", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
Expand Down Expand Up @@ -1453,3 +1454,45 @@ func TestTemplateVersionPatch(t *testing.T) {
require.Error(t, err)
})
}

func TestTemplateVersionWarnings(t *testing.T) {
t.Parallel()

client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

templateVersion := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: []*proto.Parse_Response{{
Type: &proto.Parse_Response_Complete{
Complete: &proto.Parse_Complete{
ParameterSchemas: []*proto.ParameterSchema{
{
AllowOverrideSource: true,
Name: "example",
Description: "description 1",
DefaultSource: &proto.ParameterSource{
Scheme: proto.ParameterSource_DATA,
Value: "tomato",
},
DefaultDestination: &proto.ParameterDestination{
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
},
},
},
},
},
}},
ProvisionApply: echo.ProvisionComplete,
ProvisionPlan: echo.ProvisionComplete,
})
coderdtest.AwaitTemplateVersionJob(t, client, templateVersion.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, templateVersion.ID)

templateVersion, err := client.TemplateVersion(ctx, template.ActiveVersionID)
require.NoError(t, err)

require.Contains(t, templateVersion.Warnings, codersdk.TemplateVersionWarningDeprecatedParameters)
}
8 changes: 8 additions & 0 deletions codersdk/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
"github.com/google/uuid"
)

type TemplateVersionWarning string

const (
TemplateVersionWarningDeprecatedParameters TemplateVersionWarning = "DEPRECATED_PARAMETERS"
)

// TemplateVersion represents a single version of a template.
type TemplateVersion struct {
ID uuid.UUID `json:"id" format:"uuid"`
Expand All @@ -22,6 +28,8 @@ type TemplateVersion struct {
Job ProvisionerJob `json:"job"`
Readme string `json:"readme"`
CreatedBy User `json:"created_by"`

Warnings []TemplateVersionWarning `json:"warnings,omitempty" enums:"DEPRECATED_PARAMETERS"`
}

type TemplateVersionGitAuth struct {
Expand Down
40 changes: 28 additions & 12 deletions docs/api/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -4106,23 +4106,25 @@ Parameter represents a set value for the scope.
"organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6",
"readme": "string",
"template_id": "c6d67e98-83ea-49f0-8812-e4abae2b68bc",
"updated_at": "2019-08-24T14:15:22Z"
"updated_at": "2019-08-24T14:15:22Z",
"warnings": ["DEPRECATED_PARAMETERS"]
}
```

### Properties

| Name | Type | Required | Restrictions | Description |
| ----------------- | -------------------------------------------------- | -------- | ------------ | ----------- |
| `created_at` | string | false | | |
| `created_by` | [codersdk.User](#codersdkuser) | false | | |
| `id` | string | false | | |
| `job` | [codersdk.ProvisionerJob](#codersdkprovisionerjob) | false | | |
| `name` | string | false | | |
| `organization_id` | string | false | | |
| `readme` | string | false | | |
| `template_id` | string | false | | |
| `updated_at` | string | false | | |
| Name | Type | Required | Restrictions | Description |
| ----------------- | --------------------------------------------------------------------------- | -------- | ------------ | ----------- |
| `created_at` | string | false | | |
| `created_by` | [codersdk.User](#codersdkuser) | false | | |
| `id` | string | false | | |
| `job` | [codersdk.ProvisionerJob](#codersdkprovisionerjob) | false | | |
| `name` | string | false | | |
| `organization_id` | string | false | | |
| `readme` | string | false | | |
| `template_id` | string | false | | |
| `updated_at` | string | false | | |
| `warnings` | array of [codersdk.TemplateVersionWarning](#codersdktemplateversionwarning) | false | | |

## codersdk.TemplateVersionGitAuth

Expand Down Expand Up @@ -4260,6 +4262,20 @@ Parameter represents a set value for the scope.
| `type` | `number` |
| `type` | `bool` |

## codersdk.TemplateVersionWarning

```json
"DEPRECATED_PARAMETERS"
```

### Properties

#### Enumerated Values

| Value |
| ----------------------- |
| `DEPRECATED_PARAMETERS` |

## codersdk.TokenConfig

```json
Expand Down
Loading