Serviceaccounts: feat - tabview for serviceaccounts (#43573)

This commit is contained in:
Eric Leijonmarck
2022-01-05 15:32:38 +01:00
committed by GitHub
parent 5c88acd5aa
commit 0aa905bb1f
16 changed files with 435 additions and 5 deletions
+4 -1
View File
@@ -14,6 +14,7 @@ import (
"sync"
"github.com/grafana/grafana/pkg/services/query"
"github.com/grafana/grafana/pkg/services/serviceaccounts"
"github.com/grafana/grafana/pkg/services/thumbs"
"github.com/grafana/grafana/pkg/api/routing"
@@ -113,6 +114,7 @@ type HTTPServer struct {
updateChecker *updatechecker.Service
searchUsersService searchusers.Service
queryDataService *query.Service
serviceAccountsService serviceaccounts.Service
}
type ServerOptions struct {
@@ -137,7 +139,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
quotaService *quota.QuotaService, socialService social.Service, tracingService tracing.Tracer,
encryptionService encryption.Internal, updateChecker *updatechecker.Service, searchUsersService searchusers.Service,
dataSourcesService *datasources.Service, secretsService secrets.Service,
queryDataService *query.Service) (*HTTPServer, error) {
queryDataService *query.Service, serviceaccountsService serviceaccounts.Service) (*HTTPServer, error) {
web.Env = cfg.Env
m := web.New()
@@ -189,6 +191,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
DataSourcesService: dataSourcesService,
searchUsersService: searchUsersService,
queryDataService: queryDataService,
serviceAccountsService: serviceaccountsService,
}
if hs.Listener != nil {
hs.log.Debug("Using provided listener")
+20 -1
View File
@@ -142,6 +142,14 @@ func (hs *HTTPServer) getAppLinks(c *models.ReqContext) ([]*dtos.NavLink, error)
return appLinks, nil
}
func enableServiceAccount(hs *HTTPServer, c *models.ReqContext) bool {
return c.OrgRole == models.ROLE_ADMIN && hs.Cfg.IsServiceAccountEnabled() && hs.serviceAccountsService.Migrated(c.Req.Context(), c.OrgId)
}
func enableTeams(hs *HTTPServer, c *models.ReqContext) bool {
return c.OrgRole == models.ROLE_ADMIN || (hs.Cfg.EditorsCanAdmin && c.OrgRole == models.ROLE_EDITOR)
}
func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dtos.NavLink, error) {
hasAccess := ac.HasAccess(hs.AccessControl, c)
navTree := []*dtos.NavLink{}
@@ -253,7 +261,7 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
})
}
if c.OrgRole == models.ROLE_ADMIN || (hs.Cfg.EditorsCanAdmin && c.OrgRole == models.ROLE_EDITOR) {
if enableTeams(hs, c) {
configNodes = append(configNodes, &dtos.NavLink{
Text: "Teams",
Id: "teams",
@@ -292,6 +300,17 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
Url: hs.Cfg.AppSubURL + "/org/apikeys",
})
}
// needs both feature flag and migration to be able to show service accounts
if enableServiceAccount(hs, c) {
configNodes = append(configNodes, &dtos.NavLink{
Text: "Service accounts",
Id: "serviceaccounts",
Description: "Manage service accounts",
// TODO: change icon to "key-skeleton-alt" when it's available
Icon: "key-skeleton-alt",
Url: hs.Cfg.AppSubURL + "/org/serviceaccounts",
})
}
if hs.Cfg.FeatureToggles["live-pipeline"] {
liveNavLinks := []*dtos.NavLink{}
@@ -61,3 +61,9 @@ func (sa *ServiceAccountsService) DeleteServiceAccount(ctx context.Context, orgI
}
return sa.store.DeleteServiceAccount(ctx, orgID, serviceAccountID)
}
func (sa *ServiceAccountsService) Migrated(ctx context.Context, orgID int64) bool {
// TODO: implement migration logic
// change this to return true for development of service accounts page
return false
}
@@ -9,7 +9,9 @@ import (
type Service interface {
CreateServiceAccount(ctx context.Context, saForm *CreateServiceaccountForm) (*models.User, error)
DeleteServiceAccount(ctx context.Context, orgID, serviceAccountID int64) error
Migrated(ctx context.Context, orgID int64) bool
}
type Store interface {
CreateServiceAccount(ctx context.Context, saForm *CreateServiceaccountForm) (*models.User, error)
DeleteServiceAccount(ctx context.Context, orgID, serviceAccountID int64) error
@@ -37,6 +37,10 @@ func (s *ServiceAccountMock) DeleteServiceAccount(ctx context.Context, orgID, se
return nil
}
func (s *ServiceAccountMock) Migrated(ctx context.Context, orgID int64) bool {
return false
}
func SetupMockAccesscontrol(t *testing.T, userpermissionsfunc func(c context.Context, siu *models.SignedInUser) ([]*accesscontrol.Permission, error), disableAccessControl bool) *accesscontrolmock.Mock {
t.Helper()
acmock := accesscontrolmock.New()
+4
View File
@@ -459,6 +459,10 @@ func (cfg Cfg) IsNewNavigationEnabled() bool {
return cfg.FeatureToggles["newNavigation"]
}
func (cfg Cfg) IsServiceAccountEnabled() bool {
return cfg.FeatureToggles["service-accounts"]
}
type CommandLineArgs struct {
Config string
HomePath string