2022-07-06 18:51:44 -05:00
|
|
|
package publicdashboards
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-08-29 16:13:06 -05:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
2022-09-07 13:08:52 -05:00
|
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
2023-01-16 09:33:55 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
2022-07-06 18:51:44 -05:00
|
|
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
2022-08-10 04:56:48 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
2022-07-06 18:51:44 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// These are the api contracts. The API should match the underlying service and store
|
|
|
|
|
2022-11-02 14:35:57 -05:00
|
|
|
//go:generate go run ./commands/generate_datasources/main.go
|
2022-07-06 18:51:44 -05:00
|
|
|
//go:generate mockery --name Service --structname FakePublicDashboardService --inpackage --filename public_dashboard_service_mock.go
|
|
|
|
type Service interface {
|
2023-01-16 09:33:55 -06:00
|
|
|
FindPublicDashboardAndDashboardByAccessToken(ctx context.Context, accessToken string) (*PublicDashboard, *dashboards.Dashboard, error)
|
2023-03-09 11:17:54 -06:00
|
|
|
FindEnabledPublicDashboardAndDashboardByAccessToken(ctx context.Context, accessToken string) (*PublicDashboard, *dashboards.Dashboard, error)
|
2023-01-11 15:25:18 -06:00
|
|
|
FindByAccessToken(ctx context.Context, accessToken string) (*PublicDashboard, error)
|
2022-10-25 19:40:42 -05:00
|
|
|
FindByDashboardUid(ctx context.Context, orgId int64, dashboardUid string) (*PublicDashboard, error)
|
|
|
|
FindAnnotations(ctx context.Context, reqDTO AnnotationsQueryDTO, accessToken string) ([]AnnotationEvent, error)
|
2023-01-16 09:33:55 -06:00
|
|
|
FindDashboard(ctx context.Context, orgId int64, dashboardUid string) (*dashboards.Dashboard, error)
|
2022-10-25 19:40:42 -05:00
|
|
|
FindAll(ctx context.Context, u *user.SignedInUser, orgId int64) ([]PublicDashboardListResponse, error)
|
2023-01-27 08:20:22 -06:00
|
|
|
Find(ctx context.Context, uid string) (*PublicDashboard, error)
|
2022-11-03 14:30:12 -05:00
|
|
|
Create(ctx context.Context, u *user.SignedInUser, dto *SavePublicDashboardDTO) (*PublicDashboard, error)
|
|
|
|
Update(ctx context.Context, u *user.SignedInUser, dto *SavePublicDashboardDTO) (*PublicDashboard, error)
|
2023-03-08 14:54:35 -06:00
|
|
|
Delete(ctx context.Context, uid string) error
|
|
|
|
DeleteByDashboard(ctx context.Context, dashboard *dashboards.Dashboard) error
|
2022-10-25 19:40:42 -05:00
|
|
|
|
2023-01-16 09:33:55 -06:00
|
|
|
GetMetricRequest(ctx context.Context, dashboard *dashboards.Dashboard, publicDashboard *PublicDashboard, panelId int64, reqDTO PublicDashboardQueryDTO) (dtos.MetricRequest, error)
|
2023-04-12 11:30:33 -05:00
|
|
|
GetQueryDataResponse(ctx context.Context, skipDSCache bool, reqDTO PublicDashboardQueryDTO, panelId int64, accessToken string) (*backend.QueryDataResponse, error)
|
2022-10-25 19:40:42 -05:00
|
|
|
GetOrgIdByAccessToken(ctx context.Context, accessToken string) (int64, error)
|
|
|
|
NewPublicDashboardAccessToken(ctx context.Context) (string, error)
|
|
|
|
NewPublicDashboardUid(ctx context.Context) (string, error)
|
|
|
|
|
|
|
|
ExistsEnabledByAccessToken(ctx context.Context, accessToken string) (bool, error)
|
|
|
|
ExistsEnabledByDashboardUid(ctx context.Context, dashboardUid string) (bool, error)
|
2022-07-06 18:51:44 -05:00
|
|
|
}
|
|
|
|
|
2023-02-10 12:01:26 -06:00
|
|
|
// ServiceWrapper these methods have different behavior between OSS and Enterprise. The latter would call the OSS service first
|
|
|
|
//
|
|
|
|
//go:generate mockery --name ServiceWrapper --structname FakePublicDashboardServiceWrapper --inpackage --filename public_dashboard_service_wrapper_mock.go
|
|
|
|
type ServiceWrapper interface {
|
|
|
|
FindByDashboardUid(ctx context.Context, orgId int64, dashboardUid string) (*PublicDashboard, error)
|
2023-03-08 14:54:35 -06:00
|
|
|
Delete(ctx context.Context, uid string) error
|
2023-02-10 12:01:26 -06:00
|
|
|
}
|
|
|
|
|
2022-07-06 18:51:44 -05:00
|
|
|
//go:generate mockery --name Store --structname FakePublicDashboardStore --inpackage --filename public_dashboard_store_mock.go
|
|
|
|
type Store interface {
|
2022-10-25 19:40:42 -05:00
|
|
|
Find(ctx context.Context, uid string) (*PublicDashboard, error)
|
|
|
|
FindByAccessToken(ctx context.Context, accessToken string) (*PublicDashboard, error)
|
|
|
|
FindByDashboardUid(ctx context.Context, orgId int64, dashboardUid string) (*PublicDashboard, error)
|
2023-01-16 09:33:55 -06:00
|
|
|
FindDashboard(ctx context.Context, orgId int64, dashboardUid string) (*dashboards.Dashboard, error)
|
2022-10-25 19:40:42 -05:00
|
|
|
FindAll(ctx context.Context, orgId int64) ([]PublicDashboardListResponse, error)
|
2022-11-03 14:30:12 -05:00
|
|
|
Create(ctx context.Context, cmd SavePublicDashboardCommand) (int64, error)
|
|
|
|
Update(ctx context.Context, cmd SavePublicDashboardCommand) (int64, error)
|
2023-03-08 14:54:35 -06:00
|
|
|
Delete(ctx context.Context, uid string) (int64, error)
|
2022-10-25 19:40:42 -05:00
|
|
|
|
|
|
|
GetOrgIdByAccessToken(ctx context.Context, accessToken string) (int64, error)
|
2023-03-08 14:54:35 -06:00
|
|
|
FindByDashboardFolder(ctx context.Context, dashboard *dashboards.Dashboard) ([]*PublicDashboard, error)
|
2022-10-25 19:40:42 -05:00
|
|
|
ExistsEnabledByAccessToken(ctx context.Context, accessToken string) (bool, error)
|
|
|
|
ExistsEnabledByDashboardUid(ctx context.Context, dashboardUid string) (bool, error)
|
2023-04-11 12:36:50 -05:00
|
|
|
GetMetrics(ctx context.Context) (*Metrics, error)
|
2022-07-06 18:51:44 -05:00
|
|
|
}
|