From 969e6a17bab9f553fc812af3342379f59dd62def Mon Sep 17 00:00:00 2001 From: Gabriel MABILLE Date: Thu, 28 Sep 2023 12:18:09 +0200 Subject: [PATCH] Plugins: Rename oauth package to auth (#75611) * Plugins: Rename oauth package to auth * Missed one comment --- pkg/plugins/{oauth => auth}/models.go | 2 +- pkg/plugins/envvars/envvars.go | 4 ++-- pkg/plugins/envvars/envvars_test.go | 4 ++-- pkg/plugins/manager/fakes/fakes.go | 8 ++++---- pkg/plugins/plugins.go | 6 +++--- .../pluginsintegration/loader/loader_test.go | 20 +++++++++---------- .../pluginsintegration/pipeline/pipeline.go | 4 ++-- .../pluginsintegration/pipeline/steps.go | 8 ++++---- .../pluginsintegration/pluginsintegration.go | 4 ++-- .../pluginsintegration/pluginstore/plugins.go | 4 ++-- .../serviceregistration.go | 6 +++--- .../pluginsintegration/test_helper.go | 4 ++-- 12 files changed, 37 insertions(+), 37 deletions(-) rename pkg/plugins/{oauth => auth}/models.go (96%) diff --git a/pkg/plugins/oauth/models.go b/pkg/plugins/auth/models.go similarity index 96% rename from pkg/plugins/oauth/models.go rename to pkg/plugins/auth/models.go index 728035cd5de..8c0f902203a 100644 --- a/pkg/plugins/oauth/models.go +++ b/pkg/plugins/auth/models.go @@ -1,4 +1,4 @@ -package oauth +package auth import ( "context" diff --git a/pkg/plugins/envvars/envvars.go b/pkg/plugins/envvars/envvars.go index 1b48d78f634..3bd03d561dd 100644 --- a/pkg/plugins/envvars/envvars.go +++ b/pkg/plugins/envvars/envvars.go @@ -14,8 +14,8 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/experimental/featuretoggles" "github.com/grafana/grafana/pkg/plugins" + "github.com/grafana/grafana/pkg/plugins/auth" "github.com/grafana/grafana/pkg/plugins/config" - "github.com/grafana/grafana/pkg/plugins/oauth" ) const ( @@ -74,7 +74,7 @@ func (s *Service) Get(ctx context.Context, p *plugins.Plugin) []string { } // GetConfigMap returns a map of configuration that should be passed in a plugin request. -func (s *Service) GetConfigMap(ctx context.Context, _ string, _ *oauth.ExternalService) map[string]string { +func (s *Service) GetConfigMap(ctx context.Context, _ string, _ *auth.ExternalService) map[string]string { m := make(map[string]string) // TODO add support via plugin SDK diff --git a/pkg/plugins/envvars/envvars_test.go b/pkg/plugins/envvars/envvars_test.go index 0655d383579..a1654ab1d70 100644 --- a/pkg/plugins/envvars/envvars_test.go +++ b/pkg/plugins/envvars/envvars_test.go @@ -9,9 +9,9 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/plugins" + "github.com/grafana/grafana/pkg/plugins/auth" "github.com/grafana/grafana/pkg/plugins/config" "github.com/grafana/grafana/pkg/plugins/manager/fakes" - "github.com/grafana/grafana/pkg/plugins/oauth" "github.com/grafana/grafana/pkg/plugins/plugindef" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/setting" @@ -313,7 +313,7 @@ func TestInitializer_oauthEnvVars(t *testing.T) { ID: "test", ExternalServiceRegistration: &plugindef.ExternalServiceRegistration{}, }, - ExternalService: &oauth.ExternalService{ + ExternalService: &auth.ExternalService{ ClientID: "clientID", ClientSecret: "clientSecret", PrivateKey: "privatePem", diff --git a/pkg/plugins/manager/fakes/fakes.go b/pkg/plugins/manager/fakes/fakes.go index 2ef1183eea9..7d6d9b5ee64 100644 --- a/pkg/plugins/manager/fakes/fakes.go +++ b/pkg/plugins/manager/fakes/fakes.go @@ -10,9 +10,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana/pkg/plugins" + "github.com/grafana/grafana/pkg/plugins/auth" "github.com/grafana/grafana/pkg/plugins/backendplugin" "github.com/grafana/grafana/pkg/plugins/log" - "github.com/grafana/grafana/pkg/plugins/oauth" "github.com/grafana/grafana/pkg/plugins/plugindef" "github.com/grafana/grafana/pkg/plugins/repo" "github.com/grafana/grafana/pkg/plugins/storage" @@ -425,11 +425,11 @@ func (f *FakePluginFileStore) File(ctx context.Context, pluginID, filename strin return nil, nil } -type FakeOauthService struct { - Result *oauth.ExternalService +type FakeAuthService struct { + Result *auth.ExternalService } -func (f *FakeOauthService) RegisterExternalService(ctx context.Context, name string, svc *plugindef.ExternalServiceRegistration) (*oauth.ExternalService, error) { +func (f *FakeAuthService) RegisterExternalService(ctx context.Context, name string, svc *plugindef.ExternalServiceRegistration) (*auth.ExternalService, error) { return f.Result, nil } diff --git a/pkg/plugins/plugins.go b/pkg/plugins/plugins.go index 84aad871c5f..a4dba460e78 100644 --- a/pkg/plugins/plugins.go +++ b/pkg/plugins/plugins.go @@ -14,11 +14,11 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" + "github.com/grafana/grafana/pkg/plugins/auth" "github.com/grafana/grafana/pkg/plugins/backendplugin" "github.com/grafana/grafana/pkg/plugins/backendplugin/pluginextensionv2" "github.com/grafana/grafana/pkg/plugins/backendplugin/secretsmanagerplugin" "github.com/grafana/grafana/pkg/plugins/log" - "github.com/grafana/grafana/pkg/plugins/oauth" "github.com/grafana/grafana/pkg/plugins/plugindef" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/util" @@ -56,7 +56,7 @@ type Plugin struct { AngularDetected bool - ExternalService *oauth.ExternalService + ExternalService *auth.ExternalService Renderer pluginextensionv2.RendererPlugin SecretsManager secretsmanagerplugin.SecretsManagerPlugin @@ -112,7 +112,7 @@ type JSONData struct { // Backend (Datasource + Renderer + SecretsManager) Executable string `json:"executable,omitempty"` - // Oauth App Service Registration + // App Service Auth Registration ExternalServiceRegistration *plugindef.ExternalServiceRegistration `json:"externalServiceRegistration,omitempty"` } diff --git a/pkg/services/pluginsintegration/loader/loader_test.go b/pkg/services/pluginsintegration/loader/loader_test.go index 11cadc85e98..d062955e7fa 100644 --- a/pkg/services/pluginsintegration/loader/loader_test.go +++ b/pkg/services/pluginsintegration/loader/loader_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/plugins" + "github.com/grafana/grafana/pkg/plugins/auth" "github.com/grafana/grafana/pkg/plugins/backendplugin" "github.com/grafana/grafana/pkg/plugins/config" "github.com/grafana/grafana/pkg/plugins/log" @@ -23,7 +24,6 @@ import ( "github.com/grafana/grafana/pkg/plugins/manager/registry" "github.com/grafana/grafana/pkg/plugins/manager/signature" "github.com/grafana/grafana/pkg/plugins/manager/sources" - "github.com/grafana/grafana/pkg/plugins/oauth" "github.com/grafana/grafana/pkg/plugins/plugindef" "github.com/grafana/grafana/pkg/plugins/pluginscdn" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -555,7 +555,7 @@ func TestLoader_Load_ExternalRegistration(t *testing.T) { Signature: plugins.SignatureStatusUnsigned, Module: "/public/plugins/grafana-test-datasource/module.js", BaseURL: "/public/plugins/grafana-test-datasource", - ExternalService: &oauth.ExternalService{ + ExternalService: &auth.ExternalService{ ClientID: "client-id", ClientSecret: "secretz", PrivateKey: "priv@t3", @@ -576,8 +576,8 @@ func TestLoader_Load_ExternalRegistration(t *testing.T) { } l := newLoaderWithOpts(t, cfg, loaderDepOpts{ - oauthServiceRegistry: &fakes.FakeOauthService{ - Result: &oauth.ExternalService{ + authServiceRegistry: &fakes.FakeAuthService{ + Result: &auth.ExternalService{ ClientID: "client-id", ClientSecret: "secretz", PrivateKey: "priv@t3", @@ -1468,7 +1468,7 @@ func TestLoader_Load_NestedPlugins(t *testing.T) { type loaderDepOpts struct { angularInspector angularinspector.Inspector - oauthServiceRegistry oauth.ExternalServiceRegistry + authServiceRegistry auth.ExternalServiceRegistry backendFactoryProvider plugins.BackendFactoryProvider } @@ -1484,7 +1484,7 @@ func newLoader(t *testing.T, cfg *config.Cfg, reg registry.Service, proc process return ProvideService(pipeline.ProvideDiscoveryStage(cfg, finder.NewLocalFinder(false), reg), pipeline.ProvideBootstrapStage(cfg, signature.DefaultCalculator(cfg), assets), pipeline.ProvideValidationStage(cfg, signature.NewValidator(signature.NewUnsignedAuthorizer(cfg)), angularInspector, sigErrTracker), - pipeline.ProvideInitializationStage(cfg, reg, lic, backendFactory, proc, &fakes.FakeOauthService{}, fakes.NewFakeRoleRegistry()), + pipeline.ProvideInitializationStage(cfg, reg, lic, backendFactory, proc, &fakes.FakeAuthService{}, fakes.NewFakeRoleRegistry()), terminate) } @@ -1503,9 +1503,9 @@ func newLoaderWithOpts(t *testing.T, cfg *config.Cfg, opts loaderDepOpts) *Loade angularInspector = angularinspector.NewStaticInspector() } - oauthServiceRegistry := opts.oauthServiceRegistry - if oauthServiceRegistry == nil { - oauthServiceRegistry = &fakes.FakeOauthService{} + authServiceRegistry := opts.authServiceRegistry + if authServiceRegistry == nil { + authServiceRegistry = &fakes.FakeAuthService{} } backendFactoryProvider := opts.backendFactoryProvider @@ -1516,7 +1516,7 @@ func newLoaderWithOpts(t *testing.T, cfg *config.Cfg, opts loaderDepOpts) *Loade return ProvideService(pipeline.ProvideDiscoveryStage(cfg, finder.NewLocalFinder(false), reg), pipeline.ProvideBootstrapStage(cfg, signature.DefaultCalculator(cfg), assets), pipeline.ProvideValidationStage(cfg, signature.NewValidator(signature.NewUnsignedAuthorizer(cfg)), angularInspector, sigErrTracker), - pipeline.ProvideInitializationStage(cfg, reg, lic, backendFactoryProvider, proc, oauthServiceRegistry, fakes.NewFakeRoleRegistry()), + pipeline.ProvideInitializationStage(cfg, reg, lic, backendFactoryProvider, proc, authServiceRegistry, fakes.NewFakeRoleRegistry()), terminate) } diff --git a/pkg/services/pluginsintegration/pipeline/pipeline.go b/pkg/services/pluginsintegration/pipeline/pipeline.go index 5d1e0a02b1b..2ac5b3ac068 100644 --- a/pkg/services/pluginsintegration/pipeline/pipeline.go +++ b/pkg/services/pluginsintegration/pipeline/pipeline.go @@ -4,6 +4,7 @@ import ( "context" "github.com/grafana/grafana/pkg/plugins" + "github.com/grafana/grafana/pkg/plugins/auth" "github.com/grafana/grafana/pkg/plugins/config" "github.com/grafana/grafana/pkg/plugins/envvars" "github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angularinspector" @@ -17,7 +18,6 @@ import ( "github.com/grafana/grafana/pkg/plugins/manager/process" "github.com/grafana/grafana/pkg/plugins/manager/registry" "github.com/grafana/grafana/pkg/plugins/manager/signature" - "github.com/grafana/grafana/pkg/plugins/oauth" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginerrs" ) @@ -59,7 +59,7 @@ func ProvideValidationStage(cfg *config.Cfg, sv signature.Validator, ai angulari } func ProvideInitializationStage(cfg *config.Cfg, pr registry.Service, l plugins.Licensing, - bp plugins.BackendFactoryProvider, pm process.Manager, externalServiceRegistry oauth.ExternalServiceRegistry, + bp plugins.BackendFactoryProvider, pm process.Manager, externalServiceRegistry auth.ExternalServiceRegistry, roleRegistry plugins.RoleRegistry) *initialization.Initialize { return initialization.New(cfg, initialization.Opts{ InitializeFuncs: []initialization.InitializeFunc{ diff --git a/pkg/services/pluginsintegration/pipeline/steps.go b/pkg/services/pluginsintegration/pipeline/steps.go index 50e710a1743..6e2bc6c0c2d 100644 --- a/pkg/services/pluginsintegration/pipeline/steps.go +++ b/pkg/services/pluginsintegration/pipeline/steps.go @@ -6,12 +6,12 @@ import ( "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/plugins" + "github.com/grafana/grafana/pkg/plugins/auth" "github.com/grafana/grafana/pkg/plugins/config" "github.com/grafana/grafana/pkg/plugins/log" "github.com/grafana/grafana/pkg/plugins/manager/pipeline/initialization" "github.com/grafana/grafana/pkg/plugins/manager/pipeline/validation" "github.com/grafana/grafana/pkg/plugins/manager/signature" - "github.com/grafana/grafana/pkg/plugins/oauth" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginerrs" ) @@ -19,16 +19,16 @@ import ( // ExternalServiceRegistration implements an InitializeFunc for registering external services. type ExternalServiceRegistration struct { cfg *config.Cfg - externalServiceRegistry oauth.ExternalServiceRegistry + externalServiceRegistry auth.ExternalServiceRegistry log log.Logger } // ExternalServiceRegistrationStep returns an InitializeFunc for registering external services. -func ExternalServiceRegistrationStep(cfg *config.Cfg, externalServiceRegistry oauth.ExternalServiceRegistry) initialization.InitializeFunc { +func ExternalServiceRegistrationStep(cfg *config.Cfg, externalServiceRegistry auth.ExternalServiceRegistry) initialization.InitializeFunc { return newExternalServiceRegistration(cfg, externalServiceRegistry).Register } -func newExternalServiceRegistration(cfg *config.Cfg, serviceRegistry oauth.ExternalServiceRegistry) *ExternalServiceRegistration { +func newExternalServiceRegistration(cfg *config.Cfg, serviceRegistry auth.ExternalServiceRegistry) *ExternalServiceRegistration { return &ExternalServiceRegistration{ cfg: cfg, externalServiceRegistry: serviceRegistry, diff --git a/pkg/services/pluginsintegration/pluginsintegration.go b/pkg/services/pluginsintegration/pluginsintegration.go index 63dd48a0b82..e4b5abdfa87 100644 --- a/pkg/services/pluginsintegration/pluginsintegration.go +++ b/pkg/services/pluginsintegration/pluginsintegration.go @@ -5,6 +5,7 @@ import ( "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/plugins" + "github.com/grafana/grafana/pkg/plugins/auth" "github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin" "github.com/grafana/grafana/pkg/plugins/backendplugin/provider" pCfg "github.com/grafana/grafana/pkg/plugins/config" @@ -25,7 +26,6 @@ import ( "github.com/grafana/grafana/pkg/plugins/manager/registry" "github.com/grafana/grafana/pkg/plugins/manager/signature" "github.com/grafana/grafana/pkg/plugins/manager/sources" - "github.com/grafana/grafana/pkg/plugins/oauth" "github.com/grafana/grafana/pkg/plugins/pluginscdn" "github.com/grafana/grafana/pkg/plugins/repo" "github.com/grafana/grafana/pkg/services/caching" @@ -114,7 +114,7 @@ var WireSet = wire.NewSet( keyretriever.ProvideService, dynamic.ProvideService, serviceregistration.ProvideService, - wire.Bind(new(oauth.ExternalServiceRegistry), new(*serviceregistration.Service)), + wire.Bind(new(auth.ExternalServiceRegistry), new(*serviceregistration.Service)), ) // WireExtensionSet provides a wire.ProviderSet of plugin providers that can be diff --git a/pkg/services/pluginsintegration/pluginstore/plugins.go b/pkg/services/pluginsintegration/pluginstore/plugins.go index 4617f48b377..2ac1fad9ae9 100644 --- a/pkg/services/pluginsintegration/pluginstore/plugins.go +++ b/pkg/services/pluginsintegration/pluginstore/plugins.go @@ -4,7 +4,7 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana/pkg/plugins" - "github.com/grafana/grafana/pkg/plugins/oauth" + "github.com/grafana/grafana/pkg/plugins/auth" ) type Plugin struct { @@ -35,7 +35,7 @@ type Plugin struct { // This will be moved to plugin.json when we have general support in gcom Alias string - ExternalService *oauth.ExternalService + ExternalService *auth.ExternalService } func (p Plugin) SupportsStreaming() bool { diff --git a/pkg/services/pluginsintegration/serviceregistration/serviceregistration.go b/pkg/services/pluginsintegration/serviceregistration/serviceregistration.go index a10f8cfa553..6065c1751c2 100644 --- a/pkg/services/pluginsintegration/serviceregistration/serviceregistration.go +++ b/pkg/services/pluginsintegration/serviceregistration/serviceregistration.go @@ -3,7 +3,7 @@ package serviceregistration import ( "context" - "github.com/grafana/grafana/pkg/plugins/oauth" + "github.com/grafana/grafana/pkg/plugins/auth" "github.com/grafana/grafana/pkg/plugins/plugindef" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/oauthserver" @@ -21,7 +21,7 @@ func ProvideService(os oauthserver.OAuth2Server) *Service { } // RegisterExternalService is a simplified wrapper around SaveExternalService for the plugin use case. -func (s *Service) RegisterExternalService(ctx context.Context, svcName string, svc *plugindef.ExternalServiceRegistration) (*oauth.ExternalService, error) { +func (s *Service) RegisterExternalService(ctx context.Context, svcName string, svc *plugindef.ExternalServiceRegistration) (*auth.ExternalService, error) { impersonation := oauthserver.ImpersonationCfg{} if svc.Impersonation != nil { impersonation.Permissions = toAccessControlPermissions(svc.Impersonation.Permissions) @@ -56,7 +56,7 @@ func (s *Service) RegisterExternalService(ctx context.Context, svcName string, s return nil, err } - return &oauth.ExternalService{ + return &auth.ExternalService{ ClientID: extSvc.ID, ClientSecret: extSvc.Secret, PrivateKey: extSvc.KeyResult.PrivatePem, diff --git a/pkg/services/pluginsintegration/test_helper.go b/pkg/services/pluginsintegration/test_helper.go index b30996ad451..b958b05681c 100644 --- a/pkg/services/pluginsintegration/test_helper.go +++ b/pkg/services/pluginsintegration/test_helper.go @@ -54,7 +54,7 @@ func CreateIntegrationTestCtx(t *testing.T, cfg *setting.Cfg, coreRegistry *core disc := pipeline.ProvideDiscoveryStage(pCfg, finder.NewLocalFinder(true), reg) boot := pipeline.ProvideBootstrapStage(pCfg, signature.ProvideService(pCfg, statickey.New()), assetpath.ProvideService(pCfg, cdn)) valid := pipeline.ProvideValidationStage(pCfg, signature.NewValidator(signature.NewUnsignedAuthorizer(pCfg)), angularInspector, errTracker) - init := pipeline.ProvideInitializationStage(pCfg, reg, fakes.NewFakeLicensingService(), provider.ProvideService(coreRegistry), proc, &fakes.FakeOauthService{}, fakes.NewFakeRoleRegistry()) + init := pipeline.ProvideInitializationStage(pCfg, reg, fakes.NewFakeLicensingService(), provider.ProvideService(coreRegistry), proc, &fakes.FakeAuthService{}, fakes.NewFakeRoleRegistry()) term, err := pipeline.ProvideTerminationStage(pCfg, reg, proc) require.NoError(t, err) @@ -100,7 +100,7 @@ func CreateTestLoader(t *testing.T, cfg *pluginsCfg.Cfg, opts LoaderOpts) *loade if opts.Initializer == nil { reg := registry.ProvideService() coreRegistry := coreplugin.NewRegistry(make(map[string]backendplugin.PluginFactoryFunc)) - opts.Initializer = pipeline.ProvideInitializationStage(cfg, reg, fakes.NewFakeLicensingService(), provider.ProvideService(coreRegistry), process.ProvideService(), &fakes.FakeOauthService{}, fakes.NewFakeRoleRegistry()) + opts.Initializer = pipeline.ProvideInitializationStage(cfg, reg, fakes.NewFakeLicensingService(), provider.ProvideService(coreRegistry), process.ProvideService(), &fakes.FakeAuthService{}, fakes.NewFakeRoleRegistry()) } if opts.Terminator == nil {