utils

package
v1.8.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const KubeVelaAdminGroupPrefix = "kubevela:admin:"

KubeVelaAdminGroupPrefix the prefix kubevela admin

View Source
const KubeVelaProjectGroupPrefix = "kubevela:project:"

KubeVelaProjectGroupPrefix the prefix kubevela project

View Source
const KubeVelaProjectReadGroupPrefix = "kubevela:project-ro:"

KubeVelaProjectReadGroupPrefix the prefix kubevela project group that only has the read permissions

View Source
const TemplateReaderGroup = "template-reader"

TemplateReaderGroup This group includes the permission that read the ConfigMap in the vela-system namespace.

View Source
const UXDefaultGroup = "kubevela:ux"

UXDefaultGroup This group means directly using the original identity registered by the cluster.

Variables

This section is empty.

Functions

func CleanRelativePath

func CleanRelativePath(path string) (string, error)

CleanRelativePath returns the shortest path name equivalent to path by purely lexical processing. It make sure the provided path is rooted and then uses filepath.Clean and filepath.Rel to make sure the path doesn't include any separators or elements that shouldn't be there like ., .., //.

func ClientIP

func ClientIP(r *http.Request) string

ClientIP get client ip

func ContextWithUserInfo

func ContextWithUserInfo(ctx context.Context) context.Context

ContextWithUserInfo extract user from context (parse username and project) for impersonation

func ExtractPagingParams

func ExtractPagingParams(req *restful.Request, minPageSize, maxPageSize int) (int, int, error)

ExtractPagingParams extract `page` and `pageSize` params from request

func GenerateVersion

func GenerateVersion(pre string) string

GenerateVersion Generate version numbers by time

func GetDexConnectors

func GetDexConnectors(ctx context.Context, k8sClient client.Client) ([]map[string]interface{}, error)

GetDexConnectors returns the dex connectors for Dex connector controller

func NewAuthClient

func NewAuthClient(cli client.Client) client.Client

NewAuthClient will carry UserInfo for mutating requests automatically

func ProjectFrom

func ProjectFrom(ctx context.Context) (string, bool)

ProjectFrom extract project from context

func SetUsernameAndProjectInRequestContext

func SetUsernameAndProjectInRequestContext(req *restful.Request, userName string, projectName string)

SetUsernameAndProjectInRequestContext .

func UsernameFrom

func UsernameFrom(ctx context.Context) (string, bool)

UsernameFrom extract username from context

func WithProject

func WithProject(parent context.Context, project string) context.Context

WithProject carries project in context

func WithUsername

func WithUsername(parent context.Context, username string) context.Context

WithUsername carries username in context

Types

type MemoryCacheStore

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

MemoryCacheStore a sample memory cache instance, if data set cache duration, will auto clear after timeout. But, Expired cleanup is not necessarily accurate, it has a 3-second window.

func NewMemoryCacheStore

func NewMemoryCacheStore(ctx context.Context) *MemoryCacheStore

NewMemoryCacheStore memory cache store

func (*MemoryCacheStore) Delete

func (m *MemoryCacheStore) Delete(key interface{})

Delete cache data from store

func (*MemoryCacheStore) Get

func (m *MemoryCacheStore) Get(key interface{}) (value interface{})

Get cache data from store, if not exist or timeout, will return nil

func (*MemoryCacheStore) Put

func (m *MemoryCacheStore) Put(key, value interface{}, cacheDuration time.Duration)

Put cache data, if cacheDuration>0, store will clear data after timeout.

type ResponseCapture

type ResponseCapture struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseCapture capture response and get response info

func NewResponseCapture

func NewResponseCapture(w http.ResponseWriter) *ResponseCapture

NewResponseCapture new response capture

func (ResponseCapture) Bytes

func (c ResponseCapture) Bytes() []byte

Bytes return response body bytes

func (ResponseCapture) Header

func (c ResponseCapture) Header() http.Header

Header return response writer header

func (ResponseCapture) StatusCode

func (c ResponseCapture) StatusCode() int

StatusCode return status code

func (ResponseCapture) Write

func (c ResponseCapture) Write(data []byte) (int, error)

Write write data to response writer and body

func (*ResponseCapture) WriteHeader

func (c *ResponseCapture) WriteHeader(statusCode int)

WriteHeader write header to response writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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