Authlib: Use types package rather than claims (#99243)
This commit is contained in:
@@ -4,8 +4,7 @@ import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/authlib/authz"
|
||||
"github.com/grafana/authlib/claims"
|
||||
authlib "github.com/grafana/authlib/types"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
iamv0 "github.com/grafana/grafana/pkg/apis/iam/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
|
||||
@@ -41,14 +40,14 @@ type ListResponse[T Resource] struct {
|
||||
Continue int64
|
||||
}
|
||||
|
||||
type ListFunc[T Resource] func(ctx context.Context, ns claims.NamespaceInfo, p Pagination) (*ListResponse[T], error)
|
||||
type ListFunc[T Resource] func(ctx context.Context, ns authlib.NamespaceInfo, p Pagination) (*ListResponse[T], error)
|
||||
|
||||
// List is a helper function that will perform access check on resources if
|
||||
// prvovided with a claims.AccessClient.
|
||||
// prvovided with a authlib.AccessClient.
|
||||
func List[T Resource](
|
||||
ctx context.Context,
|
||||
resourceName string,
|
||||
ac authz.AccessClient,
|
||||
ac authlib.AccessClient,
|
||||
p Pagination,
|
||||
fn ListFunc[T],
|
||||
) (*ListResponse[T], error) {
|
||||
@@ -65,7 +64,7 @@ func List[T Resource](
|
||||
check := func(_, _, _ string) bool { return true }
|
||||
if ac != nil {
|
||||
var err error
|
||||
check, err = ac.Compile(ctx, ident, authz.ListRequest{
|
||||
check, err = ac.Compile(ctx, ident, authlib.ListRequest{
|
||||
Resource: resourceName,
|
||||
Namespace: ns.Value,
|
||||
})
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/authlib/claims"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
|
||||
authlib "github.com/grafana/authlib/types"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||
@@ -28,7 +28,7 @@ func TestList(t *testing.T) {
|
||||
t.Run("should allow all items if no access client is passed", func(t *testing.T) {
|
||||
ctx := newContext("stacks-1", newIdent())
|
||||
|
||||
res, err := List(ctx, "items", nil, Pagination{Limit: 2}, func(ctx context.Context, ns claims.NamespaceInfo, p Pagination) (*ListResponse[item], error) {
|
||||
res, err := List(ctx, "items", nil, Pagination{Limit: 2}, func(ctx context.Context, ns authlib.NamespaceInfo, p Pagination) (*ListResponse[item], error) {
|
||||
return &ListResponse[item]{
|
||||
Items: []item{{"1"}, {"2"}},
|
||||
}, nil
|
||||
@@ -44,7 +44,7 @@ func TestList(t *testing.T) {
|
||||
Resource: "items",
|
||||
Attr: "uid",
|
||||
})
|
||||
res, err := List(ctx, "items", a, Pagination{Limit: 2}, func(ctx context.Context, ns claims.NamespaceInfo, p Pagination) (*ListResponse[item], error) {
|
||||
res, err := List(ctx, "items", a, Pagination{Limit: 2}, func(ctx context.Context, ns authlib.NamespaceInfo, p Pagination) (*ListResponse[item], error) {
|
||||
return &ListResponse[item]{
|
||||
Items: []item{{"1"}, {"2"}},
|
||||
}, nil
|
||||
@@ -66,7 +66,7 @@ func TestList(t *testing.T) {
|
||||
|
||||
var called bool
|
||||
|
||||
res, err := List(ctx, "items", a, Pagination{Limit: 2}, func(ctx context.Context, ns claims.NamespaceInfo, p Pagination) (*ListResponse[item], error) {
|
||||
res, err := List(ctx, "items", a, Pagination{Limit: 2}, func(ctx context.Context, ns authlib.NamespaceInfo, p Pagination) (*ListResponse[item], error) {
|
||||
if called {
|
||||
return &ListResponse[item]{
|
||||
Items: []item{{"3"}},
|
||||
|
||||
Reference in New Issue
Block a user