2022-10-21 17:08:23 -05:00
|
|
|
package coderd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2023-08-18 13:55:43 -05:00
|
|
|
"github.com/coder/coder/v2/coderd/httpapi"
|
|
|
|
|
"github.com/coder/coder/v2/coderd/rbac"
|
2024-05-15 09:46:35 -05:00
|
|
|
"github.com/coder/coder/v2/coderd/rbac/policy"
|
2023-08-18 13:55:43 -05:00
|
|
|
"github.com/coder/coder/v2/codersdk"
|
2022-10-21 17:08:23 -05:00
|
|
|
)
|
|
|
|
|
|
2023-01-03 19:21:10 +01:00
|
|
|
// @Summary Get deployment config
|
|
|
|
|
// @ID get-deployment-config
|
|
|
|
|
// @Security CoderSessionToken
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Tags General
|
|
|
|
|
// @Success 200 {object} codersdk.DeploymentConfig
|
2023-03-08 21:05:45 -06:00
|
|
|
// @Router /deployment/config [get]
|
2023-03-07 15:10:01 -06:00
|
|
|
func (api *API) deploymentValues(rw http.ResponseWriter, r *http.Request) {
|
2024-05-15 11:09:42 -05:00
|
|
|
if !api.Authorize(r, policy.ActionRead, rbac.ResourceDeploymentConfig) {
|
2022-10-21 17:08:23 -05:00
|
|
|
httpapi.Forbidden(rw)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-07 15:10:01 -06:00
|
|
|
values, err := api.DeploymentValues.WithoutSecrets()
|
|
|
|
|
if err != nil {
|
|
|
|
|
httpapi.InternalServerError(rw, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
httpapi.Write(
|
|
|
|
|
r.Context(), rw, http.StatusOK,
|
|
|
|
|
codersdk.DeploymentConfig{
|
|
|
|
|
Values: values,
|
2023-09-29 12:04:28 -05:00
|
|
|
Options: api.DeploymentOptions,
|
2023-03-07 15:10:01 -06:00
|
|
|
},
|
|
|
|
|
)
|
2022-10-21 17:08:23 -05:00
|
|
|
}
|
2023-03-08 21:05:45 -06:00
|
|
|
|
|
|
|
|
// @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) {
|
2024-05-15 09:46:35 -05:00
|
|
|
if !api.Authorize(r, policy.ActionRead, rbac.ResourceDeploymentStats) {
|
2023-03-08 21:05:45 -06:00
|
|
|
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)
|
|
|
|
|
}
|
2023-03-16 13:03:37 -05:00
|
|
|
|
|
|
|
|
// @Summary Build info
|
|
|
|
|
// @ID build-info
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Tags General
|
|
|
|
|
// @Success 200 {object} codersdk.BuildInfoResponse
|
|
|
|
|
// @Router /buildinfo [get]
|
2024-04-29 20:50:49 -04:00
|
|
|
func buildInfoHandler(resp codersdk.BuildInfoResponse) http.HandlerFunc {
|
|
|
|
|
// This is in a handler so that we can generate API docs info.
|
2023-04-17 14:57:21 -05:00
|
|
|
return func(rw http.ResponseWriter, r *http.Request) {
|
2024-04-29 20:50:49 -04:00
|
|
|
httpapi.Write(r.Context(), rw, http.StatusOK, resp)
|
2023-04-17 14:57:21 -05:00
|
|
|
}
|
2023-03-16 13:03:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @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)
|
|
|
|
|
}
|