Documentation ¶
Overview ¶
Package utils provides swiss-knife tools for all services
Index ¶
- Constants
- Variables
- func AccessListLoadFrontValues(ctx context.Context, accessList *AccessList) error
- func BuildAncestorsList(ctx context.Context, treeClient tree.NodeProviderClient, node *tree.Node) (parentUuids []*tree.Node, err error)
- func BuildAncestorsListOrParent(ctx context.Context, treeClient tree.NodeProviderClient, node *tree.Node) (parentUuids []*tree.Node, err error)
- func CheckContentLock(ctx context.Context, node *tree.Node) error
- func DefaultBigCacheConfig() bigcache.Config
- func FindUserNameInContext(ctx context.Context) (string, claim.Claims)
- func GenMarkdown(cmd *cobra.Command, w io.Writer) error
- func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error
- func GenMarkdownTree(cmd *cobra.Command, dir string) error
- func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error
- func GenPydioYaml(cmd *cobra.Command, position int, w io.Writer) error
- func GetACLsForRoles(ctx context.Context, roles []*idm.Role, actions ...*idm.ACLAction) []*idm.ACL
- func GetACLsForWorkspace(ctx context.Context, workspaceIds []string, actions ...*idm.ACLAction) (acls []*idm.ACL, err error)
- func GetAvailableIPs() (ips []net.IP, e error)
- func GetAvailablePort() int
- func GetExternalIP() (net.IP, error)
- func GetOutboundIP() (net.IP, error)
- func GetRoles(ctx context.Context, names []string) []*idm.Role
- func GetRolesForUser(ctx context.Context, user *idm.User, createMissing bool) []*idm.Role
- func GetTimeFromNtp() (time.Time, error)
- func GetWorkspacesForACLs(ctx context.Context, list *AccessList) []*idm.Workspace
- func IgnoreNodeForOutput(ctx context.Context, node *tree.Node) bool
- func IsUserLocked(user *idm.User) bool
- func PolicyContextFromMetadata(policyContext map[string]string, ctx context.Context)
- func PolicyContextFromNode(policyContext map[string]string, node *tree.Node)
- func PolicyRequestSubjectsFromClaims(claims claim.Claims) []string
- func PolicyRequestSubjectsFromUser(user *idm.User) []string
- func Randkey(n int) string
- func RunJavaScript(ctx context.Context, script string, inputs map[string]interface{}, ...) error
- func SearchUniqueUser(ctx context.Context, login string, uuid string, ...) (user *idm.User, err error)
- func ToPath(f *Fraction) string
- func ToPathUint(f *Fraction) []uint64
- type AccessList
- func AccessListFromContextClaims(ctx context.Context) (accessList *AccessList, err error)
- func AccessListFromRoles(ctx context.Context, roles []*idm.Role, countPolicies bool, ...) (accessList *AccessList, err error)
- func AccessListFromUser(ctx context.Context, userNameOrUuid string, isUuid bool) (accessList *AccessList, user *idm.User, err error)
- func NewAccessList(orderedRoles []*idm.Role, Acls ...[]*idm.ACL) *AccessList
- func (a *AccessList) Append(acls []*idm.ACL)
- func (a *AccessList) BelongsToWorkspaces(ctx context.Context, nodes ...*tree.Node) (workspaces []*idm.Workspace, workspacesRoots map[string]string)
- func (a *AccessList) CanRead(ctx context.Context, nodes ...*tree.Node) bool
- func (a *AccessList) CanWrite(ctx context.Context, nodes ...*tree.Node) bool
- func (a *AccessList) FirstMaskForParents(ctx context.Context, nodes ...*tree.Node) (Bitmask, *tree.Node)
- func (a *AccessList) Flatten(ctx context.Context)
- func (a *AccessList) GetAccessibleWorkspaces(ctx context.Context) map[string]string
- func (a *AccessList) GetNodesBitmasks() map[string]Bitmask
- func (a *AccessList) GetWorkspacesNodes() map[string]map[string]Bitmask
- func (a *AccessList) HasPolicyBasedAcls() bool
- func (a *AccessList) ParentMaskOrDeny(ctx context.Context, nodes ...*tree.Node) (bool, Bitmask)
- func (a *AccessList) Zap() zapcore.Field
- type Bitmask
- type BitmaskFlag
- type Float
- type Fraction
- type JsRequest
- type JsUser
- type MPath
- type MPathProvider
- type Matrix
- type Nat
- type PolicyResolver
- type Rat
- type Right
- type TreeNode
- func (t *TreeNode) Bytes() []byte
- func (t *TreeNode) DV() *big.Int
- func (t *TreeNode) GetMeta(name string, value interface{})
- func (t *TreeNode) NV() *big.Int
- func (t *TreeNode) Name() string
- func (t *TreeNode) SDV() *big.Int
- func (t *TreeNode) SNV() *big.Int
- func (t *TreeNode) SetBytes(b []byte)
- func (t *TreeNode) SetMPath(mpath ...uint64)
- func (t *TreeNode) SetMeta(name string, value interface{})
- func (t *TreeNode) SetName(name string)
- func (t *TreeNode) SetRat(rat *Rat)
Constants ¶
const ( PolicyNodeMetaName = "NodeMetaName" PolicyNodeMetaPath = "NodeMetaPath" PolicyNodeMetaExtension = "NodeMetaExtension" PolicyNodeMetaMimeType = "NodeMetaMimeType" PolicyNodeMetaSize = "NodeMetaSize" PolicyNodeMetaMTime = "NodeMetaMTime" PolicyNodeMeta_ = "NodeMeta:" )
const PRECISION = 100
Variables ¶
var ( NamesToFlags = map[string]BitmaskFlag{ "read": FLAG_READ, "write": FLAG_WRITE, "deny": FLAG_DENY, "list": FLAG_LIST, "delete": FLAG_DELETE, "policy": FLAG_POLICY, "quota": FLAG_QUOTA, } FlagsToNames = map[BitmaskFlag]string{ FLAG_READ: "read", FLAG_WRITE: "write", FLAG_DENY: "deny", FLAG_LIST: "list", FLAG_DELETE: "delete", FLAG_POLICY: "policy", FLAG_QUOTA: "quota", } ACL_READ = &idm.ACLAction{Name: "read", Value: "1"} ACL_WRITE = &idm.ACLAction{Name: "write", Value: "1"} ACL_DENY = &idm.ACLAction{Name: "deny", Value: "1"} ACL_POLICY = &idm.ACLAction{Name: "policy"} ACL_QUOTA = &idm.ACLAction{Name: "quota"} ACL_CONTENT_LOCK = &idm.ACLAction{Name: "content_lock"} // Not used yet ACL_FRONT_ACTION_ = &idm.ACLAction{Name: "action:*"} ACL_FRONT_PARAM_ = &idm.ACLAction{Name: "parameter:*"} ACL_DELETE = &idm.ACLAction{Name: "delete", Value: "1"} ACL_LIST = &idm.ACLAction{Name: "list", Value: "1"} ACL_WSROOT_ACTION_NAME = "workspace-path" ACL_RECYCLE_ROOT = &idm.ACLAction{Name: "recycle_root", Value: "1"} ResolvePolicyRequest PolicyResolver )
Functions ¶
func AccessListLoadFrontValues ¶ added in v1.2.0
func AccessListLoadFrontValues(ctx context.Context, accessList *AccessList) error
func BuildAncestorsList ¶
func BuildAncestorsList(ctx context.Context, treeClient tree.NodeProviderClient, node *tree.Node) (parentUuids []*tree.Node, err error)
BuildAncestorsList uses ListNodes with Ancestors flag set to build the list of parent nodes.
func BuildAncestorsListOrParent ¶
func BuildAncestorsListOrParent(ctx context.Context, treeClient tree.NodeProviderClient, node *tree.Node) (parentUuids []*tree.Node, err error)
Recursive listing to build ancestors list when the node does not exists yet : try to find all existing parents
func CheckContentLock ¶ added in v1.2.0
CheckContentLock finds if there is a global lock registered in ACLs.
func DefaultBigCacheConfig ¶ added in v1.2.0
DefaultBigCacheConfig returns a bigcache default config with an eviction time of 30minutes and a HadMaxCachesize of 20MB
func GenMarkdown ¶ added in v1.0.2
GenMarkdown creates markdown output.
func GenMarkdownCustom ¶ added in v1.0.2
GenMarkdownCustom creates custom markdown output.
func GenMarkdownTree ¶ added in v1.0.2
GenMarkdownTree will generate a markdown page for this command and all descendants in the directory given. The header may be nil. This function may not work correctly if your command names have `-` in them. If you have `cmd` with two subcmds, `sub` and `sub-third`, and `sub` has a subcommand called `third`, it is undefined which help output will be in the file `cmd-sub-third.1`.
func GenMarkdownTreeCustom ¶ added in v1.0.2
func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error
GenMarkdownTreeCustom is the the same as GenMarkdownTree, but with custom filePrepender and linkHandler.
func GenPydioYaml ¶ added in v1.0.2
GenPydioYaml generates yaml file for pydio docs Sample output title: "Command Name" language: und menu: "Command Name" weight: 1 menu_name: menu-administration-guide
func GetACLsForRoles ¶
GetACLsForRoles compiles ALCs for a list of roles
func GetACLsForWorkspace ¶
func GetACLsForWorkspace(ctx context.Context, workspaceIds []string, actions ...*idm.ACLAction) (acls []*idm.ACL, err error)
GetACLsForWorkspace compiles ACLs list attached to a given workspace
func GetAvailableIPs ¶
GetExternalIP retrieves the preferred outbound ip of this machine by scanning the network interfaces of this (virtual) machine
func GetAvailablePort ¶
func GetAvailablePort() int
func GetExternalIP ¶
GetExternalIP retrieves the preferred outbound ip of this machine by scanning the network interfaces of this (virtual) machine
func GetOutboundIP ¶
GetOutboundIP restrieves the preferred outbound ip of this machine by simply connecting to a well known ip of the internet.
func GetRolesForUser ¶
Load roles for a given user
func GetTimeFromNtp ¶
func GetWorkspacesForACLs ¶
func GetWorkspacesForACLs(ctx context.Context, list *AccessList) []*idm.Workspace
Compute a list of accessible workspaces, given a set of Read and Deny ACLs.
func IgnoreNodeForOutput ¶
IgnoreNodeForOutput checks wether a node shall be ignored for outputs sent to end user (typically websocket events, activities, etc)
func IsUserLocked ¶ added in v1.2.2
IsUserLocked checks if the passed user has a logout attribute defined.
func PolicyContextFromMetadata ¶
PolicyContextFromMetadata extracts metadata directly from the context and enriches the passed policyContext.
func PolicyContextFromNode ¶
PolicyContextFromNode extracts metadata from the Node and enriches the passed policyContext.
func PolicyRequestSubjectsFromClaims ¶
PolicyRequestSubjectsFromClaims builds an array of string subjects from the passed Claims.
func PolicyRequestSubjectsFromUser ¶
PolicyRequestSubjectsFromUser builds an array of string subjects from the passed User.
func RunJavaScript ¶
func SearchUniqueUser ¶
func SearchUniqueUser(ctx context.Context, login string, uuid string, queries ...*idm.UserSingleQuery) (user *idm.User, err error)
SearchUniqueUser provides a shortcurt to search user services for one specific user
func ToPathUint ¶
Types ¶
type AccessList ¶
type AccessList struct { Workspaces map[string]*idm.Workspace Acls []*idm.ACL NodesAcls map[string]Bitmask WorkspacesNodes map[string]map[string]Bitmask OrderedRoles []*idm.Role FrontPluginsValues []*idm.ACL }
AccessList is a merged representation of all ACLs that a user has access to. ACLs are merged using a Bitmask form to ease flags detections and comparisons.
func AccessListFromContextClaims ¶
func AccessListFromContextClaims(ctx context.Context) (accessList *AccessList, err error)
Use package function to compile ACL and Workspaces for a given user ( = list of roles inside the Claims)
func AccessListFromRoles ¶
func AccessListFromRoles(ctx context.Context, roles []*idm.Role, countPolicies bool, loadWorkspaces bool) (accessList *AccessList, err error)
AccessListFromRoles loads the Acls and flatten them, eventually loading the discovered workspaces
func AccessListFromUser ¶
func NewAccessList ¶
func NewAccessList(orderedRoles []*idm.Role, Acls ...[]*idm.ACL) *AccessList
NewAccessList creates a new AccessList.
func (*AccessList) Append ¶
func (a *AccessList) Append(acls []*idm.ACL)
Append appends an additional list of ACLs.
func (*AccessList) BelongsToWorkspaces ¶
func (a *AccessList) BelongsToWorkspaces(ctx context.Context, nodes ...*tree.Node) (workspaces []*idm.Workspace, workspacesRoots map[string]string)
BelongsToWorkspaces finds corresponding workspace parents for this node.
func (*AccessList) FirstMaskForParents ¶
func (a *AccessList) FirstMaskForParents(ctx context.Context, nodes ...*tree.Node) (Bitmask, *tree.Node)
FirstMaskForParents just climbs up the tree and gets the first non empty mask found.
func (*AccessList) Flatten ¶
func (a *AccessList) Flatten(ctx context.Context)
Flatten performs actual flatten.
func (*AccessList) GetAccessibleWorkspaces ¶
func (a *AccessList) GetAccessibleWorkspaces(ctx context.Context) map[string]string
GetAccessibleWorkspaces retrieves a map of accessible workspaces.
func (*AccessList) GetNodesBitmasks ¶
func (a *AccessList) GetNodesBitmasks() map[string]Bitmask
func (*AccessList) GetWorkspacesNodes ¶
func (a *AccessList) GetWorkspacesNodes() map[string]map[string]Bitmask
GetWorkspacesNodes gets detected workspace root nodes that are then used to populate the Workspace keys.
func (*AccessList) HasPolicyBasedAcls ¶
func (a *AccessList) HasPolicyBasedAcls() bool
HasPolicyBasedAcls checks if there are policy based acls.
func (*AccessList) ParentMaskOrDeny ¶
ParentMaskOrDeny browses access list from current node to ROOT, going through each parent. If there is a deny anywhere up the path, it returns that deny, otherwise it sends the first Bitmask found (closest parent having a Bitmask set).
func (*AccessList) Zap ¶
func (a *AccessList) Zap() zapcore.Field
LOGGING SUPPORT
Zap simply returns a zapcore.Field object populated with this aggregated AccessList under a standard key
type Bitmask ¶
type Bitmask struct { BitmaskFlag PolicyIds map[string]string ValueFlags map[BitmaskFlag]string }
func (*Bitmask) AddPolicyFlag ¶
AddPolicyFlag adds a policy flag and stacks policies.
func (*Bitmask) AddValueFlag ¶
func (f *Bitmask) AddValueFlag(flag BitmaskFlag, value string)
AddValueFlag stores the value of a BitmaskFlag.
type BitmaskFlag ¶
type BitmaskFlag uint32
const ( FLAG_READ BitmaskFlag = 1 << iota FLAG_WRITE FLAG_DENY FLAG_LIST FLAG_DELETE FLAG_POLICY FLAG_QUOTA )
type Fraction ¶
type Fraction struct {
// contains filtered or unexported fields
}
Fraction type
func NewFraction ¶
NewFraction from a numerator and denominator
func NewFractionFromMaterializedPath ¶
NewFractionFromMaterializedPath function
type MPath ¶
type MPath []uint64
MPath type struct
func NewMPathFromMPath ¶
NewMPathFromMPath returns a copy of a slice
type MPathProvider ¶
type MPathProvider interface { }
type Matrix ¶
func MoveSubtree ¶
type PolicyResolver ¶
type PolicyResolver func(ctx context.Context, request *idm.PolicyEngineRequest) (*idm.PolicyEngineResponse, error)
type Right ¶
func (*Right) IsAccessible ¶
type TreeNode ¶
TreeNode definition
func NewTreeNode ¶
func NewTreeNode() *TreeNode
NewTreeNode wraps a node with its rational equivalent of the mpath
func (*TreeNode) SetBytes ¶
SetBytes decodes the byte representation of the rat and applies it to the current node
func (*TreeNode) SetMPath ¶
SetMPath triggers the calculation of the rat representation and the sibling rat representation for the node