Skip to content

Commit 45fd5ac

Browse files
committed
feat(enterprise): add embeddable dashboard endpoint
- Add POST /api/v2/licenses/usage/embeddable-dashboard endpoint - Requires license read permission (admin-only) - Returns 404 when no license supports usage publishing - Validates dashboard URL is from metronome.com domain - Converts codersdk types to tallymansdk types - Includes Swagger documentation for API - Auto-generated API docs and TypeScript types
1 parent 196c188 commit 45fd5ac

File tree

8 files changed

+399
-0
lines changed

8 files changed

+399
-0
lines changed

coderd/apidoc/docs.go

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codersdk/licenses.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,34 @@ func (c *Client) DeleteLicense(ctx context.Context, id int32) error {
134134
}
135135
return nil
136136
}
137+
138+
// GetUsageEmbeddableDashboardRequest is a request to get an embeddable dashboard URL.
139+
type GetUsageEmbeddableDashboardRequest struct {
140+
Dashboard string `json:"dashboard"`
141+
ColorOverrides []DashboardColorOverride `json:"color_overrides,omitempty"`
142+
}
143+
144+
// DashboardColorOverride represents a color override for a dashboard.
145+
type DashboardColorOverride struct {
146+
Name string `json:"name"`
147+
Value string `json:"value"`
148+
}
149+
150+
// GetUsageEmbeddableDashboardResponse contains the embeddable dashboard URL.
151+
type GetUsageEmbeddableDashboardResponse struct {
152+
DashboardURL string `json:"dashboard_url"`
153+
}
154+
155+
// GetUsageEmbeddableDashboard retrieves an embeddable dashboard URL.
156+
func (c *Client) GetUsageEmbeddableDashboard(ctx context.Context, req GetUsageEmbeddableDashboardRequest) (GetUsageEmbeddableDashboardResponse, error) {
157+
res, err := c.Request(ctx, http.MethodPost, "/api/v2/licenses/usage/embeddable-dashboard", req)
158+
if err != nil {
159+
return GetUsageEmbeddableDashboardResponse{}, err
160+
}
161+
defer res.Body.Close()
162+
if res.StatusCode != http.StatusOK {
163+
return GetUsageEmbeddableDashboardResponse{}, ReadBodyAsError(res)
164+
}
165+
var resp GetUsageEmbeddableDashboardResponse
166+
return resp, json.NewDecoder(res.Body).Decode(&resp)
167+
}

docs/reference/api/enterprise.md

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/api/schemas.md

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
260260
r.Post("/", api.postLicense)
261261
r.Get("/", api.licenses)
262262
r.Delete("/{id}", api.deleteLicense)
263+
r.Post("/usage/embeddable-dashboard", api.postUsageEmbeddableDashboard)
263264
})
264265
r.Route("/applications/reconnecting-pty-signed-token", func(r chi.Router) {
265266
r.Use(apiKeyMiddleware)

0 commit comments

Comments
 (0)