client

package
v1.21.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RelationKey

func RelationKey(obj1, obj2 ObjectTypeIface) string

Types

type BelongToOption

type BelongToOption struct {
	// contains filtered or unexported fields
}

func BelongTo

func BelongTo(obj Object) *BelongToOption

func (*BelongToOption) Apply

func (o *BelongToOption) Apply(q *Query)

type Common

type Common struct {
	Name              string    `gorm:"primaryKey;type:varchar(60);not null"`
	Namespace         string    `gorm:"primaryKey;type:varchar(60);not null"`
	UID               string    `gorm:"uniqueIndex;type:varchar(36)"`
	CreationTimestamp time.Time `gorm:"not null"`
	DeletionTimestamp time.Time
	Labels            datatypes.JSON
	Annotations       datatypes.JSON
	OwnerReferences   datatypes.JSON
	Spec              datatypes.JSON
	Status            datatypes.JSON
}

func (*Common) DecodeInto

func (c *Common) DecodeInto(obj client.Object) error

func (*Common) From

func (c *Common) From(obj client.Object) error

type CommonResourceIfe

type CommonResourceIfe interface {
	GetKind() string
	GetID() uint
	GetTenantID() uint
	GetProjectID() uint
	GetEnvironmentID() uint
	GetVirtualSpaceID() uint
	GetName() string
	GetCluster() string
	GetNamespace() string
	GetOwners() []CommonResourceIfe
}

type CommonUser

type CommonUser struct {
	ID           uint
	Username     string
	Email        string
	Phone        string
	Password     string
	IsActive     *bool
	Kind         string
	Source       string
	CreatedAt    *time.Time
	LastLoginAt  *time.Time
	SystemRole   *SystemRole
	SystemRoleID uint
}

func (*CommonUser) GetEmail

func (u *CommonUser) GetEmail() string

func (*CommonUser) GetID

func (u *CommonUser) GetID() uint

func (*CommonUser) GetKind

func (u *CommonUser) GetKind() string

func (*CommonUser) GetSource

func (u *CommonUser) GetSource() string

func (*CommonUser) GetSystemRoleID

func (u *CommonUser) GetSystemRoleID() uint

func (*CommonUser) GetUsername

func (u *CommonUser) GetUsername() string

type CommonUserIfe

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 Cond

type Cond struct {
	Field string
	Op    ConditionOperator
	Value interface{}
}

func (*Cond) AsQuery

func (cond *Cond) AsQuery() (string, interface{})

type ConditionOperator

type ConditionOperator string
var Eq, Gt, Lt, Neq, Gte, Lte, In, Like ConditionOperator = "=", ">", "<", "<>", ">=", "<=", "in", "like"

type DefaultClient

type DefaultClient struct {
	// contains filtered or unexported fields
}

func NewTypedClient

func NewTypedClient(db *gorm.DB) *DefaultClient

func (*DefaultClient) Create

func (c *DefaultClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

Create saves the object obj in the Kubernetes cluster.

func (*DefaultClient) Delete

func (c *DefaultClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

Delete deletes the given obj from Kubernetes cluster.

func (*DefaultClient) DeleteAllOf

func (c *DefaultClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

DeleteAllOf deletes all objects of the given type matching the given options.

func (*DefaultClient) Get

Get retrieves an obj for the given object key from the Kubernetes Cluster. obj must be a struct pointer so that obj can be updated with the response returned by the Server.

func (*DefaultClient) List

func (c *DefaultClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

List retrieves list of objects for a given namespace and list options. On a successful call, Items field in the list will be populated with the result returned from the server.

func (*DefaultClient) Migrate

func (c *DefaultClient) Migrate(ctx context.Context, obj client.Object) error

Metadata create/update the table in database

func (*DefaultClient) Patch

func (c *DefaultClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

Patch patches the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

func (*DefaultClient) RESTMapper

func (c *DefaultClient) RESTMapper() meta.RESTMapper

RESTMapper returns the rest this client is using.

func (*DefaultClient) Scheme

func (c *DefaultClient) Scheme() *runtime.Scheme

Scheme returns the scheme this client is using.

func (*DefaultClient) Status

func (c *DefaultClient) Status() client.StatusWriter

func (*DefaultClient) Update

func (c *DefaultClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

Update updates the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

type HookPhase

type HookPhase string
var (
	BeforeUpdate HookPhase = "BeforeUpdate"
	BeforeCreate HookPhase = "BeforeCreate"
	BeforeDelete HookPhase = "BeforeDelete"

	AfterUpdate HookPhase = "AfterUpdate"
	AfterCreate HookPhase = "AfterCreate"
	AfterDelete HookPhase = "AfterDelete"
)

type KubeClientIfe

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 ModelCacheIfe

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)
}

type ModelClientIface

type ModelClientIface interface {
	Create(ctx context.Context, obj Object, opts ...Option) error
	Get(ctx context.Context, obj Object, opts ...Option) error
	Update(ctx context.Context, obj Object, opts ...Option) error
	Delete(ctx context.Context, obj Object, opts ...Option) error
	CreateInBatches(ctx context.Context, objs ObjectListIface, opts ...Option) error
	List(ctx context.Context, olist ObjectListIface, opts ...Option) error
	Count(ctx context.Context, o ObjectTypeIface, t *int64, opts ...Option) error
}

type Object

type Object interface {
	ObjectTypeIface
	PrimaryKeyValue() interface{}
	PreloadFields() *[]string
}

type ObjectListIface

type ObjectListIface interface {
	ObjectTypeIface
	GetPageSize() (*int64, *int64)
	GetTotal() *int64
	SetPageSize(int64, int64)
	SetTotal(int64)
	DataPtr() interface{}
}

type ObjectTypeIface

type ObjectTypeIface interface {
	GetKind() *string
	PrimaryKeyField() *string
}

type Option

type Option interface {
	Apply(*Query)
}

type OrderOption

type OrderOption struct {
	// contains filtered or unexported fields
}

func OrderAsc

func OrderAsc(field string) *OrderOption

对字段正序排序

func OrderDesc

func OrderDesc(field string) *OrderOption

对字段倒序排序

func (*OrderOption) Apply

func (o *OrderOption) Apply(q *Query)

type PageSizeOption

type PageSizeOption struct {
	// contains filtered or unexported fields
}

func PageSize

func PageSize(page, size int64) *PageSizeOption

func (*PageSizeOption) Apply

func (p *PageSizeOption) Apply(q *Query)

type PreloadOption

type PreloadOption struct {
	// contains filtered or unexported fields
}

func Preloads

func Preloads(preloads []string) *PreloadOption

预加载关联资源

func (*PreloadOption) Apply

func (p *PreloadOption) Apply(q *Query)

type Query

type Query struct {
	Page            int64
	Size            int64
	Search          string
	SearchFields    []string
	Orders          []string
	Preloads        []string
	Where           []*Cond
	Belong          []Object
	RelationOptions []RelationCondition
}

type Relation

type Relation struct {
	Key  string
	Kind RelationKind
	Via  ObjectTypeIface
}

func GetRelation

func GetRelation(source, target, via ObjectTypeIface, relkind RelationKind) Relation

type RelationCondition

type RelationCondition struct {
	Key    string
	Value  interface{}
	Target Object
}

type RelationKind

type RelationKind string
var (
	RelationM2M RelationKind = "m2m"
	RelationOwn RelationKind = "own"
)

type RelationOption

type RelationOption struct {
	// contains filtered or unexported fields
}

func ExistRelation

func ExistRelation(obj Object) *RelationOption

func ExistRelationWithKeyValue

func ExistRelationWithKeyValue(obj Object, key string, value interface{}) *RelationOption

func (*RelationOption) Apply

func (o *RelationOption) Apply(q *Query)

type SearchOption

type SearchOption struct {
	// contains filtered or unexported fields
}
func Search(value string) *SearchOption

搜索内容

func (*SearchOption) Apply

func (o *SearchOption) Apply(q *Query)

type SystemRole

type SystemRole struct {
	ID       uint
	RoleName string
	RoleCode string
}

type UserAuthorityIfe

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 WhereOption

type WhereOption struct {
	// contains filtered or unexported fields
}

func Where

func Where(field string, op ConditionOperator, value interface{}) *WhereOption

func WhereEqual

func WhereEqual(field string, value interface{}) *WhereOption

func WhereNameEqual

func WhereNameEqual(value interface{}) *WhereOption

func (*WhereOption) Apply

func (w *WhereOption) Apply(q *Query)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL