K8s: improve openapi generation (#83796)

This commit is contained in:
Ryan McKinley 2024-03-01 14:26:04 -08:00 committed by GitHub
parent 2184592174
commit d7bcd119c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 216 additions and 115 deletions

View File

@ -51,7 +51,7 @@ type DashboardSummaryList struct {
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DashboardVersionsInfo struct {
type DashboardVersionList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
@ -60,11 +60,20 @@ type DashboardVersionsInfo struct {
}
type DashboardVersionInfo struct {
Version int `json:"version"`
ParentVersion int `json:"parentVersion,omitempty"`
Created int64 `json:"created"`
Message string `json:"message,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
// The internal ID for this version (will be replaced with resourceVersion)
Version int `json:"version"`
// If the dashboard came from a previous version, it is set here
ParentVersion int `json:"parentVersion,omitempty"`
// The creation timestamp for this version
Created int64 `json:"created"`
// The user who created this version
CreatedBy string `json:"createdBy,omitempty"`
// Message passed while saving the version
Message string `json:"message,omitempty"`
}
// +k8s:conversion-gen:explicit-from=net/url.Values

View File

@ -233,7 +233,7 @@ func (in *DashboardVersionInfo) DeepCopy() *DashboardVersionInfo {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DashboardVersionsInfo) DeepCopyInto(out *DashboardVersionsInfo) {
func (in *DashboardVersionList) DeepCopyInto(out *DashboardVersionList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
@ -245,18 +245,18 @@ func (in *DashboardVersionsInfo) DeepCopyInto(out *DashboardVersionsInfo) {
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardVersionsInfo.
func (in *DashboardVersionsInfo) DeepCopy() *DashboardVersionsInfo {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardVersionList.
func (in *DashboardVersionList) DeepCopy() *DashboardVersionList {
if in == nil {
return nil
}
out := new(DashboardVersionsInfo)
out := new(DashboardVersionList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *DashboardVersionsInfo) DeepCopyObject() runtime.Object {
func (in *DashboardVersionList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}

View File

@ -16,17 +16,17 @@ import (
func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.AnnotationActions": schema_pkg_apis_dashboard_v0alpha1_AnnotationActions(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.AnnotationPermission": schema_pkg_apis_dashboard_v0alpha1_AnnotationPermission(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.Dashboard": schema_pkg_apis_dashboard_v0alpha1_Dashboard(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardAccessInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardAccessInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardList": schema_pkg_apis_dashboard_v0alpha1_DashboardList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummary": schema_pkg_apis_dashboard_v0alpha1_DashboardSummary(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummaryList": schema_pkg_apis_dashboard_v0alpha1_DashboardSummaryList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummarySpec": schema_pkg_apis_dashboard_v0alpha1_DashboardSummarySpec(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionsInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionsInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.VersionsQueryOptions": schema_pkg_apis_dashboard_v0alpha1_VersionsQueryOptions(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.AnnotationActions": schema_pkg_apis_dashboard_v0alpha1_AnnotationActions(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.AnnotationPermission": schema_pkg_apis_dashboard_v0alpha1_AnnotationPermission(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.Dashboard": schema_pkg_apis_dashboard_v0alpha1_Dashboard(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardAccessInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardAccessInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardList": schema_pkg_apis_dashboard_v0alpha1_DashboardList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummary": schema_pkg_apis_dashboard_v0alpha1_DashboardSummary(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummaryList": schema_pkg_apis_dashboard_v0alpha1_DashboardSummaryList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummarySpec": schema_pkg_apis_dashboard_v0alpha1_DashboardSummarySpec(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionInfo(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionList": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.VersionsQueryOptions": schema_pkg_apis_dashboard_v0alpha1_VersionsQueryOptions(ref),
}
}
@ -380,34 +380,39 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardVersionInfo(ref common.Referenc
Properties: map[string]spec.Schema{
"version": {
SchemaProps: spec.SchemaProps{
Default: 0,
Type: []string{"integer"},
Format: "int32",
Description: "The internal ID for this version (will be replaced with resourceVersion)",
Default: 0,
Type: []string{"integer"},
Format: "int32",
},
},
"parentVersion": {
SchemaProps: spec.SchemaProps{
Type: []string{"integer"},
Format: "int32",
Description: "If the dashboard came from a previous version, it is set here",
Type: []string{"integer"},
Format: "int32",
},
},
"created": {
SchemaProps: spec.SchemaProps{
Default: 0,
Type: []string{"integer"},
Format: "int64",
},
},
"message": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
Description: "The creation timestamp for this version",
Default: 0,
Type: []string{"integer"},
Format: "int64",
},
},
"createdBy": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
Description: "The user who created this version",
Type: []string{"string"},
Format: "",
},
},
"message": {
SchemaProps: spec.SchemaProps{
Description: "Message passed while saving the version",
Type: []string{"string"},
Format: "",
},
},
},
@ -417,7 +422,7 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardVersionInfo(ref common.Referenc
}
}
func schema_pkg_apis_dashboard_v0alpha1_DashboardVersionsInfo(ref common.ReferenceCallback) common.OpenAPIDefinition {
func schema_pkg_apis_dashboard_v0alpha1_DashboardVersionList(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{

View File

@ -13,6 +13,7 @@ import (
"k8s.io/apiserver/pkg/registry/rest"
genericapiserver "k8s.io/apiserver/pkg/server"
common "k8s.io/kube-openapi/pkg/common"
"k8s.io/kube-openapi/pkg/spec3"
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
"github.com/grafana/grafana/pkg/apiserver/builder"
@ -82,7 +83,7 @@ func addKnownTypes(scheme *runtime.Scheme, gv schema.GroupVersion) {
&v0alpha1.Dashboard{},
&v0alpha1.DashboardList{},
&v0alpha1.DashboardAccessInfo{},
&v0alpha1.DashboardVersionsInfo{},
&v0alpha1.DashboardVersionList{},
&v0alpha1.DashboardSummary{},
&v0alpha1.DashboardSummaryList{},
&v0alpha1.VersionsQueryOptions{},
@ -196,6 +197,26 @@ func (b *DashboardsAPIBuilder) GetOpenAPIDefinitions() common.GetOpenAPIDefiniti
return v0alpha1.GetOpenAPIDefinitions
}
func (b *DashboardsAPIBuilder) PostProcessOpenAPI(oas *spec3.OpenAPI) (*spec3.OpenAPI, error) {
// The plugin description
oas.Info.Description = "Grafana dashboards as resources"
// The root api URL
root := "/apis/" + b.GetGroupVersion().String() + "/"
// Hide the ability to list or watch across all tenants
delete(oas.Paths.Paths, root+v0alpha1.DashboardResourceInfo.GroupResource().Resource)
delete(oas.Paths.Paths, root+"watch/"+v0alpha1.DashboardResourceInfo.GroupResource().Resource)
delete(oas.Paths.Paths, root+v0alpha1.DashboardSummaryResourceInfo.GroupResource().Resource)
// The root API discovery list
sub := oas.Paths.Paths[root]
if sub != nil && sub.Get != nil {
sub.Get.Tags = []string{"API Discovery"} // sorts first in the list
}
return oas, nil
}
func (b *DashboardsAPIBuilder) GetAPIRoutes() *builder.APIRoutes {
return nil // no custom API routes
}

View File

@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
dashboard "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
"github.com/grafana/grafana/pkg/infra/appcontext"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
@ -22,9 +22,10 @@ type AccessREST struct {
}
var _ = rest.Connecter(&AccessREST{})
var _ = rest.StorageMetadata(&AccessREST{})
func (r *AccessREST) New() runtime.Object {
return &v0alpha1.DashboardAccessInfo{}
return &dashboard.DashboardAccessInfo{}
}
func (r *AccessREST) Destroy() {
@ -35,7 +36,15 @@ func (r *AccessREST) ConnectMethods() []string {
}
func (r *AccessREST) NewConnectOptions() (runtime.Object, bool, string) {
return &v0alpha1.VersionsQueryOptions{}, false, ""
return &dashboard.VersionsQueryOptions{}, false, ""
}
func (r *AccessREST) ProducesMIMETypes(verb string) []string {
return nil
}
func (r *AccessREST) ProducesObject(verb string) interface{} {
return &dashboard.DashboardAccessInfo{}
}
func (r *AccessREST) Connect(ctx context.Context, name string, opts runtime.Object, responder rest.Responder) (http.Handler, error) {
@ -66,14 +75,14 @@ func (r *AccessREST) Connect(ctx context.Context, name string, opts runtime.Obje
return nil, fmt.Errorf("not allowed to view")
}
access := &v0alpha1.DashboardAccessInfo{}
access := &dashboard.DashboardAccessInfo{}
access.CanEdit, _ = guardian.CanEdit()
access.CanSave, _ = guardian.CanSave()
access.CanAdmin, _ = guardian.CanAdmin()
access.CanDelete, _ = guardian.CanDelete()
access.CanStar = user.IsRealUser() && !user.IsAnonymous
access.AnnotationsPermissions = &v0alpha1.AnnotationPermission{}
access.AnnotationsPermissions = &dashboard.AnnotationPermission{}
r.getAnnotationPermissionsByScope(ctx, user, &access.AnnotationsPermissions.Dashboard, accesscontrol.ScopeAnnotationsTypeDashboard)
r.getAnnotationPermissionsByScope(ctx, user, &access.AnnotationsPermissions.Organization, accesscontrol.ScopeAnnotationsTypeOrganization)
@ -82,7 +91,7 @@ func (r *AccessREST) Connect(ctx context.Context, name string, opts runtime.Obje
}), nil
}
func (r *AccessREST) getAnnotationPermissionsByScope(ctx context.Context, user identity.Requester, actions *v0alpha1.AnnotationActions, scope string) {
func (r *AccessREST) getAnnotationPermissionsByScope(ctx context.Context, user identity.Requester, actions *dashboard.AnnotationActions, scope string) {
var err error
evaluate := accesscontrol.EvalPermission(accesscontrol.ActionAnnotationsCreate, scope)

View File

@ -12,7 +12,7 @@ import (
"k8s.io/apiserver/pkg/registry/rest"
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
dashboard "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
)
@ -22,9 +22,10 @@ type VersionsREST struct {
}
var _ = rest.Connecter(&VersionsREST{})
var _ = rest.StorageMetadata(&VersionsREST{})
func (r *VersionsREST) New() runtime.Object {
return &v0alpha1.DashboardVersionsInfo{}
return &dashboard.DashboardVersionList{}
}
func (r *VersionsREST) Destroy() {
@ -34,6 +35,14 @@ func (r *VersionsREST) ConnectMethods() []string {
return []string{"GET"}
}
func (r *VersionsREST) ProducesMIMETypes(verb string) []string {
return nil
}
func (r *VersionsREST) ProducesObject(verb string) interface{} {
return &dashboard.DashboardVersionList{}
}
func (r *VersionsREST) NewConnectOptions() (runtime.Object, bool, string) {
return nil, true, ""
}
@ -68,7 +77,7 @@ func (r *VersionsREST) Connect(ctx context.Context, uid string, opts runtime.Obj
data, _ := dto.Data.Map()
// Convert the version to a regular dashboard
dash := &v0alpha1.Dashboard{
dash := &dashboard.Dashboard{
ObjectMeta: metav1.ObjectMeta{
Name: uid,
CreationTimestamp: metav1.NewTime(dto.Created),
@ -88,9 +97,9 @@ func (r *VersionsREST) Connect(ctx context.Context, uid string, opts runtime.Obj
responder.Error(err)
return
}
versions := &v0alpha1.DashboardVersionsInfo{}
versions := &dashboard.DashboardVersionList{}
for _, v := range rsp {
info := v0alpha1.DashboardVersionInfo{
info := dashboard.DashboardVersionInfo{
Version: v.Version,
Created: v.Created.UnixMilli(),
Message: v.Message,

View File

@ -14,12 +14,13 @@ import (
"k8s.io/apiserver/pkg/registry/rest"
genericapiserver "k8s.io/apiserver/pkg/server"
openapi "k8s.io/kube-openapi/pkg/common"
"k8s.io/kube-openapi/pkg/spec3"
"k8s.io/utils/strings/slices"
"github.com/grafana/grafana-plugin-sdk-go/backend"
common "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1"
datasource "github.com/grafana/grafana/pkg/apis/datasource/v0alpha1"
query "github.com/grafana/grafana/pkg/apis/query/v0alpha1"
"github.com/grafana/grafana/pkg/apiserver/builder"
"github.com/grafana/grafana/pkg/plugins"
@ -117,9 +118,9 @@ func (b *DataSourceAPIBuilder) GetGroupVersion() schema.GroupVersion {
func addKnownTypes(scheme *runtime.Scheme, gv schema.GroupVersion) {
scheme.AddKnownTypes(gv,
&v0alpha1.DataSourceConnection{},
&v0alpha1.DataSourceConnectionList{},
&v0alpha1.HealthCheckResult{},
&datasource.DataSourceConnection{},
&datasource.DataSourceConnectionList{},
&datasource.HealthCheckResult{},
&unstructured.Unstructured{},
// Query handler
&query.QueryDataResponse{},
@ -152,7 +153,7 @@ func resourceFromPluginID(pluginID string) (common.ResourceInfo, error) {
if err != nil {
return common.ResourceInfo{}, err
}
return v0alpha1.GenericConnectionResourceInfo.WithGroupAndShortName(group, pluginID+"-connection"), nil
return datasource.GenericConnectionResourceInfo.WithGroupAndShortName(group, pluginID+"-connection"), nil
}
func (b *DataSourceAPIBuilder) GetAPIGroupInfo(
@ -177,7 +178,7 @@ func (b *DataSourceAPIBuilder) GetAPIGroupInfo(
{Name: "Created At", Type: "date"},
},
func(obj any) ([]interface{}, error) {
m, ok := obj.(*v0alpha1.DataSourceConnection)
m, ok := obj.(*datasource.DataSourceConnection)
if !ok {
return nil, fmt.Errorf("expected connection")
}
@ -220,13 +221,31 @@ func (b *DataSourceAPIBuilder) getPluginContext(ctx context.Context, uid string)
func (b *DataSourceAPIBuilder) GetOpenAPIDefinitions() openapi.GetOpenAPIDefinitions {
return func(ref openapi.ReferenceCallback) map[string]openapi.OpenAPIDefinition {
defs := query.GetOpenAPIDefinitions(ref) // required when running standalone
for k, v := range v0alpha1.GetOpenAPIDefinitions(ref) {
for k, v := range datasource.GetOpenAPIDefinitions(ref) {
defs[k] = v
}
return defs
}
}
func (b *DataSourceAPIBuilder) PostProcessOpenAPI(oas *spec3.OpenAPI) (*spec3.OpenAPI, error) {
// The plugin description
oas.Info.Description = b.pluginJSON.Info.Description
// The root api URL
root := "/apis/" + b.connectionResourceInfo.GroupVersion().String() + "/"
// Hide the ability to list all connections across tenants
delete(oas.Paths.Paths, root+b.connectionResourceInfo.GroupResource().Resource)
// The root API discovery list
sub := oas.Paths.Paths[root]
if sub != nil && sub.Get != nil {
sub.Get.Tags = []string{"API Discovery"} // sorts first in the list
}
return oas, nil
}
// Register additional routes with the server
func (b *DataSourceAPIBuilder) GetAPIRoutes() *builder.APIRoutes {
return nil

View File

@ -9,17 +9,20 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
"github.com/grafana/grafana/pkg/apis/datasource/v0alpha1"
datasource "github.com/grafana/grafana/pkg/apis/datasource/v0alpha1"
)
type subHealthREST struct {
builder *DataSourceAPIBuilder
}
var _ = rest.Connecter(&subHealthREST{})
var (
_ = rest.Connecter(&subHealthREST{})
_ = rest.StorageMetadata(&subHealthREST{})
)
func (r *subHealthREST) New() runtime.Object {
return &v0alpha1.HealthCheckResult{}
return &datasource.HealthCheckResult{}
}
func (r *subHealthREST) Destroy() {
@ -29,28 +32,34 @@ func (r *subHealthREST) ConnectMethods() []string {
return []string{"GET"}
}
func (r *subHealthREST) ProducesMIMETypes(verb string) []string {
return nil
}
func (r *subHealthREST) ProducesObject(verb string) interface{} {
return &datasource.HealthCheckResult{}
}
func (r *subHealthREST) NewConnectOptions() (runtime.Object, bool, string) {
return nil, false, ""
}
func (r *subHealthREST) Connect(ctx context.Context, name string, opts runtime.Object, responder rest.Responder) (http.Handler, error) {
pluginCtx, err := r.builder.getPluginContext(ctx, name)
if err != nil {
return nil, err
}
ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)
healthResponse, err := r.builder.client.CheckHealth(ctx, &backend.CheckHealthRequest{
PluginContext: pluginCtx,
})
if err != nil {
return nil, err
}
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
pluginCtx, err := r.builder.getPluginContext(ctx, name)
if err != nil {
responder.Error(err)
return
}
ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)
healthResponse, err := r.builder.client.CheckHealth(ctx, &backend.CheckHealthRequest{
PluginContext: pluginCtx,
})
if err != nil {
responder.Error(err)
return
}
rsp := &v0alpha1.HealthCheckResult{}
rsp := &datasource.HealthCheckResult{}
rsp.Code = int(healthResponse.Status)
rsp.Status = healthResponse.Status.String()
rsp.Message = healthResponse.Message

View File

@ -5,13 +5,12 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
"github.com/grafana/grafana/pkg/apis/query/v0alpha1"
query "github.com/grafana/grafana/pkg/apis/query/v0alpha1"
"github.com/grafana/grafana/pkg/middleware/requestmeta"
"github.com/grafana/grafana/pkg/tsdb/legacydata"
"github.com/grafana/grafana/pkg/web"
@ -24,51 +23,24 @@ type subQueryREST struct {
var _ = rest.Connecter(&subQueryREST{})
func (r *subQueryREST) New() runtime.Object {
return &v0alpha1.QueryDataResponse{}
return &query.QueryDataResponse{}
}
func (r *subQueryREST) Destroy() {}
func (r *subQueryREST) ConnectMethods() []string {
return []string{"POST", "GET"}
return []string{"POST"}
}
func (r *subQueryREST) NewConnectOptions() (runtime.Object, bool, string) {
return nil, false, ""
}
func (r *subQueryREST) readQueries(req *http.Request) ([]backend.DataQuery, *v0alpha1.DataSourceRef, error) {
reqDTO := v0alpha1.GenericQueryRequest{}
// Simple URL to JSON mapping
if req.Method == http.MethodGet {
query := v0alpha1.GenericDataQuery{
RefID: "A",
MaxDataPoints: 1000,
IntervalMS: 10,
}
params := req.URL.Query()
for k := range params {
v := params.Get(k) // the singular value
switch k {
case "to":
reqDTO.To = v
case "from":
reqDTO.From = v
case "maxDataPoints":
query.MaxDataPoints, _ = strconv.ParseInt(v, 10, 64)
case "intervalMs":
query.IntervalMS, _ = strconv.ParseFloat(v, 64)
case "queryType":
query.QueryType = v
default:
query.AdditionalProperties()[k] = v
}
}
reqDTO.Queries = []v0alpha1.GenericDataQuery{query}
} else if err := web.Bind(req, &reqDTO); err != nil {
func (r *subQueryREST) readQueries(req *http.Request) ([]backend.DataQuery, *query.DataSourceRef, error) {
reqDTO := query.GenericQueryRequest{}
if err := web.Bind(req, &reqDTO); err != nil {
return nil, nil, err
}
return legacydata.ToDataSourceQueries(reqDTO)
}

View File

@ -13,6 +13,7 @@ import (
"k8s.io/apiserver/pkg/registry/rest"
genericapiserver "k8s.io/apiserver/pkg/server"
common "k8s.io/kube-openapi/pkg/common"
"k8s.io/kube-openapi/pkg/spec3"
"github.com/grafana/grafana/pkg/apis/folder/v0alpha1"
"github.com/grafana/grafana/pkg/apiserver/builder"
@ -153,6 +154,25 @@ func (b *FolderAPIBuilder) GetAPIRoutes() *builder.APIRoutes {
return nil // no custom API routes
}
func (b *FolderAPIBuilder) PostProcessOpenAPI(oas *spec3.OpenAPI) (*spec3.OpenAPI, error) {
// The plugin description
oas.Info.Description = "Grafana folders"
// The root api URL
root := "/apis/" + b.GetGroupVersion().String() + "/"
// Hide the ability to list or watch across all tenants
delete(oas.Paths.Paths, root+v0alpha1.FolderResourceInfo.GroupResource().Resource)
delete(oas.Paths.Paths, root+"watch/"+v0alpha1.FolderResourceInfo.GroupResource().Resource)
// The root API discovery list
sub := oas.Paths.Paths[root]
if sub != nil && sub.Get != nil {
sub.Get.Tags = []string{"API Discovery"} // sorts first in the list
}
return oas, nil
}
func (b *FolderAPIBuilder) GetAuthorizer() authorizer.Authorizer {
return authorizer.AuthorizerFunc(
func(ctx context.Context, attr authorizer.Attributes) (authorized authorizer.Decision, reason string, err error) {

View File

@ -19,6 +19,7 @@ type subAccessREST struct {
}
var _ = rest.Connecter(&subAccessREST{})
var _ = rest.StorageMetadata(&subAccessREST{})
func (r *subAccessREST) New() runtime.Object {
return &v0alpha1.FolderAccessInfo{}
@ -31,6 +32,14 @@ func (r *subAccessREST) ConnectMethods() []string {
return []string{"GET"}
}
func (r *subAccessREST) ProducesMIMETypes(verb string) []string {
return nil
}
func (r *subAccessREST) ProducesObject(verb string) interface{} {
return &v0alpha1.FolderAccessInfo{}
}
func (r *subAccessREST) NewConnectOptions() (runtime.Object, bool, string) {
return nil, false, "" // true means you can use the trailing path as a variable
}

View File

@ -17,7 +17,10 @@ type subCountREST struct {
service folder.Service
}
var _ = rest.Connecter(&subCountREST{})
var (
_ = rest.Connecter(&subCountREST{})
_ = rest.StorageMetadata(&subCountREST{})
)
func (r *subCountREST) New() runtime.Object {
return &v0alpha1.DescendantCounts{}
@ -30,6 +33,14 @@ func (r *subCountREST) ConnectMethods() []string {
return []string{"GET"}
}
func (r *subCountREST) ProducesMIMETypes(verb string) []string {
return nil
}
func (r *subCountREST) ProducesObject(verb string) interface{} {
return &v0alpha1.DescendantCounts{}
}
func (r *subCountREST) NewConnectOptions() (runtime.Object, bool, string) {
return nil, false, "" // true means you can use the trailing path as a variable
}

View File

@ -17,6 +17,7 @@ type subParentsREST struct {
}
var _ = rest.Connecter(&subParentsREST{})
var _ = rest.StorageMetadata(&subParentsREST{})
func (r *subParentsREST) New() runtime.Object {
return &v0alpha1.FolderInfoList{}
@ -29,6 +30,14 @@ func (r *subParentsREST) ConnectMethods() []string {
return []string{"GET"}
}
func (r *subParentsREST) ProducesMIMETypes(verb string) []string {
return nil
}
func (r *subParentsREST) ProducesObject(verb string) interface{} {
return &v0alpha1.FolderInfoList{}
}
func (r *subParentsREST) NewConnectOptions() (runtime.Object, bool, string) {
return nil, false, "" // true means you can use the trailing path as a variable
}

View File

@ -77,7 +77,7 @@ func TestIntegrationDashboardsApp(t *testing.T) {
{
"responseKind": {
"group": "",
"kind": "DashboardVersionsInfo",
"kind": "DashboardVersionList",
"version": ""
},
"subresource": "versions",

View File

@ -80,8 +80,7 @@ func TestIntegrationTestDatasource(t *testing.T) {
},
"subresource": "query",
"verbs": [
"create",
"get"
"create"
]
},
{