session

package
v0.3.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetSubject

func SetSubject(ctx context.Context, subject Subject)

SetSubject sets the Subject into the given context.Context.

Types

type Project

type Project struct {
	// ID indicates the id of the project.
	ID object.ID `json:"id"`
	// Name indicates the name of the project.
	Name string `json:"name"`
}

type ProjectRole

type ProjectRole struct {
	// Project indicates the project of the role.
	Project Project `json:"project"`
	// Roles indicates the roles.
	Roles []Role `json:"roles"`
}

type Role

type Role struct {
	// ID indicates the id of the role.
	ID string `json:"id"`
	// Policies indicates the policies of the role.
	Policies types.RolePolicies `json:"policies"`
}

type Subject

type Subject struct {
	// Ctx holds the request gin.Context.
	Ctx *gin.Context `json:"-"`
	// ID indicates the id of the subject.
	ID object.ID `json:"id"`
	// Domain indicates the domain of the subject.
	Domain string `json:"domain"`
	// Groups indicates all superior groups which the subject belong to.
	Groups []string `json:"groups"`
	// Name indicates the name of the subject.
	Name string `json:"name"`
	// Roles indicates the roles of the subject.
	Roles []Role `json:"roles"`
	// ProjectRoles indicates the project roles of the subject.
	ProjectRoles []ProjectRole `json:"projectRoles"`
}

func GetSubject

func GetSubject(ctx context.Context) (Subject, error)

GetSubject gets the Subject from the given context.Context.

func MustGetSubject

func MustGetSubject(ctx context.Context) Subject

MustGetSubject is similar to GetSubject, but panic if error raising.

func (Subject) Enforce

func (s Subject) Enforce(projectRefer, action, resource, resourceRefer, path string) bool

Enforce returns true if the given conditions if allowing.

func (Subject) IsAdmin

func (s Subject) IsAdmin() bool

IsAdmin returns true if this subject has a system/admin role.

func (Subject) IsAnonymous

func (s Subject) IsAnonymous() bool

IsAnonymous returns true if this subject has not been authenticated.

Jump to

Keyboard shortcuts

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