The API reference is generated from Swagger comments and struct tags, and several `enums:"..."` tags narrowed a named enum type, so the docs omitted values the server returns. For example, `User.status` listed only `active` and `suspended`, not `dormant`, and `TemplateVersion.warnings` listed `DEPRECATED_PARAMETERS`, which is not a value of the type. Remove 34 `enums` tags that narrow or duplicate a named type so the referenced type's full value list is used. Tags that describe an intentional subset stay: ACL role fields (which omit the `""` deleted sentinel used only in update requests), `APIKey.scope`, and plain-string fields. `Template.provisioner` keeps its tag because `.swaggo` replaces `ProvisionerType` with `string`. Also fix enum defects that break code generators: - The provisioner jobs and daemons `status` query parameters listed their enum twice (Swagger 2.0 requires unique `enum` items) or with the wrong type. Both are now `[]codersdk.ProvisionerJobStatus` and `[]codersdk.ProvisionerDaemonStatus`, matching what each handler parses, including comma-separated values. The daemons route previously documented job statuses, which the handler rejects with a 500. - Replace the `_` zero placeholder of `WatchErrorCode` with `iota + 1`, so the spec no longer lists 0 or `x-enum-varnames: ["_", ...]`. Wire values are unchanged. Where the narrowed tag hid values the server returns, the SDK type now includes them: `LoginTypeOAuth2ProviderApp`, `BuildReasonAutodelete`, and `MissingTemplateParameter` widen the generated TypeScript unions. The dashboard attributes `autodelete` builds to Coder like other system builds. `APIKey.login_type` and `AuthorizationCheck.action` set explicit examples so the generated samples stay representative. `TestSwaggerEnumsNotNarrowed` fails when a property's enum list drops values of its named type (other than the 15 allowlisted intentional subsets), lists a value the type lacks, or repeats a value. Part of DOCS-1122, split from #30121. --- 🤖 Built with AI assistance.
115 lines
4.2 KiB
Go
115 lines
4.2 KiB
Go
package coderd
|
|
|
|
import (
|
|
"database/sql"
|
|
"net/http"
|
|
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
"github.com/coder/coder/v2/coderd/database/db2sdk"
|
|
"github.com/coder/coder/v2/coderd/database/sdk2db"
|
|
"github.com/coder/coder/v2/coderd/httpapi"
|
|
"github.com/coder/coder/v2/coderd/httpmw"
|
|
"github.com/coder/coder/v2/coderd/provisionerdserver"
|
|
"github.com/coder/coder/v2/coderd/rbac"
|
|
"github.com/coder/coder/v2/coderd/rbac/policy"
|
|
"github.com/coder/coder/v2/coderd/util/slice"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
// @Summary Get provisioner daemons
|
|
// @ID get-provisioner-daemons
|
|
// @Security CoderSessionToken
|
|
// @Produce json
|
|
// @Tags Provisioning
|
|
// @Param organization path string true "Organization ID" format(uuid)
|
|
// @Param limit query int false "Page limit"
|
|
// @Param ids query []string false "Filter results by provisioner daemon IDs (UUIDs)"
|
|
// @Param status query []codersdk.ProvisionerDaemonStatus false "Filter results by status"
|
|
// @Param tags query string false "Provisioner tags to filter by (JSON of the form `{'tag1':'value1','tag2':'value2'}`)"
|
|
// @Success 200 {array} codersdk.ProvisionerDaemon
|
|
// @Router /api/v2/organizations/{organization}/provisionerdaemons [get]
|
|
func (api *API) provisionerDaemons(rw http.ResponseWriter, r *http.Request) {
|
|
var (
|
|
ctx = r.Context()
|
|
org = httpmw.OrganizationParam(r)
|
|
)
|
|
|
|
// This endpoint returns information about provisioner jobs.
|
|
// For now, only owners and template admins can access provisioner jobs.
|
|
if !api.Authorize(r, policy.ActionRead, rbac.ResourceProvisionerJobs.InOrg(org.ID)) {
|
|
httpapi.ResourceNotFound(rw)
|
|
return
|
|
}
|
|
|
|
qp := r.URL.Query()
|
|
p := httpapi.NewQueryParamParser()
|
|
limit := p.PositiveInt32(qp, 50, "limit")
|
|
ids := p.UUIDs(qp, nil, "ids")
|
|
tags := p.JSONStringMap(qp, database.StringMap{}, "tags")
|
|
includeOffline := p.NullableBoolean(qp, sql.NullBool{}, "offline")
|
|
statuses := p.ProvisionerDaemonStatuses(qp, []codersdk.ProvisionerDaemonStatus{}, "status")
|
|
maxAge := p.Duration(qp, 0, "max_age")
|
|
p.ErrorExcessParams(qp)
|
|
if len(p.Errors) > 0 {
|
|
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
|
Message: "Invalid query parameters.",
|
|
Validations: p.Errors,
|
|
})
|
|
return
|
|
}
|
|
|
|
dbStatuses := sdk2db.ProvisionerDaemonStatuses(statuses)
|
|
|
|
daemons, err := api.Database.GetProvisionerDaemonsWithStatusByOrganization(
|
|
ctx,
|
|
database.GetProvisionerDaemonsWithStatusByOrganizationParams{
|
|
OrganizationID: org.ID,
|
|
StaleIntervalMS: provisionerdserver.StaleInterval.Milliseconds(),
|
|
Limit: sql.NullInt32{Int32: limit, Valid: limit > 0},
|
|
Offline: includeOffline,
|
|
Statuses: dbStatuses,
|
|
MaxAgeMs: sql.NullInt64{Int64: maxAge.Milliseconds(), Valid: maxAge > 0},
|
|
IDs: ids,
|
|
Tags: tags,
|
|
},
|
|
)
|
|
if err != nil {
|
|
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
|
|
Message: "Internal error fetching provisioner daemons.",
|
|
Detail: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
httpapi.Write(ctx, rw, http.StatusOK, slice.List(daemons, func(dbDaemon database.GetProvisionerDaemonsWithStatusByOrganizationRow) codersdk.ProvisionerDaemon {
|
|
pd := db2sdk.ProvisionerDaemon(dbDaemon.ProvisionerDaemon)
|
|
var currentJob, previousJob *codersdk.ProvisionerDaemonJob
|
|
if dbDaemon.CurrentJobID.Valid {
|
|
currentJob = &codersdk.ProvisionerDaemonJob{
|
|
ID: dbDaemon.CurrentJobID.UUID,
|
|
Status: codersdk.ProvisionerJobStatus(dbDaemon.CurrentJobStatus.ProvisionerJobStatus),
|
|
TemplateName: dbDaemon.CurrentJobTemplateName,
|
|
TemplateIcon: dbDaemon.CurrentJobTemplateIcon,
|
|
TemplateDisplayName: dbDaemon.CurrentJobTemplateDisplayName,
|
|
}
|
|
}
|
|
if dbDaemon.PreviousJobID.Valid {
|
|
previousJob = &codersdk.ProvisionerDaemonJob{
|
|
ID: dbDaemon.PreviousJobID.UUID,
|
|
Status: codersdk.ProvisionerJobStatus(dbDaemon.PreviousJobStatus.ProvisionerJobStatus),
|
|
TemplateName: dbDaemon.PreviousJobTemplateName,
|
|
TemplateIcon: dbDaemon.PreviousJobTemplateIcon,
|
|
TemplateDisplayName: dbDaemon.PreviousJobTemplateDisplayName,
|
|
}
|
|
}
|
|
|
|
// Add optional fields.
|
|
pd.KeyName = &dbDaemon.KeyName
|
|
pd.Status = new(codersdk.ProvisionerDaemonStatus(dbDaemon.Status))
|
|
pd.CurrentJob = currentJob
|
|
pd.PreviousJob = previousJob
|
|
|
|
return pd
|
|
}))
|
|
}
|