utils

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: AGPL-3.0 Imports: 46 Imported by: 0

Documentation

Overview

Package utils provides swiss-knife tools for all services

Index

Constants

View Source
const (
	PolicyNodeMetaName      = "NodeMetaName"
	PolicyNodeMetaPath      = "NodeMetaPath"
	PolicyNodeMetaExtension = "NodeMetaExtension"
	PolicyNodeMetaMimeType  = "NodeMetaMimeType"
	PolicyNodeMetaSize      = "NodeMetaSize"
	PolicyNodeMetaMTime     = "NodeMetaMTime"
	PolicyNodeMeta_         = "NodeMeta:"
)
View Source
const PRECISION = 100

Variables

View Source
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_DELETE           = &idm.ACLAction{Name: "delete", Value: "1"}
	ACL_LIST             = &idm.ACLAction{Name: "list", Value: "1"}
	ResolvePolicyRequest PolicyResolver
)

Functions

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 FactorizeMinioServers

func FactorizeMinioServers(existingConfigs map[string]*object.MinioConfig, newSource *object.DataSource) (config *object.MinioConfig)

FactorizeMinioServers tries to find exisiting MinioConfig that can be directly reused by the new source, or creates a new one

func FindUserNameInContext

func FindUserNameInContext(ctx context.Context) (string, claim.Claims)

func GenMarkdown added in v1.0.2

func GenMarkdown(cmd *cobra.Command, w io.Writer) error

GenMarkdown creates markdown output.

func GenMarkdownCustom added in v1.0.2

func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error

GenMarkdownCustom creates custom markdown output.

func GenMarkdownTree added in v1.0.2

func GenMarkdownTree(cmd *cobra.Command, dir string) error

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

func GenPydioYaml(cmd *cobra.Command, position int, w io.Writer) error

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

func GetACLsForRoles(ctx context.Context, roles []*idm.Role, actions ...*idm.ACLAction) []*idm.ACL

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

func GetAvailableIPs() (ips []net.IP, e error)

GetExternalIP retrieves the preferred outbound ip of this machine by scanning the network interfaces of this (virtual) machine

func GetAvailablePort

func GetAvailablePort() int

func GetDefaultLanguage

func GetDefaultLanguage() string

GetDefaultLanguage reads default language from config

func GetExternalIP

func GetExternalIP() (net.IP, error)

GetExternalIP retrieves the preferred outbound ip of this machine by scanning the network interfaces of this (virtual) machine

func GetOutboundIP

func GetOutboundIP() (net.IP, error)

GetOutboundIP restrieves the preferred outbound ip of this machine by simply connecting to a well known ip of the internet.

func GetRoles

func GetRoles(ctx context.Context, names []string) []*idm.Role

GetRoles Objects from a list of role names

func GetRolesForUser

func GetRolesForUser(ctx context.Context, user *idm.User, createMissing bool) []*idm.Role

Load roles for a given user

func GetTimeFromNtp

func GetTimeFromNtp() (time.Time, error)

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

func IgnoreNodeForOutput(ctx context.Context, node *tree.Node) bool

IgnoreNodeForOutput checks wether a node shall be ignored for outputs sent to end user (typically websocket events, activities, etc)

func IndexServiceTableNames

func IndexServiceTableNames(dsName string) map[string]string

func ListMinioConfigsFromConfig

func ListMinioConfigsFromConfig() map[string]*object.MinioConfig

ListMinioConfigsFromConfig scans configs for objects services configs

func ListSourcesFromConfig

func ListSourcesFromConfig() map[string]*object.DataSource

ListSourcesFromConfig scans configs for sync services configs

func MinioConfigNamesToConfig

func MinioConfigNamesToConfig(sources map[string]*object.MinioConfig)

func PolicyContextFromMetadata

func PolicyContextFromMetadata(policyContext map[string]string, ctx context.Context)

PolicyContextFromMetadata extracts metadata directly from the context and enriches the passed policyContext.

func PolicyContextFromNode

func PolicyContextFromNode(policyContext map[string]string, node *tree.Node)

PolicyContextFromNode extracts metadata from the Node and enriches the passed policyContext.

func PolicyRequestSubjectsFromClaims

func PolicyRequestSubjectsFromClaims(claims claim.Claims) []string

PolicyRequestSubjectsFromClaims builds an array of string subjects from the passed Claims.

func PolicyRequestSubjectsFromUser

func PolicyRequestSubjectsFromUser(user *idm.User) []string

PolicyRequestSubjectsFromUser builds an array of string subjects from the passed User.

func Randkey

func Randkey(n int) string

func RunJavaScript

func RunJavaScript(ctx context.Context, script string, inputs map[string]interface{}, outputs map[string]interface{}) error

func SearchUniqueUser

func SearchUniqueUser(ctx context.Context, login string, uuid string, attributes ...string) (user *idm.User, err error)

SearchUniqueUser provides a shortcurt to search user services for one specific user

func SourceNamesToConfig

func SourceNamesToConfig(sources map[string]*object.DataSource)

func ToPath

func ToPath(f *Fraction) string

ToPath a Fraction

func ToPathUint

func ToPathUint(f *Fraction) []uint64

func UnusedMinioServers

func UnusedMinioServers(minios map[string]*object.MinioConfig, sources map[string]*object.DataSource) string

UnusedMinioServers searches for existing minio configs that are not used anywhere in datasources

func UserLanguage

func UserLanguage(ctx context.Context, user *idm.User) string

UserLanguage looks for the user roles and check if a language parameter is set (starting from the last). Otherwise returns the default language from config

func UserLanguageFromContext

func UserLanguageFromContext(ctx context.Context, returnDefault bool) string

UserLanguageFromContext tries to find Claims in context and get the language for the corresponding user. If nothing is found, if returnDefault is true it returns the global default language, otherwise it returns an empty string.

func UserLanguagesFromRestRequest

func UserLanguagesFromRestRequest(req *restful.Request) []string

UserLanguagesFromRestRequest tries to find user language from various sources: X-Pydio-Language header, user language inside the system (set via roles), or Accept-Language standard header.

func ValidateDataSourceConfig added in v1.0.1

func ValidateDataSourceConfig(newSource *object.DataSource) error

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
}

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 AccessListFromUser(ctx context.Context, userNameOrUuid string, isUuid bool) (accessList *AccessList, user *idm.User, err error)

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) CanRead

func (a *AccessList) CanRead(ctx context.Context, nodes ...*tree.Node) bool

CanRead checks if a node has READ access.

func (*AccessList) CanWrite

func (a *AccessList) CanWrite(ctx context.Context, nodes ...*tree.Node) bool

CanWrite checks if a node has WRITE access.

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

func (a *AccessList) ParentMaskOrDeny(ctx context.Context, nodes ...*tree.Node) (bool, Bitmask)

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

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) AddFlag

func (f *Bitmask) AddFlag(flag BitmaskFlag)

AddFlag adds a simple flag.

func (*Bitmask) AddPolicyFlag

func (f *Bitmask) AddPolicyFlag(policyId string)

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.

func (Bitmask) HasFlag

func (f Bitmask) HasFlag(ctx context.Context, flag BitmaskFlag, ctxNode ...*tree.Node) bool

type BitmaskFlag

type BitmaskFlag uint32
const (
	FLAG_READ BitmaskFlag = 1 << iota
	FLAG_WRITE
	FLAG_DENY
	FLAG_LIST
	FLAG_DELETE
	FLAG_POLICY
	FLAG_QUOTA
)

type Float

type Float struct {
	*big.Float
}

Float type

func NewFloat

func NewFloat() *Float

NewFloat returns a big Float with a 512 precision

func (*Float) Nat

func (f *Float) Nat() Nat

Nat representation of a float

type Fraction

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

Fraction type

func NewFraction

func NewFraction(n *big.Int, d *big.Int) *Fraction

NewFraction from a numerator and denominator

func NewFractionFromMaterializedPath

func NewFractionFromMaterializedPath(path ...uint64) *Fraction

NewFractionFromMaterializedPath function

func (Fraction) Decimal

func (f Fraction) Decimal() *big.Rat

Decimal representation of the fraction

func (Fraction) Den

func (f Fraction) Den() *big.Int

Den value of the fraction

func (Fraction) Num

func (f Fraction) Num() *big.Int

Num value of the fraction

type I18nBundle

type I18nBundle struct {
	bundle.Bundle
}

func NewI18nBundle

func NewI18nBundle(box packr.Box) *I18nBundle

func (*I18nBundle) GetTranslationFunc

func (b *I18nBundle) GetTranslationFunc(languages ...string) i18n.TranslateFunc

GetTranslationFunc provides the correct translation func for language or the IdentityFunc if language is not supported. Languages can be a list of weighted languages as provided in the http header Accept-Language

func (*I18nBundle) LoadPackrTranslationFiles

func (b *I18nBundle) LoadPackrTranslationFiles(box packr.Box)

LoadPackrTranslationFiles loads goi18n translation files from packr boxes

type JsRequest

type JsRequest struct {
	UserAgent string
	UserIP    string
}

type JsUser

type JsUser struct {
	Name               string
	GroupPath          string
	GroupPathFlattened string
}

type MPath

type MPath []uint64

MPath type struct

func NewMPath

func NewMPath(mpath ...uint64) MPath

NewMPath from mpath

func NewMPathFromMPath

func NewMPathFromMPath(b MPath) MPath

NewMPathFromMPath returns a copy of a slice

func (MPath) Hash

func (m MPath) Hash() uint32

func (MPath) Index

func (m MPath) Index() uint64

func (MPath) Parent

func (m MPath) Parent() MPath

Parent of a specific path

func (MPath) Parents

func (m MPath) Parents() []MPath

func (MPath) Rat

func (m MPath) Rat() *Rat

Rat representation of a materialized path

func (MPath) Sibling

func (m MPath) Sibling() MPath

Sibling of a specific path

func (MPath) String

func (m MPath) String() string

String representation of a mpath

type MPathProvider

type MPathProvider interface {
}

type Matrix

type Matrix [][]*big.Int

func MoveSubtree

func MoveSubtree(p0 *Matrix, m *big.Int, p1 *Matrix, n *big.Int, M *Matrix) *Matrix

func NewMatrix

func NewMatrix(m00 *big.Int, m01 *big.Int, m10 *big.Int, m11 *big.Int) *Matrix

func (Matrix) GetA11

func (m Matrix) GetA11() *big.Int

func (Matrix) GetA12

func (m Matrix) GetA12() *big.Int

func (Matrix) GetA21

func (m Matrix) GetA21() *big.Int

func (Matrix) GetA22

func (m Matrix) GetA22() *big.Int

type Nat

type Nat []big.Word

type PolicyResolver

type PolicyResolver func(ctx context.Context, request *idm.PolicyEngineRequest) (*idm.PolicyEngineResponse, error)

type Rat

type Rat struct {
	*big.Rat
}

Float type

func NewRat

func NewRat() *Rat

func (*Rat) SetMPath

func (f *Rat) SetMPath(path ...uint64) *Rat

SetMPath sets the value of the float based on the materialized path given

type Right struct {
	Read  bool
	Write bool
}

func (*Right) IsAccessible

func (r *Right) IsAccessible() bool

func (*Right) String

func (r *Right) String() string

type TreeNode

type TreeNode struct {
	*tree.Node

	MPath MPath

	Level int
	// contains filtered or unexported fields
}

TreeNode definition

func NewTreeNode

func NewTreeNode() *TreeNode

NewTreeNode wraps a node with its rational equivalent of the mpath

func (*TreeNode) Bytes

func (t *TreeNode) Bytes() []byte

Bytes encoding of the rational

func (*TreeNode) DV

func (t *TreeNode) DV() *big.Int

DV represents the denominator value of the rational

func (*TreeNode) GetMeta

func (t *TreeNode) GetMeta(name string, value interface{})

GetMeta gets a meta from a meta store using the lock

func (*TreeNode) NV

func (t *TreeNode) NV() *big.Int

NV represents the numerator value of the rational

func (*TreeNode) Name

func (t *TreeNode) Name() string

Name from the metastore (uses a rwlock)

func (*TreeNode) SDV

func (t *TreeNode) SDV() *big.Int

SDV represents the denominator value of the node sibling

func (*TreeNode) SNV

func (t *TreeNode) SNV() *big.Int

SNV represents the numerator value of the node sibling

func (*TreeNode) SetBytes

func (t *TreeNode) SetBytes(b []byte)

SetBytes decodes the byte representation of the rat and applies it to the current node

func (*TreeNode) SetMPath

func (t *TreeNode) SetMPath(mpath ...uint64)

SetMPath triggers the calculation of the rat representation and the sibling rat representation for the node

func (*TreeNode) SetMeta

func (t *TreeNode) SetMeta(name string, value interface{})

SetMeta sets a meta using a lock

func (*TreeNode) SetName

func (t *TreeNode) SetName(name string)

SetName records the name of the node in the metastore (uses a lock)

func (*TreeNode) SetRat

func (t *TreeNode) SetRat(rat *Rat)

SetRat triggers the calculation of the mpath based on the rational value given for the node

Jump to

Keyboard shortcuts

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