Documentation ¶
Index ¶
- Constants
- Variables
- func AddStore(s *Safe, storeConfig StoreConfig) error
- func CheckForUpdates(s *Safe, dir string, after time.Time, depth int) ([]string, error)
- func Close(s *Safe)
- func DeleteFile(s *Safe, bucket string, fileId uint64) error
- func Federate(names []string, buckets []string, options FederateOptions) error
- func GetCached(name string, store storage.Store, key string, data any, creatorId string) (synced bool, err error)
- func InitTest()
- func ListDirs(s *Safe, bucket string, listDirsOptions ListDirsOptions) ([]string, error)
- func SetCached(name string, store storage.Store, key string, value any, creatorId string) error
- func SetUsers(s *Safe, users Users, options SetUsersOptions) error
- func StartTestDB(t *testing.T, dbPath string)
- func SyncBucket(s *Safe, bucket string, SyncOptions SyncOptions, async func(int, error)) (changes int, err error)
- func SyncUsers(s *Safe) (int, error)
- type Admins
- type Attributes
- type Change
- type ChangeLog
- type ChangeType
- type CompactHeader
- type CreateOptions
- type FederateOptions
- type GetOptions
- type Header
- func Get(s *Safe, bucket, name string, dest any, options GetOptions) (Header, error)
- func ListFiles(s *Safe, bucket string, listOptions ListOptions) ([]Header, error)
- func Patch(s *Safe, bucket string, header Header, options PatchOptions) (Header, error)
- func Put(s *Safe, bucket, name string, src any, options PutOptions, ...) (Header, error)
- type HeadersFile
- type Index
- type Initiate
- type Keys
- type Keystore
- type KeystoreFile
- type Level2
- type ListDirsOptions
- type ListOptions
- type OpenOptions
- type PatchOptions
- type Permission
- type PermissionChange
- type PutOptions
- type Safe
- type SetUsersOptions
- type StoreConfig
- type StoreType
- type SyncOptions
- type UploadTask
- type Users
Constants ¶
const ( DefaultChangeLogWatch = time.Minute DefaultReplicaWatch = 10 * time.Minute )
const ( MaxSizeForCompression = 1 << 26 // 64 MB MaxThumbnailSize = 64 * 1024 // 64 KB MaxThumbnailWidth = 512 // 512 px ErrInvalidName = "invalid name: %s should not start with /" )
const ( ConfigFolder = "config" DataFolder = "data" InitiateFolder = "initiate" HeaderFolder = "h" BodyFolder = "b" BucketFile = ".bucket" )
const ( StoreMaster = 1 StoreCDN = 2 )
const ( TestMemStoreUrl = "mem://0" TestLocalStoreUrl = "file:///tmp" )
const ( ErrZoneNotExist = "zone '%s' does not exist" // Returned when a zone does not exist ErrZoneNameTooLong = "zone name '%s' too long, max length 32" // Returned when a zone name is too long ErrZoneExist = "zone '%s' already exists" // ErrNoAuth = "user '%s['%s']' has not authorization for box '%s'" )
const KeySize = 32
const TestSafeName = "test-safe"
Variables ¶
var CacheFolder string
var DefaultSyncUsersRefreshRate = 10 * time.Minute
var DelayForDestination = 100 * time.Millisecond // Delay before checking if the file is downloaded to the specified destination
var ErrFileNotExist = fmt.Errorf("file does not exist") // Returned when a file does not exist
var ErrInvalidHeaders = fmt.Errorf("headers are invalid")
var ErrInvalidTag = fmt.Errorf("invalid tag. Only alphanumeric characters are allowed")
var ErrNoEncryptionKey = fmt.Errorf("no encryption key")
var ErrNoStoreAvailable = fmt.Errorf("no store available")
var ErrSignatureMismatch = fmt.Errorf("provided signature does not match the expected identity")
var HousekeepingMaxDuration = time.Hour * 23
var IdentitiesFolder = ".identities"
var Identity1, Identity2 security.Identity
var MaxACLFilesInZone = 4
var MaxCacheSize = int64(128 * 1024 * 1024) // Maximum size of the cache
var MaxHeaderFileSize = 1024 * 1024 * 4 // 4MB
var MaxHeadersFiles = 16
var MergeBatchSize = 4
Functions ¶
func AddStore ¶
func AddStore(s *Safe, storeConfig StoreConfig) error
func CheckForUpdates ¶
func GetCached ¶
func GetCached(name string, store storage.Store, key string, data any, creatorId string) (synced bool, err error)
GetCached returns the modification time of the guard file. If the creatorID is not empty, it returns true if the guard file creator has the same ID.
func ListDirs ¶
func ListDirs(s *Safe, bucket string, listDirsOptions ListDirsOptions) ([]string, error)
func SetUsers ¶
func SetUsers(s *Safe, users Users, options SetUsersOptions) error
SetUsers sets some users with corresponding permissions for a zone.
func StartTestDB ¶
func SyncBucket ¶
Types ¶
type Admins ¶
Admins defines the users who are administrators of a box and for each those that have level2, i.e. can add or remove other administrators
type Attributes ¶
type Attributes struct { Hash []byte `json:"ha,omitempty"` // Hash of the file ContentType string `json:"co,omitempty"` // Content type of the file Thumbnail []byte `json:"th,omitempty"` // Thumbnail of the file Tags []string `json:"ta,omitempty"` // Tags of the file Meta map[string]any `json:"mt,omitempty"` // Extra attributes of the file }
type ChangeType ¶
type ChangeType string
const ( ChangePermission ChangeType = "permission" ChangeReplicas ChangeType = "replicas" )
type CompactHeader ¶
type CreateOptions ¶
type CreateOptions struct { Wipe bool `json:"wipe"` // Wipe is true if the safe should be wiped before creating it Description string `json:"description"` // Description of the safe ChangeLogWatch time.Duration `json:"changeLogWatch"` // ChangeLogWatch is the period for watching changes in the change log ReplicaWatch time.Duration `json:"replicaWatch"` // ReplicaWatch is the period for synchronizing replicas MinimalSyncTime time.Duration `json:"minimalSyncTime"` // MinimalSyncTime is the minimal time between syncs }
type FederateOptions ¶
type FederateOptions struct { }
type GetOptions ¶
type GetOptions struct { Progress chan int64 `json:"progress"` // Send progress updates to the channel FileId uint64 `json:"fileId"` // Get the file with the specified body ID NoCache bool `json:"noCache"` // Do not cache the file CacheExpire time.Duration `json:"cacheExpire"` // Cache expiration time Range *storage.Range `json:"range"` // Range of bytes to read NoSync bool `json:"noSync"` // Do not sync the headers before getting the file }
type Header ¶
type Header struct { Name string `json:"na"` // Full path of the file Creator string `json:"cr"` // Creator of the file Size int64 `json:"si"` // Size of the file ModTime time.Time `json:"mo"` // Last modification time of the file FileId uint64 `json:"fi"` // ID used in the storage to identify the file IV []byte `json:"iv"` // IV used to encrypt the attributes Zip bool `json:"zi,omitempty"` // True if the file is zipped Attributes Attributes `json:"at,omitempty"` // Attributes of the file EncryptedAttributes []byte `json:"en,omitempty"` // Encrypted attributes of the file BodyKey []byte `json:"bo,omitempty"` // Key used to encrypt the body PrivateId string `json:"pr,omitempty"` // ID of the user in case of private encryption Deleted bool `json:"de,omitempty"` // True if the file is deleted Cached string `json:"ca,omitempty"` // Location where the file is cached CachedExpires time.Time `json:"cac,omitempty"` // Time when the cache expires Uploading bool `json:"up,omitempty"` // Number of uploads retries SourceFile string `json:"so,omitempty"` // Source of the file ReplaceId uint64 `json:"re,omitempty"` // ID of the file to replace Replace bool `json:"rp,omitempty"` // True if the file is replacing another file Downloads map[string]time.Time `json:"do,omitempty"` // Map of download locations and times }
func Get ¶
Get reads a file from a bucket. The destination can be a filename (string) or an io.Writer. If the destination is nil, the file is not written but the header is returned.
type HeadersFile ¶
type KeystoreFile ¶
KeystoreFile is the file that contains the primary key of box encrypted for each user
type ListDirsOptions ¶
type ListOptions ¶
type ListOptions struct { Name string `json:"name"` // Filter on the file name Dir string `json:"dir"` // Filter on the directory NoSync bool `json:"noSync"` // Skip syncing with the store Recursive bool `json:"recursive"` // Recursively list files in subfolders Prefix string `json:"prefix"` // Filter on the file prefix Suffix string `json:"suffix"` // Filter on the file suffix ContentType string `json:"contentType"` // Filter on the content type FileId uint64 `json:"bodyId"` // Filter on the body ID Tags []string `json:"tags"` // Filter on the tags Before time.Time `json:"before"` // Filter on the modification time After time.Time `json:"after"` // Filter on the modification time KnownSince time.Time `json:"knownSince"` // Filter on the sync time OnlyChanges bool `json:"onlyChanges"` // Only return files that have changed since the last sync Offset int `json:"offset"` // Offset of the first file to return Limit int `json:"limit"` // Maximum number of files to return IncludeDeleted bool `json:"includeDeleted"` // Include deleted files Creator string `json:"creator"` // Filter on the creator NoPrivate bool `json:"noPrivate"` // Ignore private files PrivateId string `json:"privateId"` // Filter on private files either created by the current user or the specified user Prefetch bool `json:"prefetch"` // Prefetch the file bodies ErrorIfNotExist bool `json:"errorIfNotExist"` // Return an error if the directory does not exist. Otherwise, return empty list OrderBy string `json:"orderBy"` // Order by name or modTime. Default is name ReverseOrder bool `json:"reverseOrder"` // Order descending when true. Default is false }
type OpenOptions ¶
type PatchOptions ¶
type Permission ¶
type Permission int
const ( Suspended Permission = 1 Reader Permission = 2 Standard Permission = 4 Admin Permission = 16 Creator Permission = 32 )
type PermissionChange ¶
type PermissionChange struct { UserId string `json:"userId"` Permission Permission `json:"permission"` }
type PutOptions ¶
type PutOptions struct { Progress chan int64 // Progress channel Async bool `json:"async"` // Do not wait for the file to be uploaded Replace bool `json:"replace"` // Replace all other files with the same name ReplaceID uint64 `json:"replaceId"` // Replace the file with the specified ID Tags []string `json:"tags"` // Tags associated with the file Thumbnail []byte `json:"thumbnail"` // Thumbnail associated with the file ThumbnailWidth int `json:"thumbnailWidth"` // Thumbnail width AutoThumbnail bool `json:"autoThumbnail"` // Generate a thumbnail from the file ContentType string `json:"contentType"` // Content type of the file Zip bool `json:"zip"` // Zip the file if it is smaller than 64MB Meta map[string]any `json:"meta"` // Metadata associated with the file Private string `json:"private"` // Id of the target user in case of private message }
type Safe ¶
type Safe struct { Hnd int `json:"hnd"` // Handle of the safe CurrentUser security.Identity `json:"currentUser"` // Current user Permission Permission `json:"permission"` // Permission of the current user CreatorId string `json:"creatorId"` // Creator of the safe Name string `json:"name"` // Name of the safe including the path Description string `json:"description"` // Description of the safe Size int64 `json:"size"` // Size of the safe in bytes StoreConfigs []StoreConfig `json:"storeConfigs"` // Stores of the safe MinimalSyncTime time.Duration `json:"minimalSyncTime"` // Minimal time between syncs // contains filtered or unexported fields }
func Create ¶
func Create(currentUser security.Identity, name string, storeConfig StoreConfig, users Users, options CreateOptions) (*Safe, error)
Create creates a new safe with the given name and store. The current user is the creator of the safe and it is automatically added to the list of users with creator permissions. Other users are optional.
type SetUsersOptions ¶
type SetUsersOptions struct {
SyncAlign bool `json:"syncAlign"` // SyncAlign is true if the keys are refreshed before ending the function
}
type StoreConfig ¶
type SyncOptions ¶
type SyncOptions struct {
Replicate bool `json:"replicate"`
}
type UploadTask ¶
Source Files ¶
- access.go
- addStore.go
- background.go
- changelog.go
- close.go
- create.go
- crypt.go
- db.go
- delete.go
- federate.go
- get.go
- gzip.go
- hashReadSeeker.go
- header.go
- housekeeping.go
- identity.go
- index.go
- initiates.go
- keystore.go
- list.go
- manifest.go
- open.go
- patch.go
- put.go
- safe.go
- sync.go
- test_utils.go
- touch.go
- updates.go
- users.go
- utils.go
- wipe.go