Backend: Migrate to using non-global configuration (#31856)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2021-03-10 12:41:29 +01:00
committed by GitHub
parent bac1721546
commit 47f13abf7a
19 changed files with 241 additions and 260 deletions

View File

@@ -435,7 +435,7 @@ func (hs *HTTPServer) registerRoutes() {
r.Any("/api/gnet/*", reqSignedIn, ProxyGnetRequest)
// Gravatar service.
avatarCacheServer := avatar.NewCacheServer()
avatarCacheServer := avatar.NewCacheServer(hs.Cfg)
r.Get("/avatar/:hash", avatarCacheServer.Handler)
// Snapshots

View File

@@ -69,6 +69,7 @@ func (a *Avatar) Update() (err error) {
}
type CacheServer struct {
cfg *setting.Cfg
notFound *Avatar
cache *gocache.Cache
}
@@ -109,7 +110,7 @@ func (a *CacheServer) Handler(ctx *models.ReqContext) {
ctx.Resp.Header().Set("Content-Type", "image/jpeg")
if !setting.EnableGzip {
if !a.cfg.EnableGzip {
ctx.Resp.Header().Set("Content-Length", strconv.Itoa(len(avatar.data.Bytes())))
}
@@ -121,21 +122,22 @@ func (a *CacheServer) Handler(ctx *models.ReqContext) {
}
}
func NewCacheServer() *CacheServer {
func NewCacheServer(cfg *setting.Cfg) *CacheServer {
return &CacheServer{
notFound: newNotFound(),
cfg: cfg,
notFound: newNotFound(cfg),
cache: gocache.New(time.Hour, time.Hour*2),
}
}
func newNotFound() *Avatar {
func newNotFound(cfg *setting.Cfg) *Avatar {
avatar := &Avatar{notFound: true}
// load user_profile png into buffer
// It's safe to ignore gosec warning G304 since the variable part of the file path comes from a configuration
// variable.
// nolint:gosec
path := filepath.Join(setting.StaticRootPath, "img", "user_profile.png")
path := filepath.Join(cfg.StaticRootPath, "img", "user_profile.png")
// It's safe to ignore gosec warning G304 since the variable part of the file path comes from a configuration
// variable.
// nolint:gosec

View File

@@ -16,9 +16,10 @@ import (
)
func TestHealthAPI_Version(t *testing.T) {
m, _ := setupHealthAPITestEnvironment(t)
setting.BuildVersion = "7.4.0"
setting.BuildCommit = "59906ab1bf"
m, _ := setupHealthAPITestEnvironment(t, func(cfg *setting.Cfg) {
cfg.BuildVersion = "7.4.0"
cfg.BuildCommit = "59906ab1bf"
})
bus.AddHandler("test", func(query *models.GetDBHealthQuery) error {
return nil
@@ -166,23 +167,20 @@ func TestHealthAPI_DatabaseHealthCached(t *testing.T) {
require.True(t, healthy.(bool))
}
func setupHealthAPITestEnvironment(t *testing.T) (*macaron.Macaron, *HTTPServer) {
func setupHealthAPITestEnvironment(t *testing.T, cbs ...func(*setting.Cfg)) (*macaron.Macaron, *HTTPServer) {
t.Helper()
oldVersion := setting.BuildVersion
oldCommit := setting.BuildCommit
t.Cleanup(func() {
setting.BuildVersion = oldVersion
setting.BuildCommit = oldCommit
})
bus.ClearBusHandlers()
t.Cleanup(bus.ClearBusHandlers)
m := macaron.New()
cfg := setting.NewCfg()
for _, cb := range cbs {
cb(cfg)
}
hs := &HTTPServer{
CacheService: localcache.New(5*time.Minute, 10*time.Minute),
Cfg: setting.NewCfg(),
Cfg: cfg,
}
m.Get("/api/health", hs.apiHealthHandler)

View File

@@ -111,9 +111,9 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
hs.applyRoutes()
// Remove any square brackets enclosing IPv6 addresses, a format we support for backwards compatibility
host := strings.TrimSuffix(strings.TrimPrefix(setting.HttpAddr, "["), "]")
host := strings.TrimSuffix(strings.TrimPrefix(hs.Cfg.HTTPAddr, "["), "]")
hs.httpSrv = &http.Server{
Addr: net.JoinHostPort(host, setting.HttpPort),
Addr: net.JoinHostPort(host, hs.Cfg.HTTPPort),
Handler: hs.macaron,
}
switch hs.Cfg.Protocol {
@@ -159,7 +159,7 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
return err
}
case setting.HTTP2Scheme, setting.HTTPSScheme:
if err := hs.httpSrv.ServeTLS(listener, setting.CertFile, setting.KeyFile); err != nil {
if err := hs.httpSrv.ServeTLS(listener, hs.Cfg.CertFile, hs.Cfg.KeyFile); err != nil {
if errors.Is(err, http.ErrServerClosed) {
hs.log.Debug("server was shutdown gracefully")
return nil
@@ -207,20 +207,20 @@ func (hs *HTTPServer) getListener() (net.Listener, error) {
}
func (hs *HTTPServer) configureHttps() error {
if setting.CertFile == "" {
if hs.Cfg.CertFile == "" {
return fmt.Errorf("cert_file cannot be empty when using HTTPS")
}
if setting.KeyFile == "" {
if hs.Cfg.KeyFile == "" {
return fmt.Errorf("cert_key cannot be empty when using HTTPS")
}
if _, err := os.Stat(setting.CertFile); os.IsNotExist(err) {
return fmt.Errorf(`cannot find SSL cert_file at %q`, setting.CertFile)
if _, err := os.Stat(hs.Cfg.CertFile); os.IsNotExist(err) {
return fmt.Errorf(`cannot find SSL cert_file at %q`, hs.Cfg.CertFile)
}
if _, err := os.Stat(setting.KeyFile); os.IsNotExist(err) {
return fmt.Errorf(`cannot find SSL key_file at %q`, setting.KeyFile)
if _, err := os.Stat(hs.Cfg.KeyFile); os.IsNotExist(err) {
return fmt.Errorf(`cannot find SSL key_file at %q`, hs.Cfg.KeyFile)
}
tlsCfg := &tls.Config{
@@ -248,20 +248,20 @@ func (hs *HTTPServer) configureHttps() error {
}
func (hs *HTTPServer) configureHttp2() error {
if setting.CertFile == "" {
if hs.Cfg.CertFile == "" {
return fmt.Errorf("cert_file cannot be empty when using HTTP2")
}
if setting.KeyFile == "" {
if hs.Cfg.KeyFile == "" {
return fmt.Errorf("cert_key cannot be empty when using HTTP2")
}
if _, err := os.Stat(setting.CertFile); os.IsNotExist(err) {
return fmt.Errorf(`cannot find SSL cert_file at %q`, setting.CertFile)
if _, err := os.Stat(hs.Cfg.CertFile); os.IsNotExist(err) {
return fmt.Errorf(`cannot find SSL cert_file at %q`, hs.Cfg.CertFile)
}
if _, err := os.Stat(setting.KeyFile); os.IsNotExist(err) {
return fmt.Errorf(`cannot find SSL key_file at %q`, setting.KeyFile)
if _, err := os.Stat(hs.Cfg.KeyFile); os.IsNotExist(err) {
return fmt.Errorf(`cannot find SSL key_file at %q`, hs.Cfg.KeyFile)
}
tlsCfg := &tls.Config{
@@ -312,7 +312,7 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
m.Use(middleware.Logger(hs.Cfg))
if setting.EnableGzip {
if hs.Cfg.EnableGzip {
m.Use(middleware.Gziper())
}
@@ -324,22 +324,22 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
hs.mapStatic(m, route.Directory, "", pluginRoute)
}
hs.mapStatic(m, setting.StaticRootPath, "build", "public/build")
hs.mapStatic(m, setting.StaticRootPath, "", "public")
hs.mapStatic(m, setting.StaticRootPath, "robots.txt", "robots.txt")
hs.mapStatic(m, hs.Cfg.StaticRootPath, "build", "public/build")
hs.mapStatic(m, hs.Cfg.StaticRootPath, "", "public")
hs.mapStatic(m, hs.Cfg.StaticRootPath, "robots.txt", "robots.txt")
if setting.ImageUploadProvider == "local" {
if hs.Cfg.ImageUploadProvider == "local" {
hs.mapStatic(m, hs.Cfg.ImagesDir, "", "/public/img/attachments")
}
m.Use(middleware.AddDefaultResponseHeaders(hs.Cfg))
if setting.ServeFromSubPath && setting.AppSubUrl != "" {
m.SetURLPrefix(setting.AppSubUrl)
if hs.Cfg.ServeFromSubPath && hs.Cfg.AppSubURL != "" {
m.SetURLPrefix(hs.Cfg.AppSubURL)
}
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: filepath.Join(setting.StaticRootPath, "views"),
Directory: filepath.Join(hs.Cfg.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
@@ -354,7 +354,7 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
m.Use(middleware.OrgRedirect(hs.Cfg))
// needs to be after context handler
if setting.EnforceDomain {
if hs.Cfg.EnforceDomain {
m.Use(middleware.ValidateHostHeader(hs.Cfg))
}
@@ -411,8 +411,8 @@ func (hs *HTTPServer) apiHealthHandler(ctx *macaron.Context) {
data := simplejson.New()
data.Set("database", "ok")
if !hs.Cfg.AnonymousHideVersion {
data.Set("version", setting.BuildVersion)
data.Set("commit", setting.BuildCommit)
data.Set("version", hs.Cfg.BuildVersion)
data.Set("commit", hs.Cfg.BuildCommit)
}
if !hs.databaseHealthy() {

View File

@@ -17,7 +17,7 @@ const (
darkName = "dark"
)
func getProfileNode(c *models.ReqContext) *dtos.NavLink {
func (hs *HTTPServer) getProfileNode(c *models.ReqContext) *dtos.NavLink {
// Only set login if it's different from the name
var login string
if c.SignedInUser.Login != c.SignedInUser.NameOrFallback() {
@@ -27,13 +27,13 @@ func getProfileNode(c *models.ReqContext) *dtos.NavLink {
children := []*dtos.NavLink{
{
Text: "Preferences", Id: "profile-settings", Url: setting.AppSubUrl + "/profile", Icon: "sliders-v-alt",
Text: "Preferences", Id: "profile-settings", Url: hs.Cfg.AppSubURL + "/profile", Icon: "sliders-v-alt",
},
}
if setting.AddChangePasswordLink() {
children = append(children, &dtos.NavLink{
Text: "Change Password", Id: "change-password", Url: setting.AppSubUrl + "/profile/password",
Text: "Change Password", Id: "change-password", Url: hs.Cfg.AppSubURL + "/profile/password",
Icon: "lock", HideFromMenu: true,
})
}
@@ -43,7 +43,7 @@ func getProfileNode(c *models.ReqContext) *dtos.NavLink {
children = append(children, &dtos.NavLink{
Text: "Sign out",
Id: "sign-out",
Url: setting.AppSubUrl + "/logout",
Url: hs.Cfg.AppSubURL + "/logout",
Icon: "arrow-from-right",
Target: "_self",
HideFromTabs: true,
@@ -55,7 +55,7 @@ func getProfileNode(c *models.ReqContext) *dtos.NavLink {
SubTitle: login,
Id: "profile",
Img: gravatarURL,
Url: setting.AppSubUrl + "/profile",
Url: hs.Cfg.AppSubURL + "/profile",
HideFromMenu: true,
SortWeight: dtos.WeightProfile,
Children: children,
@@ -91,7 +91,7 @@ func (hs *HTTPServer) getAppLinks(c *models.ReqContext) ([]*dtos.NavLink, error)
var link *dtos.NavLink
if len(include.Path) > 0 {
link = &dtos.NavLink{
Url: setting.AppSubUrl + include.Path,
Url: hs.Cfg.AppSubURL + include.Path,
Text: include.Name,
}
if include.DefaultNav {
@@ -99,7 +99,7 @@ func (hs *HTTPServer) getAppLinks(c *models.ReqContext) ([]*dtos.NavLink, error)
}
} else {
link = &dtos.NavLink{
Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/page/" + include.Slug,
Url: hs.Cfg.AppSubURL + "/plugins/" + plugin.Id + "/page/" + include.Slug,
Text: include.Name,
}
}
@@ -109,7 +109,7 @@ func (hs *HTTPServer) getAppLinks(c *models.ReqContext) ([]*dtos.NavLink, error)
if include.Type == "dashboard" && include.AddToNav {
link := &dtos.NavLink{
Url: setting.AppSubUrl + "/dashboard/db/" + include.Slug,
Url: hs.Cfg.AppSubURL + "/dashboard/db/" + include.Slug,
Text: include.Name,
}
appLink.Children = append(appLink.Children, link)
@@ -129,40 +129,40 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
if hasEditPerm {
children := []*dtos.NavLink{
{Text: "Dashboard", Icon: "apps", Url: setting.AppSubUrl + "/dashboard/new"},
{Text: "Dashboard", Icon: "apps", Url: hs.Cfg.AppSubURL + "/dashboard/new"},
}
if c.OrgRole == models.ROLE_ADMIN || c.OrgRole == models.ROLE_EDITOR {
children = append(children, &dtos.NavLink{
Text: "Folder", SubTitle: "Create a new folder to organize your dashboards", Id: "folder",
Icon: "folder-plus", Url: setting.AppSubUrl + "/dashboards/folder/new",
Icon: "folder-plus", Url: hs.Cfg.AppSubURL + "/dashboards/folder/new",
})
}
children = append(children, &dtos.NavLink{
Text: "Import", SubTitle: "Import dashboard from file or Grafana.com", Id: "import", Icon: "import",
Url: setting.AppSubUrl + "/dashboard/import",
Url: hs.Cfg.AppSubURL + "/dashboard/import",
})
navTree = append(navTree, &dtos.NavLink{
Text: "Create",
Id: "create",
Icon: "plus",
Url: setting.AppSubUrl + "/dashboard/new",
Url: hs.Cfg.AppSubURL + "/dashboard/new",
Children: children,
SortWeight: dtos.WeightCreate,
})
}
dashboardChildNavs := []*dtos.NavLink{
{Text: "Home", Id: "home", Url: setting.AppSubUrl + "/", Icon: "home-alt", HideFromTabs: true},
{Text: "Home", Id: "home", Url: hs.Cfg.AppSubURL + "/", Icon: "home-alt", HideFromTabs: true},
{Text: "Divider", Divider: true, Id: "divider", HideFromTabs: true},
{Text: "Manage", Id: "manage-dashboards", Url: setting.AppSubUrl + "/dashboards", Icon: "sitemap"},
{Text: "Playlists", Id: "playlists", Url: setting.AppSubUrl + "/playlists", Icon: "presentation-play"},
{Text: "Manage", Id: "manage-dashboards", Url: hs.Cfg.AppSubURL + "/dashboards", Icon: "sitemap"},
{Text: "Playlists", Id: "playlists", Url: hs.Cfg.AppSubURL + "/playlists", Icon: "presentation-play"},
}
if c.IsSignedIn {
dashboardChildNavs = append(dashboardChildNavs, &dtos.NavLink{
Text: "Snapshots",
Id: "snapshots",
Url: setting.AppSubUrl + "/dashboard/snapshots",
Url: hs.Cfg.AppSubURL + "/dashboard/snapshots",
Icon: "camera",
})
}
@@ -172,7 +172,7 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
Id: "dashboards",
SubTitle: "Manage dashboards & folders",
Icon: "apps",
Url: setting.AppSubUrl + "/",
Url: hs.Cfg.AppSubURL + "/",
SortWeight: dtos.WeightDashboard,
Children: dashboardChildNavs,
})
@@ -184,19 +184,19 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
SubTitle: "Explore your data",
Icon: "compass",
SortWeight: dtos.WeightExplore,
Url: setting.AppSubUrl + "/explore",
Url: hs.Cfg.AppSubURL + "/explore",
})
}
if c.IsSignedIn {
navTree = append(navTree, getProfileNode(c))
navTree = append(navTree, hs.getProfileNode(c))
}
if setting.AlertingEnabled && (c.OrgRole == models.ROLE_ADMIN || c.OrgRole == models.ROLE_EDITOR) {
alertChildNavs := []*dtos.NavLink{
{Text: "Alert Rules", Id: "alert-list", Url: setting.AppSubUrl + "/alerting/list", Icon: "list-ul"},
{Text: "Alert Rules", Id: "alert-list", Url: hs.Cfg.AppSubURL + "/alerting/list", Icon: "list-ul"},
{
Text: "Notification channels", Id: "channels", Url: setting.AppSubUrl + "/alerting/notifications",
Text: "Notification channels", Id: "channels", Url: hs.Cfg.AppSubURL + "/alerting/notifications",
Icon: "comment-alt-share",
},
}
@@ -206,7 +206,7 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
SubTitle: "Alert rules & notifications",
Id: "alerting",
Icon: "bell",
Url: setting.AppSubUrl + "/alerting/list",
Url: hs.Cfg.AppSubURL + "/alerting/list",
Children: alertChildNavs,
SortWeight: dtos.WeightAlerting,
})
@@ -226,14 +226,14 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
Icon: "database",
Description: "Add and configure data sources",
Id: "datasources",
Url: setting.AppSubUrl + "/datasources",
Url: hs.Cfg.AppSubURL + "/datasources",
})
configNodes = append(configNodes, &dtos.NavLink{
Text: "Users",
Id: "users",
Description: "Manage org members",
Icon: "user",
Url: setting.AppSubUrl + "/org/users",
Url: hs.Cfg.AppSubURL + "/org/users",
})
}
@@ -243,7 +243,7 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
Id: "teams",
Description: "Manage org groups",
Icon: "users-alt",
Url: setting.AppSubUrl + "/org/teams",
Url: hs.Cfg.AppSubURL + "/org/teams",
})
}
@@ -253,7 +253,7 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
Id: "plugins",
Description: "View and configure plugins",
Icon: "plug",
Url: setting.AppSubUrl + "/plugins",
Url: hs.Cfg.AppSubURL + "/plugins",
})
configNodes = append(configNodes, &dtos.NavLink{
@@ -261,14 +261,14 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
Id: "org-settings",
Description: "Organization preferences",
Icon: "sliders-v-alt",
Url: setting.AppSubUrl + "/org",
Url: hs.Cfg.AppSubURL + "/org",
})
configNodes = append(configNodes, &dtos.NavLink{
Text: "API Keys",
Id: "apikeys",
Description: "Create & manage API keys",
Icon: "key-skeleton-alt",
Url: setting.AppSubUrl + "/org/apikeys",
Url: hs.Cfg.AppSubURL + "/org/apikeys",
})
}
@@ -286,15 +286,15 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
if c.IsGrafanaAdmin {
adminNavLinks := []*dtos.NavLink{
{Text: "Users", Id: "global-users", Url: setting.AppSubUrl + "/admin/users", Icon: "user"},
{Text: "Orgs", Id: "global-orgs", Url: setting.AppSubUrl + "/admin/orgs", Icon: "building"},
{Text: "Settings", Id: "server-settings", Url: setting.AppSubUrl + "/admin/settings", Icon: "sliders-v-alt"},
{Text: "Stats", Id: "server-stats", Url: setting.AppSubUrl + "/admin/stats", Icon: "graph-bar"},
{Text: "Users", Id: "global-users", Url: hs.Cfg.AppSubURL + "/admin/users", Icon: "user"},
{Text: "Orgs", Id: "global-orgs", Url: hs.Cfg.AppSubURL + "/admin/orgs", Icon: "building"},
{Text: "Settings", Id: "server-settings", Url: hs.Cfg.AppSubURL + "/admin/settings", Icon: "sliders-v-alt"},
{Text: "Stats", Id: "server-stats", Url: hs.Cfg.AppSubURL + "/admin/stats", Icon: "graph-bar"},
}
if hs.Cfg.LDAPEnabled {
adminNavLinks = append(adminNavLinks, &dtos.NavLink{
Text: "LDAP", Id: "ldap", Url: setting.AppSubUrl + "/admin/ldap", Icon: "book",
Text: "LDAP", Id: "ldap", Url: hs.Cfg.AppSubURL + "/admin/ldap", Icon: "book",
})
}
@@ -304,7 +304,7 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
HideFromTabs: true,
Id: "admin",
Icon: "shield",
Url: setting.AppSubUrl + "/admin/users",
Url: hs.Cfg.AppSubURL + "/admin/users",
SortWeight: dtos.WeightAdmin,
Children: adminNavLinks,
})
@@ -359,11 +359,11 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
}
appURL := setting.AppUrl
appSubURL := setting.AppSubUrl
appSubURL := hs.Cfg.AppSubURL
// special case when doing localhost call from image renderer
if c.IsRenderCall && !hs.Cfg.ServeFromSubPath {
appURL = fmt.Sprintf("%s://localhost:%s", hs.Cfg.Protocol, setting.HttpPort)
appURL = fmt.Sprintf("%s://localhost:%s", hs.Cfg.Protocol, hs.Cfg.HTTPPort)
appSubURL = ""
settings["appSubUrl"] = ""
}
@@ -414,7 +414,7 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
}
if setting.DisableGravatar {
data.User.GravatarUrl = setting.AppSubUrl + "/public/img/user_profile.png"
data.User.GravatarUrl = hs.Cfg.AppSubURL + "/public/img/user_profile.png"
}
if len(data.User.Name) == 0 {

View File

@@ -109,7 +109,7 @@ func (hs *HTTPServer) LoginView(c *models.ReqContext) {
return
}
if tryOAuthAutoLogin(c) {
if hs.tryOAuthAutoLogin(c) {
return
}
@@ -136,14 +136,14 @@ func (hs *HTTPServer) LoginView(c *models.ReqContext) {
return
}
c.Redirect(setting.AppSubUrl + "/")
c.Redirect(hs.Cfg.AppSubURL + "/")
return
}
c.HTML(200, getViewIndex(), viewData)
}
func tryOAuthAutoLogin(c *models.ReqContext) bool {
func (hs *HTTPServer) tryOAuthAutoLogin(c *models.ReqContext) bool {
if !setting.OAuthAutoLogin {
return false
}
@@ -153,7 +153,7 @@ func tryOAuthAutoLogin(c *models.ReqContext) bool {
return false
}
for key := range setting.OAuthService.OAuthInfos {
redirectUrl := setting.AppSubUrl + "/login/" + key
redirectUrl := hs.Cfg.AppSubURL + "/login/" + key
log.Infof("OAuth auto login enabled. Redirecting to " + redirectUrl)
c.Redirect(redirectUrl, 307)
return true
@@ -279,7 +279,7 @@ func (hs *HTTPServer) loginUserWithUser(user *models.User, c *models.ReqContext)
func (hs *HTTPServer) Logout(c *models.ReqContext) {
if hs.Cfg.SAMLEnabled && hs.Cfg.SAMLSingleLogoutEnabled && hs.License.HasValidLicense() {
c.Redirect(setting.AppSubUrl + "/logout/saml")
c.Redirect(hs.Cfg.AppSubURL + "/logout/saml")
return
}
@@ -294,7 +294,7 @@ func (hs *HTTPServer) Logout(c *models.ReqContext) {
c.Redirect(setting.SignoutRedirectUrl)
} else {
hs.log.Info("Successful Logout", "User", c.Email)
c.Redirect(setting.AppSubUrl + "/login")
c.Redirect(hs.Cfg.AppSubURL + "/login")
}
}
@@ -330,7 +330,7 @@ func (hs *HTTPServer) redirectWithError(ctx *models.ReqContext, err error, v ...
hs.log.Error("Failed to set encrypted cookie", "err", err)
}
ctx.Redirect(setting.AppSubUrl + "/login")
ctx.Redirect(hs.Cfg.AppSubURL + "/login")
}
func (hs *HTTPServer) RedirectResponseWithError(ctx *models.ReqContext, err error, v ...interface{}) *response.RedirectResponse {
@@ -339,7 +339,7 @@ func (hs *HTTPServer) RedirectResponseWithError(ctx *models.ReqContext, err erro
hs.log.Error("Failed to set encrypted cookie", "err", err)
}
return response.Redirect(setting.AppSubUrl + "/login")
return response.Redirect(hs.Cfg.AppSubURL + "/login")
}
func getLoginExternalError(err error) string {

View File

@@ -17,7 +17,6 @@ import (
"github.com/grafana/grafana/pkg/plugins/adapters"
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/plugins/manager"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util/errutil"
)
@@ -122,7 +121,7 @@ func (hs *HTTPServer) GetPluginList(c *models.ReqContext) response.Response {
}
if listItem.DefaultNavUrl == "" || !listItem.Enabled {
listItem.DefaultNavUrl = setting.AppSubUrl + "/plugins/" + listItem.Id + "/"
listItem.DefaultNavUrl = hs.Cfg.AppSubURL + "/plugins/" + listItem.Id + "/"
}
// filter out disabled plugins

View File

@@ -213,7 +213,7 @@ func (hs *HTTPServer) ChangeActiveOrgAndRedirectToHome(c *models.ReqContext) {
hs.NotFoundHandler(c)
}
c.Redirect(setting.AppSubUrl + "/")
c.Redirect(hs.Cfg.AppSubURL + "/")
}
func ChangeUserPassword(c *models.ReqContext, cmd models.ChangeUserPasswordCommand) response.Response {