session

package
v0.4.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: Apache-2.0 Imports: 8 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 ActionResource added in v0.4.0

type ActionResource struct {
	// Name indicates the name of resource.
	Name string
	// Refer indicates the refer of resource, either ID or name.
	Refer string
}

type Project

type Project struct {
	Resource `json:",inline"`

	// ReadOnlyEnvironments indicates the read-only environment list of the project.
	ReadOnlyEnvironments []Resource `json:"readOnlyEnvironments"`
	// ReadOnlyConnectors indicates the read-only connector list of the project.
	ReadOnlyConnectors []Resource `json:"readOnlyConnectors"`
}

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 Resource added in v0.4.0

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

func (Resource) Match added in v0.4.0

func (r Resource) Match(refer string) bool

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"`
	// ApplicableEnvironmentTypes indicates which environment type are the subject to apply.
	ApplicableEnvironmentTypes []string `json:"applicableEnvironmentTypes"`
}

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(action string, resources []ActionResource, 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.

func (Subject) IsApplicableEnvironmentType added in v0.4.0

func (s Subject) IsApplicableEnvironmentType(et string) bool

IsApplicableEnvironmentType returns true if the given environment type is applicable.

Jump to

Keyboard shortcuts

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