- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: get org scoped provisioners#13953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from7 commits
06214ee5c267258d9dbe511d1899de4b71b6ef3bc4f629752e04b331File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -21,7 +21,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" | ||
| @@ -65,22 +64,15 @@ func (api *API) provisionerDaemonsEnabledMW(next http.Handler) http.Handler { | ||
| // @Router /organizations/{organization}/provisionerdaemons [get] | ||
| func (api *API) provisionerDaemons(rw http.ResponseWriter, r *http.Request) { | ||
| ctx := r.Context() | ||
| org := httpmw.OrganizationParam(r) | ||
| daemons, err := api.Database.GetProvisionerDaemonsByOrganization(ctx, org.ID) | ||
| if err != nil { | ||
| if errors.Is(err, sql.ErrNoRows) { | ||
| httpapi.Write(ctx, rw, http.StatusOK, []codersdk.ProvisionerDaemon{}) | ||
| return | ||
| } | ||
f0ssel marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ | ||
| Message: "Internal error fetching provisioner daemons.", | ||
| Detail: err.Error(), | ||
| @@ -98,7 +90,7 @@ type provisionerDaemonAuth struct { | ||
| // authorize returns mutated tags and true if the given HTTP request is authorized to access the provisioner daemon | ||
| // protobuf API, and returns nil, false otherwise. | ||
| func (p *provisionerDaemonAuth) authorize(r *http.Request,orgID uuid.UUID,tags map[string]string) (map[string]string, bool) { | ||
| ctx := r.Context() | ||
| apiKey, ok := httpmw.APIKeyOptional(r) | ||
| if ok { | ||
| @@ -109,7 +101,7 @@ func (p *provisionerDaemonAuth) authorize(r *http.Request, tags map[string]strin | ||
| return tags, true | ||
| } | ||
| ua := httpmw.UserAuthorization(r) | ||
| if err := p.authorizer.Authorize(ctx, ua, policy.ActionCreate, rbac.ResourceProvisionerDaemon.InOrg(orgID)); err == nil { | ||
| // User is allowed to create provisioner daemons | ||
| return tags, true | ||
| } | ||
| @@ -185,7 +177,7 @@ func (api *API) provisionerDaemonServe(rw http.ResponseWriter, r *http.Request) | ||
| api.Logger.Warn(ctx, "unnamed provisioner daemon") | ||
| } | ||
| tags, authorized := api.provisionerDaemonAuth.authorize(r,organization.ID,tags) | ||
| if !authorized { | ||
| api.Logger.Warn(ctx, "unauthorized provisioner daemon serve request", slog.F("tags", tags)) | ||
| httpapi.Write(ctx, rw, http.StatusForbidden, | ||