mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: implement provisioner auth middleware and proper org params (#12330)
* feat: provisioner auth in mw to allow ExtractOrg Step to enable org scoped provisioner daemons * chore: handle default org handling for provisioner daemons
This commit is contained in:
@ -53,15 +53,30 @@ func ExtractOrganizationParam(db database.Store) func(http.Handler) http.Handler
|
||||
}
|
||||
|
||||
var organization database.Organization
|
||||
var err error
|
||||
// Try by name or uuid.
|
||||
id, err := uuid.Parse(arg)
|
||||
if err == nil {
|
||||
organization, err = db.GetOrganizationByID(ctx, id)
|
||||
var dbErr error
|
||||
|
||||
// If the name is exactly "default", then we fetch the default
|
||||
// organization. This is a special case to make it easier
|
||||
// for single org deployments.
|
||||
//
|
||||
// arg == uuid.Nil.String() should be a temporary workaround for
|
||||
// legacy provisioners that don't provide an organization ID.
|
||||
// This prevents a breaking change.
|
||||
// TODO: This change was added March 2024. Nil uuid returning the
|
||||
// default org should be removed some number of months after
|
||||
// that date.
|
||||
if arg == codersdk.DefaultOrganization || arg == uuid.Nil.String() {
|
||||
organization, dbErr = db.GetDefaultOrganization(ctx)
|
||||
} else {
|
||||
organization, err = db.GetOrganizationByName(ctx, arg)
|
||||
// Try by name or uuid.
|
||||
id, err := uuid.Parse(arg)
|
||||
if err == nil {
|
||||
organization, dbErr = db.GetOrganizationByID(ctx, id)
|
||||
} else {
|
||||
organization, dbErr = db.GetOrganizationByName(ctx, arg)
|
||||
}
|
||||
}
|
||||
if httpapi.Is404Error(err) {
|
||||
if httpapi.Is404Error(dbErr) {
|
||||
httpapi.ResourceNotFound(rw)
|
||||
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
|
||||
Message: fmt.Sprintf("Organization %q not found.", arg),
|
||||
@ -69,10 +84,10 @@ func ExtractOrganizationParam(db database.Store) func(http.Handler) http.Handler
|
||||
})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if dbErr != nil {
|
||||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
|
||||
Message: fmt.Sprintf("Internal error fetching organization %q.", arg),
|
||||
Detail: err.Error(),
|
||||
Detail: dbErr.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user