From 354f6d9e23eaacde73515418508ecd71174b7e04 Mon Sep 17 00:00:00 2001 From: Ezequiel Victorero Date: Thu, 26 Jan 2023 10:51:00 -0300 Subject: [PATCH] Schema: Create PublicDashboard core kind (#62155) --- .../core/publicdashboard/schema-reference.md | 25 ++++ .../publicdashboard/public_dashboard_kind.cue | 26 ++++ packages/grafana-schema/src/index.gen.ts | 3 + .../x/publicdashboard_types.gen.ts | 36 ++++++ .../publicdashboard_kind_gen.go | 113 ++++++++++++++++++ .../publicdashboard_types_gen.go | 32 +++++ pkg/kindsys/report.json | 32 ++++- pkg/registry/corekind/base_gen.go | 26 +++- 8 files changed, 285 insertions(+), 8 deletions(-) create mode 100644 docs/sources/developers/kinds/core/publicdashboard/schema-reference.md create mode 100644 kinds/publicdashboard/public_dashboard_kind.cue create mode 100644 packages/grafana-schema/src/raw/publicdashboard/x/publicdashboard_types.gen.ts create mode 100644 pkg/kinds/publicdashboard/publicdashboard_kind_gen.go create mode 100644 pkg/kinds/publicdashboard/publicdashboard_types_gen.go diff --git a/docs/sources/developers/kinds/core/publicdashboard/schema-reference.md b/docs/sources/developers/kinds/core/publicdashboard/schema-reference.md new file mode 100644 index 00000000000..afc5180618b --- /dev/null +++ b/docs/sources/developers/kinds/core/publicdashboard/schema-reference.md @@ -0,0 +1,25 @@ +--- +keywords: + - grafana + - schema +title: PublicDashboard kind +--- +> Both documentation generation and kinds schemas are in active development and subject to change without prior notice. + +# PublicDashboard kind + +## Maturity: merged +## Version: 0.0 + +## Properties + +| Property | Type | Required | Description | +|------------------------|---------|----------|-----------------------------------------------------------------| +| `annotationsEnabled` | boolean | **Yes** | Flag that indicates if annotations are enabled | +| `dashboardUid` | string | **Yes** | Dashboard unique identifier referenced by this public dashboard | +| `isEnabled` | boolean | **Yes** | Flag that indicates if the public dashboard is enabled | +| `timeSelectionEnabled` | boolean | **Yes** | Flag that indicates if the time range picker is enabled | +| `uid` | string | **Yes** | Unique public dashboard identifier | +| `accessToken` | string | No | Unique public access token | + + diff --git a/kinds/publicdashboard/public_dashboard_kind.cue b/kinds/publicdashboard/public_dashboard_kind.cue new file mode 100644 index 00000000000..1e960fa7cb4 --- /dev/null +++ b/kinds/publicdashboard/public_dashboard_kind.cue @@ -0,0 +1,26 @@ +package kind + +name: "PublicDashboard" +maturity: "merged" + +lineage: seqs: [ + { + schemas: [ + // 0.0 + { + // Unique public dashboard identifier + uid: string + // Dashboard unique identifier referenced by this public dashboard + dashboardUid: string + // Unique public access token + accessToken?: string + // Flag that indicates if the public dashboard is enabled + isEnabled: bool + // Flag that indicates if annotations are enabled + annotationsEnabled: bool + // Flag that indicates if the time range picker is enabled + timeSelectionEnabled: bool + }, + ] + }, +] diff --git a/packages/grafana-schema/src/index.gen.ts b/packages/grafana-schema/src/index.gen.ts index f0b02135a78..a7a76a0c3df 100644 --- a/packages/grafana-schema/src/index.gen.ts +++ b/packages/grafana-schema/src/index.gen.ts @@ -101,6 +101,9 @@ export type { QueryHistoryPreference } from './raw/preferences/x/preferences_types.gen'; +// Raw generated types from PublicDashboard kind. +export type { PublicDashboard } from './raw/publicdashboard/x/publicdashboard_types.gen'; + // Raw generated types from ServiceAccount kind. export type { ServiceAccount, diff --git a/packages/grafana-schema/src/raw/publicdashboard/x/publicdashboard_types.gen.ts b/packages/grafana-schema/src/raw/publicdashboard/x/publicdashboard_types.gen.ts new file mode 100644 index 00000000000..b94e4baefe3 --- /dev/null +++ b/packages/grafana-schema/src/raw/publicdashboard/x/publicdashboard_types.gen.ts @@ -0,0 +1,36 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. +// +// Generated by: +// kinds/gen.go +// Using jennies: +// TSTypesJenny +// LatestMajorsOrXJenny +// +// Run 'make gen-cue' from repository root to regenerate. + +export interface PublicDashboard { + /** + * Unique public access token + */ + accessToken?: string; + /** + * Flag that indicates if annotations are enabled + */ + annotationsEnabled: boolean; + /** + * Dashboard unique identifier referenced by this public dashboard + */ + dashboardUid: string; + /** + * Flag that indicates if the public dashboard is enabled + */ + isEnabled: boolean; + /** + * Flag that indicates if the time range picker is enabled + */ + timeSelectionEnabled: boolean; + /** + * Unique public dashboard identifier + */ + uid: string; +} diff --git a/pkg/kinds/publicdashboard/publicdashboard_kind_gen.go b/pkg/kinds/publicdashboard/publicdashboard_kind_gen.go new file mode 100644 index 00000000000..70add7f3adb --- /dev/null +++ b/pkg/kinds/publicdashboard/publicdashboard_kind_gen.go @@ -0,0 +1,113 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. +// +// Generated by: +// kinds/gen.go +// Using jennies: +// CoreKindJenny +// +// Run 'make gen-cue' from repository root to regenerate. + +package publicdashboard + +import ( + "github.com/grafana/grafana/pkg/kindsys" + "github.com/grafana/thema" + "github.com/grafana/thema/vmux" +) + +// rootrel is the relative path from the grafana repository root to the +// directory containing the .cue files in which this kind is declared. Necessary +// for runtime errors related to the declaration and/or lineage to provide +// a real path to the correct .cue file. +const rootrel string = "kinds/publicdashboard" + +// TODO standard generated docs +type Kind struct { + lin thema.ConvergentLineage[*PublicDashboard] + jcodec vmux.Codec + valmux vmux.ValueMux[*PublicDashboard] + decl kindsys.Decl[kindsys.CoreProperties] +} + +// type guard +var _ kindsys.Core = &Kind{} + +// TODO standard generated docs +func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) { + decl, err := kindsys.LoadCoreKind(rootrel, rt.Context(), nil) + if err != nil { + return nil, err + } + k := &Kind{ + decl: decl, + } + + lin, err := decl.Some().BindKindLineage(rt, opts...) + if err != nil { + return nil, err + } + + // 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[*PublicDashboard](cursch, &PublicDashboard{}) + if err != nil { + // Should be unreachable, modulo bugs in the Thema->Go code generator + return nil, err + } + + k.jcodec = vmux.NewJSONCodec("publicdashboard.json") + k.lin = tsch.ConvergentLineage() + k.valmux = vmux.NewValueMux(k.lin.TypedSchema(), k.jcodec) + return k, nil +} + +// TODO standard generated docs +func (k *Kind) Name() string { + return "publicdashboard" +} + +// TODO standard generated docs +func (k *Kind) MachineName() string { + return "publicdashboard" +} + +// TODO standard generated docs +func (k *Kind) Lineage() thema.Lineage { + return k.lin +} + +// TODO standard generated docs +func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*PublicDashboard] { + return k.lin +} + +// JSONValueMux is a version multiplexer that maps a []byte containing JSON data +// at any schematized dashboard version to an instance of PublicDashboard. +// +// 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) (*PublicDashboard, thema.TranslationLacunas, error) { + return k.valmux(b) +} + +// TODO standard generated docs +func (k *Kind) Maturity() kindsys.Maturity { + return k.decl.Properties.Maturity +} + +// Decl returns the [kindsys.Decl] containing both CUE and Go representations of the +// publicdashboard declaration in .cue files. +func (k *Kind) Decl() kindsys.Decl[kindsys.CoreProperties] { + return k.decl +} + +// Props returns a [kindsys.SomeKindProps], with underlying type [kindsys.CoreProperties], +// representing the static properties declared in the publicdashboard kind. +// +// This method is identical to calling Decl().Props. It is provided to satisfy [kindsys.Interface]. +func (k *Kind) Props() kindsys.SomeKindProperties { + return k.decl.Properties +} diff --git a/pkg/kinds/publicdashboard/publicdashboard_types_gen.go b/pkg/kinds/publicdashboard/publicdashboard_types_gen.go new file mode 100644 index 00000000000..80da0c962c1 --- /dev/null +++ b/pkg/kinds/publicdashboard/publicdashboard_types_gen.go @@ -0,0 +1,32 @@ +// Code generated - EDITING IS FUTILE. DO NOT EDIT. +// +// Generated by: +// kinds/gen.go +// Using jennies: +// GoTypesJenny +// LatestJenny +// +// Run 'make gen-cue' from repository root to regenerate. + +package publicdashboard + +// PublicDashboard defines model for PublicDashboard. +type PublicDashboard struct { + // Unique public access token + AccessToken *string `json:"accessToken,omitempty"` + + // Flag that indicates if annotations are enabled + AnnotationsEnabled bool `json:"annotationsEnabled"` + + // Dashboard unique identifier referenced by this public dashboard + DashboardUid string `json:"dashboardUid"` + + // Flag that indicates if the public dashboard is enabled + IsEnabled bool `json:"isEnabled"` + + // Flag that indicates if the time range picker is enabled + TimeSelectionEnabled bool `json:"timeSelectionEnabled"` + + // Unique public dashboard identifier + Uid string `json:"uid"` +} diff --git a/pkg/kindsys/report.json b/pkg/kindsys/report.json index a2db2a60086..bd30c27facf 100644 --- a/pkg/kindsys/report.json +++ b/pkg/kindsys/report.json @@ -1281,6 +1281,32 @@ "pluralName": "PrometheusDataSourceCfgs", "schemaInterface": "DataSourceCfg" }, + "publicdashboard": { + "category": "core", + "codeowners": [ + "grafana/grafana-as-code", + "grafana/grafana-bi-squad", + "grafana/plugins-platform-frontend", + "grafana/user-essentials" + ], + "currentVersion": [ + 0, + 0 + ], + "grafanaMaturityCount": 0, + "lineageIsGroup": false, + "links": { + "docs": "https://grafana.com/docs/grafana/next/developers/kinds/core/publicdashboard/schema-reference", + "go": "https://github.com/grafana/grafana/tree/main/pkg/kinds/publicdashboard", + "schema": "https://github.com/grafana/grafana/tree/main/kinds/publicdashboard/publicdashboard_kind.cue", + "ts": "https://github.com/grafana/grafana/tree/main/packages/grafana-schema/src/raw/publicdashboard/x/publicdashboard_types.gen.ts" + }, + "machineName": "publicdashboard", + "maturity": "merged", + "name": "PublicDashboard", + "pluralMachineName": "publicdashboards", + "pluralName": "PublicDashboards" + }, "query": { "category": "core", "codeowners": [], @@ -1818,6 +1844,7 @@ "folder", "playlist", "preferences", + "publicdashboard", "query", "queryhistory", "serviceaccount", @@ -1825,7 +1852,7 @@ "thumb", "user" ], - "count": 12 + "count": 13 } }, "maturity": { @@ -1860,10 +1887,11 @@ "alertgroupspanelcfg", "playlist", "preferences", + "publicdashboard", "serviceaccount", "team" ], - "count": 5 + "count": 6 }, "planned": { "name": "planned", diff --git a/pkg/registry/corekind/base_gen.go b/pkg/registry/corekind/base_gen.go index c9488dc66a7..8a180db1ca0 100644 --- a/pkg/registry/corekind/base_gen.go +++ b/pkg/registry/corekind/base_gen.go @@ -15,6 +15,7 @@ import ( "github.com/grafana/grafana/pkg/kinds/dashboard" "github.com/grafana/grafana/pkg/kinds/playlist" "github.com/grafana/grafana/pkg/kinds/preferences" + "github.com/grafana/grafana/pkg/kinds/publicdashboard" "github.com/grafana/grafana/pkg/kinds/serviceaccount" "github.com/grafana/grafana/pkg/kinds/team" "github.com/grafana/grafana/pkg/kindsys" @@ -32,12 +33,13 @@ import ( // Prefer All*() methods when performing operations generically across all kinds. // For example, a validation HTTP middleware for any kind-schematized object type. type Base struct { - all []kindsys.Core - dashboard *dashboard.Kind - playlist *playlist.Kind - preferences *preferences.Kind - serviceaccount *serviceaccount.Kind - team *team.Kind + all []kindsys.Core + dashboard *dashboard.Kind + playlist *playlist.Kind + preferences *preferences.Kind + publicdashboard *publicdashboard.Kind + serviceaccount *serviceaccount.Kind + team *team.Kind } // type guards @@ -45,6 +47,7 @@ var ( _ kindsys.Core = &dashboard.Kind{} _ kindsys.Core = &playlist.Kind{} _ kindsys.Core = &preferences.Kind{} + _ kindsys.Core = &publicdashboard.Kind{} _ kindsys.Core = &serviceaccount.Kind{} _ kindsys.Core = &team.Kind{} ) @@ -64,6 +67,11 @@ func (b *Base) Preferences() *preferences.Kind { return b.preferences } +// PublicDashboard returns the [kindsys.Interface] implementation for the publicdashboard kind. +func (b *Base) PublicDashboard() *publicdashboard.Kind { + return b.publicdashboard +} + // ServiceAccount returns the [kindsys.Interface] implementation for the serviceaccount kind. func (b *Base) ServiceAccount() *serviceaccount.Kind { return b.serviceaccount @@ -96,6 +104,12 @@ func doNewBase(rt *thema.Runtime) *Base { } reg.all = append(reg.all, reg.preferences) + reg.publicdashboard, err = publicdashboard.NewKind(rt) + if err != nil { + panic(fmt.Sprintf("error while initializing the publicdashboard Kind: %s", err)) + } + reg.all = append(reg.all, reg.publicdashboard) + reg.serviceaccount, err = serviceaccount.NewKind(rt) if err != nil { panic(fmt.Sprintf("error while initializing the serviceaccount Kind: %s", err))