-
Notifications
You must be signed in to change notification settings - Fork 85
/
extra.go
107 lines (96 loc) · 3.52 KB
/
extra.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package client
import (
"time"
v1 "k8s.io/api/core/v1"
"kubegems.io/kubegems/pkg/apis/gems/v1beta1"
)
type KubeClientIfe interface {
GetEnvironment(cluster, name string, _ map[string]string) (*v1beta1.Environment, error)
PatchEnvironment(cluster, name string, data *v1beta1.Environment) (*v1beta1.Environment, error)
DeleteEnvironment(clustername, environment string) error
CreateOrUpdateEnvironment(clustername, environment string, spec v1beta1.EnvironmentSpec) error
CreateOrUpdateTenant(clustername, tenantname string, admins, members []string) error
CreateOrUpdateTenantResourceQuota(clustername, tenantname string, content []byte) error
CreateOrUpdateSecret(clustername, namespace, name string, data map[string][]byte) error
DeleteSecretIfExist(clustername, namespace, name string) error
DeleteTenant(clustername, tenantname string) error
ClusterResourceStatistics(cluster string, ret interface{}) error
GetServiceAccount(cluster, namespace, name string, labels map[string]string) (*v1.ServiceAccount, error)
PatchServiceAccount(cluster, namespace, name string, data *v1.ServiceAccount) (*v1.ServiceAccount, error)
}
type CommonResourceIfe interface {
GetKind() string
GetID() uint
GetTenantID() uint
GetProjectID() uint
GetEnvironmentID() uint
GetVirtualSpaceID() uint
GetName() string
GetCluster() string
GetNamespace() string
GetOwners() []CommonResourceIfe
}
type CommonUserIfe interface {
GetID() uint
GetSystemRoleID() uint
GetUsername() string
GetUserKind() string
GetEmail() string
GetSource() string
SetLastLogin(*time.Time)
UnmarshalBinary(data []byte) error
MarshalBinary() (data []byte, err error)
}
type UserAuthorityIfe interface {
// 资源角色
GetResourceRole(kind string, id uint) string
// 是否是系统管理员
IsSystemAdmin() bool
// 是否是租户管理员
IsTenantAdmin(tenantid uint) bool
// 是否是租户成员
IsTenantMember(tenantid uint) bool
// 是否是项目管理员
IsProjectAdmin(projectid uint) bool
// 是否是项目开发
IsProjectDev(projectid uint) bool
// 是否是项目测试
IsProjectTest(projectid uint) bool
// 是否是项目运维
IsProjectOps(projectid uint) bool
// 是否是环境op
IsEnvironmentOperator(envid uint) bool
// 是否是环境reader
IsEnvironmentReader(envid uint) bool
// 是否是虚拟空间管理员
IsVirtualSpaceAdmin(vsid uint) bool
// 是否是虚拟空间成员
IsVirtualSpaceMember(vsid uint) bool
// 是否是一个租户的管理员
IsAnyTenantAdmin() bool
}
type ModelCacheIfe interface {
// 构建缓存
BuildCache() error
// 资源相关
UpsertTenant(tid uint, name string)
DelTenant(tid uint)
UpsertProject(tid, pid uint, name string) error
DelProject(tid, pid uint) error
UpsertEnvironment(pid, eid uint, name, cluster, namespace string) error
DelEnvironment(pid, eid uint) error
UpsertVirtualSpace(vid uint, name string)
DelVirtualSpace(vid uint)
FindParents(kind string, id uint) []CommonResourceIfe
FindResource(kind string, id uint) CommonResourceIfe
FindEnvironment(cluster, namespace string) CommonResourceIfe
// 普通用户相关
GetUserAuthority(user CommonUserIfe) UserAuthorityIfe
FlushUserAuthority(user CommonUserIfe) UserAuthorityIfe
CacheUserInfo(userinfo CommonUserIfe) error
GetUserInfo(username string, user CommonUserIfe) error
// openapi 相关用户
CacheUserInfoViaToken(token string, user CommonUserIfe, ex time.Duration) error
GetUserInfoViaToken(token string, username string, user CommonUserIfe) error
UserRequestLimitAllow(user CommonUserIfe, d time.Duration, rate int) (bool, error)
}