utils

package
v2.16.1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: Apache-2.0 Imports: 32 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ShareStorageProviderID is the provider id used by the sharestorageprovider
	ShareStorageProviderID = "a0ca6a90-a365-4782-871e-d44447bbc668"
	// ShareStorageSpaceID is the space id used by the sharestorageprovider share jail space
	ShareStorageSpaceID = "a0ca6a90-a365-4782-871e-d44447bbc668"

	// PublicStorageProviderID is the storage id used by the sharestorageprovider
	PublicStorageProviderID = "7993447f-687f-490d-875c-ac95e89a62a4"
	// PublicStorageSpaceID is the space id used by the sharestorageprovider
	PublicStorageSpaceID = "7993447f-687f-490d-875c-ac95e89a62a4"

	// SpaceGrant is used to signal the storageprovider that the grant is on a space
	SpaceGrant struct{}
)

Functions

func AppendJSONToOpaque added in v2.13.0

func AppendJSONToOpaque(o *types.Opaque, key string, value interface{}) *types.Opaque

AppendJSONToOpaque adds a new key value pair as a json on the given opaque and returns it. Ignores errors

func AppendPlainToOpaque

func AppendPlainToOpaque(o *types.Opaque, key, value string) *types.Opaque

AppendPlainToOpaque adds a new key value pair as a plain string on the given opaque and returns it

func ExistsInOpaque added in v2.1.0

func ExistsInOpaque(o *types.Opaque, key string) bool

ExistsInOpaque returns true if the key exists in the opaque (ignoring the value)

func ExtractGranteeID

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

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

func GetClientIP

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

GetClientIP retrieves the client IP from incoming requests

func GetLDAPClientForAuth added in v2.2.0

func GetLDAPClientForAuth(c *LDAPConn) (ldap.Client, error)

GetLDAPClientForAuth initializes an LDAP connection. The connection is not authenticated when returned. The main purpose for GetLDAPClientForAuth is to get and LDAP connection that can be used to issue a single bind request to authenticate a user.

func GetLDAPClientWithReconnect added in v2.2.0

func GetLDAPClientWithReconnect(c *LDAPConn) (ldap.Client, error)

GetLDAPClientWithReconnect initializes a long-lived LDAP connection that automatically reconnects on connection errors. It allows to set TLS options e.g. to add trusted Certificates or disable Certificate verification

func GetUser added in v2.13.0

func GetUser(userID *user.UserId, gwc gateway.GatewayAPIClient, machineAuthAPIKey string) (*user.User, error)

GetUser gets the specified user

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 Impersonate added in v2.13.0

func Impersonate(userID *user.UserId, gwc gateway.GatewayAPIClient, machineAuthAPIKey string) (context.Context, *user.User, error)

Impersonate returns an authenticated reva context and the user it represents

func ImpersonateUser added in v2.13.0

func ImpersonateUser(usr *user.User, gwc gateway.GatewayAPIClient, machineAuthAPIKey string) (context.Context, error)

ImpersonateUser impersonates the given user

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 MTimeToTS added in v2.8.0

func MTimeToTS(v string) (ts types.Timestamp, err error)

MTimeToTS converts a string in the form "<unix>.<nanoseconds>" into a CS3 Timestamp

func MTimeToTime added in v2.16.0

func MTimeToTime(v string) (t time.Time, err error)

MTimeToTime converts a string in the form "<unix>.<nanoseconds>" into a go time.Time

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 MergeOpaques added in v2.6.0

func MergeOpaques(o *types.Opaque, p *types.Opaque) *types.Opaque

MergeOpaques will merge the opaques. If a key exists in both opaques the values from the first opaque will be taken

func RandString

func RandString(n int) string

RandString is a helper to create tokens.

func ReadJSONFromOpaque added in v2.13.0

func ReadJSONFromOpaque(o *types.Opaque, key string, valptr interface{}) error

ReadJSONFromOpaque reads and unmarshals a value from the opaque in the given interface{} (Make sure it's a pointer!)

func ReadPlainFromOpaque

func ReadPlainFromOpaque(o *types.Opaque, key string) string

ReadPlainFromOpaque reads a plain string from the given opaque map

func RemoveItem added in v2.4.0

func RemoveItem(path string) error

RemoveItem removes the given item, its children and all empty parent folders

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 TSNow

func TSNow() *types.Timestamp

TSNow returns the current UTC timestamp

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 TimeToTS added in v2.8.0

func TimeToTS(t time.Time) *types.Timestamp

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

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 UserIDEqual added in v2.11.0

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

UserIDEqual returns whether two users have the same opaqueid values. The idp is ignored

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 {
	URI          string `mapstructure:"uri"`
	Insecure     bool   `mapstructure:"insecure"`
	CACert       string `mapstructure:"cacert"`
	BindDN       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