utils

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 27 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// GlobalRegistry configures a service registry globally accessible. It defaults to a memory registry. The usage of
	// globals is not encouraged, and this is a workaround until the PR is out of a draft state.
	GlobalRegistry registry.Registry = memory.New(map[string]interface{}{})
)

Functions

func Cast added in v1.25.0

func Cast(v any, to any)

Cast casts a value `v` to the value `to`. `v` is expected to be the underlying type of `to`. For example, if the type A is defined as func() and v is func(), to is of type A. to must be a pointer, otherwise the method panics.

func ExtractGranteeID

func ExtractGranteeID(grantee *provider.Grantee) (*userpb.UserId, *grouppb.GroupId)

ExtractGranteeID returns the ID, user or group, set in the GranteeId object.

func GetAppViewMode added in v1.24.0

func GetAppViewMode(viewMode string) appprovider.ViewMode

GetAppViewMode converts a human-readable string to an appprovider view mode for opening a resource in an app.

func GetClientIP

func GetClientIP(r *http.Request) (string, error)

GetClientIP retrieves the client IP from incoming requests.

func GetLDAPConnection

func GetLDAPConnection(c *LDAPConn) (*ldap.Conn, error)

GetLDAPConnection initializes an LDAPS connection and allows to set TLS options e.g. to add trusted Certificates or disable Certificate verification.

func GetViewMode

func GetViewMode(viewMode string) gateway.OpenInAppRequest_ViewMode

GetViewMode converts a human-readable string to a view mode for opening a resource in an app.

func GranteeEqual

func GranteeEqual(u, v *provider.Grantee) bool

GranteeEqual returns whether two grantees have the same field values.

func GroupEqual

func GroupEqual(u, v *grouppb.GroupId) bool

GroupEqual returns whether two groups have the same field values.

func HasOCMShareRole added in v0.0.29

func HasOCMShareRole(u *userpb.User) (string, bool)

HasOCMShareRole return true if the user has a ocm share role. If yes, the string is the type of role, viewer, editor or uploader.

func HasPermissions added in v0.0.20

func HasPermissions(target, toCheck *provider.ResourcePermissions) bool

HasPermissions returns true if all permissions defined in the struct toCheck are set in the target.

func HasPublicShareRole added in v0.0.3

func HasPublicShareRole(u *userpb.User) (string, bool)

HasPublicShareRole return true if the user has a public share role. If yes, the string is the type of role, viewer, editor or uploader.

func IsAbsolutePathReference

func IsAbsolutePathReference(ref *provider.Reference) bool

IsAbsolutePathReference returns true if the given reference qualifies as a global path when only the path is set and starts with /.

func IsAbsoluteReference

func IsAbsoluteReference(ref *provider.Reference) bool

IsAbsoluteReference returns true if the given reference qualifies as absolute when either only the resource id is set or only the path is set and starts with /

TODO(corby): Currently if the path is empty, the ResourceId is set but has empty storageId and OpaqueId then the reference is still being viewed as absolute. We need to check if we want that because in some places we might not want to set both StorageId and OpaqueId so we can't do a hard check if they are set.

func IsEmailValid

func IsEmailValid(e string) bool

IsEmailValid checks whether the provided email has a valid format.

func IsRelativeReference

func IsRelativeReference(ref *provider.Reference) bool

IsRelativeReference returns true if the given reference qualifies as relative when the resource id is set and the path starts with a .

TODO(corby): Currently if the path begins with a dot, the ResourceId is set but has empty storageId and OpaqueId then the reference is still being viewed as relative. We need to check if we want that because in some places we might not want to set both StorageId and OpaqueId so we can't do a hard check if they are set.

func IsValidName

func IsValidName(name string) bool

IsValidName cheks if the given name doesn't contain any non-alpha, space or dash characters.

func IsValidPhoneNumber

func IsValidPhoneNumber(number string) bool

IsValidPhoneNumber checks whether the provided phone number has a valid format.

func IsValidWebAddress

func IsValidWebAddress(address string) bool

IsValidWebAddress checks whether the provided address is a valid URL.

func LaterTS

func LaterTS(t1 *types.Timestamp, t2 *types.Timestamp) *types.Timestamp

LaterTS returns the timestamp which occurs later.

func MakeRelativePath

func MakeRelativePath(p string) string

MakeRelativePath prefixes the path with a . to use it in a relative reference.

func MarshalProtoV1ToJSON

func MarshalProtoV1ToJSON(m proto.Message) ([]byte, error)

MarshalProtoV1ToJSON marshals a proto V1 message to a JSON byte array TODO: update this once we start using V2 in CS3APIs.

func ParseStorageSpaceReference

func ParseStorageSpaceReference(sRef string) (provider.Reference, error)

ParseStorageSpaceReference parses a string into a spaces reference. The expected format is `<storageid>!<nodeid>/<path>`.

func RandString

func RandString(n int) string

RandString is a helper to create tokens.

func ResolvePath

func ResolvePath(path string) (string, error)

ResolvePath converts relative local paths to absolute paths.

func ResourceEqual

func ResourceEqual(u, v *provider.Reference) bool

ResourceEqual returns whether two resources have the same field values.

func ResourceIDEqual

func ResourceIDEqual(u, v *provider.ResourceId) bool

ResourceIDEqual returns whether two resources have the same field values.

func Skip

func Skip(source string, prefixes []string) bool

Skip evaluates whether a source endpoint contains any of the prefixes. i.e: /a/b/c/d/e contains prefix /a/b/c.

func SplitStorageSpaceID

func SplitStorageSpaceID(ssid string) (storageid, nodeid string, err error)

SplitStorageSpaceID can be used to split `storagespaceid` into `storageid` and `nodeid` Currently they are built using `<storageid>!<nodeid>` in the decomposedfs, but other drivers might return different ids. any place in the code that relies on this function should instead use the storage registry to look up the responsible storage provider. Note: This would in effect change the storage registry into a storage space registry.

func TSToTime

func TSToTime(ts *types.Timestamp) time.Time

TSToTime converts a protobuf Timestamp to Go's time.Time.

func TSToUnixNano

func TSToUnixNano(ts *types.Timestamp) uint64

TSToUnixNano converts a protobuf Timestamp to uint64 with nanoseconds resolution.

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase converts a CamelCase string to a snake_case string.

func UnmarshalJSONToProtoV1

func UnmarshalJSONToProtoV1(b []byte, m proto.Message) error

UnmarshalJSONToProtoV1 decodes a JSON byte array to a specified proto message type TODO: update this once we start using V2 in CS3APIs.

func UserEqual

func UserEqual(u, v *userpb.UserId) bool

UserEqual returns whether two users have the same field values.

func UserIsLightweight added in v0.0.20

func UserIsLightweight(u *userpb.User) bool

UserIsLightweight returns true if the user is a lightweight or federated account.

func UserTypeMap

func UserTypeMap(accountType string) userpb.UserType

UserTypeMap translates account type string to CS3 UserType.

func UserTypeToString

func UserTypeToString(accountType userpb.UserType) string

UserTypeToString translates CS3 UserType to user-readable string.

Types

type LDAPConn

type LDAPConn struct {
	Hostname     string `mapstructure:"hostname"`
	Port         int    `mapstructure:"port"`
	Insecure     bool   `docs:"false;Whether to skip certificate checks when sending requests." mapstructure:"insecure"`
	CACert       string `mapstructure:"cacert"`
	BindUsername string `mapstructure:"bind_username"`
	BindPassword string `mapstructure:"bind_password"`
}

LDAPConn holds the basic parameter for setting up an LDAP connection.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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