IAM: Create and delete user from the legacy store (#107694)
* Add Create for User + DualWriter setup * Add delete User * Fix delete + access check * Add tests for delete user * Add tests for create user * Fixes * Use sqlx session to fix database locked issues * wip authz checks * legacyAccessClient * Update legacyAccessClient, add tests for create user * Close rows before running other queries * Use ExecWithReturningId * Verify deletion in the tests * Add Validate and Mutate * Other changes * Address feedback * Update tests --------- Co-authored-by: Gabriel Mabille <gabriel.mabille@grafana.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
authlib "github.com/grafana/authlib/types"
|
||||
iamv0alpha1 "github.com/grafana/grafana/apps/iam/pkg/apis/iam/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/utils"
|
||||
legacyiamv0 "github.com/grafana/grafana/pkg/apis/iam/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
|
||||
"github.com/grafana/grafana/pkg/services/team"
|
||||
@@ -55,7 +56,7 @@ type ListFunc[T Resource] func(ctx context.Context, ns authlib.NamespaceInfo, p
|
||||
// prvovided with a authlib.AccessClient.
|
||||
func List[T Resource](
|
||||
ctx context.Context,
|
||||
resourceName string,
|
||||
resource utils.ResourceInfo,
|
||||
ac authlib.AccessClient,
|
||||
p Pagination,
|
||||
fn ListFunc[T],
|
||||
@@ -74,7 +75,9 @@ func List[T Resource](
|
||||
if ac != nil {
|
||||
var err error
|
||||
check, err = ac.Compile(ctx, ident, authlib.ListRequest{
|
||||
Resource: resourceName,
|
||||
Resource: resource.GroupResource().Resource,
|
||||
Group: resource.GroupResource().Group,
|
||||
Verb: "list",
|
||||
Namespace: ns.Value,
|
||||
})
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
authlib "github.com/grafana/authlib/types"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/utils"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -28,7 +29,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 authlib.NamespaceInfo, p Pagination) (*ListResponse[item], error) {
|
||||
res, err := List(ctx, utils.NewResourceInfo("", "", "items", "", "", nil, nil, utils.TableColumns{}), 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 +45,7 @@ func TestList(t *testing.T) {
|
||||
Resource: "items",
|
||||
Attr: "uid",
|
||||
})
|
||||
res, err := List(ctx, "items", a, Pagination{Limit: 2}, func(ctx context.Context, ns authlib.NamespaceInfo, p Pagination) (*ListResponse[item], error) {
|
||||
res, err := List(ctx, utils.NewResourceInfo("", "", "items", "", "", nil, nil, utils.TableColumns{}), 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 +67,7 @@ func TestList(t *testing.T) {
|
||||
|
||||
var called bool
|
||||
|
||||
res, err := List(ctx, "items", a, Pagination{Limit: 2}, func(ctx context.Context, ns authlib.NamespaceInfo, p Pagination) (*ListResponse[item], error) {
|
||||
res, err := List(ctx, utils.NewResourceInfo("", "", "items", "", "", nil, nil, utils.TableColumns{}), 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