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
+37 -37
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 {