Chore: Remove public vars in setting package (#81018)
Removes the public variable setting.SecretKey plus some other ones. Introduces some new functions for creating setting.Cfg.
This commit is contained in:
+2
-3
@@ -20,7 +20,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/notifications"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/services/search/model"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -522,7 +521,7 @@ func (hs *HTTPServer) fillWithSecureSettingsData(ctx context.Context, cmd *alert
|
||||
return err
|
||||
}
|
||||
|
||||
secureSettings, err := hs.EncryptionService.DecryptJsonData(ctx, res.SecureSettings, setting.SecretKey)
|
||||
secureSettings, err := hs.EncryptionService.DecryptJsonData(ctx, res.SecureSettings, hs.Cfg.SecretKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -551,7 +550,7 @@ func (hs *HTTPServer) fillWithSecureSettingsDataByUID(ctx context.Context, cmd *
|
||||
return err
|
||||
}
|
||||
|
||||
secureSettings, err := hs.EncryptionService.DecryptJsonData(ctx, res.SecureSettings, setting.SecretKey)
|
||||
secureSettings, err := hs.EncryptionService.DecryptJsonData(ctx, res.SecureSettings, hs.Cfg.SecretKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func (hs *HTTPServer) GetAnnotations(c *contextmodel.ReqContext) response.Respon
|
||||
dashboardCache := make(map[int64]*string)
|
||||
for _, item := range items {
|
||||
if item.Email != "" {
|
||||
item.AvatarURL = dtos.GetGravatarUrl(item.Email)
|
||||
item.AvatarURL = dtos.GetGravatarUrl(hs.Cfg, item.Email)
|
||||
}
|
||||
|
||||
if item.DashboardID != 0 {
|
||||
@@ -485,7 +485,7 @@ func (hs *HTTPServer) GetAnnotationByID(c *contextmodel.ReqContext) response.Res
|
||||
}
|
||||
|
||||
if annotation.Email != "" {
|
||||
annotation.AvatarURL = dtos.GetGravatarUrl(annotation.Email)
|
||||
annotation.AvatarURL = dtos.GetGravatarUrl(hs.Cfg, annotation.Email)
|
||||
}
|
||||
|
||||
return response.JSON(200, annotation)
|
||||
|
||||
+2
-3
@@ -46,7 +46,6 @@ import (
|
||||
publicdashboardsapi "github.com/grafana/grafana/pkg/services/publicdashboards/api"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
var plog = log.New("api")
|
||||
@@ -511,7 +510,7 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
|
||||
apiRoute.Group("/alerts", func(alertsRoute routing.RouteRegister) {
|
||||
alertsRoute.Post("/test", routing.Wrap(hs.AlertTest))
|
||||
alertsRoute.Post("/:alertId/pause", reqEditorRole, routing.Wrap(hs.PauseAlert(setting.AlertingEnabled)))
|
||||
alertsRoute.Post("/:alertId/pause", reqEditorRole, routing.Wrap(hs.PauseAlert(hs.Cfg.AlertingEnabled)))
|
||||
alertsRoute.Get("/:alertId", hs.ValidateOrgAlert, routing.Wrap(hs.GetAlert))
|
||||
alertsRoute.Get("/", routing.Wrap(hs.GetAlerts))
|
||||
alertsRoute.Get("/states-for-dashboard", routing.Wrap(hs.GetAlertStatesForDashboard))
|
||||
@@ -583,7 +582,7 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
adminRoute.Get("/settings", authorize(ac.EvalPermission(ac.ActionSettingsRead)), routing.Wrap(hs.AdminGetSettings))
|
||||
adminRoute.Get("/settings-verbose", authorize(ac.EvalPermission(ac.ActionSettingsRead)), routing.Wrap(hs.AdminGetVerboseSettings))
|
||||
adminRoute.Get("/stats", authorize(ac.EvalPermission(ac.ActionServerStatsRead)), routing.Wrap(hs.AdminGetStats))
|
||||
adminRoute.Post("/pause-all-alerts", reqGrafanaAdmin, routing.Wrap(hs.PauseAllAlerts(setting.AlertingEnabled)))
|
||||
adminRoute.Post("/pause-all-alerts", reqGrafanaAdmin, routing.Wrap(hs.PauseAllAlerts(hs.Cfg.AlertingEnabled)))
|
||||
|
||||
adminRoute.Post("/encryption/rotate-data-keys", reqGrafanaAdmin, routing.Wrap(hs.AdminRotateDataEncryptionKeys))
|
||||
adminRoute.Post("/encryption/reencrypt-data-keys", reqGrafanaAdmin, routing.Wrap(hs.AdminReEncryptEncryptionKeys))
|
||||
|
||||
@@ -107,7 +107,7 @@ func (a *AvatarCacheServer) Handler(ctx *contextmodel.ReqContext) {
|
||||
return
|
||||
}
|
||||
|
||||
avatar := a.GetAvatarForHash(hash)
|
||||
avatar := a.GetAvatarForHash(a.cfg, hash)
|
||||
|
||||
ctx.Resp.Header().Set("Content-Type", "image/jpeg")
|
||||
|
||||
@@ -123,8 +123,8 @@ func (a *AvatarCacheServer) Handler(ctx *contextmodel.ReqContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AvatarCacheServer) GetAvatarForHash(hash string) *Avatar {
|
||||
if setting.DisableGravatar {
|
||||
func (a *AvatarCacheServer) GetAvatarForHash(cfg *setting.Cfg, hash string) *Avatar {
|
||||
if cfg.DisableGravatar {
|
||||
alog.Warn("'GetGravatarForHash' called despite gravatars being disabled; returning default profile image")
|
||||
return a.notFound
|
||||
}
|
||||
|
||||
@@ -69,10 +69,10 @@ func (hs *HTTPServer) GetDashboardPermissionList(c *contextmodel.ReqContext) res
|
||||
continue
|
||||
}
|
||||
|
||||
perm.UserAvatarURL = dtos.GetGravatarUrl(perm.UserEmail)
|
||||
perm.UserAvatarURL = dtos.GetGravatarUrl(hs.Cfg, perm.UserEmail)
|
||||
|
||||
if perm.TeamID > 0 {
|
||||
perm.TeamAvatarURL = dtos.GetGravatarUrlWithDefault(perm.TeamEmail, perm.Team)
|
||||
perm.TeamAvatarURL = dtos.GetGravatarUrlWithDefault(hs.Cfg, perm.TeamEmail, perm.Team)
|
||||
}
|
||||
if perm.Slug != "" {
|
||||
perm.URL = dashboards.GetDashboardFolderURL(perm.IsFolder, perm.UID, perm.Slug)
|
||||
|
||||
@@ -108,9 +108,9 @@ func (mr *MetricRequest) CloneWithQueries(queries []*simplejson.Json) MetricRequ
|
||||
}
|
||||
}
|
||||
|
||||
func GetGravatarUrl(text string) string {
|
||||
if setting.DisableGravatar {
|
||||
return setting.AppSubUrl + "/public/img/user_profile.png"
|
||||
func GetGravatarUrl(cfg *setting.Cfg, text string) string {
|
||||
if cfg.DisableGravatar {
|
||||
return cfg.AppSubURL + "/public/img/user_profile.png"
|
||||
}
|
||||
|
||||
if text == "" {
|
||||
@@ -118,7 +118,7 @@ func GetGravatarUrl(text string) string {
|
||||
}
|
||||
|
||||
hash, _ := GetGravatarHash(text)
|
||||
return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hash)
|
||||
return fmt.Sprintf(cfg.AppSubURL+"/avatar/%x", hash)
|
||||
}
|
||||
|
||||
func GetGravatarHash(text string) ([]byte, bool) {
|
||||
@@ -133,14 +133,14 @@ func GetGravatarHash(text string) ([]byte, bool) {
|
||||
return hasher.Sum(nil), true
|
||||
}
|
||||
|
||||
func GetGravatarUrlWithDefault(text string, defaultText string) string {
|
||||
func GetGravatarUrlWithDefault(cfg *setting.Cfg, text string, defaultText string) string {
|
||||
if text != "" {
|
||||
return GetGravatarUrl(text)
|
||||
return GetGravatarUrl(cfg, text)
|
||||
}
|
||||
|
||||
text = regNonAlphaNumeric.ReplaceAllString(defaultText, "") + "@localhost"
|
||||
|
||||
return GetGravatarUrl(text)
|
||||
return GetGravatarUrl(cfg, text)
|
||||
}
|
||||
|
||||
func IsHiddenUser(userLogin string, signedInUser identity.Requester, cfg *setting.Cfg) bool {
|
||||
|
||||
@@ -451,11 +451,12 @@ func setupServer(b testing.TB, sc benchScenario, features featuremgmt.FeatureTog
|
||||
ac := acimpl.ProvideAccessControl(sc.cfg)
|
||||
folderServiceWithFlagOn := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), sc.cfg, dashStore, folderStore, sc.db, features, nil)
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
folderPermissions, err := ossaccesscontrol.ProvideFolderPermissions(
|
||||
features, routing.NewRouteRegister(), sc.db, ac, license, &dashboards.FakeDashboardStore{}, folderServiceWithFlagOn, acSvc, sc.teamSvc, sc.userSvc)
|
||||
cfg, features, routing.NewRouteRegister(), sc.db, ac, license, &dashboards.FakeDashboardStore{}, folderServiceWithFlagOn, acSvc, sc.teamSvc, sc.userSvc)
|
||||
require.NoError(b, err)
|
||||
dashboardPermissions, err := ossaccesscontrol.ProvideDashboardPermissions(
|
||||
features, routing.NewRouteRegister(), sc.db, ac, license, &dashboards.FakeDashboardStore{}, folderServiceWithFlagOn, acSvc, sc.teamSvc, sc.userSvc)
|
||||
cfg, features, routing.NewRouteRegister(), sc.db, ac, license, &dashboards.FakeDashboardStore{}, folderServiceWithFlagOn, acSvc, sc.teamSvc, sc.userSvc)
|
||||
require.NoError(b, err)
|
||||
|
||||
dashboardSvc, err := dashboardservice.ProvideDashboardServiceImpl(
|
||||
|
||||
@@ -50,10 +50,10 @@ func (hs *HTTPServer) GetFolderPermissionList(c *contextmodel.ReqContext) respon
|
||||
perm.FolderID = folder.ID
|
||||
perm.DashboardID = 0
|
||||
|
||||
perm.UserAvatarURL = dtos.GetGravatarUrl(perm.UserEmail)
|
||||
perm.UserAvatarURL = dtos.GetGravatarUrl(hs.Cfg, perm.UserEmail)
|
||||
|
||||
if perm.TeamID > 0 {
|
||||
perm.TeamAvatarURL = dtos.GetGravatarUrlWithDefault(perm.TeamEmail, perm.Team)
|
||||
perm.TeamAvatarURL = dtos.GetGravatarUrlWithDefault(hs.Cfg, perm.TeamEmail, perm.Team)
|
||||
}
|
||||
|
||||
if perm.Slug != "" {
|
||||
|
||||
+21
-21
@@ -165,29 +165,29 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
||||
frontendSettings := &dtos.FrontendSettingsDTO{
|
||||
DefaultDatasource: defaultDS,
|
||||
Datasources: dataSources,
|
||||
MinRefreshInterval: setting.MinRefreshInterval,
|
||||
MinRefreshInterval: hs.Cfg.MinRefreshInterval,
|
||||
Panels: panels,
|
||||
Apps: apps,
|
||||
AppUrl: hs.Cfg.AppURL,
|
||||
AppSubUrl: hs.Cfg.AppSubURL,
|
||||
AllowOrgCreate: (setting.AllowUserOrgCreate && c.IsSignedIn) || c.IsGrafanaAdmin,
|
||||
AllowOrgCreate: (hs.Cfg.AllowUserOrgCreate && c.IsSignedIn) || c.IsGrafanaAdmin,
|
||||
AuthProxyEnabled: hs.Cfg.AuthProxyEnabled,
|
||||
LdapEnabled: hs.Cfg.LDAPAuthEnabled,
|
||||
JwtHeaderName: hs.Cfg.JWTAuthHeaderName,
|
||||
JwtUrlLogin: hs.Cfg.JWTAuthURLLogin,
|
||||
AlertingErrorOrTimeout: setting.AlertingErrorOrTimeout,
|
||||
AlertingNoDataOrNullValues: setting.AlertingNoDataOrNullValues,
|
||||
AlertingMinInterval: setting.AlertingMinInterval,
|
||||
AlertingErrorOrTimeout: hs.Cfg.AlertingErrorOrTimeout,
|
||||
AlertingNoDataOrNullValues: hs.Cfg.AlertingNoDataOrNullValues,
|
||||
AlertingMinInterval: hs.Cfg.AlertingMinInterval,
|
||||
LiveEnabled: hs.Cfg.LiveMaxConnections != 0,
|
||||
AutoAssignOrg: hs.Cfg.AutoAssignOrg,
|
||||
VerifyEmailEnabled: setting.VerifyEmailEnabled,
|
||||
SigV4AuthEnabled: setting.SigV4AuthEnabled,
|
||||
AzureAuthEnabled: setting.AzureAuthEnabled,
|
||||
VerifyEmailEnabled: hs.Cfg.VerifyEmailEnabled,
|
||||
SigV4AuthEnabled: hs.Cfg.SigV4AuthEnabled,
|
||||
AzureAuthEnabled: hs.Cfg.AzureAuthEnabled,
|
||||
RbacEnabled: true,
|
||||
ExploreEnabled: setting.ExploreEnabled,
|
||||
HelpEnabled: setting.HelpEnabled,
|
||||
ProfileEnabled: setting.ProfileEnabled,
|
||||
NewsFeedEnabled: setting.NewsFeedEnabled,
|
||||
ExploreEnabled: hs.Cfg.ExploreEnabled,
|
||||
HelpEnabled: hs.Cfg.HelpEnabled,
|
||||
ProfileEnabled: hs.Cfg.ProfileEnabled,
|
||||
NewsFeedEnabled: hs.Cfg.NewsFeedEnabled,
|
||||
QueryHistoryEnabled: hs.Cfg.QueryHistoryEnabled,
|
||||
GoogleAnalyticsId: hs.Cfg.GoogleAnalyticsID,
|
||||
GoogleAnalytics4Id: hs.Cfg.GoogleAnalytics4ID,
|
||||
@@ -201,12 +201,12 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
||||
ApplicationInsightsConnectionString: hs.Cfg.ApplicationInsightsConnectionString,
|
||||
ApplicationInsightsEndpointUrl: hs.Cfg.ApplicationInsightsEndpointUrl,
|
||||
DisableLoginForm: hs.Cfg.DisableLoginForm,
|
||||
DisableUserSignUp: !setting.AllowUserSignUp,
|
||||
LoginHint: setting.LoginHint,
|
||||
PasswordHint: setting.PasswordHint,
|
||||
ExternalUserMngInfo: setting.ExternalUserMngInfo,
|
||||
ExternalUserMngLinkUrl: setting.ExternalUserMngLinkUrl,
|
||||
ExternalUserMngLinkName: setting.ExternalUserMngLinkName,
|
||||
DisableUserSignUp: !hs.Cfg.AllowUserSignUp,
|
||||
LoginHint: hs.Cfg.LoginHint,
|
||||
PasswordHint: hs.Cfg.PasswordHint,
|
||||
ExternalUserMngInfo: hs.Cfg.ExternalUserMngInfo,
|
||||
ExternalUserMngLinkUrl: hs.Cfg.ExternalUserMngLinkUrl,
|
||||
ExternalUserMngLinkName: hs.Cfg.ExternalUserMngLinkName,
|
||||
ViewersCanEdit: hs.Cfg.ViewersCanEdit,
|
||||
AngularSupportEnabled: hs.Cfg.AngularSupportEnabled,
|
||||
EditorsCanAdmin: hs.Cfg.EditorsCanAdmin,
|
||||
@@ -228,7 +228,7 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
||||
Edition: hs.License.Edition(),
|
||||
LatestVersion: hs.grafanaUpdateChecker.LatestVersion(),
|
||||
HasUpdate: hs.grafanaUpdateChecker.UpdateAvailable(),
|
||||
Env: setting.Env,
|
||||
Env: hs.Cfg.Env,
|
||||
},
|
||||
|
||||
LicenseInfo: dtos.FrontendSettingsLicenseInfoDTO{
|
||||
@@ -303,8 +303,8 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
||||
frontendSettings.UnifiedAlertingEnabled = *hs.Cfg.UnifiedAlerting.Enabled
|
||||
}
|
||||
|
||||
if setting.AlertingEnabled != nil {
|
||||
frontendSettings.AlertingEnabled = *setting.AlertingEnabled
|
||||
if hs.Cfg.AlertingEnabled != nil {
|
||||
frontendSettings.AlertingEnabled = *(hs.Cfg.AlertingEnabled)
|
||||
}
|
||||
|
||||
// It returns false if the provider is not enabled or the skip org role sync is false.
|
||||
|
||||
@@ -41,11 +41,9 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg, features featuremgmt.F
|
||||
{
|
||||
oldVersion := setting.BuildVersion
|
||||
oldCommit := setting.BuildCommit
|
||||
oldEnv := setting.Env
|
||||
t.Cleanup(func() {
|
||||
setting.BuildVersion = oldVersion
|
||||
setting.BuildCommit = oldCommit
|
||||
setting.Env = oldEnv
|
||||
})
|
||||
}
|
||||
|
||||
@@ -83,7 +81,7 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg, features featuremgmt.F
|
||||
|
||||
m := web.New()
|
||||
m.Use(getContextHandler(t, cfg).Middleware)
|
||||
m.UseMiddleware(web.Renderer(filepath.Join(setting.StaticRootPath, "views"), "[[", "]]"))
|
||||
m.UseMiddleware(web.Renderer(filepath.Join("", "views"), "[[", "]]"))
|
||||
m.Get("/api/frontend/settings/", hs.GetFrontendSettings)
|
||||
|
||||
return m, hs
|
||||
@@ -111,7 +109,6 @@ func TestHTTPServer_GetFrontendSettings_hideVersionAnonymous(t *testing.T) {
|
||||
// TODO: Remove
|
||||
setting.BuildVersion = cfg.BuildVersion
|
||||
setting.BuildCommit = cfg.BuildCommit
|
||||
setting.Env = cfg.Env
|
||||
|
||||
tests := []struct {
|
||||
desc string
|
||||
@@ -125,7 +122,7 @@ func TestHTTPServer_GetFrontendSettings_hideVersionAnonymous(t *testing.T) {
|
||||
BuildInfo: buildInfo{
|
||||
Version: setting.BuildVersion,
|
||||
Commit: setting.BuildCommit,
|
||||
Env: setting.Env,
|
||||
Env: cfg.Env,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -136,7 +133,7 @@ func TestHTTPServer_GetFrontendSettings_hideVersionAnonymous(t *testing.T) {
|
||||
BuildInfo: buildInfo{
|
||||
Version: "",
|
||||
Commit: "",
|
||||
Env: setting.Env,
|
||||
Env: cfg.Env,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
+7
-7
@@ -60,7 +60,7 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
|
||||
locale = parts[0]
|
||||
}
|
||||
|
||||
appURL := setting.AppUrl
|
||||
appURL := hs.Cfg.AppURL
|
||||
appSubURL := hs.Cfg.AppSubURL
|
||||
|
||||
// special case when doing localhost call from image renderer
|
||||
@@ -100,7 +100,7 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
|
||||
OrgName: c.OrgName,
|
||||
OrgRole: c.SignedInUser.GetOrgRole(),
|
||||
OrgCount: hs.getUserOrgCount(c, userID),
|
||||
GravatarUrl: dtos.GetGravatarUrl(c.SignedInUser.GetEmail()),
|
||||
GravatarUrl: dtos.GetGravatarUrl(hs.Cfg, c.SignedInUser.GetEmail()),
|
||||
IsGrafanaAdmin: c.IsGrafanaAdmin,
|
||||
Theme: theme.ID,
|
||||
LightTheme: theme.Type == "light",
|
||||
@@ -117,7 +117,7 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
|
||||
ThemeType: theme.Type,
|
||||
AppUrl: appURL,
|
||||
AppSubUrl: appSubURL,
|
||||
NewsFeedEnabled: setting.NewsFeedEnabled,
|
||||
NewsFeedEnabled: hs.Cfg.NewsFeedEnabled,
|
||||
GoogleAnalyticsId: settings.GoogleAnalyticsId,
|
||||
GoogleAnalytics4Id: settings.GoogleAnalytics4Id,
|
||||
GoogleAnalytics4SendManualPageViews: hs.Cfg.GoogleAnalytics4SendManualPageViews,
|
||||
@@ -149,7 +149,7 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
|
||||
|
||||
data.User.Permissions = ac.BuildPermissionsMap(userPermissions)
|
||||
|
||||
if setting.DisableGravatar {
|
||||
if hs.Cfg.DisableGravatar {
|
||||
data.User.GravatarUrl = hs.Cfg.AppSubURL + "/public/img/user_profile.png"
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (hs *HTTPServer) buildUserAnalyticsSettings(c *contextmodel.ReqContext) dto
|
||||
|
||||
// Anonymous users do not have an email or auth info
|
||||
if namespace != identity.NamespaceUser {
|
||||
return dtos.AnalyticsSettings{Identifier: "@" + setting.AppUrl}
|
||||
return dtos.AnalyticsSettings{Identifier: "@" + hs.Cfg.AppURL}
|
||||
}
|
||||
|
||||
if !c.IsSignedIn {
|
||||
@@ -180,10 +180,10 @@ func (hs *HTTPServer) buildUserAnalyticsSettings(c *contextmodel.ReqContext) dto
|
||||
userID, err := identity.IntIdentifier(namespace, id)
|
||||
if err != nil {
|
||||
hs.log.Error("Failed to parse user ID", "error", err)
|
||||
return dtos.AnalyticsSettings{Identifier: "@" + setting.AppUrl}
|
||||
return dtos.AnalyticsSettings{Identifier: "@" + hs.Cfg.AppURL}
|
||||
}
|
||||
|
||||
identifier := c.SignedInUser.GetEmail() + "@" + setting.AppUrl
|
||||
identifier := c.SignedInUser.GetEmail() + "@" + hs.Cfg.AppURL
|
||||
|
||||
authInfo, err := hs.authInfoService.GetAuthInfo(c.Req.Context(), &login.GetAuthInfoQuery{UserId: userID})
|
||||
if err != nil && !errors.Is(err, user.ErrUserNotFound) {
|
||||
|
||||
@@ -122,16 +122,14 @@ func TestLoginErrorCookieAPIEndpoint(t *testing.T) {
|
||||
})
|
||||
|
||||
cfg.LoginCookieName = loginCookieName
|
||||
setting.SecretKey = "login_testing"
|
||||
|
||||
cfg.OAuthAutoLogin = true
|
||||
|
||||
oauthError := errors.New("User not a member of one of the required organizations")
|
||||
encryptedError, err := hs.SecretsService.Encrypt(context.Background(), []byte(oauthError.Error()), secrets.WithoutScope())
|
||||
require.NoError(t, err)
|
||||
expCookiePath := "/"
|
||||
if len(setting.AppSubUrl) > 0 {
|
||||
expCookiePath = setting.AppSubUrl
|
||||
if len(cfg.AppSubURL) > 0 {
|
||||
expCookiePath = cfg.AppSubURL
|
||||
}
|
||||
cookie := http.Cookie{
|
||||
Name: loginErrorCookieName,
|
||||
|
||||
@@ -305,7 +305,7 @@ func (hs *HTTPServer) searchOrgUsersHelper(c *contextmodel.ReqContext, query *or
|
||||
if dtos.IsHiddenUser(user.Login, c.SignedInUser, hs.Cfg) {
|
||||
continue
|
||||
}
|
||||
user.AvatarURL = dtos.GetGravatarUrl(user.Email)
|
||||
user.AvatarURL = dtos.GetGravatarUrl(hs.Cfg, user.Email)
|
||||
|
||||
userIDs[fmt.Sprint(user.UserID)] = true
|
||||
authLabelsUserIDs = append(authLabelsUserIDs, user.UserID)
|
||||
|
||||
@@ -275,7 +275,7 @@ func (proxy *DataSourceProxy) director(req *http.Request) {
|
||||
}
|
||||
|
||||
func (proxy *DataSourceProxy) validateRequest() error {
|
||||
if !checkWhiteList(proxy.ctx, proxy.targetUrl.Host) {
|
||||
if !proxy.checkWhiteList() {
|
||||
return errors.New("target URL is not a valid target")
|
||||
}
|
||||
|
||||
@@ -354,10 +354,10 @@ func (proxy *DataSourceProxy) logRequest() {
|
||||
"body", body)
|
||||
}
|
||||
|
||||
func checkWhiteList(c *contextmodel.ReqContext, host string) bool {
|
||||
if host != "" && len(setting.DataProxyWhiteList) > 0 {
|
||||
if _, exists := setting.DataProxyWhiteList[host]; !exists {
|
||||
c.JsonApiErr(403, "Data proxy hostname and ip are not included in whitelist", nil)
|
||||
func (proxy *DataSourceProxy) checkWhiteList() bool {
|
||||
if proxy.targetUrl.Host != "" && len(proxy.cfg.DataProxyWhiteList) > 0 {
|
||||
if _, exists := proxy.cfg.DataProxyWhiteList[proxy.targetUrl.Host]; !exists {
|
||||
proxy.ctx.JsonApiErr(403, "Data proxy hostname and ip are not included in whitelist", nil)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
)
|
||||
|
||||
func TestPluginProxy(t *testing.T) {
|
||||
setting.SecretKey = "password"
|
||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||
|
||||
t.Run("When getting proxy headers", func(t *testing.T) {
|
||||
|
||||
@@ -26,7 +26,7 @@ func (hs *HTTPServer) createShortURL(c *contextmodel.ReqContext) response.Respon
|
||||
return response.Err(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/goto/%s?orgId=%d", strings.TrimSuffix(setting.AppUrl, "/"), shortURL.Uid, c.SignedInUser.GetOrgID())
|
||||
url := fmt.Sprintf("%s/goto/%s?orgId=%d", strings.TrimSuffix(hs.Cfg.AppURL, "/"), shortURL.Uid, c.SignedInUser.GetOrgID())
|
||||
c.Logger.Debug("Created short URL", "url", url)
|
||||
|
||||
dto := dtos.ShortURL{
|
||||
|
||||
+4
-5
@@ -14,7 +14,6 @@ import (
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
tempuser "github.com/grafana/grafana/pkg/services/temp_user"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -22,7 +21,7 @@ import (
|
||||
// GET /api/user/signup/options
|
||||
func (hs *HTTPServer) GetSignUpOptions(c *contextmodel.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, util.DynMap{
|
||||
"verifyEmailEnabled": setting.VerifyEmailEnabled,
|
||||
"verifyEmailEnabled": hs.Cfg.VerifyEmailEnabled,
|
||||
"autoAssignOrg": hs.Cfg.AutoAssignOrg,
|
||||
})
|
||||
}
|
||||
@@ -34,7 +33,7 @@ func (hs *HTTPServer) SignUp(c *contextmodel.ReqContext) response.Response {
|
||||
if err = web.Bind(c.Req, &form); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
if !setting.AllowUserSignUp {
|
||||
if !hs.Cfg.AllowUserSignUp {
|
||||
return response.Error(401, "User signup is disabled", nil)
|
||||
}
|
||||
|
||||
@@ -86,7 +85,7 @@ func (hs *HTTPServer) SignUpStep2(c *contextmodel.ReqContext) response.Response
|
||||
if err := web.Bind(c.Req, &form); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
if !setting.AllowUserSignUp {
|
||||
if !hs.Cfg.AllowUserSignUp {
|
||||
return response.Error(401, "User signup is disabled", nil)
|
||||
}
|
||||
|
||||
@@ -102,7 +101,7 @@ func (hs *HTTPServer) SignUpStep2(c *contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
// verify email
|
||||
if setting.VerifyEmailEnabled {
|
||||
if hs.Cfg.VerifyEmailEnabled {
|
||||
if ok, rsp := hs.verifyUserSignUpEmail(c.Req.Context(), form.Email, form.Code); !ok {
|
||||
return rsp
|
||||
}
|
||||
|
||||
+2
-2
@@ -79,7 +79,7 @@ func (hs *HTTPServer) getUserUserProfile(c *contextmodel.ReqContext, userID int6
|
||||
}
|
||||
|
||||
userProfile.AccessControl = hs.getAccessControlMetadata(c, c.SignedInUser.GetOrgID(), "global.users:id:", strconv.FormatInt(userID, 10))
|
||||
userProfile.AvatarURL = dtos.GetGravatarUrl(userProfile.Email)
|
||||
userProfile.AvatarURL = dtos.GetGravatarUrl(hs.Cfg, userProfile.Email)
|
||||
|
||||
return response.JSON(http.StatusOK, userProfile)
|
||||
}
|
||||
@@ -324,7 +324,7 @@ func (hs *HTTPServer) getUserTeamList(c *contextmodel.ReqContext, orgID int64, u
|
||||
}
|
||||
|
||||
for _, team := range queryResult {
|
||||
team.AvatarURL = dtos.GetGravatarUrlWithDefault(team.Email, team.Name)
|
||||
team.AvatarURL = dtos.GetGravatarUrlWithDefault(hs.Cfg, team.Email, team.Name)
|
||||
}
|
||||
return response.JSON(http.StatusOK, queryResult)
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
}
|
||||
err = srv.UpdateAuthInfo(context.Background(), cmd)
|
||||
require.NoError(t, err)
|
||||
avatarUrl := dtos.GetGravatarUrl("@test.com")
|
||||
avatarUrl := dtos.GetGravatarUrl(hs.Cfg, "@test.com")
|
||||
sc.fakeReqWithParams("GET", sc.url, map[string]string{"id": fmt.Sprintf("%v", usr.ID)}).exec()
|
||||
|
||||
expected := user.UserProfileDTO{
|
||||
@@ -160,7 +160,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/users", "/api/users", func(sc *scenarioContext) {
|
||||
userMock.ExpectedSearchUsers = mockResult
|
||||
|
||||
searchUsersService := searchusers.ProvideUsersService(filters.ProvideOSSSearchUserFilter(), userMock)
|
||||
searchUsersService := searchusers.ProvideUsersService(sc.cfg, filters.ProvideOSSSearchUserFilter(), userMock)
|
||||
sc.handlerFunc = searchUsersService.SearchUsers
|
||||
sc.fakeReqWithParams("GET", sc.url, map[string]string{}).exec()
|
||||
|
||||
@@ -173,7 +173,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET with page and limit querystring parameters on", "/api/users", "/api/users", func(sc *scenarioContext) {
|
||||
userMock.ExpectedSearchUsers = mockResult
|
||||
|
||||
searchUsersService := searchusers.ProvideUsersService(filters.ProvideOSSSearchUserFilter(), userMock)
|
||||
searchUsersService := searchusers.ProvideUsersService(sc.cfg, filters.ProvideOSSSearchUserFilter(), userMock)
|
||||
sc.handlerFunc = searchUsersService.SearchUsers
|
||||
sc.fakeReqWithParams("GET", sc.url, map[string]string{"perpage": "10", "page": "2"}).exec()
|
||||
|
||||
@@ -186,7 +186,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/users/search", "/api/users/search", func(sc *scenarioContext) {
|
||||
userMock.ExpectedSearchUsers = mockResult
|
||||
|
||||
searchUsersService := searchusers.ProvideUsersService(filters.ProvideOSSSearchUserFilter(), userMock)
|
||||
searchUsersService := searchusers.ProvideUsersService(sc.cfg, filters.ProvideOSSSearchUserFilter(), userMock)
|
||||
sc.handlerFunc = searchUsersService.SearchUsersWithPaging
|
||||
sc.fakeReqWithParams("GET", sc.url, map[string]string{}).exec()
|
||||
|
||||
@@ -202,7 +202,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET with page and perpage querystring parameters on", "/api/users/search", "/api/users/search", func(sc *scenarioContext) {
|
||||
userMock.ExpectedSearchUsers = mockResult
|
||||
|
||||
searchUsersService := searchusers.ProvideUsersService(filters.ProvideOSSSearchUserFilter(), userMock)
|
||||
searchUsersService := searchusers.ProvideUsersService(sc.cfg, filters.ProvideOSSSearchUserFilter(), userMock)
|
||||
sc.handlerFunc = searchUsersService.SearchUsersWithPaging
|
||||
sc.fakeReqWithParams("GET", sc.url, map[string]string{"perpage": "10", "page": "2"}).exec()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user