Skip to content

feat: RBAC provisionerdaemons and parameters #1755

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge remote-tracking branch 'origin/main' into stevenmasley/rbac_pro…
…visioners
  • Loading branch information
Emyrk committed May 26, 2022
commit ff3c261f372594eb2ea181079fe503d2af1343b3
15 changes: 6 additions & 9 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ func New(options *Options) *API {
apiKeyMiddleware,
authRolesMiddleware,
)
r.Get("/", a.provisionerDaemons)
r.Get("/", api.provisionerDaemons)
})
r.Route("/organizations/{organization}", func(r chi.Router) {
r.Use(
apiKeyMiddleware,
httpmw.ExtractOrganizationParam(options.Database),
authRolesMiddleware,
)
r.Get("/", a.organization)
r.Post("/templateversions", a.postTemplateVersionsByOrganization)
r.Get("/", api.organization)
r.Post("/templateversions", api.postTemplateVersionsByOrganization)
r.Route("/templates", func(r chi.Router) {
r.Post("/", api.postTemplateByOrganization)
r.Get("/", api.templatesByOrganization)
Expand All @@ -172,12 +172,9 @@ func New(options *Options) *API {
})
})
r.Route("/parameters/{scope}/{id}", func(r chi.Router) {
r.Use(
apiKeyMiddleware,
authRolesMiddleware,
)
r.Post("/", a.postParameter)
r.Get("/", a.parameters)
r.Use(apiKeyMiddleware, authRolesMiddleware)
r.Post("/", api.postParameter)
r.Get("/", api.parameters)
r.Route("/{name}", func(r chi.Router) {
r.Delete("/", api.deleteParameter)
})
Expand Down
8 changes: 3 additions & 5 deletions coderd/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import (
"fmt"
"net/http"

"github.com/coder/coder/coderd/rbac"

"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"golang.org/x/xerrors"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/coderd/parameter"
"github.com/coder/coder/coderd/rbac"
"github.com/coder/coder/codersdk"
)

func (api *api) postParameter(rw http.ResponseWriter, r *http.Request) {
func (api *API) postParameter(rw http.ResponseWriter, r *http.Request) {
scope, scopeID, valid := readScopeAndID(rw, r)
if !valid {
return
Expand All @@ -35,7 +34,6 @@ func (api *api) postParameter(rw http.ResponseWriter, r *http.Request) {
if !httpapi.Read(rw, r, &createRequest) {
return
}

_, err := api.Database.GetParameterValueByScopeAndName(r.Context(), database.GetParameterValueByScopeAndNameParams{
Scope: scope,
ScopeID: scopeID,
Expand Down Expand Up @@ -203,7 +201,7 @@ func convertParameterValue(parameterValue database.ParameterValue) codersdk.Para
// is equivalent to updating/reading the associated resource.
// This means "parameters" are not a new resource, but an extension of existing
// ones.
func (api *api) parameterRBACResource(rw http.ResponseWriter, r *http.Request, scope database.ParameterScope, scopeID uuid.UUID) (rbac.Objecter, bool) {
func (api *API) parameterRBACResource(rw http.ResponseWriter, r *http.Request, scope database.ParameterScope, scopeID uuid.UUID) (rbac.Objecter, bool) {
ctx := r.Context()
var resource rbac.Objecter
var err error
Expand Down
2 changes: 1 addition & 1 deletion coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
sdkproto "github.com/coder/coder/provisionersdk/proto"
)

func (api *api) provisionerDaemons(rw http.ResponseWriter, r *http.Request) {
func (api *API) provisionerDaemons(rw http.ResponseWriter, r *http.Request) {
daemons, err := api.Database.GetProvisionerDaemons(r.Context())
if errors.Is(err, sql.ErrNoRows) {
err = nil
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.