The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/registry/apis/iam/user/rest_user_team.go

95 lines
2.6 KiB

package user
import (
"context"
"net/http"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
legacyiamv0 "github.com/grafana/grafana/pkg/apis/iam/v0alpha1"
"github.com/grafana/grafana/pkg/registry/apis/iam/common"
"github.com/grafana/grafana/pkg/registry/apis/iam/legacy"
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
)
var (
_ rest.Storage = (*LegacyUserTeamREST)(nil)
_ rest.StorageMetadata = (*LegacyUserTeamREST)(nil)
_ rest.Connecter = (*LegacyUserTeamREST)(nil)
)
func NewLegacyTeamMemberREST(store legacy.LegacyIdentityStore) *LegacyUserTeamREST {
return &LegacyUserTeamREST{store}
}
type LegacyUserTeamREST struct {
store legacy.LegacyIdentityStore
}
// New implements rest.Storage.
func (s *LegacyUserTeamREST) New() runtime.Object {
return &legacyiamv0.UserTeamList{}
}
// Destroy implements rest.Storage.
func (s *LegacyUserTeamREST) Destroy() {}
// ProducesMIMETypes implements rest.StorageMetadata.
func (s *LegacyUserTeamREST) ProducesMIMETypes(verb string) []string {
return []string{"application/json"}
}
// ProducesObject implements rest.StorageMetadata.
func (s *LegacyUserTeamREST) ProducesObject(verb string) interface{} {
return s.New()
}
// Connect implements rest.Connecter.
func (s *LegacyUserTeamREST) Connect(ctx context.Context, name string, options runtime.Object, responder rest.Responder) (http.Handler, error) {
ns, err := request.NamespaceInfoFrom(ctx, true)
if err != nil {
return nil, err
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
res, err := s.store.ListUserTeams(ctx, ns, legacy.ListUserTeamsQuery{
UserUID: name,
Pagination: common.PaginationFromListQuery(r.URL.Query()),
})
if err != nil {
responder.Error(err)
return
}
list := &legacyiamv0.UserTeamList{Items: make([]legacyiamv0.UserTeam, 0, len(res.Items))}
for _, m := range res.Items {
list.Items = append(list.Items, mapToUserTeam(m))
}
list.Continue = common.OptionalFormatInt(res.Continue)
responder.Object(http.StatusOK, list)
}), nil
}
// NewConnectOptions implements rest.Connecter.
func (s *LegacyUserTeamREST) NewConnectOptions() (runtime.Object, bool, string) {
return nil, false, ""
}
// ConnectMethods implements rest.Connecter.
func (s *LegacyUserTeamREST) ConnectMethods() []string {
return []string{http.MethodGet}
}
func mapToUserTeam(t legacy.UserTeam) legacyiamv0.UserTeam {
return legacyiamv0.UserTeam{
Title: t.Name,
TeamRef: legacyiamv0.TeamRef{
Name: t.UID,
},
Permission: common.MapUserTeamPermission(t.Permission),
}
}