gateway

package
v0.0.0-...-4786a4a Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IsSkip                = "isSkip"
	AuthorizationUserName = "userName"
	UserIdentification    = "userIdentification"
	UnauthorizedMessage   = "user unauthorized"
	ForbiddenMessage      = "not allow to access"
)

Variables

This section is empty.

Functions

func GrantCheckFilter

func GrantCheckFilter(auth IAuthorization) plugin.Handler

func IdentificationFilter

func IdentificationFilter(auth IAuthorization) plugin.Handler

func In

func In(list []string, item string) bool

func NamespaceFilter

func NamespaceFilter(auth IAuthorization) plugin.Handler

func NewGateway

func NewGateway(datasource k8s.Interface) self.Interface

func NewMicroGateway

func NewMicroGateway(handler http.Handler, authorization IAuthorization) error

func PermissionFilter

func PermissionFilter(auth IAuthorization) plugin.Handler

func ServerFilter

func ServerFilter(self http.Handler) plugin.Handler

func SkipFilter

func SkipFilter(auth IAuthorization) plugin.Handler

func ValidateTokenFilter

func ValidateTokenFilter(auth IAuthorization) plugin.Handler

Types

type Authorization

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

func NewAuthorization

func NewAuthorization(svcInterface service.Interface) *Authorization

func (*Authorization) AllowNamespaces

func (auth *Authorization) AllowNamespaces(username string, isAdmin, isTenantOwner, isDepartmentOwner bool) ([]string, error)

func (*Authorization) CheckNamespace

func (auth *Authorization) CheckNamespace(userName, namespace string, isAdmin, isTenantOwner, isDepartmentOwner bool) (bool, error)

check whether a user allow access specified namespace

func (*Authorization) CheckPermission

func (auth *Authorization) CheckPermission(userName string, uri *uri.URI) (bool, error)

check whether a user has specified uri permission

func (*Authorization) IsAdmin

func (auth *Authorization) IsAdmin(userName string) (bool, error)

check whether a user is an admin

func (*Authorization) IsDepartmentOwner

func (auth *Authorization) IsDepartmentOwner(userName string) (bool, error)

check whether a user is a department owner

func (*Authorization) IsNeedSkip

func (auth *Authorization) IsNeedSkip(method, path string) (bool, error)

func (*Authorization) IsTenantOwner

func (auth *Authorization) IsTenantOwner(userName string) (bool, error)

check whether a user is a tenant owner

func (*Authorization) IsWithGranted

func (auth *Authorization) IsWithGranted(userName string) (bool, error)

check whether a user is with granted

func (*Authorization) ValidateToken

func (auth *Authorization) ValidateToken(token string) (*CustomClaims, error)

type CustomClaims

type CustomClaims struct {
	UserName string `json:"user_name"`
	jwt.StandardClaims
}

CustomClaims

type Gateway

type Gateway struct {
	k8s.Interface
}

func (*Gateway) DataSource

func (s *Gateway) DataSource() k8s.Interface

func (*Gateway) Handle

func (s *Gateway) Handle(pattern string, handler http.Handler) self.Interface

func (*Gateway) HandleFunc

func (s *Gateway) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) self.Interface

func (*Gateway) Name

func (s *Gateway) Name() string

func (*Gateway) Run

func (s *Gateway) Run() error

type IAuthorization

type IAuthorization interface {
	IsNeedSkip(method, path string) (bool, error)
	ValidateToken(token string) (*CustomClaims, error)
	IsAdmin(userName string) (bool, error)
	IsTenantOwner(userName string) (bool, error)
	IsDepartmentOwner(userName string) (bool, error)
	IsWithGranted(userName string) (bool, error)
	CheckPermission(userName string, op *uri.URI) (bool, error)
	CheckNamespace(userName, namespace string, isAdmin, isTenantOwner, isDepartmentOwner bool) (bool, error)
}

type Identification

type Identification string
const (
	Admin           Identification = "admin"
	TenantOwner     Identification = "tenantOwner"
	DepartmentOwner Identification = "tenantOwner"
	OrdinaryUser    Identification = "ordinaryUser"
)

type Token

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

Token jwt service

func (*Token) Decode

func (t *Token) Decode(tokenStr string) (*CustomClaims, error)

Decode

func (*Token) Encode

func (t *Token) Encode(issuer, userName string, expireTime int64) (string, error)

Encode

Jump to

Keyboard shortcuts

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