grafana/pkg/api
Jo 466f8a1f5a
Teams: Move team API to own service (#76347)
* move team API to its own service

* remove uneeded import

* reshare pref api logic
2023-10-12 10:10:54 +02:00
..
apierrors Plugins: Move store and plugin dto to pluginsintegration (#74655) 2023-09-11 13:59:24 +02:00
avatar
datasource
dtos Azure: Settings for Azure AD Workload Identity (#75283) 2023-09-28 12:05:16 +01:00
frontendlogging Chore: use any rather than interface{} (#74066) 2023-08-30 18:46:47 +03:00
pluginproxy Tracing: Standardize on otel tracing (#75528) 2023-10-03 14:54:20 +02:00
response Instrumentation: Handle context.Canceled (#75867) 2023-10-10 12:28:39 +02:00
routing
static
README.md Chore: Split OSS and Enterprise OAPI Spec Generation (#75133) 2023-09-25 15:34:57 -04:00
accesscontrol.go LibraryPanels: Add RBAC support (#73475) 2023-10-12 00:30:50 +01:00
admin.go
admin_encryption.go
admin_provisioning.go
admin_provisioning_test.go
admin_test.go
admin_users.go Authn: Prevent empty username and email during sync (#76330) 2023-10-11 14:27:43 +02:00
admin_users_test.go
alerting.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
annotations.go Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112) 2023-10-09 16:07:28 +02:00
annotations_test.go Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112) 2023-10-09 16:07:28 +02:00
api.go Teams: Move team API to own service (#76347) 2023-10-12 10:10:54 +02:00
apikey.go
basic_auth.go
basic_auth_test.go
common_test.go Teams: Move team API to own service (#76347) 2023-10-12 10:10:54 +02:00
dashboard.go chore: remove unused feature flag (#74460) 2023-09-06 11:25:44 -04:00
dashboard_permission.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
dashboard_permission_test.go
dashboard_snapshot.go Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112) 2023-10-09 16:07:28 +02:00
dashboard_snapshot_test.go
dashboard_test.go Plugins: Move store and plugin dto to pluginsintegration (#74655) 2023-09-11 13:59:24 +02:00
dataproxy.go Chore: use any rather than interface{} (#74066) 2023-08-30 18:46:47 +03:00
datasources.go Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112) 2023-10-09 16:07:28 +02:00
datasources_test.go Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112) 2023-10-09 16:07:28 +02:00
fakes.go
featuremgmt.go Feature Toggles API: Trigger webhook call when updating (#75254) 2023-09-25 19:11:24 +01:00
featuremgmt_test.go Feature Toggles API: Trigger webhook call when updating (#75254) 2023-09-25 19:11:24 +01:00
folder.go Identity: Port folder library to identity.Requester (#76105) 2023-10-06 15:02:34 +02:00
folder_bench_test.go Chore: Replace mock guardian with the actual one in folder API benchmarks (#76231) 2023-10-10 13:31:55 +03:00
folder_permission.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
folder_permission_test.go
folder_test.go Nested folders: Fix folder hierarchy in folder responses (#74516) 2023-09-08 10:43:41 +03:00
frontend_logging.go
frontend_logging_test.go Chore: use any rather than interface{} (#74066) 2023-08-30 18:46:47 +03:00
frontend_metrics.go
frontendsettings.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
frontendsettings_test.go Plugins: Move store and plugin dto to pluginsintegration (#74655) 2023-09-11 13:59:24 +02:00
grafana_com_proxy.go
health.go
health_test.go HealthCheck: show enterprise commit (#75242) 2023-09-22 08:17:10 -03:00
http_server.go Teams: Move team API to own service (#76347) 2023-10-12 10:10:54 +02:00
http_server_test.go
index.go Navigation: Split admin into subsections behind `navAdminSubsections` feature toggle (#76280) 2023-10-11 14:37:36 +01:00
login.go Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112) 2023-10-09 16:07:28 +02:00
login_oauth.go
login_oauth_test.go
login_test.go
metrics.go Chore: Remove plugincontext.ErrPluginNotFound (#74997) 2023-09-25 13:10:47 +03:00
metrics_test.go Chore: Refactor backend plugin errors (#74928) 2023-09-25 11:56:03 +02:00
openapi3.go Chore: use any rather than interface{} (#74066) 2023-08-30 18:46:47 +03:00
org.go
org_invite.go Chore: use any rather than interface{} (#74066) 2023-08-30 18:46:47 +03:00
org_invite_test.go
org_test.go
org_users.go User: Support `sort` query param for user and org user, search endpoints (#75229) 2023-09-28 10:16:18 +02:00
org_users_test.go
password.go
playlist.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
plugin_dashboards.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
plugin_dashboards_test.go
plugin_metrics.go Chore: Refactor backend plugin errors (#74928) 2023-09-25 11:56:03 +02:00
plugin_metrics_test.go Chore: Refactor backend plugin errors (#74928) 2023-09-25 11:56:03 +02:00
plugin_proxy.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
plugin_proxy_test.go
plugin_resource.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
plugin_resource_test.go Plugins: Refactoring: Implement plugin instrumentation as a middleware (#76011) 2023-10-09 14:12:57 +02:00
plugins.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
plugins_test.go Plugins: Move store and plugin dto to pluginsintegration (#74655) 2023-09-11 13:59:24 +02:00
preferences.go Teams: Move team API to own service (#76347) 2023-10-12 10:10:54 +02:00
preferences_test.go Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112) 2023-10-09 16:07:28 +02:00
quota.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
quota_test.go
render.go Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112) 2023-10-09 16:07:28 +02:00
search.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
short_url.go Auth: Unfurl OrgID in pkg/api to allow using identity.Requester interface (#76108) 2023-10-06 11:34:36 +02:00
short_url_test.go
signup.go Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112) 2023-10-09 16:07:28 +02:00
swagger.go Chore: use any rather than interface{} (#74066) 2023-08-30 18:46:47 +03:00
swagger_responses.go
swagger_tags.json Browse Dashboards: Update docs to remove reference to `General` folder (#74528) 2023-09-08 03:57:16 +01:00
user.go Authn: Prevent empty username and email during sync (#76330) 2023-10-11 14:27:43 +02:00
user_test.go Chore: use any rather than interface{} (#74066) 2023-08-30 18:46:47 +03:00
user_token.go
user_token_test.go
utils.go

README.md

OpenAPI specifications

Since version 8.4, HTTP API details are specified using OpenAPI v2. Starting from version 9.1, there is also an OpenAPI v3 specification (generated by the v2 one using this script).

OpenAPI annotations

The OpenAPI v2 specification is generated automatically from the annotated Go code using go-swagger which scans the source code for annotation rules. Refer to this getting started guide for getting familiar with the toolkit.

Developers modifying the HTTP API endpoints need to make sure to add the necessary annotations so that their changes are reflected into the generated specifications.

Example of endpoint annotation

The following route defines a PATCH endpoint under the /serviceaccounts/{serviceAccountId} path with tag service_accounts (used for grouping together several routes) and operation ID updateServiceAccount (used for uniquely identifying routes and associate parameters and response with them).


// swagger:route PATCH /serviceaccounts/{serviceAccountId} service_accounts updateServiceAccount
//
// # Update service account
//
// Required permissions (See note in the [introduction](https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#service-account-api) for an explanation):
// action: `serviceaccounts:write` scope: `serviceaccounts:id:1` (single service account)
//
// Responses:
// 200: updateServiceAccountResponse
// 400: badRequestError
// 401: unauthorisedError
// 403: forbiddenError
// 404: notFoundError
// 500: internalServerError

The go-swagger can discover such annotations by scanning any code imported by pkg/server but by convention we place the endpoint annotations above the endpoint definition.

Example of endpoint parameters

The following struct defines the route parameters for the updateServiceAccount endpoint. The route expects:

  • a path parameter denoting the service account identifier and
  • a body parameter with the new values for the specific service account

// swagger:parameters updateServiceAccount
type UpdateServiceAccountParams struct {
	// in:path
	ServiceAccountId int64 `json:"serviceAccountId"`
	// in:body
	Body serviceaccounts.UpdateServiceAccountForm
}

Example of endpoint response

The following struct defines the response for the updateServiceAccount endpoint in case of a successful 200 response.


// swagger:response updateServiceAccountResponse
type UpdateServiceAccountResponse struct {
	// in:body
	Body struct {
		Message        string                                    `json:"message"`
		ID             int64                                     `json:"id"`
		Name           string                                    `json:"name"`
		ServiceAccount *serviceaccounts.ServiceAccountProfileDTO `json:"serviceaccount"`
	}
}

OpenAPI generation

Developers can re-create the OpenAPI v2 and v3 specifications using the following command:


make swagger-clean && make openapi3-gen

They can observe its output into the public/api-merged.json and public/openapi3.json files.

Finally, they can browser and try out both the OpenAPI v2 and v3 via the Swagger UI editor (served by the grafana server) by navigating to /swagger-ui and /openapi3 respectivally.