Skip to content

docs: api root, buildinfo, csp #5493

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 31 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
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
135 changes: 135 additions & 0 deletions coderd/apidoc/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/": {
"get": {
"produces": [
"application/json"
],
"tags": [
"General"
],
"summary": "API root handler",
"operationId": "api-root-handler",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/codersdk.Response"
}
}
}
}
},
"/applications/auth-redirect": {
"get": {
"security": [
Expand Down Expand Up @@ -116,6 +136,62 @@ const docTemplate = `{
}
}
},
"/buildinfo": {
"get": {
"produces": [
"application/json"
],
"tags": [
"General"
],
"summary": "Build info",
"operationId": "build-info",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/codersdk.BuildInfoResponse"
}
}
}
}
},
"/csp/reports": {
"post": {
"security": [
{
"CoderSessionToken": []
}
],
"consumes": [
"application/json"
],
"produces": [
"text/plain"
],
"tags": [
"General"
],
"summary": "Report CSP violations",
"operationId": "report-csp-violations",
"parameters": [
{
"description": "Violation report",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/coderd.cspViolation"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/organizations/{organization-id}/templates/": {
"post": {
"security": [
Expand Down Expand Up @@ -352,6 +428,26 @@ const docTemplate = `{
}
}
},
"/updatecheck": {
"get": {
"produces": [
"application/json"
],
"tags": [
"General"
],
"summary": "Update check",
"operationId": "update-check",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/codersdk.UpdateCheckResponse"
}
}
}
}
},
"/users/{user}/workspace/{workspacename}": {
"get": {
"security": [
Expand Down Expand Up @@ -730,6 +826,15 @@ const docTemplate = `{
}
},
"definitions": {
"coderd.cspViolation": {
"type": "object",
"properties": {
"csp-report": {
"type": "object",
"additionalProperties": true
}
}
},
"codersdk.AuthorizationCheck": {
"description": "AuthorizationCheck is used to check if the currently authenticated user (or the specified user) can do a given action to a given set of objects.",
"type": "object",
Expand Down Expand Up @@ -789,6 +894,19 @@ const docTemplate = `{
"type": "boolean"
}
},
"codersdk.BuildInfoResponse": {
"type": "object",
"properties": {
"external_url": {
"description": "ExternalURL is a URL referencing the current Coder version.\nFor production builds, this will link directly to a release. For development builds, this will link to a commit.",
"type": "string"
},
"version": {
"description": "Version returns the semantic version of the build.",
"type": "string"
}
}
},
"codersdk.CreateParameterRequest": {
"description": "CreateParameterRequest is a structure used to create a new parameter value for a scope.",
"type": "object",
Expand Down Expand Up @@ -1066,6 +1184,23 @@ const docTemplate = `{
}
}
},
"codersdk.UpdateCheckResponse": {
"type": "object",
"properties": {
"current": {
"description": "Current indicates whether the server version is the same as the latest.",
"type": "boolean"
},
"url": {
"description": "URL to download the latest release of Coder.",
"type": "string"
},
"version": {
"description": "Version is the semantic version for the latest release of Coder.",
"type": "string"
}
}
},
"codersdk.UpdateWorkspaceAutostartRequest": {
"type": "object",
"properties": {
Expand Down
117 changes: 117 additions & 0 deletions coderd/apidoc/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@
},
"basePath": "/api/v2",
"paths": {
"/": {
"get": {
"produces": ["application/json"],
"tags": ["General"],
"summary": "API root handler",
"operationId": "api-root-handler",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/codersdk.Response"
}
}
}
}
},
"/applications/auth-redirect": {
"get": {
"security": [
Expand Down Expand Up @@ -96,6 +112,52 @@
}
}
},
"/buildinfo": {
"get": {
"produces": ["application/json"],
"tags": ["General"],
"summary": "Build info",
"operationId": "build-info",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/codersdk.BuildInfoResponse"
}
}
}
}
},
"/csp/reports": {
"post": {
"security": [
{
"CoderSessionToken": []
}
],
"consumes": ["application/json"],
"produces": ["text/plain"],
"tags": ["General"],
"summary": "Report CSP violations",
"operationId": "report-csp-violations",
"parameters": [
{
"description": "Violation report",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/coderd.cspViolation"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/organizations/{organization-id}/templates/": {
"post": {
"security": [
Expand Down Expand Up @@ -306,6 +368,22 @@
}
}
},
"/updatecheck": {
"get": {
"produces": ["application/json"],
"tags": ["General"],
"summary": "Update check",
"operationId": "update-check",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/codersdk.UpdateCheckResponse"
}
}
}
}
},
"/users/{user}/workspace/{workspacename}": {
"get": {
"security": [
Expand Down Expand Up @@ -639,6 +717,15 @@
}
},
"definitions": {
"coderd.cspViolation": {
"type": "object",
"properties": {
"csp-report": {
"type": "object",
"additionalProperties": true
}
}
},
"codersdk.AuthorizationCheck": {
"description": "AuthorizationCheck is used to check if the currently authenticated user (or the specified user) can do a given action to a given set of objects.",
"type": "object",
Expand Down Expand Up @@ -693,6 +780,19 @@
"type": "boolean"
}
},
"codersdk.BuildInfoResponse": {
"type": "object",
"properties": {
"external_url": {
"description": "ExternalURL is a URL referencing the current Coder version.\nFor production builds, this will link directly to a release. For development builds, this will link to a commit.",
"type": "string"
},
"version": {
"description": "Version returns the semantic version of the build.",
"type": "string"
}
}
},
"codersdk.CreateParameterRequest": {
"description": "CreateParameterRequest is a structure used to create a new parameter value for a scope.",
"type": "object",
Expand Down Expand Up @@ -960,6 +1060,23 @@
}
}
},
"codersdk.UpdateCheckResponse": {
"type": "object",
"properties": {
"current": {
"description": "Current indicates whether the server version is the same as the latest.",
"type": "boolean"
},
"url": {
"description": "URL to download the latest release of Coder.",
"type": "string"
},
"version": {
"description": "Version is the semantic version for the latest release of Coder.",
"type": "string"
}
}
},
"codersdk.UpdateWorkspaceAutostartRequest": {
"type": "object",
"properties": {
Expand Down
21 changes: 21 additions & 0 deletions coderd/apiroot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package coderd

import (
"net/http"

"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/codersdk"
)

// @Summary API root handler
// @ID api-root-handler
// @Produce json
// @Tags General
// @Success 200 {object} codersdk.Response
// @Router / [get]
func apiRoot(w http.ResponseWriter, r *http.Request) {
httpapi.Write(r.Context(), w, http.StatusOK, codersdk.Response{
//nolint:gocritic
Message: "👋",
})
}
22 changes: 22 additions & 0 deletions coderd/buildinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package coderd

import (
"net/http"

"github.com/coder/coder/buildinfo"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/codersdk"
)

// @Summary Build info
// @ID build-info
// @Produce json
// @Tags General
// @Success 200 {object} codersdk.BuildInfoResponse
// @Router /buildinfo [get]
func buildInfo(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.BuildInfoResponse{
ExternalURL: buildinfo.ExternalURL(),
Version: buildinfo.Version(),
})
}
Loading