Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 15fea1e

Browse files
committed
docs: apiroot, buildinfo, csp
1 parent 7c9002f commit 15fea1e

File tree

9 files changed

+405
-17
lines changed

9 files changed

+405
-17
lines changed

coderd/apidoc/docs.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ const docTemplate = `{
2525
"host": "{{.Host}}",
2626
"basePath": "{{.BasePath}}",
2727
"paths": {
28+
"/": {
29+
"get": {
30+
"security": [
31+
{
32+
"CoderSessionToken": []
33+
}
34+
],
35+
"produces": [
36+
"application/json"
37+
],
38+
"tags": [
39+
"General"
40+
],
41+
"summary": "API root handler",
42+
"operationId": "api-root-handler",
43+
"responses": {
44+
"200": {
45+
"description": "OK",
46+
"schema": {
47+
"$ref": "#/definitions/codersdk.Response"
48+
}
49+
}
50+
}
51+
}
52+
},
2853
"/applications/auth-redirect": {
2954
"get": {
3055
"security": [
@@ -116,6 +141,67 @@ const docTemplate = `{
116141
}
117142
}
118143
},
144+
"/buildinfo": {
145+
"post": {
146+
"security": [
147+
{
148+
"CoderSessionToken": []
149+
}
150+
],
151+
"produces": [
152+
"application/json"
153+
],
154+
"tags": [
155+
"General"
156+
],
157+
"summary": "Build info",
158+
"operationId": "build-info",
159+
"responses": {
160+
"200": {
161+
"description": "OK",
162+
"schema": {
163+
"$ref": "#/definitions/codersdk.BuildInfoResponse"
164+
}
165+
}
166+
}
167+
}
168+
},
169+
"/csp/reports": {
170+
"post": {
171+
"security": [
172+
{
173+
"CoderSessionToken": []
174+
}
175+
],
176+
"consumes": [
177+
"application/json"
178+
],
179+
"produces": [
180+
"text/plain"
181+
],
182+
"tags": [
183+
"General"
184+
],
185+
"summary": "Report CSP violations",
186+
"operationId": "report-csp-violations",
187+
"parameters": [
188+
{
189+
"description": "Violation report",
190+
"name": "request",
191+
"in": "body",
192+
"required": true,
193+
"schema": {
194+
"$ref": "#/definitions/coderd.cspViolation"
195+
}
196+
}
197+
],
198+
"responses": {
199+
"200": {
200+
"description": "OK"
201+
}
202+
}
203+
}
204+
},
119205
"/organizations/{organization-id}/templates/": {
120206
"post": {
121207
"security": [
@@ -730,6 +816,15 @@ const docTemplate = `{
730816
}
731817
},
732818
"definitions": {
819+
"coderd.cspViolation": {
820+
"type": "object",
821+
"properties": {
822+
"csp-report": {
823+
"type": "object",
824+
"additionalProperties": true
825+
}
826+
}
827+
},
733828
"codersdk.AuthorizationCheck": {
734829
"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.",
735830
"type": "object",
@@ -789,6 +884,19 @@ const docTemplate = `{
789884
"type": "boolean"
790885
}
791886
},
887+
"codersdk.BuildInfoResponse": {
888+
"type": "object",
889+
"properties": {
890+
"external_url": {
891+
"description": "ExternalURL is a URL referencing the current Coder version. For production\nbuilds, this will link directly to a release. For development builds, this\nwill link to a commit.",
892+
"type": "string"
893+
},
894+
"version": {
895+
"description": "Version returns the semantic version of the build.",
896+
"type": "string"
897+
}
898+
}
899+
},
792900
"codersdk.CreateParameterRequest": {
793901
"description": "CreateParameterRequest is a structure used to create a new parameter value for a scope.",
794902
"type": "object",

coderd/apidoc/swagger.json

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@
1717
},
1818
"basePath": "/api/v2",
1919
"paths": {
20+
"/": {
21+
"get": {
22+
"security": [
23+
{
24+
"CoderSessionToken": []
25+
}
26+
],
27+
"produces": ["application/json"],
28+
"tags": ["General"],
29+
"summary": "API root handler",
30+
"operationId": "api-root-handler",
31+
"responses": {
32+
"200": {
33+
"description": "OK",
34+
"schema": {
35+
"$ref": "#/definitions/codersdk.Response"
36+
}
37+
}
38+
}
39+
}
40+
},
2041
"/applications/auth-redirect": {
2142
"get": {
2243
"security": [
@@ -96,6 +117,57 @@
96117
}
97118
}
98119
},
120+
"/buildinfo": {
121+
"post": {
122+
"security": [
123+
{
124+
"CoderSessionToken": []
125+
}
126+
],
127+
"produces": ["application/json"],
128+
"tags": ["General"],
129+
"summary": "Build info",
130+
"operationId": "build-info",
131+
"responses": {
132+
"200": {
133+
"description": "OK",
134+
"schema": {
135+
"$ref": "#/definitions/codersdk.BuildInfoResponse"
136+
}
137+
}
138+
}
139+
}
140+
},
141+
"/csp/reports": {
142+
"post": {
143+
"security": [
144+
{
145+
"CoderSessionToken": []
146+
}
147+
],
148+
"consumes": ["application/json"],
149+
"produces": ["text/plain"],
150+
"tags": ["General"],
151+
"summary": "Report CSP violations",
152+
"operationId": "report-csp-violations",
153+
"parameters": [
154+
{
155+
"description": "Violation report",
156+
"name": "request",
157+
"in": "body",
158+
"required": true,
159+
"schema": {
160+
"$ref": "#/definitions/coderd.cspViolation"
161+
}
162+
}
163+
],
164+
"responses": {
165+
"200": {
166+
"description": "OK"
167+
}
168+
}
169+
}
170+
},
99171
"/organizations/{organization-id}/templates/": {
100172
"post": {
101173
"security": [
@@ -639,6 +711,15 @@
639711
}
640712
},
641713
"definitions": {
714+
"coderd.cspViolation": {
715+
"type": "object",
716+
"properties": {
717+
"csp-report": {
718+
"type": "object",
719+
"additionalProperties": true
720+
}
721+
}
722+
},
642723
"codersdk.AuthorizationCheck": {
643724
"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.",
644725
"type": "object",
@@ -693,6 +774,19 @@
693774
"type": "boolean"
694775
}
695776
},
777+
"codersdk.BuildInfoResponse": {
778+
"type": "object",
779+
"properties": {
780+
"external_url": {
781+
"description": "ExternalURL is a URL referencing the current Coder version. For production\nbuilds, this will link directly to a release. For development builds, this\nwill link to a commit.",
782+
"type": "string"
783+
},
784+
"version": {
785+
"description": "Version returns the semantic version of the build.",
786+
"type": "string"
787+
}
788+
}
789+
},
696790
"codersdk.CreateParameterRequest": {
697791
"description": "CreateParameterRequest is a structure used to create a new parameter value for a scope.",
698792
"type": "object",

coderd/apiroot.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package coderd
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/coder/coder/coderd/httpapi"
7+
"github.com/coder/coder/codersdk"
8+
)
9+
10+
// @Summary API root handler
11+
// @ID api-root-handler
12+
// @Security CoderSessionToken
13+
// @Produce json
14+
// @Tags General
15+
// @Success 200 {object} codersdk.Response
16+
// @Router / [get]
17+
func apiRoot(w http.ResponseWriter, r *http.Request) {
18+
httpapi.Write(r.Context(), w, http.StatusOK, codersdk.Response{
19+
//nolint:gocritic
20+
Message: "👋",
21+
})
22+
}

coderd/buildinfo.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package coderd
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/coder/coder/buildinfo"
7+
"github.com/coder/coder/coderd/httpapi"
8+
"github.com/coder/coder/codersdk"
9+
)
10+
11+
// @Summary Build info
12+
// @ID build-info
13+
// @Security CoderSessionToken
14+
// @Produce json
15+
// @Tags General
16+
// @Success 200 {object} codersdk.BuildInfoResponse
17+
// @Router /buildinfo [post]
18+
func buildInfo(rw http.ResponseWriter, r *http.Request) {
19+
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.BuildInfoResponse{
20+
ExternalURL: buildinfo.ExternalURL(),
21+
Version: buildinfo.Version(),
22+
})
23+
}

coderd/coderd.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -319,26 +319,12 @@ func New(options *Options) *API {
319319
// Specific routes can specify smaller limits.
320320
httpmw.RateLimit(options.APIRateLimit, time.Minute),
321321
)
322-
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
323-
httpapi.Write(r.Context(), w, http.StatusOK, codersdk.Response{
324-
//nolint:gocritic
325-
Message: "👋",
326-
})
327-
})
322+
r.Get("/", apiRoot)
328323
// All CSP errors will be logged
329324
r.Post("/csp/reports", api.logReportCSPViolations)
330325

331-
r.Route("/buildinfo", func(r chi.Router) {
332-
r.Get("/", func(rw http.ResponseWriter, r *http.Request) {
333-
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.BuildInfoResponse{
334-
ExternalURL: buildinfo.ExternalURL(),
335-
Version: buildinfo.Version(),
336-
})
337-
})
338-
})
339-
r.Route("/updatecheck", func(r chi.Router) {
340-
r.Get("/", api.updateCheck)
341-
})
326+
r.Get("/buildinfo", buildInfo)
327+
r.Get("/updatecheck", api.updateCheck)
342328
r.Route("/config", func(r chi.Router) {
343329
r.Use(apiKeyMiddleware)
344330
r.Get("/deployment", api.deploymentConfig)

coderd/csp.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ type cspViolation struct {
1414
Report map[string]interface{} `json:"csp-report"`
1515
}
1616

17+
// @Summary Report CSP violations
18+
// @ID report-csp-violations
19+
// @Security CoderSessionToken
20+
// @Accept json
21+
// @Produce text/plain
22+
// @Tags General
23+
// @Param request body cspViolation true "Violation report"
24+
// @Success 200
25+
// @Router /csp/reports [post]
26+
//
1727
// logReportCSPViolations will log all reported csp violations.
1828
func (api *API) logReportCSPViolations(rw http.ResponseWriter, r *http.Request) {
1929
ctx := r.Context()

0 commit comments

Comments
 (0)