mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
Just moved `rbac.Action` -> `policy.Action`. This is for the stacked PR to not have circular dependencies when doing autogen. Without this, the autogen can produce broken golang code, which prevents the autogen from compiling. So just avoiding circular dependencies. Doing this in it's own PR to reduce LoC diffs in the primary PR, since this has 0 functional changes.
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package coderd
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/coder/coder/v2/coderd/httpapi"
|
|
"github.com/coder/coder/v2/coderd/rbac"
|
|
"github.com/coder/coder/v2/coderd/rbac/policy"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
// @Summary Get deployment config
|
|
// @ID get-deployment-config
|
|
// @Security CoderSessionToken
|
|
// @Produce json
|
|
// @Tags General
|
|
// @Success 200 {object} codersdk.DeploymentConfig
|
|
// @Router /deployment/config [get]
|
|
func (api *API) deploymentValues(rw http.ResponseWriter, r *http.Request) {
|
|
if !api.Authorize(r, policy.ActionRead, rbac.ResourceDeploymentValues) {
|
|
httpapi.Forbidden(rw)
|
|
return
|
|
}
|
|
|
|
values, err := api.DeploymentValues.WithoutSecrets()
|
|
if err != nil {
|
|
httpapi.InternalServerError(rw, err)
|
|
return
|
|
}
|
|
|
|
httpapi.Write(
|
|
r.Context(), rw, http.StatusOK,
|
|
codersdk.DeploymentConfig{
|
|
Values: values,
|
|
Options: api.DeploymentOptions,
|
|
},
|
|
)
|
|
}
|
|
|
|
// @Summary Get deployment stats
|
|
// @ID get-deployment-stats
|
|
// @Security CoderSessionToken
|
|
// @Produce json
|
|
// @Tags General
|
|
// @Success 200 {object} codersdk.DeploymentStats
|
|
// @Router /deployment/stats [get]
|
|
func (api *API) deploymentStats(rw http.ResponseWriter, r *http.Request) {
|
|
if !api.Authorize(r, policy.ActionRead, rbac.ResourceDeploymentStats) {
|
|
httpapi.Forbidden(rw)
|
|
return
|
|
}
|
|
|
|
stats, ok := api.metricsCache.DeploymentStats()
|
|
if !ok {
|
|
httpapi.Write(r.Context(), rw, http.StatusBadRequest, codersdk.Response{
|
|
Message: "Deployment stats are still processing!",
|
|
})
|
|
return
|
|
}
|
|
|
|
httpapi.Write(r.Context(), rw, http.StatusOK, stats)
|
|
}
|
|
|
|
// @Summary Build info
|
|
// @ID build-info
|
|
// @Produce json
|
|
// @Tags General
|
|
// @Success 200 {object} codersdk.BuildInfoResponse
|
|
// @Router /buildinfo [get]
|
|
func buildInfoHandler(resp codersdk.BuildInfoResponse) http.HandlerFunc {
|
|
// This is in a handler so that we can generate API docs info.
|
|
return func(rw http.ResponseWriter, r *http.Request) {
|
|
httpapi.Write(r.Context(), rw, http.StatusOK, resp)
|
|
}
|
|
}
|
|
|
|
// @Summary SSH Config
|
|
// @ID ssh-config
|
|
// @Security CoderSessionToken
|
|
// @Produce json
|
|
// @Tags General
|
|
// @Success 200 {object} codersdk.SSHConfigResponse
|
|
// @Router /deployment/ssh [get]
|
|
func (api *API) sshConfig(rw http.ResponseWriter, r *http.Request) {
|
|
httpapi.Write(r.Context(), rw, http.StatusOK, api.SSHConfig)
|
|
}
|