mirror of https://github.com/grafana/grafana.git
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:
parent
3e29ca786d
commit
c6a6b9fdd2
|
|
@ -16,6 +16,13 @@ user: {
|
|||
|
||||
versions: {
|
||||
"v0alpha1": {
|
||||
validation: {
|
||||
operations: [
|
||||
"CREATE",
|
||||
"UPDATE",
|
||||
]
|
||||
}
|
||||
|
||||
schema: {
|
||||
spec: v0alpha1.UserSpec
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import (
|
|||
v0alpha1 "github.com/grafana/grafana/apps/iam/pkg/apis/iam/v0alpha1"
|
||||
)
|
||||
|
||||
var ()
|
||||
|
||||
var appManifestData = app.ManifestData{
|
||||
AppName: "iam",
|
||||
Group: "iam.grafana.app",
|
||||
|
|
@ -91,6 +93,14 @@ var appManifestData = app.ManifestData{
|
|||
Versions: []app.ManifestKindVersion{
|
||||
{
|
||||
Name: "v0alpha1",
|
||||
Admission: &app.AdmissionCapabilities{
|
||||
Validation: &app.ValidationCapability{
|
||||
Operations: []app.AdmissionOperation{
|
||||
app.AdmissionOperationCreate,
|
||||
app.AdmissionOperationUpdate,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -56,8 +56,10 @@ func newLegacyAccessClient(ac accesscontrol.AccessControl, store legacy.LegacyId
|
|||
Resource: legacyiamv0.UserResourceInfo.GetName(),
|
||||
Attr: "id",
|
||||
Mapping: map[string]string{
|
||||
utils.VerbGet: accesscontrol.ActionOrgUsersRead,
|
||||
utils.VerbList: accesscontrol.ActionOrgUsersRead,
|
||||
utils.VerbCreate: accesscontrol.ActionOrgUsersWrite,
|
||||
utils.VerbDelete: accesscontrol.ActionOrgUsersWrite,
|
||||
utils.VerbGet: accesscontrol.ActionOrgUsersRead,
|
||||
utils.VerbList: accesscontrol.ActionOrgUsersRead,
|
||||
},
|
||||
Resolver: accesscontrol.ResourceResolverFunc(func(ctx context.Context, ns authlib.NamespaceInfo, name string) ([]string, error) {
|
||||
res, err := store.GetUserInternalID(ctx, ns, legacy.GetUserInternalIDQuery{
|
||||
|
|
|
|||
|
|
@ -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"}},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO {{ .Ident .OrgUserTable }}
|
||||
(org_id, user_id, role, created, updated)
|
||||
VALUES
|
||||
({{ .Arg .Command.OrgID }}, {{ .Arg .Command.UserID }}, {{ .Arg .Command.Role }},
|
||||
{{ .Arg .Command.Created }}, {{ .Arg .Command.Updated }})
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
INSERT INTO {{ .Ident .UserTable }}
|
||||
(uid, version, login, email, name, org_id, is_admin, is_disabled, email_verified,
|
||||
is_provisioned, is_service_account, salt, rands, created, updated, last_seen_at)
|
||||
VALUES
|
||||
({{ .Arg .Command.UID }}, 0, {{ .Arg .Command.Login }}, {{ .Arg .Command.Email }},
|
||||
{{ .Arg .Command.Name }}, {{ .Arg .Command.OrgID }}, {{ .Arg .Command.IsAdmin }},
|
||||
{{ .Arg .Command.IsDisabled }}, {{ .Arg .Command.EmailVerified }},
|
||||
{{ .Arg .Command.IsProvisioned }}, false, {{ .Arg .Command.Salt }}, {{ .Arg .Command.Rands }},
|
||||
{{ .Arg .Command.Created }}, {{ .Arg .Command.Updated }}, {{ .Arg .Command.LastSeenAt }})
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
-- Delete from org_user table for a specific user
|
||||
DELETE FROM {{ .Ident .OrgUserTable }}
|
||||
WHERE user_id = {{ .Arg .UserID }}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
-- Delete from user table (org_user will be handled separately to avoid locking)
|
||||
DELETE FROM {{ .Ident .UserTable }}
|
||||
WHERE uid = {{ .Arg .Query.UID }}
|
||||
AND org_id = {{ .Arg .Query.OrgID }}
|
||||
|
|
@ -17,6 +17,8 @@ type LegacyIdentityStore interface {
|
|||
GetUserInternalID(ctx context.Context, ns claims.NamespaceInfo, query GetUserInternalIDQuery) (*GetUserInternalIDResult, error)
|
||||
ListUsers(ctx context.Context, ns claims.NamespaceInfo, query ListUserQuery) (*ListUserResult, error)
|
||||
ListUserTeams(ctx context.Context, ns claims.NamespaceInfo, query ListUserTeamsQuery) (*ListUserTeamsResult, error)
|
||||
CreateUser(ctx context.Context, ns claims.NamespaceInfo, cmd CreateUserCommand) (*CreateUserResult, error)
|
||||
DeleteUser(ctx context.Context, ns claims.NamespaceInfo, cmd DeleteUserCommand) (*DeleteUserResult, error)
|
||||
|
||||
GetServiceAccountInternalID(ctx context.Context, ns claims.NamespaceInfo, query GetServiceAccountInternalIDQuery) (*GetServiceAccountInternalIDResult, error)
|
||||
ListServiceAccounts(ctx context.Context, ns claims.NamespaceInfo, query ListServiceAccountsQuery) (*ListServiceAccountResult, error)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package legacy
|
|||
import (
|
||||
"testing"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/registry/apis/iam/common"
|
||||
"github.com/grafana/grafana/pkg/storage/legacysql"
|
||||
|
|
@ -30,6 +31,33 @@ func TestIdentityQueries(t *testing.T) {
|
|||
return &v
|
||||
}
|
||||
|
||||
deleteUser := func(q *DeleteUserQuery) sqltemplate.SQLTemplate {
|
||||
v := newDeleteUser(nodb, q)
|
||||
v.SQLTemplate = mocks.NewTestingSQLTemplate()
|
||||
return &v
|
||||
}
|
||||
|
||||
deleteOrgUser := func(userID int64) sqltemplate.SQLTemplate {
|
||||
v := deleteOrgUserQuery{
|
||||
SQLTemplate: mocks.NewTestingSQLTemplate(),
|
||||
OrgUserTable: nodb.Table("org_user"),
|
||||
UserID: userID,
|
||||
}
|
||||
return &v
|
||||
}
|
||||
|
||||
createOrgUser := func(cmd *CreateOrgUserCommand) sqltemplate.SQLTemplate {
|
||||
v := newCreateOrgUser(nodb, cmd)
|
||||
v.SQLTemplate = mocks.NewTestingSQLTemplate()
|
||||
return &v
|
||||
}
|
||||
|
||||
createUser := func(cmd *CreateUserCommand) sqltemplate.SQLTemplate {
|
||||
v := newCreateUser(nodb, cmd)
|
||||
v.SQLTemplate = mocks.NewTestingSQLTemplate()
|
||||
return &v
|
||||
}
|
||||
|
||||
listTeams := func(q *ListTeamQuery) sqltemplate.SQLTemplate {
|
||||
v := newListTeams(nodb, q)
|
||||
v.SQLTemplate = mocks.NewTestingSQLTemplate()
|
||||
|
|
@ -300,6 +328,96 @@ func TestIdentityQueries(t *testing.T) {
|
|||
}),
|
||||
},
|
||||
},
|
||||
sqlDeleteUserTemplate: {
|
||||
{
|
||||
Name: "delete_user_basic",
|
||||
Data: deleteUser(&DeleteUserQuery{
|
||||
OrgID: 1,
|
||||
UID: "user-1",
|
||||
}),
|
||||
},
|
||||
{
|
||||
Name: "delete_user_different_org",
|
||||
Data: deleteUser(&DeleteUserQuery{
|
||||
OrgID: 2,
|
||||
UID: "user-abc",
|
||||
}),
|
||||
},
|
||||
},
|
||||
sqlDeleteOrgUserTemplate: {
|
||||
{
|
||||
Name: "delete_org_user_basic",
|
||||
Data: deleteOrgUser(123),
|
||||
},
|
||||
{
|
||||
Name: "delete_org_user_different_id",
|
||||
Data: deleteOrgUser(456),
|
||||
},
|
||||
},
|
||||
sqlCreateOrgUserTemplate: {
|
||||
{
|
||||
Name: "create_org_user_basic",
|
||||
Data: createOrgUser(&CreateOrgUserCommand{
|
||||
OrgID: 1,
|
||||
UserID: 123,
|
||||
Role: "Viewer",
|
||||
Created: time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC),
|
||||
Updated: time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC),
|
||||
}),
|
||||
},
|
||||
{
|
||||
Name: "create_org_user_admin",
|
||||
Data: createOrgUser(&CreateOrgUserCommand{
|
||||
OrgID: 2,
|
||||
UserID: 456,
|
||||
Role: "Admin",
|
||||
Created: time.Date(2023, 2, 1, 10, 30, 0, 0, time.UTC),
|
||||
Updated: time.Date(2023, 2, 1, 10, 30, 0, 0, time.UTC),
|
||||
}),
|
||||
},
|
||||
},
|
||||
sqlCreateUserTemplate: {
|
||||
{
|
||||
Name: "create_user_basic",
|
||||
Data: createUser(&CreateUserCommand{
|
||||
UID: "user-1",
|
||||
Email: "user1@example.com",
|
||||
Login: "user1",
|
||||
Name: "User One",
|
||||
OrgID: 1,
|
||||
IsAdmin: false,
|
||||
IsDisabled: false,
|
||||
EmailVerified: true,
|
||||
IsProvisioned: false,
|
||||
Salt: "randomsalt",
|
||||
Rands: "randomrands",
|
||||
Created: time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC),
|
||||
Updated: time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC),
|
||||
LastSeenAt: time.Date(2013, 1, 1, 12, 0, 0, 0, time.UTC),
|
||||
Role: "Viewer",
|
||||
}),
|
||||
},
|
||||
{
|
||||
Name: "create_user_admin",
|
||||
Data: createUser(&CreateUserCommand{
|
||||
UID: "admin-1",
|
||||
Email: "admin@example.com",
|
||||
Login: "admin",
|
||||
Name: "Admin User",
|
||||
OrgID: 2,
|
||||
IsAdmin: true,
|
||||
IsDisabled: false,
|
||||
EmailVerified: true,
|
||||
IsProvisioned: true,
|
||||
Salt: "adminsalt",
|
||||
Rands: "adminrands",
|
||||
Created: time.Date(2023, 2, 1, 10, 30, 0, 0, time.UTC),
|
||||
Updated: time.Date(2023, 2, 1, 10, 30, 0, 0, time.UTC),
|
||||
LastSeenAt: time.Date(2013, 2, 1, 10, 30, 0, 0, time.UTC),
|
||||
Role: "Admin",
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
5
pkg/registry/apis/iam/legacy/testdata/mysql--create_org_user-create_org_user_admin.sql
vendored
Executable file
5
pkg/registry/apis/iam/legacy/testdata/mysql--create_org_user-create_org_user_admin.sql
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO `grafana`.`org_user`
|
||||
(org_id, user_id, role, created, updated)
|
||||
VALUES
|
||||
(2, 456, 'Admin',
|
||||
'2023-02-01 10:30:00 +0000 UTC', '2023-02-01 10:30:00 +0000 UTC')
|
||||
5
pkg/registry/apis/iam/legacy/testdata/mysql--create_org_user-create_org_user_basic.sql
vendored
Executable file
5
pkg/registry/apis/iam/legacy/testdata/mysql--create_org_user-create_org_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO `grafana`.`org_user`
|
||||
(org_id, user_id, role, created, updated)
|
||||
VALUES
|
||||
(1, 123, 'Viewer',
|
||||
'2023-01-01 12:00:00 +0000 UTC', '2023-01-01 12:00:00 +0000 UTC')
|
||||
9
pkg/registry/apis/iam/legacy/testdata/mysql--create_user-create_user_admin.sql
vendored
Executable file
9
pkg/registry/apis/iam/legacy/testdata/mysql--create_user-create_user_admin.sql
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
INSERT INTO `grafana`.`user`
|
||||
(uid, version, login, email, name, org_id, is_admin, is_disabled, email_verified,
|
||||
is_provisioned, is_service_account, salt, rands, created, updated, last_seen_at)
|
||||
VALUES
|
||||
('admin-1', 0, 'admin', 'admin@example.com',
|
||||
'Admin User', 2, TRUE,
|
||||
FALSE, TRUE,
|
||||
TRUE, false, 'adminsalt', 'adminrands',
|
||||
'2023-02-01 10:30:00 +0000 UTC', '2023-02-01 10:30:00 +0000 UTC', '2013-02-01 10:30:00 +0000 UTC')
|
||||
9
pkg/registry/apis/iam/legacy/testdata/mysql--create_user-create_user_basic.sql
vendored
Executable file
9
pkg/registry/apis/iam/legacy/testdata/mysql--create_user-create_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
INSERT INTO `grafana`.`user`
|
||||
(uid, version, login, email, name, org_id, is_admin, is_disabled, email_verified,
|
||||
is_provisioned, is_service_account, salt, rands, created, updated, last_seen_at)
|
||||
VALUES
|
||||
('user-1', 0, 'user1', 'user1@example.com',
|
||||
'User One', 1, FALSE,
|
||||
FALSE, TRUE,
|
||||
FALSE, false, 'randomsalt', 'randomrands',
|
||||
'2023-01-01 12:00:00 +0000 UTC', '2023-01-01 12:00:00 +0000 UTC', '2013-01-01 12:00:00 +0000 UTC')
|
||||
3
pkg/registry/apis/iam/legacy/testdata/mysql--delete_org_user-delete_org_user_basic.sql
vendored
Executable file
3
pkg/registry/apis/iam/legacy/testdata/mysql--delete_org_user-delete_org_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
-- Delete from org_user table for a specific user
|
||||
DELETE FROM `grafana`.`org_user`
|
||||
WHERE user_id = 123
|
||||
3
pkg/registry/apis/iam/legacy/testdata/mysql--delete_org_user-delete_org_user_different_id.sql
vendored
Executable file
3
pkg/registry/apis/iam/legacy/testdata/mysql--delete_org_user-delete_org_user_different_id.sql
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
-- Delete from org_user table for a specific user
|
||||
DELETE FROM `grafana`.`org_user`
|
||||
WHERE user_id = 456
|
||||
4
pkg/registry/apis/iam/legacy/testdata/mysql--delete_user-delete_user_basic.sql
vendored
Executable file
4
pkg/registry/apis/iam/legacy/testdata/mysql--delete_user-delete_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
-- Delete from user table (org_user will be handled separately to avoid locking)
|
||||
DELETE FROM `grafana`.`user`
|
||||
WHERE uid = 'user-1'
|
||||
AND org_id = 1
|
||||
4
pkg/registry/apis/iam/legacy/testdata/mysql--delete_user-delete_user_different_org.sql
vendored
Executable file
4
pkg/registry/apis/iam/legacy/testdata/mysql--delete_user-delete_user_different_org.sql
vendored
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
-- Delete from user table (org_user will be handled separately to avoid locking)
|
||||
DELETE FROM `grafana`.`user`
|
||||
WHERE uid = 'user-abc'
|
||||
AND org_id = 2
|
||||
5
pkg/registry/apis/iam/legacy/testdata/postgres--create_org_user-create_org_user_admin.sql
vendored
Executable file
5
pkg/registry/apis/iam/legacy/testdata/postgres--create_org_user-create_org_user_admin.sql
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO "grafana"."org_user"
|
||||
(org_id, user_id, role, created, updated)
|
||||
VALUES
|
||||
(2, 456, 'Admin',
|
||||
'2023-02-01 10:30:00 +0000 UTC', '2023-02-01 10:30:00 +0000 UTC')
|
||||
5
pkg/registry/apis/iam/legacy/testdata/postgres--create_org_user-create_org_user_basic.sql
vendored
Executable file
5
pkg/registry/apis/iam/legacy/testdata/postgres--create_org_user-create_org_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO "grafana"."org_user"
|
||||
(org_id, user_id, role, created, updated)
|
||||
VALUES
|
||||
(1, 123, 'Viewer',
|
||||
'2023-01-01 12:00:00 +0000 UTC', '2023-01-01 12:00:00 +0000 UTC')
|
||||
9
pkg/registry/apis/iam/legacy/testdata/postgres--create_user-create_user_admin.sql
vendored
Executable file
9
pkg/registry/apis/iam/legacy/testdata/postgres--create_user-create_user_admin.sql
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
INSERT INTO "grafana"."user"
|
||||
(uid, version, login, email, name, org_id, is_admin, is_disabled, email_verified,
|
||||
is_provisioned, is_service_account, salt, rands, created, updated, last_seen_at)
|
||||
VALUES
|
||||
('admin-1', 0, 'admin', 'admin@example.com',
|
||||
'Admin User', 2, TRUE,
|
||||
FALSE, TRUE,
|
||||
TRUE, false, 'adminsalt', 'adminrands',
|
||||
'2023-02-01 10:30:00 +0000 UTC', '2023-02-01 10:30:00 +0000 UTC', '2013-02-01 10:30:00 +0000 UTC')
|
||||
9
pkg/registry/apis/iam/legacy/testdata/postgres--create_user-create_user_basic.sql
vendored
Executable file
9
pkg/registry/apis/iam/legacy/testdata/postgres--create_user-create_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
INSERT INTO "grafana"."user"
|
||||
(uid, version, login, email, name, org_id, is_admin, is_disabled, email_verified,
|
||||
is_provisioned, is_service_account, salt, rands, created, updated, last_seen_at)
|
||||
VALUES
|
||||
('user-1', 0, 'user1', 'user1@example.com',
|
||||
'User One', 1, FALSE,
|
||||
FALSE, TRUE,
|
||||
FALSE, false, 'randomsalt', 'randomrands',
|
||||
'2023-01-01 12:00:00 +0000 UTC', '2023-01-01 12:00:00 +0000 UTC', '2013-01-01 12:00:00 +0000 UTC')
|
||||
3
pkg/registry/apis/iam/legacy/testdata/postgres--delete_org_user-delete_org_user_basic.sql
vendored
Executable file
3
pkg/registry/apis/iam/legacy/testdata/postgres--delete_org_user-delete_org_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
-- Delete from org_user table for a specific user
|
||||
DELETE FROM "grafana"."org_user"
|
||||
WHERE user_id = 123
|
||||
3
pkg/registry/apis/iam/legacy/testdata/postgres--delete_org_user-delete_org_user_different_id.sql
vendored
Executable file
3
pkg/registry/apis/iam/legacy/testdata/postgres--delete_org_user-delete_org_user_different_id.sql
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
-- Delete from org_user table for a specific user
|
||||
DELETE FROM "grafana"."org_user"
|
||||
WHERE user_id = 456
|
||||
4
pkg/registry/apis/iam/legacy/testdata/postgres--delete_user-delete_user_basic.sql
vendored
Executable file
4
pkg/registry/apis/iam/legacy/testdata/postgres--delete_user-delete_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
-- Delete from user table (org_user will be handled separately to avoid locking)
|
||||
DELETE FROM "grafana"."user"
|
||||
WHERE uid = 'user-1'
|
||||
AND org_id = 1
|
||||
4
pkg/registry/apis/iam/legacy/testdata/postgres--delete_user-delete_user_different_org.sql
vendored
Executable file
4
pkg/registry/apis/iam/legacy/testdata/postgres--delete_user-delete_user_different_org.sql
vendored
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
-- Delete from user table (org_user will be handled separately to avoid locking)
|
||||
DELETE FROM "grafana"."user"
|
||||
WHERE uid = 'user-abc'
|
||||
AND org_id = 2
|
||||
5
pkg/registry/apis/iam/legacy/testdata/sqlite--create_org_user-create_org_user_admin.sql
vendored
Executable file
5
pkg/registry/apis/iam/legacy/testdata/sqlite--create_org_user-create_org_user_admin.sql
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO "grafana"."org_user"
|
||||
(org_id, user_id, role, created, updated)
|
||||
VALUES
|
||||
(2, 456, 'Admin',
|
||||
'2023-02-01 10:30:00 +0000 UTC', '2023-02-01 10:30:00 +0000 UTC')
|
||||
5
pkg/registry/apis/iam/legacy/testdata/sqlite--create_org_user-create_org_user_basic.sql
vendored
Executable file
5
pkg/registry/apis/iam/legacy/testdata/sqlite--create_org_user-create_org_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO "grafana"."org_user"
|
||||
(org_id, user_id, role, created, updated)
|
||||
VALUES
|
||||
(1, 123, 'Viewer',
|
||||
'2023-01-01 12:00:00 +0000 UTC', '2023-01-01 12:00:00 +0000 UTC')
|
||||
9
pkg/registry/apis/iam/legacy/testdata/sqlite--create_user-create_user_admin.sql
vendored
Executable file
9
pkg/registry/apis/iam/legacy/testdata/sqlite--create_user-create_user_admin.sql
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
INSERT INTO "grafana"."user"
|
||||
(uid, version, login, email, name, org_id, is_admin, is_disabled, email_verified,
|
||||
is_provisioned, is_service_account, salt, rands, created, updated, last_seen_at)
|
||||
VALUES
|
||||
('admin-1', 0, 'admin', 'admin@example.com',
|
||||
'Admin User', 2, TRUE,
|
||||
FALSE, TRUE,
|
||||
TRUE, false, 'adminsalt', 'adminrands',
|
||||
'2023-02-01 10:30:00 +0000 UTC', '2023-02-01 10:30:00 +0000 UTC', '2013-02-01 10:30:00 +0000 UTC')
|
||||
9
pkg/registry/apis/iam/legacy/testdata/sqlite--create_user-create_user_basic.sql
vendored
Executable file
9
pkg/registry/apis/iam/legacy/testdata/sqlite--create_user-create_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
INSERT INTO "grafana"."user"
|
||||
(uid, version, login, email, name, org_id, is_admin, is_disabled, email_verified,
|
||||
is_provisioned, is_service_account, salt, rands, created, updated, last_seen_at)
|
||||
VALUES
|
||||
('user-1', 0, 'user1', 'user1@example.com',
|
||||
'User One', 1, FALSE,
|
||||
FALSE, TRUE,
|
||||
FALSE, false, 'randomsalt', 'randomrands',
|
||||
'2023-01-01 12:00:00 +0000 UTC', '2023-01-01 12:00:00 +0000 UTC', '2013-01-01 12:00:00 +0000 UTC')
|
||||
3
pkg/registry/apis/iam/legacy/testdata/sqlite--delete_org_user-delete_org_user_basic.sql
vendored
Executable file
3
pkg/registry/apis/iam/legacy/testdata/sqlite--delete_org_user-delete_org_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
-- Delete from org_user table for a specific user
|
||||
DELETE FROM "grafana"."org_user"
|
||||
WHERE user_id = 123
|
||||
3
pkg/registry/apis/iam/legacy/testdata/sqlite--delete_org_user-delete_org_user_different_id.sql
vendored
Executable file
3
pkg/registry/apis/iam/legacy/testdata/sqlite--delete_org_user-delete_org_user_different_id.sql
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
-- Delete from org_user table for a specific user
|
||||
DELETE FROM "grafana"."org_user"
|
||||
WHERE user_id = 456
|
||||
4
pkg/registry/apis/iam/legacy/testdata/sqlite--delete_user-delete_user_basic.sql
vendored
Executable file
4
pkg/registry/apis/iam/legacy/testdata/sqlite--delete_user-delete_user_basic.sql
vendored
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
-- Delete from user table (org_user will be handled separately to avoid locking)
|
||||
DELETE FROM "grafana"."user"
|
||||
WHERE uid = 'user-1'
|
||||
AND org_id = 1
|
||||
4
pkg/registry/apis/iam/legacy/testdata/sqlite--delete_user-delete_user_different_org.sql
vendored
Executable file
4
pkg/registry/apis/iam/legacy/testdata/sqlite--delete_user-delete_user_different_org.sql
vendored
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
-- Delete from user table (org_user will be handled separately to avoid locking)
|
||||
DELETE FROM "grafana"."user"
|
||||
WHERE uid = 'user-abc'
|
||||
AND org_id = 2
|
||||
|
|
@ -5,13 +5,16 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
claims "github.com/grafana/authlib/types"
|
||||
"github.com/grafana/grafana/pkg/registry/apis/iam/common"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
||||
"github.com/grafana/grafana/pkg/services/team"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/storage/legacysql"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/sql/sqltemplate"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
type GetUserInternalIDQuery struct {
|
||||
|
|
@ -287,3 +290,326 @@ func (s *legacySQLStore) ListUserTeams(ctx context.Context, ns claims.NamespaceI
|
|||
|
||||
return res, err
|
||||
}
|
||||
|
||||
type CreateUserCommand struct {
|
||||
UID string
|
||||
Email string
|
||||
Login string
|
||||
Name string
|
||||
OrgID int64
|
||||
IsAdmin bool
|
||||
IsDisabled bool
|
||||
EmailVerified bool
|
||||
IsProvisioned bool
|
||||
Salt string
|
||||
Rands string
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
LastSeenAt time.Time
|
||||
Role string
|
||||
}
|
||||
|
||||
type CreateUserResult struct {
|
||||
User user.User
|
||||
}
|
||||
|
||||
type CreateOrgUserCommand struct {
|
||||
OrgID int64
|
||||
UserID int64
|
||||
Role string
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
type DeleteUserCommand struct {
|
||||
UID string
|
||||
}
|
||||
|
||||
type DeleteUserQuery struct {
|
||||
OrgID int64
|
||||
UID string
|
||||
}
|
||||
|
||||
type DeleteUserResult struct {
|
||||
Success bool
|
||||
}
|
||||
|
||||
var sqlCreateUserTemplate = mustTemplate("create_user.sql")
|
||||
var sqlCreateOrgUserTemplate = mustTemplate("create_org_user.sql")
|
||||
var sqlDeleteUserTemplate = mustTemplate("delete_user.sql")
|
||||
var sqlDeleteOrgUserTemplate = mustTemplate("delete_org_user.sql")
|
||||
|
||||
func newCreateUser(sql *legacysql.LegacyDatabaseHelper, cmd *CreateUserCommand) createUserQuery {
|
||||
return createUserQuery{
|
||||
SQLTemplate: sqltemplate.New(sql.DialectForDriver()),
|
||||
UserTable: sql.Table("user"),
|
||||
OrgUserTable: sql.Table("org_user"),
|
||||
Command: cmd,
|
||||
}
|
||||
}
|
||||
|
||||
type createUserQuery struct {
|
||||
sqltemplate.SQLTemplate
|
||||
UserTable string
|
||||
OrgUserTable string
|
||||
Command *CreateUserCommand
|
||||
}
|
||||
|
||||
func (r createUserQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type createOrgUserQuery struct {
|
||||
sqltemplate.SQLTemplate
|
||||
OrgUserTable string
|
||||
Command *CreateOrgUserCommand
|
||||
}
|
||||
|
||||
func (r createOrgUserQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func newCreateOrgUser(sql *legacysql.LegacyDatabaseHelper, cmd *CreateOrgUserCommand) createOrgUserQuery {
|
||||
return createOrgUserQuery{
|
||||
SQLTemplate: sqltemplate.New(sql.DialectForDriver()),
|
||||
OrgUserTable: sql.Table("org_user"),
|
||||
Command: cmd,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateUser implements LegacyIdentityStore.
|
||||
func (s *legacySQLStore) CreateUser(ctx context.Context, ns claims.NamespaceInfo, cmd CreateUserCommand) (*CreateUserResult, error) {
|
||||
cmd.OrgID = ns.OrgID
|
||||
|
||||
salt, err := util.GetRandomString(10)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rands, err := util.GetRandomString(10)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
lastSeenAt := now.AddDate(-10, 0, 0) // Set last seen 10 years ago like in user service
|
||||
|
||||
cmd.Salt = salt
|
||||
cmd.Rands = rands
|
||||
cmd.Created = now
|
||||
cmd.Updated = now
|
||||
cmd.LastSeenAt = lastSeenAt
|
||||
cmd.Role = "Viewer" // TODO: https://github.com/grafana/identity-access-team/issues/1552
|
||||
|
||||
sql, err := s.sql(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req := newCreateUser(sql, &cmd)
|
||||
|
||||
var createdUser user.User
|
||||
err = sql.DB.GetSqlxSession().WithTransaction(ctx, func(st *session.SessionTx) error {
|
||||
userQuery, err := sqltemplate.Execute(sqlCreateUserTemplate, req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("execute user template %q: %w", sqlCreateUserTemplate.Name(), err)
|
||||
}
|
||||
|
||||
userID, err := st.ExecWithReturningId(ctx, userQuery, req.GetArgs()...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create user: %w", err)
|
||||
}
|
||||
|
||||
orgUserCmd := &CreateOrgUserCommand{
|
||||
OrgID: cmd.OrgID,
|
||||
UserID: userID,
|
||||
Role: cmd.Role,
|
||||
Created: cmd.Created,
|
||||
Updated: cmd.Updated,
|
||||
}
|
||||
orgUserReq := newCreateOrgUser(sql, orgUserCmd)
|
||||
|
||||
orgUserQuery, err := sqltemplate.Execute(sqlCreateOrgUserTemplate, orgUserReq)
|
||||
if err != nil {
|
||||
return fmt.Errorf("execute org_user template %q: %w", sqlCreateOrgUserTemplate.Name(), err)
|
||||
}
|
||||
|
||||
_, err = st.Exec(ctx, orgUserQuery, orgUserReq.GetArgs()...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create org_user relationship: %w", err)
|
||||
}
|
||||
|
||||
createdUser = user.User{
|
||||
ID: userID,
|
||||
UID: cmd.UID,
|
||||
Login: cmd.Login,
|
||||
Email: cmd.Email,
|
||||
Name: cmd.Name,
|
||||
OrgID: cmd.OrgID,
|
||||
IsAdmin: cmd.IsAdmin,
|
||||
IsDisabled: cmd.IsDisabled,
|
||||
EmailVerified: cmd.EmailVerified,
|
||||
IsProvisioned: cmd.IsProvisioned,
|
||||
Salt: cmd.Salt,
|
||||
Rands: cmd.Rands,
|
||||
Created: cmd.Created,
|
||||
Updated: cmd.Updated,
|
||||
LastSeenAt: cmd.LastSeenAt,
|
||||
IsServiceAccount: false,
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &CreateUserResult{User: createdUser}, nil
|
||||
}
|
||||
|
||||
func newDeleteUser(sql *legacysql.LegacyDatabaseHelper, q *DeleteUserQuery) deleteUserQuery {
|
||||
return deleteUserQuery{
|
||||
SQLTemplate: sqltemplate.New(sql.DialectForDriver()),
|
||||
UserTable: sql.Table("user"),
|
||||
OrgUserTable: sql.Table("org_user"),
|
||||
Query: q,
|
||||
}
|
||||
}
|
||||
|
||||
type deleteUserQuery struct {
|
||||
sqltemplate.SQLTemplate
|
||||
UserTable string
|
||||
OrgUserTable string
|
||||
Query *DeleteUserQuery
|
||||
}
|
||||
|
||||
type deleteOrgUserQuery struct {
|
||||
sqltemplate.SQLTemplate
|
||||
OrgUserTable string
|
||||
UserID int64
|
||||
}
|
||||
|
||||
func (r deleteOrgUserQuery) Validate() error {
|
||||
if r.UserID == 0 {
|
||||
return fmt.Errorf("user ID is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r deleteUserQuery) Validate() error {
|
||||
if r.Query.UID == "" {
|
||||
return fmt.Errorf("user UID is required")
|
||||
}
|
||||
if r.Query.OrgID == 0 {
|
||||
return fmt.Errorf("org ID is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteUser implements LegacyIdentityStore.
|
||||
func (s *legacySQLStore) DeleteUser(ctx context.Context, ns claims.NamespaceInfo, cmd DeleteUserCommand) (*DeleteUserResult, error) {
|
||||
if ns.OrgID == 0 {
|
||||
return nil, fmt.Errorf("expected non zero org id")
|
||||
}
|
||||
|
||||
if cmd.UID == "" {
|
||||
return nil, fmt.Errorf("user UID is required")
|
||||
}
|
||||
|
||||
sql, err := s.sql(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
query := &DeleteUserQuery{
|
||||
OrgID: ns.OrgID,
|
||||
UID: cmd.UID,
|
||||
}
|
||||
|
||||
req := newDeleteUser(sql, query)
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = sql.DB.GetSqlxSession().WithTransaction(ctx, func(st *session.SessionTx) error {
|
||||
userLookupReq := newGetUserInternalID(sql, &GetUserInternalIDQuery{
|
||||
OrgID: ns.OrgID,
|
||||
UID: req.Query.UID,
|
||||
})
|
||||
|
||||
userQuery, err := sqltemplate.Execute(sqlQueryUserInternalIDTemplate, userLookupReq)
|
||||
if err != nil {
|
||||
return fmt.Errorf("execute user lookup template: %w", err)
|
||||
}
|
||||
|
||||
rows, err := st.Query(ctx, userQuery, userLookupReq.GetArgs()...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check if user exists: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if rows != nil {
|
||||
_ = rows.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
var userID int64
|
||||
if !rows.Next() {
|
||||
if err := rows.Err(); err != nil {
|
||||
return fmt.Errorf("failed to read user lookup rows: %w", err)
|
||||
}
|
||||
// User not found, nothing to delete
|
||||
return fmt.Errorf("user not found")
|
||||
}
|
||||
if err := rows.Scan(&userID); err != nil {
|
||||
return fmt.Errorf("failed to scan user ID: %w", err)
|
||||
}
|
||||
|
||||
// Close rows to avoid the bad connection error
|
||||
if rows != nil {
|
||||
_ = rows.Close()
|
||||
}
|
||||
|
||||
orgUserReq := deleteOrgUserQuery{
|
||||
SQLTemplate: sqltemplate.New(sql.DialectForDriver()),
|
||||
OrgUserTable: sql.Table("org_user"),
|
||||
UserID: userID,
|
||||
}
|
||||
|
||||
orgUserDeleteQuery, err := sqltemplate.Execute(sqlDeleteOrgUserTemplate, orgUserReq)
|
||||
if err != nil {
|
||||
return fmt.Errorf("execute org_user delete template: %w", err)
|
||||
}
|
||||
|
||||
_, err = st.Exec(ctx, orgUserDeleteQuery, orgUserReq.GetArgs()...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete from org_user: %w", err)
|
||||
}
|
||||
|
||||
deleteQuery, err := sqltemplate.Execute(sqlDeleteUserTemplate, req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("execute delete template %q: %w", sqlDeleteUserTemplate.Name(), err)
|
||||
}
|
||||
|
||||
result, err := st.Exec(ctx, deleteQuery, req.GetArgs()...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete user: %w", err)
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get rows affected: %w", err)
|
||||
}
|
||||
|
||||
if rowsAffected == 0 {
|
||||
return fmt.Errorf("user not found")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DeleteUserResult{Success: true}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import (
|
|||
|
||||
var _ builder.APIGroupBuilder = (*IdentityAccessManagementAPIBuilder)(nil)
|
||||
var _ builder.APIGroupRouteProvider = (*IdentityAccessManagementAPIBuilder)(nil)
|
||||
var _ builder.APIGroupValidation = (*IdentityAccessManagementAPIBuilder)(nil)
|
||||
var _ builder.APIGroupMutation = (*IdentityAccessManagementAPIBuilder)(nil)
|
||||
|
||||
// CoreRoleStorageBackend uses the resource.StorageBackend interface to provide storage for core roles.
|
||||
// Used wire to identify the storage backend for core roles.
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apiserver/pkg/admission"
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
"k8s.io/apiserver/pkg/registry/generic"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
|
|
@ -124,7 +126,19 @@ func (b *IdentityAccessManagementAPIBuilder) UpdateAPIGroupInfo(apiGroupInfo *ge
|
|||
storage[teamBindingResource.StoragePath()] = team.NewLegacyBindingStore(b.store)
|
||||
|
||||
userResource := legacyiamv0.UserResourceInfo
|
||||
storage[userResource.StoragePath()] = user.NewLegacyStore(b.store, b.legacyAccessClient)
|
||||
store, err := grafanaregistry.NewRegistryStore(opts.Scheme, userResource, opts.OptsGetter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
legacyStore := user.NewLegacyStore(b.store, b.legacyAccessClient)
|
||||
|
||||
dw, err := opts.DualWriteBuilder(userResource.GroupResource(), legacyStore, store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
storage[userResource.StoragePath()] = dw
|
||||
storage[userResource.StoragePath("teams")] = user.NewLegacyTeamMemberREST(b.store)
|
||||
|
||||
serviceAccountResource := legacyiamv0.ServiceAccountResourceInfo
|
||||
|
|
@ -219,6 +233,77 @@ func (b *IdentityAccessManagementAPIBuilder) GetAuthorizer() authorizer.Authoriz
|
|||
return b.authorizer
|
||||
}
|
||||
|
||||
// Validate implements builder.APIGroupValidation.
|
||||
// TODO: Move this to the ValidateFunc of the user resource after moving the APIs to use the app-platofrm-sdk.
|
||||
// TODO: https://github.com/grafana/grafana/blob/main/apps/playlist/pkg/app/app.go#L62
|
||||
func (b *IdentityAccessManagementAPIBuilder) Validate(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) {
|
||||
switch a.GetOperation() {
|
||||
case admission.Create:
|
||||
if a.GetKind() == legacyiamv0.UserResourceInfo.GroupVersionKind() {
|
||||
return b.validateCreateUser(ctx, a, o)
|
||||
}
|
||||
return nil
|
||||
case admission.Connect:
|
||||
case admission.Delete:
|
||||
case admission.Update:
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *IdentityAccessManagementAPIBuilder) validateCreateUser(_ context.Context, a admission.Attributes, o admission.ObjectInterfaces) error {
|
||||
userObj, ok := a.GetObject().(*iamv0.User)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
if userObj.Spec.Login == "" && userObj.Spec.Email == "" {
|
||||
return apierrors.NewBadRequest("user must have either login or email")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Mutate implements builder.APIGroupMutation.
|
||||
// TODO: Move this to the MutateFunc of the user resource after moving the APIs to use the app-platofrm-sdk.
|
||||
// TODO: https://github.com/grafana/grafana/blob/main/apps/playlist/pkg/app/app.go#L62
|
||||
func (b *IdentityAccessManagementAPIBuilder) Mutate(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) {
|
||||
switch a.GetOperation() {
|
||||
case admission.Create:
|
||||
if a.GetKind() == legacyiamv0.UserResourceInfo.GroupVersionKind() {
|
||||
return b.mutateUser(ctx, a, o)
|
||||
}
|
||||
return nil
|
||||
case admission.Update:
|
||||
return nil
|
||||
case admission.Delete:
|
||||
return nil
|
||||
case admission.Connect:
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *IdentityAccessManagementAPIBuilder) mutateUser(_ context.Context, a admission.Attributes, o admission.ObjectInterfaces) error {
|
||||
userObj, ok := a.GetObject().(*iamv0.User)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
userObj.Spec.Email = strings.ToLower(userObj.Spec.Email)
|
||||
userObj.Spec.Login = strings.ToLower(userObj.Spec.Login)
|
||||
|
||||
if userObj.Spec.Login == "" {
|
||||
userObj.Spec.Login = userObj.Spec.Email
|
||||
}
|
||||
if userObj.Spec.Email == "" {
|
||||
userObj.Spec.Email = userObj.Spec.Login
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewLocalStore(resourceInfo utils.ResourceInfo, scheme *runtime.Scheme, defaultOptsGetter generic.RESTOptionsGetter,
|
||||
reg prometheus.Registerer, ac types.AccessClient, storageBackend resource.StorageBackend) (grafanarest.Storage, error) {
|
||||
server, err := resource.NewResourceServer(resource.ResourceServerOptions{
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func (s *LegacyStore) ConvertToTable(ctx context.Context, object runtime.Object,
|
|||
|
||||
func (s *LegacyStore) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) {
|
||||
res, err := common.List(
|
||||
ctx, resource.GetName(), s.ac, common.PaginationFromListOptions(options),
|
||||
ctx, resource, s.ac, common.PaginationFromListOptions(options),
|
||||
func(ctx context.Context, ns claims.NamespaceInfo, p common.Pagination) (*common.ListResponse[iamv0alpha1.ServiceAccount], error) {
|
||||
found, err := s.store.ListServiceAccounts(ctx, ns, legacy.ListServiceAccountsQuery{
|
||||
Pagination: p,
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func (s *LegacyStore) ConvertToTable(ctx context.Context, object runtime.Object,
|
|||
|
||||
func (s *LegacyStore) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) {
|
||||
res, err := common.List(
|
||||
ctx, resource.GetName(), s.ac, common.PaginationFromListOptions(options),
|
||||
ctx, resource, s.ac, common.PaginationFromListOptions(options),
|
||||
func(ctx context.Context, ns claims.NamespaceInfo, p common.Pagination) (*common.ListResponse[iamv0alpha1.Team], error) {
|
||||
found, err := s.store.ListTeams(ctx, ns, legacy.ListTeamQuery{
|
||||
Pagination: p,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/registry/apis/iam/legacy"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
)
|
||||
|
||||
const AnnoKeyLastSeenAt = "iam.grafana.app/lastSeenAt"
|
||||
|
|
@ -28,6 +29,10 @@ var (
|
|||
_ rest.Getter = (*LegacyStore)(nil)
|
||||
_ rest.Lister = (*LegacyStore)(nil)
|
||||
_ rest.Storage = (*LegacyStore)(nil)
|
||||
_ rest.CreaterUpdater = (*LegacyStore)(nil)
|
||||
_ rest.GracefulDeleter = (*LegacyStore)(nil)
|
||||
_ rest.CollectionDeleter = (*LegacyStore)(nil)
|
||||
_ rest.TableConvertor = (*LegacyStore)(nil)
|
||||
)
|
||||
|
||||
var resource = iamv0.UserResourceInfo
|
||||
|
|
@ -41,6 +46,57 @@ type LegacyStore struct {
|
|||
ac claims.AccessClient
|
||||
}
|
||||
|
||||
// Update implements rest.Updater.
|
||||
func (s *LegacyStore) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
|
||||
return nil, false, fmt.Errorf("method not yet implemented")
|
||||
}
|
||||
|
||||
// DeleteCollection implements rest.CollectionDeleter.
|
||||
func (s *LegacyStore) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, listOptions *internalversion.ListOptions) (runtime.Object, error) {
|
||||
return nil, apierrors.NewMethodNotSupported(resource.GroupResource(), "deletecollection")
|
||||
}
|
||||
|
||||
// Delete implements rest.GracefulDeleter.
|
||||
func (s *LegacyStore) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error) {
|
||||
ns, err := request.NamespaceInfoFrom(ctx, true)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
found, err := s.store.ListUsers(ctx, ns, legacy.ListUserQuery{
|
||||
OrgID: ns.OrgID,
|
||||
UID: name,
|
||||
Pagination: common.Pagination{Limit: 1},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if found == nil || len(found.Users) < 1 {
|
||||
return nil, false, resource.NewNotFound(name)
|
||||
}
|
||||
|
||||
userToDelete := &found.Users[0]
|
||||
|
||||
if deleteValidation != nil {
|
||||
userObj := toUserItem(userToDelete, ns.Value)
|
||||
if err := deleteValidation(ctx, &userObj); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
deleteCmd := legacy.DeleteUserCommand{
|
||||
UID: name,
|
||||
}
|
||||
|
||||
_, err = s.store.DeleteUser(ctx, ns, deleteCmd)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("failed to delete user: %w", err)
|
||||
}
|
||||
|
||||
deletedUser := toUserItem(userToDelete, ns.Value)
|
||||
return &deletedUser, true, nil
|
||||
}
|
||||
|
||||
func (s *LegacyStore) New() runtime.Object {
|
||||
return resource.NewFunc()
|
||||
}
|
||||
|
|
@ -65,7 +121,7 @@ func (s *LegacyStore) ConvertToTable(ctx context.Context, object runtime.Object,
|
|||
|
||||
func (s *LegacyStore) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) {
|
||||
res, err := common.List(
|
||||
ctx, resource.GetName(), s.ac, common.PaginationFromListOptions(options),
|
||||
ctx, resource, s.ac, common.PaginationFromListOptions(options),
|
||||
func(ctx context.Context, ns claims.NamespaceInfo, p common.Pagination) (*common.ListResponse[iamv0alpha.User], error) {
|
||||
found, err := s.store.ListUsers(ctx, ns, legacy.ListUserQuery{
|
||||
Pagination: p,
|
||||
|
|
@ -120,6 +176,48 @@ func (s *LegacyStore) Get(ctx context.Context, name string, options *metav1.GetO
|
|||
return &obj, nil
|
||||
}
|
||||
|
||||
// Create implements rest.Creater.
|
||||
func (s *LegacyStore) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
|
||||
ns, err := request.NamespaceInfoFrom(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
userObj, ok := obj.(*iamv0alpha.User)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("expected User object, got %T", obj)
|
||||
}
|
||||
|
||||
if createValidation != nil {
|
||||
if err := createValidation(ctx, obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if userObj.Spec.Login == "" && userObj.Spec.Email == "" {
|
||||
return nil, fmt.Errorf("user must have either login or email")
|
||||
}
|
||||
|
||||
createCmd := legacy.CreateUserCommand{
|
||||
UID: userObj.Name,
|
||||
Login: userObj.Spec.Login,
|
||||
Email: userObj.Spec.Email,
|
||||
Name: userObj.Spec.Name,
|
||||
IsAdmin: userObj.Spec.GrafanaAdmin,
|
||||
IsDisabled: userObj.Spec.Disabled,
|
||||
EmailVerified: userObj.Spec.EmailVerified,
|
||||
IsProvisioned: userObj.Spec.Provisioned,
|
||||
}
|
||||
|
||||
result, err := s.store.CreateUser(ctx, ns, createCmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
iamUser := toUserItem(&result.User, ns.Value)
|
||||
return &iamUser, nil
|
||||
}
|
||||
|
||||
func toUserItem(u *user.User, ns string) iamv0alpha.User {
|
||||
item := &iamv0alpha.User{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
|||
|
|
@ -125,8 +125,9 @@ func (c *LegacyAccessClient) Check(ctx context.Context, id claims.AuthInfo, req
|
|||
} else {
|
||||
eval = EvalPermission(action, fmt.Sprintf("%s:%s:%s", opts.Resource, opts.Attr, req.Name))
|
||||
}
|
||||
} else if req.Verb == utils.VerbList {
|
||||
} else if req.Verb == utils.VerbList || req.Verb == utils.VerbCreate {
|
||||
// For list request we need to filter out in storage layer.
|
||||
// For create requests we don't have a name yet, so we can only check if the action is allowed.
|
||||
eval = EvalPermission(action)
|
||||
} else {
|
||||
// Assuming that all non list request should have a valid name
|
||||
|
|
|
|||
|
|
@ -2,13 +2,17 @@ package identity
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apiserver/rest"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tests/apis"
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
|
|
@ -173,3 +177,164 @@ func TestIntegrationIdentity(t *testing.T) {
|
|||
]`, found)
|
||||
})
|
||||
}
|
||||
|
||||
func TestIntegrationUsers(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
// TODO: Figure out why rest.Mode4 is failing
|
||||
modes := []rest.DualWriterMode{rest.Mode0, rest.Mode1, rest.Mode2, rest.Mode3}
|
||||
for _, mode := range modes {
|
||||
t.Run(fmt.Sprintf("User CRUD operations with dual writer mode %d", mode), func(t *testing.T) {
|
||||
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||
AppModeProduction: false,
|
||||
DisableAnonymous: true,
|
||||
APIServerStorageType: "unified",
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
||||
"users.iam.grafana.app": {
|
||||
DualWriterMode: mode,
|
||||
},
|
||||
},
|
||||
EnableFeatureToggles: []string{
|
||||
featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs,
|
||||
},
|
||||
})
|
||||
doUserCRUDTestsUsingTheNewAPIs(t, helper)
|
||||
|
||||
if mode < 3 {
|
||||
doUserCRUDTestsUsingTheLegacyAPIs(t, helper)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func doUserCRUDTestsUsingTheNewAPIs(t *testing.T, helper *apis.K8sTestHelper) {
|
||||
t.Run("should create user and delete it using the new APIs", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
userClient := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: helper.Org1.Admin,
|
||||
GVR: gvrUsers,
|
||||
})
|
||||
|
||||
// Create the user
|
||||
created, err := userClient.Resource.Create(ctx, helper.LoadYAMLOrJSONFile("testdata/user-test-create-v0.yaml"), metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, created)
|
||||
|
||||
// Verify creation response
|
||||
createdSpec := created.Object["spec"].(map[string]interface{})
|
||||
require.Equal(t, "testuser1@example123.com", createdSpec["email"])
|
||||
require.Equal(t, "testuser1", createdSpec["login"])
|
||||
require.Equal(t, "Test User 1", createdSpec["name"])
|
||||
require.Equal(t, false, createdSpec["provisioned"])
|
||||
|
||||
// Get the UID from created user for fetching
|
||||
createdUID := created.GetName()
|
||||
require.NotEmpty(t, createdUID)
|
||||
|
||||
_, err = userClient.Resource.List(ctx, metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
fetched, err := userClient.Resource.Get(ctx, createdUID, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, fetched)
|
||||
|
||||
// Verify fetched user matches created user
|
||||
fetchedSpec := fetched.Object["spec"].(map[string]interface{})
|
||||
require.Equal(t, "testuser1@example123.com", fetchedSpec["email"])
|
||||
require.Equal(t, "testuser1", fetchedSpec["login"])
|
||||
require.Equal(t, "Test User 1", fetchedSpec["name"])
|
||||
require.Equal(t, false, fetchedSpec["provisioned"])
|
||||
|
||||
// Verify metadata
|
||||
require.Equal(t, createdUID, fetched.GetName())
|
||||
require.Equal(t, "default", fetched.GetNamespace())
|
||||
|
||||
err = userClient.Resource.Delete(ctx, createdUID, metav1.DeleteOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify deletion
|
||||
_, err = userClient.Resource.Get(ctx, createdUID, metav1.GetOptions{})
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "not found")
|
||||
})
|
||||
|
||||
t.Run("should not be able to create user when using a user with insufficient permissions", func(t *testing.T) {
|
||||
for _, user := range []apis.User{
|
||||
helper.Org1.Editor,
|
||||
helper.Org1.Viewer,
|
||||
} {
|
||||
t.Run(fmt.Sprintf("with basic role: %s", user.Identity.GetOrgRole()), func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
userClient := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: user,
|
||||
GVR: gvrUsers,
|
||||
})
|
||||
|
||||
// Create the user
|
||||
_, err := userClient.Resource.Create(ctx, helper.LoadYAMLOrJSONFile("testdata/user-test-create-v0.yaml"), metav1.CreateOptions{})
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "unauthorized request")
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func doUserCRUDTestsUsingTheLegacyAPIs(t *testing.T, helper *apis.K8sTestHelper) {
|
||||
t.Run("should create user using legacy APIs and delete it using the new APIs", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
userClient := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: helper.Org1.Admin,
|
||||
GVR: gvrUsers,
|
||||
})
|
||||
|
||||
legacyUserPayload := `{
|
||||
"name": "Test User 2",
|
||||
"email": "testuser2@example.com",
|
||||
"login": "testuser2",
|
||||
"password": "password123"
|
||||
}`
|
||||
|
||||
rsp := apis.DoRequest(helper, apis.RequestParams{
|
||||
User: helper.Org1.Admin,
|
||||
Method: "POST",
|
||||
Path: "/api/admin/users",
|
||||
Body: []byte(legacyUserPayload),
|
||||
}, &user.User{})
|
||||
|
||||
require.NotNil(t, rsp)
|
||||
require.Equal(t, 200, rsp.Response.StatusCode)
|
||||
require.NotEmpty(t, rsp.Result.UID)
|
||||
|
||||
// Now try to fetch the user via the new API
|
||||
user, err := userClient.Resource.Get(context.Background(), rsp.Result.UID, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, user)
|
||||
|
||||
// Verify fetched user matches created user
|
||||
userSpec := user.Object["spec"].(map[string]interface{})
|
||||
require.Equal(t, "testuser2@example.com", userSpec["email"])
|
||||
require.Equal(t, "testuser2", userSpec["login"])
|
||||
require.Equal(t, "Test User 2", userSpec["name"])
|
||||
require.Equal(t, false, userSpec["provisioned"])
|
||||
|
||||
// Verify metadata
|
||||
require.Equal(t, rsp.Result.UID, user.GetName())
|
||||
require.Equal(t, "default", user.GetNamespace())
|
||||
|
||||
// Now delete the user using the legacy API
|
||||
deleteRsp := apis.DoRequest(helper, apis.RequestParams{
|
||||
User: helper.Org1.Admin,
|
||||
Method: "DELETE",
|
||||
Path: fmt.Sprintf("/api/admin/users/%d", rsp.Result.ID),
|
||||
}, &apis.AnyResource{})
|
||||
require.Equal(t, 200, deleteRsp.Response.StatusCode)
|
||||
|
||||
// Verify deletion
|
||||
_, err = userClient.Resource.Get(ctx, rsp.Result.UID, metav1.GetOptions{})
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "not found")
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
apiVersion: iam.grafana.app/v0alpha1
|
||||
kind: User
|
||||
metadata:
|
||||
namespace: default
|
||||
name: abcdefghijkl
|
||||
spec:
|
||||
email: testuser1@example123.com
|
||||
login: testuser1
|
||||
name: Test User 1
|
||||
provisioned: false
|
||||
|
|
@ -1415,6 +1415,98 @@
|
|||
],
|
||||
"description": "list objects of kind User",
|
||||
"operationId": "listUser",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "allowWatchBookmarks",
|
||||
"in": "query",
|
||||
"description": "allowWatchBookmarks requests watch events with type \"BOOKMARK\". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "continue",
|
||||
"in": "query",
|
||||
"description": "The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the \"next key\".\n\nThis field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fieldSelector",
|
||||
"in": "query",
|
||||
"description": "A selector to restrict the list of returned objects by their fields. Defaults to everything.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "labelSelector",
|
||||
"in": "query",
|
||||
"description": "A selector to restrict the list of returned objects by their labels. Defaults to everything.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true.\n\nThe server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned.",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "resourceVersion",
|
||||
"in": "query",
|
||||
"description": "resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "resourceVersionMatch",
|
||||
"in": "query",
|
||||
"description": "resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "sendInitialEvents",
|
||||
"in": "query",
|
||||
"description": "`sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic \"Bookmark\" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `\"k8s.io/initial-events-end\": \"true\"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched.\n\nWhen `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: - `resourceVersionMatch` = NotOlderThan\n is interpreted as \"data at least as new as the provided `resourceVersion`\"\n and the bookmark event is send when the state is synced\n to a `resourceVersion` at least as fresh as the one provided by the ListOptions.\n If `resourceVersion` is unset, this is interpreted as \"consistent read\" and the\n bookmark event is send when the state is synced at least to the moment\n when request started being processed.\n- `resourceVersionMatch` set to any other value or unset\n Invalid error is returned.\n\nDefaults to true if `resourceVersion=\"\"` or `resourceVersion=\"0\"` (for backward compatibility reasons) and to false otherwise.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "timeoutSeconds",
|
||||
"in": "query",
|
||||
"description": "Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity.",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "watch",
|
||||
"in": "query",
|
||||
"description": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
|
|
@ -1454,52 +1546,285 @@
|
|||
"kind": "User"
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"tags": [
|
||||
"User"
|
||||
],
|
||||
"description": "create an User",
|
||||
"operationId": "createUser",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "dryRun",
|
||||
"in": "query",
|
||||
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fieldManager",
|
||||
"in": "query",
|
||||
"description": "fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fieldValidation",
|
||||
"in": "query",
|
||||
"description": "fieldValidation instructs the server on how to handle objects in the request (POST/PUT/PATCH) containing unknown or duplicate fields. Valid values are: - Ignore: This will ignore any unknown fields that are silently dropped from the object, and will ignore all but the last duplicate field that the decoder encounters. This is the default behavior prior to v1.23. - Warn: This will send a warning via the standard warning response header for each unknown field that is dropped from the object, and for each duplicate field that is encountered. The request will still succeed if there are no other errors, and will only persist the last of any duplicate fields. This is the default in v1.23+ - Strict: This will fail the request with a BadRequest error if any unknown fields would be dropped from the object, or if any duplicate fields are present. The error returned from the server will contain all unknown and duplicate fields encountered.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"201": {
|
||||
"description": "Created",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"202": {
|
||||
"description": "Accepted",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-kubernetes-action": "post",
|
||||
"x-kubernetes-group-version-kind": {
|
||||
"group": "iam.grafana.app",
|
||||
"version": "v0alpha1",
|
||||
"kind": "User"
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"User"
|
||||
],
|
||||
"description": "delete collection of User",
|
||||
"operationId": "deletecollectionUser",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "continue",
|
||||
"in": "query",
|
||||
"description": "The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the \"next key\".\n\nThis field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "dryRun",
|
||||
"in": "query",
|
||||
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fieldSelector",
|
||||
"in": "query",
|
||||
"description": "A selector to restrict the list of returned objects by their fields. Defaults to everything.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "gracePeriodSeconds",
|
||||
"in": "query",
|
||||
"description": "The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ignoreStoreReadErrorWithClusterBreakingPotential",
|
||||
"in": "query",
|
||||
"description": "if set to true, it will trigger an unsafe deletion of the resource in case the normal deletion flow fails with a corrupt object error. A resource is considered corrupt if it can not be retrieved from the underlying storage successfully because of a) its data can not be transformed e.g. decryption failure, or b) it fails to decode into an object. NOTE: unsafe deletion ignores finalizer constraints, skips precondition checks, and removes the object from the storage. WARNING: This may potentially break the cluster if the workload associated with the resource being unsafe-deleted relies on normal deletion flow. Use only if you REALLY know what you are doing. The default value is false, and the user must opt in to enable it",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "labelSelector",
|
||||
"in": "query",
|
||||
"description": "A selector to restrict the list of returned objects by their labels. Defaults to everything.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true.\n\nThe server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned.",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "orphanDependents",
|
||||
"in": "query",
|
||||
"description": "Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "propagationPolicy",
|
||||
"in": "query",
|
||||
"description": "Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "resourceVersion",
|
||||
"in": "query",
|
||||
"description": "resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "resourceVersionMatch",
|
||||
"in": "query",
|
||||
"description": "resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "sendInitialEvents",
|
||||
"in": "query",
|
||||
"description": "`sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic \"Bookmark\" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `\"k8s.io/initial-events-end\": \"true\"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched.\n\nWhen `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: - `resourceVersionMatch` = NotOlderThan\n is interpreted as \"data at least as new as the provided `resourceVersion`\"\n and the bookmark event is send when the state is synced\n to a `resourceVersion` at least as fresh as the one provided by the ListOptions.\n If `resourceVersion` is unset, this is interpreted as \"consistent read\" and the\n bookmark event is send when the state is synced at least to the moment\n when request started being processed.\n- `resourceVersionMatch` set to any other value or unset\n Invalid error is returned.\n\nDefaults to true if `resourceVersion=\"\"` or `resourceVersion=\"0\"` (for backward compatibility reasons) and to false otherwise.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "timeoutSeconds",
|
||||
"in": "query",
|
||||
"description": "Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity.",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-kubernetes-action": "deletecollection",
|
||||
"x-kubernetes-group-version-kind": {
|
||||
"group": "iam.grafana.app",
|
||||
"version": "v0alpha1",
|
||||
"kind": "User"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "allowWatchBookmarks",
|
||||
"in": "query",
|
||||
"description": "allowWatchBookmarks requests watch events with type \"BOOKMARK\". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "continue",
|
||||
"in": "query",
|
||||
"description": "The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the \"next key\".\n\nThis field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fieldSelector",
|
||||
"in": "query",
|
||||
"description": "A selector to restrict the list of returned objects by their fields. Defaults to everything.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "labelSelector",
|
||||
"in": "query",
|
||||
"description": "A selector to restrict the list of returned objects by their labels. Defaults to everything.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true.\n\nThe server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned.",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "namespace",
|
||||
"in": "path",
|
||||
|
|
@ -1518,51 +1843,6 @@
|
|||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "resourceVersion",
|
||||
"in": "query",
|
||||
"description": "resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "resourceVersionMatch",
|
||||
"in": "query",
|
||||
"description": "resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.\n\nDefaults to unset",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "sendInitialEvents",
|
||||
"in": "query",
|
||||
"description": "`sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic \"Bookmark\" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `\"k8s.io/initial-events-end\": \"true\"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched.\n\nWhen `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: - `resourceVersionMatch` = NotOlderThan\n is interpreted as \"data at least as new as the provided `resourceVersion`\"\n and the bookmark event is send when the state is synced\n to a `resourceVersion` at least as fresh as the one provided by the ListOptions.\n If `resourceVersion` is unset, this is interpreted as \"consistent read\" and the\n bookmark event is send when the state is synced at least to the moment\n when request started being processed.\n- `resourceVersionMatch` set to any other value or unset\n Invalid error is returned.\n\nDefaults to true if `resourceVersion=\"\"` or `resourceVersion=\"0\"` (for backward compatibility reasons) and to false otherwise.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "timeoutSeconds",
|
||||
"in": "query",
|
||||
"description": "Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity.",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "watch",
|
||||
"in": "query",
|
||||
"description": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -1602,6 +1882,330 @@
|
|||
"kind": "User"
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"tags": [
|
||||
"User"
|
||||
],
|
||||
"description": "replace the specified User",
|
||||
"operationId": "replaceUser",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "dryRun",
|
||||
"in": "query",
|
||||
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fieldManager",
|
||||
"in": "query",
|
||||
"description": "fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fieldValidation",
|
||||
"in": "query",
|
||||
"description": "fieldValidation instructs the server on how to handle objects in the request (POST/PUT/PATCH) containing unknown or duplicate fields. Valid values are: - Ignore: This will ignore any unknown fields that are silently dropped from the object, and will ignore all but the last duplicate field that the decoder encounters. This is the default behavior prior to v1.23. - Warn: This will send a warning via the standard warning response header for each unknown field that is dropped from the object, and for each duplicate field that is encountered. The request will still succeed if there are no other errors, and will only persist the last of any duplicate fields. This is the default in v1.23+ - Strict: This will fail the request with a BadRequest error if any unknown fields would be dropped from the object, or if any duplicate fields are present. The error returned from the server will contain all unknown and duplicate fields encountered.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"201": {
|
||||
"description": "Created",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-kubernetes-action": "put",
|
||||
"x-kubernetes-group-version-kind": {
|
||||
"group": "iam.grafana.app",
|
||||
"version": "v0alpha1",
|
||||
"kind": "User"
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"User"
|
||||
],
|
||||
"description": "delete an User",
|
||||
"operationId": "deleteUser",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "dryRun",
|
||||
"in": "query",
|
||||
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "gracePeriodSeconds",
|
||||
"in": "query",
|
||||
"description": "The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.",
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ignoreStoreReadErrorWithClusterBreakingPotential",
|
||||
"in": "query",
|
||||
"description": "if set to true, it will trigger an unsafe deletion of the resource in case the normal deletion flow fails with a corrupt object error. A resource is considered corrupt if it can not be retrieved from the underlying storage successfully because of a) its data can not be transformed e.g. decryption failure, or b) it fails to decode into an object. NOTE: unsafe deletion ignores finalizer constraints, skips precondition checks, and removes the object from the storage. WARNING: This may potentially break the cluster if the workload associated with the resource being unsafe-deleted relies on normal deletion flow. Use only if you REALLY know what you are doing. The default value is false, and the user must opt in to enable it",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "orphanDependents",
|
||||
"in": "query",
|
||||
"description": "Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "propagationPolicy",
|
||||
"in": "query",
|
||||
"description": "Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"202": {
|
||||
"description": "Accepted",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Status"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-kubernetes-action": "delete",
|
||||
"x-kubernetes-group-version-kind": {
|
||||
"group": "iam.grafana.app",
|
||||
"version": "v0alpha1",
|
||||
"kind": "User"
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"tags": [
|
||||
"User"
|
||||
],
|
||||
"description": "partially update the specified User",
|
||||
"operationId": "updateUser",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "dryRun",
|
||||
"in": "query",
|
||||
"description": "When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fieldManager",
|
||||
"in": "query",
|
||||
"description": "fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. This field is required for apply requests (application/apply-patch) but optional for non-apply patch types (JsonPatch, MergePatch, StrategicMergePatch).",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fieldValidation",
|
||||
"in": "query",
|
||||
"description": "fieldValidation instructs the server on how to handle objects in the request (POST/PUT/PATCH) containing unknown or duplicate fields. Valid values are: - Ignore: This will ignore any unknown fields that are silently dropped from the object, and will ignore all but the last duplicate field that the decoder encounters. This is the default behavior prior to v1.23. - Warn: This will send a warning via the standard warning response header for each unknown field that is dropped from the object, and for each duplicate field that is encountered. The request will still succeed if there are no other errors, and will only persist the last of any duplicate fields. This is the default in v1.23+ - Strict: This will fail the request with a BadRequest error if any unknown fields would be dropped from the object, or if any duplicate fields are present. The error returned from the server will contain all unknown and duplicate fields encountered.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "force",
|
||||
"in": "query",
|
||||
"description": "Force is going to \"force\" Apply requests. It means user will re-acquire conflicting fields owned by other people. Force flag must be unset for non-apply patch requests.",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/apply-patch+yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Patch"
|
||||
}
|
||||
},
|
||||
"application/json-patch+json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Patch"
|
||||
}
|
||||
},
|
||||
"application/merge-patch+json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Patch"
|
||||
}
|
||||
},
|
||||
"application/strategic-merge-patch+json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.Patch"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"201": {
|
||||
"description": "Created",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/vnd.kubernetes.protobuf": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
},
|
||||
"application/yaml": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.iam.pkg.apis.iam.v0alpha1.User"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-kubernetes-action": "patch",
|
||||
"x-kubernetes-group-version-kind": {
|
||||
"group": "iam.grafana.app",
|
||||
"version": "v0alpha1",
|
||||
"kind": "User"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "name",
|
||||
|
|
|
|||
Loading…
Reference in New Issue