mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd): add endpoint to list provisioner daemons (#16028)
Updates #15190 Updates #15084 Supersedes #15940
This commit is contained in:
@@ -440,7 +440,6 @@ func TestProvisionerDaemon_ProvisionerKey(t *testing.T) {
|
||||
clitest.Start(t, inv)
|
||||
pty.ExpectNoMatchBefore(ctx, "check entitlement", "starting provisioner daemon")
|
||||
pty.ExpectMatchContext(ctx, "matt-daemon")
|
||||
|
||||
var daemons []codersdk.ProvisionerDaemon
|
||||
require.Eventually(t, func() bool {
|
||||
daemons, err = client.OrganizationProvisionerDaemons(ctx, anotherOrg.ID, nil)
|
||||
|
||||
@@ -379,7 +379,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
|
||||
//
|
||||
// We may in future decide to scope provisioner daemons to organizations, so we'll keep the API
|
||||
// route as is.
|
||||
r.Route("/organizations/{organization}/provisionerdaemons", func(r chi.Router) {
|
||||
r.Route("/organizations/{organization}/provisionerdaemons/serve", func(r chi.Router) {
|
||||
r.Use(
|
||||
api.provisionerDaemonsEnabledMW,
|
||||
apiKeyMiddlewareOptional,
|
||||
@@ -393,8 +393,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
|
||||
httpmw.RequireAPIKeyOrProvisionerDaemonAuth(),
|
||||
httpmw.ExtractOrganizationParam(api.Database),
|
||||
)
|
||||
r.With(apiKeyMiddleware).Get("/", api.provisionerDaemons)
|
||||
r.With(apiKeyMiddlewareOptional).Get("/serve", api.provisionerDaemonServe)
|
||||
r.Get("/", api.provisionerDaemonServe)
|
||||
})
|
||||
r.Route("/templates/{template}/acl", func(r chi.Router) {
|
||||
r.Use(
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
|
||||
"cdr.dev/slog"
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
"github.com/coder/coder/v2/coderd/database/db2sdk"
|
||||
"github.com/coder/coder/v2/coderd/database/dbauthz"
|
||||
"github.com/coder/coder/v2/coderd/database/dbtime"
|
||||
"github.com/coder/coder/v2/coderd/httpapi"
|
||||
@@ -49,50 +48,6 @@ func (api *API) provisionerDaemonsEnabledMW(next http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary Get provisioner daemons
|
||||
// @ID get-provisioner-daemons
|
||||
// @Security CoderSessionToken
|
||||
// @Produce json
|
||||
// @Tags Enterprise
|
||||
// @Param organization path string true "Organization ID" format(uuid)
|
||||
// @Param tags query object false "Provisioner tags to filter by (JSON of the form {'tag1':'value1','tag2':'value2'})"
|
||||
// @Success 200 {array} codersdk.ProvisionerDaemon
|
||||
// @Router /organizations/{organization}/provisionerdaemons [get]
|
||||
func (api *API) provisionerDaemons(rw http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
org = httpmw.OrganizationParam(r)
|
||||
tagParam = r.URL.Query().Get("tags")
|
||||
tags = database.StringMap{}
|
||||
err = tags.Scan([]byte(tagParam))
|
||||
)
|
||||
|
||||
if tagParam != "" && err != nil {
|
||||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
||||
Message: "Invalid tags query parameter",
|
||||
Detail: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
daemons, err := api.Database.GetProvisionerDaemonsByOrganization(
|
||||
ctx,
|
||||
database.GetProvisionerDaemonsByOrganizationParams{
|
||||
OrganizationID: org.ID,
|
||||
WantTags: 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, db2sdk.List(daemons, db2sdk.ProvisionerDaemon))
|
||||
}
|
||||
|
||||
type provisiionerDaemonAuthResponse struct {
|
||||
keyID uuid.UUID
|
||||
orgID uuid.UUID
|
||||
|
||||
Reference in New Issue
Block a user