From 4a1d418157afd99ba536836d6f29e8e503987674 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Wed, 25 Jan 2023 15:29:10 -0500 Subject: [PATCH] Kindsys: Simpler PascalCase name handling (#62150) --- .../core/serviceaccount/schema-reference.md | 4 +- kinds/serviceaccount/serviceaccount_kind.cue | 2 +- packages/grafana-schema/src/index.gen.ts | 6 +- .../x/serviceaccount_types.gen.ts | 4 +- pkg/codegen/jenny_gotypes.go | 3 +- pkg/kinds/dashboard/dashboard_types_gen.go | 242 +++++++++--------- pkg/kinds/playlist/playlist_types_gen.go | 36 +-- .../preferences/preferences_types_gen.go | 14 +- .../serviceaccount/serviceaccount_kind_gen.go | 12 +- .../serviceaccount_types_gen.go | 4 +- pkg/kinds/team/team_types_gen.go | 2 +- pkg/kindsys/report.go | 2 +- pkg/kindsys/report.json | 4 +- pkg/plugins/plugindef/gen.go | 5 +- pkg/plugins/plugindef/plugindef_types_gen.go | 199 +++++++------- pkg/registry/corekind/base_gen.go | 4 +- 16 files changed, 269 insertions(+), 274 deletions(-) diff --git a/docs/sources/developers/kinds/core/serviceaccount/schema-reference.md b/docs/sources/developers/kinds/core/serviceaccount/schema-reference.md index e668f64aa2f..7a9b487e6d1 100644 --- a/docs/sources/developers/kinds/core/serviceaccount/schema-reference.md +++ b/docs/sources/developers/kinds/core/serviceaccount/schema-reference.md @@ -2,11 +2,11 @@ keywords: - grafana - schema -title: Serviceaccount kind +title: ServiceAccount kind --- > Both documentation generation and kinds schemas are in active development and subject to change without prior notice. -# Serviceaccount kind +# ServiceAccount kind ## Maturity: merged ## Version: 0.0 diff --git a/kinds/serviceaccount/serviceaccount_kind.cue b/kinds/serviceaccount/serviceaccount_kind.cue index befc567bc9a..afa0f818394 100644 --- a/kinds/serviceaccount/serviceaccount_kind.cue +++ b/kinds/serviceaccount/serviceaccount_kind.cue @@ -1,6 +1,6 @@ package kind -name: "Serviceaccount" +name: "ServiceAccount" maturity: "merged" lineage: seqs: [ diff --git a/packages/grafana-schema/src/index.gen.ts b/packages/grafana-schema/src/index.gen.ts index 500568d6555..f0b02135a78 100644 --- a/packages/grafana-schema/src/index.gen.ts +++ b/packages/grafana-schema/src/index.gen.ts @@ -101,14 +101,14 @@ export type { QueryHistoryPreference } from './raw/preferences/x/preferences_types.gen'; -// Raw generated types from Serviceaccount kind. +// Raw generated types from ServiceAccount kind. export type { - Serviceaccount, + ServiceAccount, OrgRole } from './raw/serviceaccount/x/serviceaccount_types.gen'; // Raw generated enums and default consts from serviceaccount kind. -export { defaultServiceaccount } from './raw/serviceaccount/x/serviceaccount_types.gen'; +export { defaultServiceAccount } from './raw/serviceaccount/x/serviceaccount_types.gen'; // Raw generated types from Team kind. export type { Team } from './raw/team/x/team_types.gen'; diff --git a/packages/grafana-schema/src/raw/serviceaccount/x/serviceaccount_types.gen.ts b/packages/grafana-schema/src/raw/serviceaccount/x/serviceaccount_types.gen.ts index 4abfa4f7cbc..a06b06ff31f 100644 --- a/packages/grafana-schema/src/raw/serviceaccount/x/serviceaccount_types.gen.ts +++ b/packages/grafana-schema/src/raw/serviceaccount/x/serviceaccount_types.gen.ts @@ -13,7 +13,7 @@ */ export type OrgRole = ('Admin' | 'Editor' | 'Viewer'); -export interface Serviceaccount { +export interface ServiceAccount { /** * AccessControl metadata associated with a given resource. */ @@ -66,6 +66,6 @@ export interface Serviceaccount { updated?: number; } -export const defaultServiceaccount: Partial = { +export const defaultServiceAccount: Partial = { teams: [], }; diff --git a/pkg/codegen/jenny_gotypes.go b/pkg/codegen/jenny_gotypes.go index 85acc8b0508..57061ab4095 100644 --- a/pkg/codegen/jenny_gotypes.go +++ b/pkg/codegen/jenny_gotypes.go @@ -24,7 +24,8 @@ func (j GoTypesJenny) Generate(sfg SchemaForGen) (*codejen.File, error) { b, err := gocode.GenerateTypesOpenAPI(sfg.Schema, &gocode.TypeConfigOpenAPI{ // TODO will need to account for sanitizing e.g. dashes here at some point Config: &openapi.Config{ - Group: sfg.IsGroup, + Group: sfg.IsGroup, + RootName: sfg.Name, Config: &copenapi.Config{ ExpandReferences: j.ExpandReferences, }, diff --git a/pkg/kinds/dashboard/dashboard_types_gen.go b/pkg/kinds/dashboard/dashboard_types_gen.go index 2e65c507032..d44b14ad79f 100644 --- a/pkg/kinds/dashboard/dashboard_types_gen.go +++ b/pkg/kinds/dashboard/dashboard_types_gen.go @@ -10,6 +10,22 @@ package dashboard +// Defines values for Style. +const ( + StyleDark Style = "dark" + + StyleLight Style = "light" +) + +// Defines values for Timezone. +const ( + TimezoneBrowser Timezone = "browser" + + TimezoneEmpty Timezone = "" + + TimezoneUtc Timezone = "utc" +) + // Defines values for CursorSync. const ( CursorSyncN0 CursorSync = 0 @@ -151,22 +167,6 @@ const ( VariableTypeTextbox VariableType = "textbox" ) -// Defines values for Style. -const ( - StyleDark Style = "dark" - - StyleLight Style = "light" -) - -// Defines values for Timezone. -const ( - TimezoneBrowser Timezone = "browser" - - TimezoneEmpty Timezone = "" - - TimezoneUtc Timezone = "utc" -) - // TODO docs // FROM: AnnotationQuery in grafana-data/src/types/annotations.ts type AnnotationQuery struct { @@ -207,6 +207,111 @@ type AnnotationTarget struct { Type string `json:"type"` } +// Dashboard defines model for Dashboard. +type Dashboard struct { + // TODO docs + Annotations *struct { + List *[]AnnotationQuery `json:"list,omitempty"` + } `json:"annotations,omitempty"` + + // Description of dashboard. + Description *string `json:"description,omitempty"` + + // Whether a dashboard is editable or not. + Editable bool `json:"editable"` + + // The month that the fiscal year starts on. 0 = January, 11 = December + FiscalYearStartMonth *int `json:"fiscalYearStartMonth,omitempty"` + GnetId *string `json:"gnetId,omitempty"` + + // 0 for no shared crosshair or tooltip (default). + // 1 for shared crosshair. + // 2 for shared crosshair AND shared tooltip. + GraphTooltip CursorSync `json:"graphTooltip"` + + // Unique numeric identifier for the dashboard. + // TODO must isolate or remove identifiers local to a Grafana instance...? + Id *int64 `json:"id,omitempty"` + + // TODO docs + Links *[]Link `json:"links,omitempty"` + + // TODO docs + LiveNow *bool `json:"liveNow,omitempty"` + Panels *[]interface{} `json:"panels,omitempty"` + + // TODO docs + Refresh *interface{} `json:"refresh,omitempty"` + + // Version of the current dashboard data + Revision int `json:"revision"` + + // Version of the JSON schema, incremented each time a Grafana update brings + // changes to said schema. + // TODO this is the existing schema numbering system. It will be replaced by Thema's themaVersion + SchemaVersion int `json:"schemaVersion"` + + // TODO docs + Snapshot *Snapshot `json:"snapshot,omitempty"` + + // Theme of dashboard. + Style Style `json:"style"` + + // Tags associated with dashboard. + Tags *[]string `json:"tags,omitempty"` + + // TODO docs + Templating *struct { + List *[]VariableModel `json:"list,omitempty"` + } `json:"templating,omitempty"` + + // Time range for dashboard, e.g. last 6 hours, last 7 days, etc + Time *struct { + From string `json:"from"` + To string `json:"to"` + } `json:"time,omitempty"` + + // TODO docs + // TODO this appears to be spread all over in the frontend. Concepts will likely need tidying in tandem with schema changes + Timepicker *struct { + // Whether timepicker is collapsed or not. + Collapse bool `json:"collapse"` + + // Whether timepicker is enabled or not. + Enable bool `json:"enable"` + + // Whether timepicker is visible or not. + Hidden bool `json:"hidden"` + + // Selectable intervals for auto-refresh. + RefreshIntervals []string `json:"refresh_intervals"` + + // TODO docs + TimeOptions []string `json:"time_options"` + } `json:"timepicker,omitempty"` + + // Timezone of dashboard, + Timezone *Timezone `json:"timezone,omitempty"` + + // Title of dashboard. + Title *string `json:"title,omitempty"` + + // Unique dashboard identifier that can be generated by anyone. string (8-40) + Uid *string `json:"uid,omitempty"` + + // Version of the dashboard, incremented each time the dashboard is updated. + Version *int `json:"version,omitempty"` + + // TODO docs + WeekStart *string `json:"weekStart,omitempty"` +} + +// Theme of dashboard. +type Style string + +// Timezone of dashboard, +type Timezone string + // 0 for no shared crosshair or tooltip (default). // 1 for shared crosshair. // 2 for shared crosshair AND shared tooltip. @@ -670,108 +775,3 @@ type VariableModel struct { // TODO docs // TODO this implies some wider pattern/discriminated union, probably? type VariableType string - -// Dashboard defines model for dashboard. -type Dashboard struct { - // TODO docs - Annotations *struct { - List *[]AnnotationQuery `json:"list,omitempty"` - } `json:"annotations,omitempty"` - - // Description of dashboard. - Description *string `json:"description,omitempty"` - - // Whether a dashboard is editable or not. - Editable bool `json:"editable"` - - // The month that the fiscal year starts on. 0 = January, 11 = December - FiscalYearStartMonth *int `json:"fiscalYearStartMonth,omitempty"` - GnetId *string `json:"gnetId,omitempty"` - - // 0 for no shared crosshair or tooltip (default). - // 1 for shared crosshair. - // 2 for shared crosshair AND shared tooltip. - GraphTooltip CursorSync `json:"graphTooltip"` - - // Unique numeric identifier for the dashboard. - // TODO must isolate or remove identifiers local to a Grafana instance...? - Id *int64 `json:"id,omitempty"` - - // TODO docs - Links *[]Link `json:"links,omitempty"` - - // TODO docs - LiveNow *bool `json:"liveNow,omitempty"` - Panels *[]interface{} `json:"panels,omitempty"` - - // TODO docs - Refresh *interface{} `json:"refresh,omitempty"` - - // Version of the current dashboard data - Revision int `json:"revision"` - - // Version of the JSON schema, incremented each time a Grafana update brings - // changes to said schema. - // TODO this is the existing schema numbering system. It will be replaced by Thema's themaVersion - SchemaVersion int `json:"schemaVersion"` - - // TODO docs - Snapshot *Snapshot `json:"snapshot,omitempty"` - - // Theme of dashboard. - Style Style `json:"style"` - - // Tags associated with dashboard. - Tags *[]string `json:"tags,omitempty"` - - // TODO docs - Templating *struct { - List *[]VariableModel `json:"list,omitempty"` - } `json:"templating,omitempty"` - - // Time range for dashboard, e.g. last 6 hours, last 7 days, etc - Time *struct { - From string `json:"from"` - To string `json:"to"` - } `json:"time,omitempty"` - - // TODO docs - // TODO this appears to be spread all over in the frontend. Concepts will likely need tidying in tandem with schema changes - Timepicker *struct { - // Whether timepicker is collapsed or not. - Collapse bool `json:"collapse"` - - // Whether timepicker is enabled or not. - Enable bool `json:"enable"` - - // Whether timepicker is visible or not. - Hidden bool `json:"hidden"` - - // Selectable intervals for auto-refresh. - RefreshIntervals []string `json:"refresh_intervals"` - - // TODO docs - TimeOptions []string `json:"time_options"` - } `json:"timepicker,omitempty"` - - // Timezone of dashboard, - Timezone *Timezone `json:"timezone,omitempty"` - - // Title of dashboard. - Title *string `json:"title,omitempty"` - - // Unique dashboard identifier that can be generated by anyone. string (8-40) - Uid *string `json:"uid,omitempty"` - - // Version of the dashboard, incremented each time the dashboard is updated. - Version *int `json:"version,omitempty"` - - // TODO docs - WeekStart *string `json:"weekStart,omitempty"` -} - -// Theme of dashboard. -type Style string - -// Timezone of dashboard, -type Timezone string diff --git a/pkg/kinds/playlist/playlist_types_gen.go b/pkg/kinds/playlist/playlist_types_gen.go index c8f3608e883..b46a38b247b 100644 --- a/pkg/kinds/playlist/playlist_types_gen.go +++ b/pkg/kinds/playlist/playlist_types_gen.go @@ -19,6 +19,24 @@ const ( ItemTypeDashboardByUid ItemType = "dashboard_by_uid" ) +// Playlist defines model for Playlist. +type Playlist struct { + // Interval sets the time between switching views in a playlist. + // FIXME: Is this based on a standardized format or what options are available? Can datemath be used? + Interval string `json:"interval"` + + // The ordered list of items that the playlist will iterate over. + // FIXME! This should not be optional, but changing it makes the godegen awkward + Items *[]Item `json:"items,omitempty"` + + // Name of the playlist. + Name string `json:"name"` + + // Unique playlist identifier. Generated on creation, either by the + // creator of the playlist of by the application. + Uid string `json:"uid"` +} + // Item defines model for Item. type Item struct { // Title is an unused property -- it will be removed in the future @@ -40,21 +58,3 @@ type Item struct { // Type of the item. type ItemType string - -// Playlist defines model for playlist. -type Playlist struct { - // Interval sets the time between switching views in a playlist. - // FIXME: Is this based on a standardized format or what options are available? Can datemath be used? - Interval string `json:"interval"` - - // The ordered list of items that the playlist will iterate over. - // FIXME! This should not be optional, but changing it makes the godegen awkward - Items *[]Item `json:"items,omitempty"` - - // Name of the playlist. - Name string `json:"name"` - - // Unique playlist identifier. Generated on creation, either by the - // creator of the playlist of by the application. - Uid string `json:"uid"` -} diff --git a/pkg/kinds/preferences/preferences_types_gen.go b/pkg/kinds/preferences/preferences_types_gen.go index 9ab65c6c388..1d5d7909e28 100644 --- a/pkg/kinds/preferences/preferences_types_gen.go +++ b/pkg/kinds/preferences/preferences_types_gen.go @@ -10,13 +10,7 @@ package preferences -// QueryHistoryPreference defines model for QueryHistoryPreference. -type QueryHistoryPreference struct { - // one of: '' | 'query' | 'starred'; - HomeTab *string `json:"homeTab,omitempty"` -} - -// Preferences defines model for preferences. +// Preferences defines model for Preferences. type Preferences struct { // UID for the home dashboard HomeDashboardUID *string `json:"homeDashboardUID,omitempty"` @@ -35,3 +29,9 @@ type Preferences struct { // day of the week (sunday, monday, etc) WeekStart *string `json:"weekStart,omitempty"` } + +// QueryHistoryPreference defines model for QueryHistoryPreference. +type QueryHistoryPreference struct { + // one of: '' | 'query' | 'starred'; + HomeTab *string `json:"homeTab,omitempty"` +} diff --git a/pkg/kinds/serviceaccount/serviceaccount_kind_gen.go b/pkg/kinds/serviceaccount/serviceaccount_kind_gen.go index 097d21c12c1..8f3e18add3f 100644 --- a/pkg/kinds/serviceaccount/serviceaccount_kind_gen.go +++ b/pkg/kinds/serviceaccount/serviceaccount_kind_gen.go @@ -23,9 +23,9 @@ const rootrel string = "kinds/serviceaccount" // TODO standard generated docs type Kind struct { - lin thema.ConvergentLineage[*Serviceaccount] + lin thema.ConvergentLineage[*ServiceAccount] jcodec vmux.Codec - valmux vmux.ValueMux[*Serviceaccount] + valmux vmux.ValueMux[*ServiceAccount] decl kindsys.Decl[kindsys.CoreProperties] } @@ -50,7 +50,7 @@ func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) { // Get the thema.Schema that the meta says is in the current version (which // codegen ensures is always the latest) cursch := thema.SchemaP(lin, k.decl.Properties.CurrentVersion) - tsch, err := thema.BindType[*Serviceaccount](cursch, &Serviceaccount{}) + tsch, err := thema.BindType[*ServiceAccount](cursch, &ServiceAccount{}) if err != nil { // Should be unreachable, modulo bugs in the Thema->Go code generator return nil, err @@ -78,18 +78,18 @@ func (k *Kind) Lineage() thema.Lineage { } // TODO standard generated docs -func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Serviceaccount] { +func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*ServiceAccount] { return k.lin } // JSONValueMux is a version multiplexer that maps a []byte containing JSON data -// at any schematized dashboard version to an instance of Serviceaccount. +// at any schematized dashboard version to an instance of ServiceAccount. // // Validation and translation errors emitted from this func will identify the // input bytes as "dashboard.json". // // This is a thin wrapper around Thema's [vmux.ValueMux]. -func (k *Kind) JSONValueMux(b []byte) (*Serviceaccount, thema.TranslationLacunas, error) { +func (k *Kind) JSONValueMux(b []byte) (*ServiceAccount, thema.TranslationLacunas, error) { return k.valmux(b) } diff --git a/pkg/kinds/serviceaccount/serviceaccount_types_gen.go b/pkg/kinds/serviceaccount/serviceaccount_types_gen.go index c539cf24d1b..9e80405af2f 100644 --- a/pkg/kinds/serviceaccount/serviceaccount_types_gen.go +++ b/pkg/kinds/serviceaccount/serviceaccount_types_gen.go @@ -22,8 +22,8 @@ const ( // OrgRole is a Grafana Organization Role which can be 'Viewer', 'Editor', 'Admin'. type OrgRole string -// Serviceaccount defines model for serviceaccount. -type Serviceaccount struct { +// ServiceAccount defines model for ServiceAccount. +type ServiceAccount struct { // AccessControl metadata associated with a given resource. AccessControl map[string]bool `json:"accessControl,omitempty"` diff --git a/pkg/kinds/team/team_types_gen.go b/pkg/kinds/team/team_types_gen.go index 4c58ef6a557..c619d03ab8d 100644 --- a/pkg/kinds/team/team_types_gen.go +++ b/pkg/kinds/team/team_types_gen.go @@ -24,7 +24,7 @@ const ( // Permission defines model for Permission. type Permission int -// Team defines model for team. +// Team defines model for Team. type Team struct { // AccessControl metadata associated with a given resource. AccessControl map[string]bool `json:"accessControl,omitempty"` diff --git a/pkg/kindsys/report.go b/pkg/kindsys/report.go index 97f12d894fd..b853abbe97d 100644 --- a/pkg/kindsys/report.go +++ b/pkg/kindsys/report.go @@ -71,7 +71,7 @@ var plannedCoreKinds = []string{ "Folder", "DataSource", "APIKey", - "Serviceaccount", + "ServiceAccount", "Thumb", "Query", "QueryHistory", diff --git a/pkg/kindsys/report.json b/pkg/kindsys/report.json index 2f97bb2c5dd..ce70bb1ffce 100644 --- a/pkg/kindsys/report.json +++ b/pkg/kindsys/report.json @@ -1345,9 +1345,9 @@ }, "machineName": "serviceaccount", "maturity": "merged", - "name": "Serviceaccount", + "name": "ServiceAccount", "pluralMachineName": "serviceaccounts", - "pluralName": "Serviceaccounts" + "pluralName": "ServiceAccounts" }, "statpanelcfg": { "category": "composable", diff --git a/pkg/plugins/plugindef/gen.go b/pkg/plugins/plugindef/gen.go index d3a7333282b..c72795da2e9 100644 --- a/pkg/plugins/plugindef/gen.go +++ b/pkg/plugins/plugindef/gen.go @@ -14,7 +14,6 @@ import ( "cuelang.org/go/cue/cuecontext" "github.com/dave/dst" - "github.com/dave/dst/dstutil" "github.com/grafana/codejen" "github.com/grafana/grafana/pkg/codegen" "github.com/grafana/grafana/pkg/cuectx" @@ -62,9 +61,7 @@ func (j *jennytypego) JennyName() string { } func (j *jennytypego) Generate(lin thema.Lineage) (*codejen.File, error) { - f, err := codegen.GoTypesJenny{ApplyFuncs: []dstutil.ApplyFunc{ - codegen.PrefixReplacer("Plugindef", "PluginDef"), - }}.Generate(codegen.SchemaForGen{ + f, err := codegen.GoTypesJenny{}.Generate(codegen.SchemaForGen{ Name: "PluginDef", Schema: lin.Latest(), IsGroup: false, diff --git a/pkg/plugins/plugindef/plugindef_types_gen.go b/pkg/plugins/plugindef/plugindef_types_gen.go index a38336c20a4..7b2f793eef3 100644 --- a/pkg/plugins/plugindef/plugindef_types_gen.go +++ b/pkg/plugins/plugindef/plugindef_types_gen.go @@ -55,19 +55,7 @@ const ( IncludeTypeSecretsmanager IncludeType = "secretsmanager" ) -// Defines values for ReleaseState. -const ( - ReleaseStateAlpha ReleaseState = "alpha" - - ReleaseStateBeta ReleaseState = "beta" - - ReleaseStateDeprecated ReleaseState = "deprecated" - - ReleaseStateStable ReleaseState = "stable" -) - // Defines values for Category. -// Defines values for PlugindefCategory. const ( CategoryCloud Category = "cloud" @@ -87,7 +75,6 @@ const ( ) // Defines values for Type. -// Defines values for PlugindefType. const ( TypeApp Type = "app" @@ -100,6 +87,17 @@ const ( TypeSecretsmanager Type = "secretsmanager" ) +// Defines values for ReleaseState. +const ( + ReleaseStateAlpha ReleaseState = "alpha" + + ReleaseStateBeta ReleaseState = "beta" + + ReleaseStateDeprecated ReleaseState = "deprecated" + + ReleaseStateStable ReleaseState = "stable" +) + // BasicRole is a Grafana basic role, which can be 'Viewer', 'Editor', 'Admin' or 'Grafana Admin'. // With RBAC, the Admin basic role inherits its default permissions from the Editor basic role which // in turn inherits them from the Viewer basic role. @@ -274,94 +272,7 @@ type Permission struct { Scope *string `json:"scope,omitempty"` } -// ReleaseState indicates release maturity state of a plugin. -type ReleaseState string - -// Role describes an RBAC role which allows grouping multiple related permissions on the plugin, -// each of which has an action and an optional scope. -// Example: the role 'Schedules Reader' bundles permissions to view all schedules of the plugin. -type Role struct { - Description string `json:"description"` - Name string `json:"name"` - Permissions []Permission `json:"permissions"` -} - -// RoleRegistration describes an RBAC role and its assignments to basic roles. -// It organizes related RBAC permissions on the plugin into a role and defines which basic roles -// will get them by default. -// Example: the role 'Schedules Reader' bundles permissions to view all schedules of the plugin -// which will be granted to Admins by default. -type RoleRegistration struct { - // Default assignment of the role to Grafana basic roles (Viewer, Editor, Admin, Grafana Admin) - // The Admin basic role inherits its default permissions from the Editor basic role which in turn - // inherits them from the Viewer basic role. - Grants []BasicRole `json:"grants"` - - // Role describes an RBAC role which allows grouping multiple related permissions on the plugin, - // each of which has an action and an optional scope. - // Example: the role 'Schedules Reader' bundles permissions to view all schedules of the plugin. - Role Role `json:"role"` -} - -// A proxy route used in datasource plugins for plugin authentication -// and adding headers to HTTP requests made by the plugin. -// For more information, refer to [Authentication for data source -// plugins](https://grafana.com/docs/grafana/latest/developers/plugins/authentication/). -type Route struct { - // For data source plugins. Route headers set the body content and - // length to the proxied request. - Body *map[string]interface{} `json:"body,omitempty"` - - // For data source plugins. Route headers adds HTTP headers to the - // proxied request. - Headers *[]Header `json:"headers,omitempty"` - - // TODO docs - // TODO should this really be separate from TokenAuth? - JwtTokenAuth *JWTTokenAuth `json:"jwtTokenAuth,omitempty"` - - // For data source plugins. Route method matches the HTTP verb - // like GET or POST. Multiple methods can be provided as a - // comma-separated list. - Method *string `json:"method,omitempty"` - - // For data source plugins. The route path that is replaced by the - // route URL field when proxying the call. - Path *string `json:"path,omitempty"` - ReqRole *string `json:"reqRole,omitempty"` - ReqSignedIn *bool `json:"reqSignedIn,omitempty"` - - // TODO docs - TokenAuth *TokenAuth `json:"tokenAuth,omitempty"` - - // For data source plugins. Route URL is where the request is - // proxied to. - Url *string `json:"url,omitempty"` - UrlParams *[]URLParam `json:"urlParams,omitempty"` -} - -// TODO docs -type TokenAuth struct { - // Parameters for the token authentication request. - Params map[string]string `json:"params"` - - // The list of scopes that your application should be granted - // access to. - Scopes *[]string `json:"scopes,omitempty"` - - // URL to fetch the authentication token. - Url *string `json:"url,omitempty"` -} - -// URLParam describes query string parameters for -// a url in a plugin route -type URLParam struct { - Content string `json:"content"` - Name string `json:"name"` -} - -// Plugindef defines model for plugindef. -// PluginDef defines model for plugindef. +// PluginDef defines model for PluginDef. type PluginDef struct { // For data source plugins, if the plugin supports alerting. Alerting *bool `json:"alerting,omitempty"` @@ -496,3 +407,89 @@ type Category string // type indicates which type of Grafana plugin this is, of the defined // set of Grafana plugin types. type Type string + +// ReleaseState indicates release maturity state of a plugin. +type ReleaseState string + +// Role describes an RBAC role which allows grouping multiple related permissions on the plugin, +// each of which has an action and an optional scope. +// Example: the role 'Schedules Reader' bundles permissions to view all schedules of the plugin. +type Role struct { + Description string `json:"description"` + Name string `json:"name"` + Permissions []Permission `json:"permissions"` +} + +// RoleRegistration describes an RBAC role and its assignments to basic roles. +// It organizes related RBAC permissions on the plugin into a role and defines which basic roles +// will get them by default. +// Example: the role 'Schedules Reader' bundles permissions to view all schedules of the plugin +// which will be granted to Admins by default. +type RoleRegistration struct { + // Default assignment of the role to Grafana basic roles (Viewer, Editor, Admin, Grafana Admin) + // The Admin basic role inherits its default permissions from the Editor basic role which in turn + // inherits them from the Viewer basic role. + Grants []BasicRole `json:"grants"` + + // Role describes an RBAC role which allows grouping multiple related permissions on the plugin, + // each of which has an action and an optional scope. + // Example: the role 'Schedules Reader' bundles permissions to view all schedules of the plugin. + Role Role `json:"role"` +} + +// A proxy route used in datasource plugins for plugin authentication +// and adding headers to HTTP requests made by the plugin. +// For more information, refer to [Authentication for data source +// plugins](https://grafana.com/docs/grafana/latest/developers/plugins/authentication/). +type Route struct { + // For data source plugins. Route headers set the body content and + // length to the proxied request. + Body *map[string]interface{} `json:"body,omitempty"` + + // For data source plugins. Route headers adds HTTP headers to the + // proxied request. + Headers *[]Header `json:"headers,omitempty"` + + // TODO docs + // TODO should this really be separate from TokenAuth? + JwtTokenAuth *JWTTokenAuth `json:"jwtTokenAuth,omitempty"` + + // For data source plugins. Route method matches the HTTP verb + // like GET or POST. Multiple methods can be provided as a + // comma-separated list. + Method *string `json:"method,omitempty"` + + // For data source plugins. The route path that is replaced by the + // route URL field when proxying the call. + Path *string `json:"path,omitempty"` + ReqRole *string `json:"reqRole,omitempty"` + ReqSignedIn *bool `json:"reqSignedIn,omitempty"` + + // TODO docs + TokenAuth *TokenAuth `json:"tokenAuth,omitempty"` + + // For data source plugins. Route URL is where the request is + // proxied to. + Url *string `json:"url,omitempty"` + UrlParams *[]URLParam `json:"urlParams,omitempty"` +} + +// TODO docs +type TokenAuth struct { + // Parameters for the token authentication request. + Params map[string]string `json:"params"` + + // The list of scopes that your application should be granted + // access to. + Scopes *[]string `json:"scopes,omitempty"` + + // URL to fetch the authentication token. + Url *string `json:"url,omitempty"` +} + +// URLParam describes query string parameters for +// a url in a plugin route +type URLParam struct { + Content string `json:"content"` + Name string `json:"name"` +} diff --git a/pkg/registry/corekind/base_gen.go b/pkg/registry/corekind/base_gen.go index 3770ae0250e..c9488dc66a7 100644 --- a/pkg/registry/corekind/base_gen.go +++ b/pkg/registry/corekind/base_gen.go @@ -64,8 +64,8 @@ func (b *Base) Preferences() *preferences.Kind { return b.preferences } -// Serviceaccount returns the [kindsys.Interface] implementation for the serviceaccount kind. -func (b *Base) Serviceaccount() *serviceaccount.Kind { +// ServiceAccount returns the [kindsys.Interface] implementation for the serviceaccount kind. +func (b *Base) ServiceAccount() *serviceaccount.Kind { return b.serviceaccount }