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