Identity: Add endpoint to get display info for an identifier (#91828)

This commit is contained in:
Ryan McKinley
2024-08-15 14:38:43 +03:00
committed by GitHub
parent c7fdf8ce70
commit a0cd89860e
67 changed files with 1535 additions and 282 deletions
@@ -41,6 +41,11 @@ func (auth orgIDAuthorizer) Authorize(ctx context.Context, a authorizer.Attribut
return authorizer.DecisionNoOpinion, "", nil
}
// Grafana super admins can see things in every org
if signedInUser.GetIsGrafanaAdmin() {
return authorizer.DecisionNoOpinion, "", nil
}
if info.OrgID == -1 {
return authorizer.DecisionDeny, "org id is required", nil
}
+6
View File
@@ -43,6 +43,12 @@ var pathRewriters = []filters.PathRewriter{
return matches[1] + "/name" // connector requires a name
},
},
{
Pattern: regexp.MustCompile(`(/apis/identity.grafana.app/v0alpha1/namespaces/.*/display$)`),
ReplaceFunc: func(matches []string) string {
return matches[1] + "/name" // connector requires a name
},
},
}
func SetupConfig(
-7
View File
@@ -90,13 +90,6 @@ type SearchTeamsQuery struct {
HiddenUsers map[string]struct{}
}
type ListTeamsCommand struct {
Limit int
Start int
OrgID int64
UID string
}
type TeamDTO struct {
ID int64 `json:"id" xorm:"id"`
UID string `json:"uid" xorm:"uid"`
-1
View File
@@ -8,7 +8,6 @@ type Service interface {
CreateTeam(ctx context.Context, name, email string, orgID int64) (Team, error)
UpdateTeam(ctx context.Context, cmd *UpdateTeamCommand) error
DeleteTeam(ctx context.Context, cmd *DeleteTeamCommand) error
ListTeams(ctx context.Context, query *ListTeamsCommand) ([]*Team, error)
SearchTeams(ctx context.Context, query *SearchTeamsQuery) (SearchTeamQueryResult, error)
GetTeamByID(ctx context.Context, query *GetTeamByIDQuery) (*TeamDTO, error)
GetTeamsByUser(ctx context.Context, query *GetTeamsByUserQuery) ([]*TeamDTO, error)
-16
View File
@@ -20,7 +20,6 @@ type store interface {
Create(name, email string, orgID int64) (team.Team, error)
Update(ctx context.Context, cmd *team.UpdateTeamCommand) error
Delete(ctx context.Context, cmd *team.DeleteTeamCommand) error
ListTeams(ctx context.Context, query *team.ListTeamsCommand) ([]*team.Team, error)
Search(ctx context.Context, query *team.SearchTeamsQuery) (team.SearchTeamQueryResult, error)
GetByID(ctx context.Context, query *team.GetTeamByIDQuery) (*team.TeamDTO, error)
GetByUser(ctx context.Context, query *team.GetTeamsByUserQuery) ([]*team.TeamDTO, error)
@@ -268,21 +267,6 @@ func (ss *xormStore) Search(ctx context.Context, query *team.SearchTeamsQuery) (
return queryResult, nil
}
func (ss *xormStore) ListTeams(ctx context.Context, query *team.ListTeamsCommand) ([]*team.Team, error) {
results := make([]*team.Team, 0)
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
q := sess.Table("team")
q.Where("team.org_id=?", query.OrgID)
if query.UID != "" {
q.Where("team.uid=?", query.UID)
}
q.Limit(query.Limit, query.Start)
return q.Find(&results)
})
return results, err
}
func (ss *xormStore) GetByID(ctx context.Context, query *team.GetTeamByIDQuery) (*team.TeamDTO, error) {
var queryResult *team.TeamDTO
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
-8
View File
@@ -51,14 +51,6 @@ func (s *Service) DeleteTeam(ctx context.Context, cmd *team.DeleteTeamCommand) e
return s.store.Delete(ctx, cmd)
}
func (s *Service) ListTeams(ctx context.Context, query *team.ListTeamsCommand) ([]*team.Team, error) {
ctx, span := s.tracer.Start(ctx, "team.ListTeams", trace.WithAttributes(
attribute.Int64("orgID", query.OrgID),
))
defer span.End()
return s.store.ListTeams(ctx, query)
}
func (s *Service) SearchTeams(ctx context.Context, query *team.SearchTeamsQuery) (team.SearchTeamQueryResult, error) {
ctx, span := s.tracer.Start(ctx, "team.SearchTeams", trace.WithAttributes(
attribute.Int64("orgID", query.OrgID),
-4
View File
@@ -36,10 +36,6 @@ func (s *FakeService) SearchTeams(ctx context.Context, query *team.SearchTeamsQu
return team.SearchTeamQueryResult{}, s.ExpectedError
}
func (s *FakeService) ListTeams(ctx context.Context, query *team.ListTeamsCommand) ([]*team.Team, error) {
return nil, s.ExpectedError
}
func (s *FakeService) GetTeamByID(ctx context.Context, query *team.GetTeamByIDQuery) (*team.TeamDTO, error) {
return s.ExpectedTeamDTO, s.ExpectedError
}
-7
View File
@@ -98,13 +98,6 @@ type UpdateUserLastSeenAtCommand struct {
OrgID int64
}
type ListUsersCommand struct {
OrgID int64
Limit int64
ContinueID int64
IsServiceAccount bool
}
type ListUserResult struct {
Users []*User
ContinueID int64
-1
View File
@@ -16,7 +16,6 @@ type Service interface {
GetByUID(context.Context, *GetUserByUIDQuery) (*User, error)
GetByLogin(context.Context, *GetUserByLoginQuery) (*User, error)
GetByEmail(context.Context, *GetUserByEmailQuery) (*User, error)
List(context.Context, *ListUsersCommand) (*ListUserResult, error)
Update(context.Context, *UpdateUserCommand) error
UpdateLastSeenAt(context.Context, *UpdateUserLastSeenAtCommand) error
GetSignedInUser(context.Context, *GetSignedInUserQuery) (*SignedInUser, error)
-35
View File
@@ -23,7 +23,6 @@ type store interface {
GetByUID(ctx context.Context, orgId int64, uid string) (*user.User, error)
GetByLogin(context.Context, *user.GetUserByLoginQuery) (*user.User, error)
GetByEmail(context.Context, *user.GetUserByEmailQuery) (*user.User, error)
List(context.Context, *user.ListUsersCommand) (*user.ListUserResult, error)
Delete(context.Context, int64) error
LoginConflict(ctx context.Context, login, email string) error
Update(context.Context, *user.UpdateUserCommand) error
@@ -579,40 +578,6 @@ func (ss *sqlStore) Search(ctx context.Context, query *user.SearchUsersQuery) (*
return &result, err
}
func (ss *sqlStore) List(ctx context.Context, query *user.ListUsersCommand) (*user.ListUserResult, error) {
limit := int(query.Limit)
if limit <= 0 {
limit = 25
}
result := &user.ListUserResult{
Users: make([]*user.User, 0),
}
max := ""
err := ss.db.WithDbSession(ctx, func(dbSess *db.Session) error {
sess := dbSess.Table("user")
sess.Where("id >= ? AND is_service_account = ?", query.ContinueID, query.IsServiceAccount)
err := sess.OrderBy("id asc").Limit(limit + 1).Find(&result.Users)
if err != nil {
return err
}
// Set the revision version
_, err = dbSess.Table("user").Select("MAX(updated)").Get(&max)
return err
})
if max != "" {
t, err := time.Parse(time.DateTime, max)
if err == nil {
result.RV = t.UnixMilli()
}
}
if len(result.Users) > limit {
result.ContinueID = result.Users[limit].ID
result.Users = result.Users[:limit]
}
return result, err
}
func setOptional[T any](v *T, add func(v T)) {
if v != nil {
add(*v)
-9
View File
@@ -378,15 +378,6 @@ func (s *Service) getSignedInUser(ctx context.Context, query *user.GetSignedInUs
return usr, err
}
func (s *Service) List(ctx context.Context, query *user.ListUsersCommand) (*user.ListUserResult, error) {
ctx, span := s.tracer.Start(ctx, "user.List", trace.WithAttributes(
attribute.Int64("orgID", query.OrgID),
))
defer span.End()
return s.store.List(ctx, query)
}
func (s *Service) Search(ctx context.Context, query *user.SearchUsersQuery) (*user.SearchUserQueryResult, error) {
ctx, span := s.tracer.Start(ctx, "user.Search", trace.WithAttributes(
attribute.Int64("orgID", query.OrgID),
-4
View File
@@ -331,10 +331,6 @@ func (f *FakeUserStore) Search(ctx context.Context, query *user.SearchUsersQuery
return f.ExpectedSearchUserQueryResult, f.ExpectedError
}
func (f *FakeUserStore) List(ctx context.Context, query *user.ListUsersCommand) (*user.ListUserResult, error) {
return nil, f.ExpectedError
}
func (f *FakeUserStore) Count(ctx context.Context) (int64, error) {
return 0, nil
}
-4
View File
@@ -98,10 +98,6 @@ func (f *FakeUserService) Search(ctx context.Context, query *user.SearchUsersQue
return &f.ExpectedSearchUsers, f.ExpectedError
}
func (f *FakeUserService) List(ctx context.Context, query *user.ListUsersCommand) (*user.ListUserResult, error) {
return &f.ExpectedListUsers, f.ExpectedError
}
func (f *FakeUserService) BatchDisableUsers(ctx context.Context, cmd *user.BatchDisableUsersCommand) error {
if f.BatchDisableUsersFn != nil {
return f.BatchDisableUsersFn(ctx, cmd)
-30
View File
@@ -310,36 +310,6 @@ func (_m *MockService) GetUsageStats(ctx context.Context) map[string]interface{}
return r0
}
// List provides a mock function with given fields: _a0, _a1
func (_m *MockService) List(_a0 context.Context, _a1 *user.ListUsersCommand) (*user.ListUserResult, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for List")
}
var r0 *user.ListUserResult
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *user.ListUsersCommand) (*user.ListUserResult, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *user.ListUsersCommand) *user.ListUserResult); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*user.ListUserResult)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *user.ListUsersCommand) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Search provides a mock function with given fields: _a0, _a1
func (_m *MockService) Search(_a0 context.Context, _a1 *user.SearchUsersQuery) (*user.SearchUserQueryResult, error) {
ret := _m.Called(_a0, _a1)