chore: move models/licensing into licensing service (#61878)

This commit is contained in:
Kristin Laemmert
2023-01-23 11:53:43 -05:00
committed by GitHub
parent 50faeba07e
commit 857649e30b
13 changed files with 39 additions and 36 deletions

View File

@@ -18,6 +18,7 @@ import (
"github.com/grafana/grafana/pkg/services/auth" "github.com/grafana/grafana/pkg/services/auth"
"github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/authn"
"github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/folder"
"github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/services/oauthtoken" "github.com/grafana/grafana/pkg/services/oauthtoken"
"github.com/grafana/grafana/pkg/services/querylibrary" "github.com/grafana/grafana/pkg/services/querylibrary"
"github.com/grafana/grafana/pkg/services/searchV2" "github.com/grafana/grafana/pkg/services/searchV2"
@@ -129,7 +130,7 @@ type HTTPServer struct {
RemoteCacheService *remotecache.RemoteCache RemoteCacheService *remotecache.RemoteCache
ProvisioningService provisioning.ProvisioningService ProvisioningService provisioning.ProvisioningService
Login login.Service Login login.Service
License models.Licensing License licensing.Licensing
AccessControl accesscontrol.AccessControl AccessControl accesscontrol.AccessControl
DataProxy *datasourceproxy.DataSourceProxyService DataProxy *datasourceproxy.DataSourceProxyService
PluginRequestValidator models.PluginRequestValidator PluginRequestValidator models.PluginRequestValidator
@@ -220,7 +221,7 @@ type ServerOptions struct {
} }
func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routing.RouteRegister, bus bus.Bus, func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routing.RouteRegister, bus bus.Bus,
renderService rendering.Service, licensing models.Licensing, hooksService *hooks.HooksService, renderService rendering.Service, licensing licensing.Licensing, hooksService *hooks.HooksService,
cacheService *localcache.CacheService, sqlStore *sqlstore.SQLStore, alertEngine *alerting.AlertEngine, cacheService *localcache.CacheService, sqlStore *sqlstore.SQLStore, alertEngine *alerting.AlertEngine,
pluginRequestValidator models.PluginRequestValidator, pluginStaticRouteResolver plugins.StaticRouteResolver, pluginRequestValidator models.PluginRequestValidator, pluginStaticRouteResolver plugins.StaticRouteResolver,
pluginDashboardService plugindashboards.Service, pluginStore plugins.Store, pluginClient plugins.Client, pluginDashboardService plugindashboards.Service, pluginStore plugins.Store, pluginClient plugins.Client,

View File

@@ -41,7 +41,7 @@ var wireExtsSet = wire.NewSet(
wireSet, wireSet,
migrations.ProvideOSSMigrations, migrations.ProvideOSSMigrations,
licensing.ProvideService, licensing.ProvideService,
wire.Bind(new(models.Licensing), new(*licensing.OSSLicensingService)), wire.Bind(new(licensing.Licensing), new(*licensing.OSSLicensingService)),
wire.Bind(new(registry.DatabaseMigrator), new(*migrations.OSSMigrations)), wire.Bind(new(registry.DatabaseMigrator), new(*migrations.OSSMigrations)),
setting.ProvideProvider, setting.ProvideProvider,
wire.Bind(new(setting.Provider), new(*setting.OSSImpl)), wire.Bind(new(setting.Provider), new(*setting.OSSImpl)),

View File

@@ -3,16 +3,16 @@ package licensing
import ( import (
"fmt" "fmt"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
type Service struct { type Service struct {
licensePath string licensePath string
license models.Licensing license licensing.Licensing
} }
func ProvideLicensing(cfg *setting.Cfg, l models.Licensing) *Service { func ProvideLicensing(cfg *setting.Cfg, l licensing.Licensing) *Service {
return &Service{ return &Service{
licensePath: cfg.EnterpriseLicensePath, licensePath: cfg.EnterpriseLicensePath,
license: l, license: l,
@@ -21,7 +21,7 @@ func ProvideLicensing(cfg *setting.Cfg, l models.Licensing) *Service {
func (l Service) Environment() []string { func (l Service) Environment() []string {
var env []string var env []string
if envProvider, ok := l.license.(models.LicenseEnvironment); ok { if envProvider, ok := l.license.(licensing.LicenseEnvironment); ok {
for k, v := range envProvider.Environment() { for k, v := range envProvider.Environment() {
env = append(env, fmt.Sprintf("%s=%s", k, v)) env = append(env, fmt.Sprintf("%s=%s", k, v))
} }

View File

@@ -43,7 +43,7 @@ var wireExtsBasicSet = wire.NewSet(
wire.Bind(new(auth.UserTokenService), new(*authimpl.UserAuthTokenService)), wire.Bind(new(auth.UserTokenService), new(*authimpl.UserAuthTokenService)),
wire.Bind(new(auth.UserTokenBackgroundService), new(*authimpl.UserAuthTokenService)), wire.Bind(new(auth.UserTokenBackgroundService), new(*authimpl.UserAuthTokenService)),
licensing.ProvideService, licensing.ProvideService,
wire.Bind(new(models.Licensing), new(*licensing.OSSLicensingService)), wire.Bind(new(licensing.Licensing), new(*licensing.OSSLicensingService)),
setting.ProvideProvider, setting.ProvideProvider,
wire.Bind(new(setting.Provider), new(*setting.OSSImpl)), wire.Bind(new(setting.Provider), new(*setting.OSSImpl)),
acimpl.ProvideService, acimpl.ProvideService,

View File

@@ -11,13 +11,13 @@ import (
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/models/roletype" "github.com/grafana/grafana/pkg/models/roletype"
"github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/accesscontrol/actest" "github.com/grafana/grafana/pkg/services/accesscontrol/actest"
"github.com/grafana/grafana/pkg/services/accesscontrol/database" "github.com/grafana/grafana/pkg/services/accesscontrol/database"
"github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -278,7 +278,7 @@ func TestService_DeclarePluginRoles(t *testing.T) {
func TestService_RegisterFixedRoles(t *testing.T) { func TestService_RegisterFixedRoles(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
token models.Licensing token licensing.Licensing
registrations []accesscontrol.RoleRegistration registrations []accesscontrol.RoleRegistration
wantErr bool wantErr bool
}{ }{

View File

@@ -12,6 +12,7 @@ import (
"github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/services/serviceaccounts" "github.com/grafana/grafana/pkg/services/serviceaccounts"
"github.com/grafana/grafana/pkg/services/serviceaccounts/retriever" "github.com/grafana/grafana/pkg/services/serviceaccounts/retriever"
"github.com/grafana/grafana/pkg/services/team" "github.com/grafana/grafana/pkg/services/team"
@@ -40,7 +41,7 @@ var (
func ProvideTeamPermissions( func ProvideTeamPermissions(
cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, cfg *setting.Cfg, router routing.RouteRegister, sql db.DB,
ac accesscontrol.AccessControl, license models.Licensing, service accesscontrol.Service, ac accesscontrol.AccessControl, license licensing.Licensing, service accesscontrol.Service,
teamService team.Service, userService user.Service, teamService team.Service, userService user.Service,
) (*TeamPermissionsService, error) { ) (*TeamPermissionsService, error) {
options := resourcepermissions.Options{ options := resourcepermissions.Options{
@@ -114,7 +115,7 @@ var DashboardAdminActions = append(DashboardEditActions, []string{dashboards.Act
func ProvideDashboardPermissions( func ProvideDashboardPermissions(
cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, ac accesscontrol.AccessControl, cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, ac accesscontrol.AccessControl,
license models.Licensing, dashboardStore dashboards.Store, service accesscontrol.Service, license licensing.Licensing, dashboardStore dashboards.Store, service accesscontrol.Service,
teamService team.Service, userService user.Service, teamService team.Service, userService user.Service,
) (*DashboardPermissionsService, error) { ) (*DashboardPermissionsService, error) {
getDashboard := func(ctx context.Context, orgID int64, resourceID string) (*dashboards.Dashboard, error) { getDashboard := func(ctx context.Context, orgID int64, resourceID string) (*dashboards.Dashboard, error) {
@@ -193,7 +194,7 @@ var FolderAdminActions = append(FolderEditActions, []string{dashboards.ActionFol
func ProvideFolderPermissions( func ProvideFolderPermissions(
cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, accesscontrol accesscontrol.AccessControl, cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, accesscontrol accesscontrol.AccessControl,
license models.Licensing, dashboardStore dashboards.Store, service accesscontrol.Service, license licensing.Licensing, dashboardStore dashboards.Store, service accesscontrol.Service,
teamService team.Service, userService user.Service, teamService team.Service, userService user.Service,
) (*FolderPermissionsService, error) { ) (*FolderPermissionsService, error) {
options := resourcepermissions.Options{ options := resourcepermissions.Options{
@@ -284,7 +285,7 @@ type ServiceAccountPermissionsService struct {
func ProvideServiceAccountPermissions( func ProvideServiceAccountPermissions(
cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, ac accesscontrol.AccessControl, cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, ac accesscontrol.AccessControl,
license models.Licensing, serviceAccountRetrieverService *retriever.Service, service accesscontrol.Service, license licensing.Licensing, serviceAccountRetrieverService *retriever.Service, service accesscontrol.Service,
teamService team.Service, userService user.Service, teamService team.Service, userService user.Service,
) (*ServiceAccountPermissionsService, error) { ) (*ServiceAccountPermissionsService, error) {
options := resourcepermissions.Options{ options := resourcepermissions.Options{

View File

@@ -7,8 +7,8 @@ import (
"github.com/grafana/grafana/pkg/api/routing" "github.com/grafana/grafana/pkg/api/routing"
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/team" "github.com/grafana/grafana/pkg/services/team"
"github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/services/user"
@@ -49,7 +49,7 @@ type Store interface {
} }
func New( func New(
options Options, cfg *setting.Cfg, router routing.RouteRegister, license models.Licensing, options Options, cfg *setting.Cfg, router routing.RouteRegister, license licensing.Licensing,
ac accesscontrol.AccessControl, service accesscontrol.Service, sqlStore db.DB, ac accesscontrol.AccessControl, service accesscontrol.Service, sqlStore db.DB,
teamService team.Service, userService user.Service, teamService team.Service, userService user.Service,
) (*Service, error) { ) (*Service, error) {
@@ -104,7 +104,7 @@ type Service struct {
service accesscontrol.Service service accesscontrol.Service
store Store store Store
api *api api *api
license models.Licensing license licensing.Licensing
options Options options Options
permissions []string permissions []string

View File

@@ -6,10 +6,10 @@ import (
"net/http" "net/http"
"reflect" "reflect"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/licensing"
) )
var ( var (
@@ -18,7 +18,7 @@ var (
type FeatureManager struct { type FeatureManager struct {
isDevMod bool isDevMod bool
licensing models.Licensing licensing licensing.Licensing
flags map[string]*FeatureFlag flags map[string]*FeatureFlag
enabled map[string]bool // only the "on" values enabled map[string]bool // only the "on" values
config string // path to config file config string // path to config file

View File

@@ -5,12 +5,12 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promauto"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/setting"
) )
var ( var (
@@ -22,7 +22,7 @@ var (
}, []string{"name"}) }, []string{"name"})
) )
func ProvideManagerService(cfg *setting.Cfg, licensing models.Licensing) (*FeatureManager, error) { func ProvideManagerService(cfg *setting.Cfg, licensing licensing.Licensing) (*FeatureManager, error) {
mgmt := &FeatureManager{ mgmt := &FeatureManager{
isDevMod: setting.Env != setting.Prod, isDevMod: setting.Env != setting.Prod,
licensing: licensing, licensing: licensing,

View File

@@ -3,9 +3,10 @@ package featuremgmt
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/setting"
) )
func TestFeatureService(t *testing.T) { func TestFeatureService(t *testing.T) {
@@ -47,7 +48,7 @@ func TestFeatureService(t *testing.T) {
} }
var ( var (
_ models.Licensing = (*stubLicenseServier)(nil) _ licensing.Licensing = (*stubLicenseServier)(nil)
) )
type stubLicenseServier struct { type stubLicenseServier struct {

View File

@@ -3,10 +3,10 @@ package licensingtest
import ( import (
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/licensing"
) )
var _ models.Licensing = new(FakeLicensing) var _ licensing.Licensing = new(FakeLicensing)
func NewFakeLicensing() *FakeLicensing { func NewFakeLicensing() *FakeLicensing {
return &FakeLicensing{&mock.Mock{}} return &FakeLicensing{&mock.Mock{}}

View File

@@ -1,4 +1,4 @@
package models package licensing
type Licensing interface { type Licensing interface {
// Expiry returns the unix epoch timestamp when the license expires, or 0 if no valid license is provided // Expiry returns the unix epoch timestamp when the license expires, or 0 if no valid license is provided

View File

@@ -10,9 +10,6 @@ import (
"github.com/segmentio/encoding/json" "github.com/segmentio/encoding/json"
"github.com/grafana/grafana/pkg/services/datasources/permissions"
"github.com/grafana/grafana/pkg/services/searchV2"
"github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
@@ -20,10 +17,13 @@ import (
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/registry" "github.com/grafana/grafana/pkg/registry"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/datasources/permissions"
"github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/guardian" "github.com/grafana/grafana/pkg/services/guardian"
"github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/services/live" "github.com/grafana/grafana/pkg/services/live"
"github.com/grafana/grafana/pkg/services/rendering" "github.com/grafana/grafana/pkg/services/rendering"
"github.com/grafana/grafana/pkg/services/searchV2"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/web" "github.com/grafana/grafana/pkg/web"
) )
@@ -60,7 +60,7 @@ type thumbService struct {
dashboardService dashboards.DashboardService dashboardService dashboards.DashboardService
dsUidsLookup getDatasourceUidsForDashboard dsUidsLookup getDatasourceUidsForDashboard
dsPermissionsService permissions.DatasourcePermissionsService dsPermissionsService permissions.DatasourcePermissionsService
licensing models.Licensing licensing licensing.Licensing
searchService searchV2.SearchService searchService searchV2.SearchService
} }
@@ -78,7 +78,7 @@ func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles,
lockService *serverlock.ServerLockService, renderService rendering.Service, lockService *serverlock.ServerLockService, renderService rendering.Service,
gl *live.GrafanaLive, store db.DB, authSetupService CrawlerAuthSetupService, gl *live.GrafanaLive, store db.DB, authSetupService CrawlerAuthSetupService,
dashboardService dashboards.DashboardService, dashboardThumbsService DashboardThumbService, searchService searchV2.SearchService, dashboardService dashboards.DashboardService, dashboardThumbsService DashboardThumbService, searchService searchV2.SearchService,
dsPermissionsService permissions.DatasourcePermissionsService, licensing models.Licensing) Service { dsPermissionsService permissions.DatasourcePermissionsService, licensing licensing.Licensing) Service {
if !features.IsEnabled(featuremgmt.FlagDashboardPreviews) { if !features.IsEnabled(featuremgmt.FlagDashboardPreviews) {
return &dummyService{} return &dummyService{}
} }