enforcement

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: MIT Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultTenant  = "default"
	DefaultTimeout = 30
	AllowKey       = "allow"
)

Variables

This section is empty.

Functions

func MapToJson

func MapToJson(m map[string]interface{}) string

Types

type Action

type Action string

type AllTenantsCheckResponse added in v0.0.14

type AllTenantsCheckResponse struct {
	CheckResponse
	Tenant TenantDetails `json:"tenant"`
}

type AssignedRole

type AssignedRole struct {
	Role   string
	Tenant string
}

type CheckRequest

type CheckRequest struct {
	User     User              `json:"user"`
	Action   Action            `json:"action"`
	Resource Resource          `json:"resource"`
	Context  map[string]string `json:"context"`
}

func NewBulkCheckRequest added in v0.0.14

func NewBulkCheckRequest(requests ...CheckRequest) []CheckRequest

func NewBulkCheckRequestParameterized added in v0.0.14

func NewBulkCheckRequestParameterized(user []User, action []Action, resource []Resource, context []map[string]string) ([]CheckRequest, error)

func NewCheckRequest

func NewCheckRequest(user User, action Action, resource Resource, context map[string]string) *CheckRequest

type CheckResponse

type CheckResponse struct {
	Allow  bool                   `json:"allow"`
	Query  map[string]interface{} `json:"query"`
	Debug  map[string]interface{} `json:"debug"`
	Result bool                   `json:"result"`
}

type GetUserPermissionsRequest added in v0.0.19

type GetUserPermissionsRequest struct {
	User          User                   `json:"user"`
	Tenants       []string               `json:"tenants,omitempty"`
	Resources     []string               `json:"resources,omitempty"`
	ResourceTypes []string               `json:"resource_types,omitempty"`
	Context       map[string]interface{} `json:"context,omitempty"`
}

func NewGetUserPermissionsRequest added in v0.0.19

func NewGetUserPermissionsRequest(user User, tenants []string) *GetUserPermissionsRequest

type PermitBaseEnforcer

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

type PermitEnforcer

type PermitEnforcer struct {
	PermitBaseEnforcer
}

func NewPermitEnforcerClient

func NewPermitEnforcerClient(config *config.PermitConfig) *PermitEnforcer

func (*PermitEnforcer) AllTenantsCheck added in v0.0.14

func (e *PermitEnforcer) AllTenantsCheck(user User, action Action, resource Resource, additionalContext ...map[string]string) ([]TenantDetails, error)

func (*PermitEnforcer) BulkCheck added in v0.0.14

func (e *PermitEnforcer) BulkCheck(requests ...CheckRequest) ([]bool, error)

func (*PermitEnforcer) Check

func (e *PermitEnforcer) Check(user User, action Action, resource Resource, additionalContext ...map[string]string) (bool, error)

func (*PermitEnforcer) FilterObjects added in v0.0.15

func (e *PermitEnforcer) FilterObjects(user User, action Action, context map[string]string, resources ...ResourceI) ([]ResourceI, error)

func (*PermitEnforcer) GetUserPermissions added in v0.0.19

func (e *PermitEnforcer) GetUserPermissions(user User, tenants ...string) (UserPermissions, error)

func (*PermitEnforcer) GetUserPermissionsWithOptions added in v1.2.5

func (e *PermitEnforcer) GetUserPermissionsWithOptions(user User, opts ...UserPermissionsOption) (UserPermissions, error)

type Resource

type Resource struct {
	Type       string                 `json:"type,omitempty"`
	ID         string                 `json:"id,omitempty"`
	Key        string                 `json:"key,omitempty"`
	Tenant     string                 `json:"tenant,omitempty"`
	Attributes map[string]interface{} `json:"attributes,omitempty"`
	Context    map[string]string      `json:"context,omitempty"`
}

func ResourceBuilder

func ResourceBuilder(resourceType string) *Resource

func (*Resource) Build

func (r *Resource) Build() Resource

func (*Resource) GetAttributes added in v0.0.15

func (r *Resource) GetAttributes() map[string]interface{}

func (*Resource) GetContext added in v0.0.15

func (r *Resource) GetContext() map[string]string

func (*Resource) GetID added in v0.0.15

func (r *Resource) GetID() string

func (*Resource) GetTenant added in v0.0.15

func (r *Resource) GetTenant() string

func (*Resource) GetType added in v0.0.15

func (r *Resource) GetType() string

func (*Resource) WithAttributes

func (r *Resource) WithAttributes(attributes map[string]interface{}) *Resource

func (*Resource) WithContext

func (r *Resource) WithContext(context map[string]string) *Resource

func (*Resource) WithID

func (r *Resource) WithID(ID string) *Resource

func (*Resource) WithKey added in v1.0.6

func (r *Resource) WithKey(key string) *Resource

func (*Resource) WithTenant

func (r *Resource) WithTenant(tenant string) *Resource

type ResourceDetails added in v1.2.2

type ResourceDetails struct {
	Type       string                 `json:"type,omitempty"`
	Key        string                 `json:"key,omitempty"`
	Attributes map[string]interface{} `json:"attributes,omitempty"`
}

type ResourceI added in v0.0.15

type ResourceI interface {
	GetID() string
	GetType() string
	GetTenant() string
	GetAttributes() map[string]interface{}
	GetContext() map[string]string
}

type TenantDetails added in v0.0.14

type TenantDetails struct {
	Key        string                 `json:"key"`
	Attributes map[string]interface{} `json:"attributes"`
}

type TenantUserPermissions added in v0.0.19

type TenantUserPermissions struct {
	Tenant      TenantDetails    `json:"tenant"`
	Resource    *ResourceDetails `json:"resource,omitempty"`
	Permissions []string         `json:"permissions"`
	Roles       []string         `json:"roles"`
}

type User

type User struct {
	Key        string                 `json:"key,omitempty"`
	FirstName  string                 `json:"first_name,omitempty"`
	LastName   string                 `json:"last_name,omitempty"`
	Email      string                 `json:"email,omitempty"`
	Roles      []AssignedRole         `json:"roles,omitempty"`
	Attributes map[string]interface{} `json:"attributes,omitempty"`
}

func UserBuilder

func UserBuilder(key string) *User

func (*User) Build

func (u *User) Build() User

func (*User) WithAttributes

func (u *User) WithAttributes(attributes map[string]interface{}) *User

func (*User) WithEmail

func (u *User) WithEmail(email string) *User

func (*User) WithFirstName

func (u *User) WithFirstName(firstName string) *User

func (*User) WithLastName

func (u *User) WithLastName(lastName string) *User

func (*User) WithRoles

func (u *User) WithRoles(roles []AssignedRole) *User

type UserPermissions added in v0.0.19

type UserPermissions map[string]TenantUserPermissions

type UserPermissionsOption added in v1.2.5

type UserPermissionsOption func(*GetUserPermissionsRequest)

func WithContext added in v1.2.5

func WithContext(context map[string]interface{}) UserPermissionsOption

func WithResourceTypes added in v1.2.5

func WithResourceTypes(resourceTypes []string) UserPermissionsOption

func WithResources added in v1.2.5

func WithResources(resources []string) UserPermissionsOption

func WithTenants added in v1.2.5

func WithTenants(tenants []string) UserPermissionsOption

Jump to

Keyboard shortcuts

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