Documentation ¶
Index ¶
- Constants
- type State
- func (s *State) AddUser(store *filefreezer.Storage, username string, password string, quota int) (*filefreezer.User, error)
- func (s *State) Authenticate(hostURI, username, password string) error
- func (s *State) DecryptString(encoded string) (string, error)
- func (s *State) EncryptString(source string) (string, error)
- func (s *State) GetAllFileHashes() ([]filefreezer.FileInfo, error)
- func (s *State) GetFileInfoByFilename(filename string) (foundFile filefreezer.FileInfo, e error)
- func (s *State) GetFileVersions(filename string) (versions []filefreezer.FileVersionInfo, err error)
- func (s *State) GetMissingChunksForFile(fileID int) ([]int, error)
- func (s *State) GetUserStats() (stats filefreezer.UserStats, e error)
- func (s *State) ModUser(store *filefreezer.Storage, username string, newQuota int, newUsername string, ...) error
- func (s *State) RmFile(filename string, dryRun bool) error
- func (s *State) RmFileByID(fileID int) error
- func (s *State) RmFileVersions(filename string, minVersion int, maxVersion int, dryRun bool) error
- func (s *State) RmRxFileVersions(pattern string, minVersion int, maxVersionStr string, dryRun bool) error
- func (s *State) RmRxFiles(pattern string, dryRun bool) error
- func (s *State) RmUser(store *filefreezer.Storage, username string) error
- func (s *State) RunAuthRequest(target string, method string, token string, reqBody interface{}) ([]byte, error)
- func (s *State) SetCryptoHashForPassword(cryptoPassword string) error
- func (s *State) SetQuiet(quiet bool)
- func (s *State) SyncDirectory(localDir string, remoteDir string) (changeCount int, e error)
- func (s *State) SyncFile(localFilename string, remoteFilepath string, versionNum int) (status int, changeCount int, e error)
Constants ¶
const ( SyncStatusMissing = 1 // chunks missing SyncStatusLocalNewer = 2 // local file newer SyncStatusRemoteNewer = 3 // remote file newer SyncStatusSame = 4 // local and remote files are the same SyncStatusUnsupportedFileType = 5 // returned when sync encouters device files or socket files, etc... )
SyncStatus enumeration used to indicate the findings of the SyncFile and SyncDirectory functions.
const ( // SyncCurrentVersion is the value to pass to SyncFile to sync the current version // of the file and not a particular version number. SyncCurrentVersion = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type State ¶
type State struct { // the host URI used for calls HostURI string // the authentication token returned after logging in AuthToken string // the stored crypto hash for the client that is used // to verify the client-entered plaintext password. CryptoHash []byte // the key used to encrypt/decrypt file chunks and names // and is derived from a plaintext password. CryptoKey []byte // the capabilities returned by the authenticated server ServerCapabilities models.ServerCapabilities // an overridable Println implementation that defaults to using // the fmt package version from the stdlib. Println func(v ...interface{}) // an overridable Printf implementation that defaults to using // the fmt package version from the stdlib. Printf func(format string, v ...interface{}) // the HTTPS TLS public crt file TLSCrt string // the HTTPS TLS private key file TLSKey string // extra strict file checking during sync operations ExtraStrict bool }
State tracks the state of the freezer commands during execution.
func (*State) AddUser ¶
func (s *State) AddUser(store *filefreezer.Storage, username string, password string, quota int) (*filefreezer.User, error)
AddUser adds a user to the database using the username, password and quota provided. The store object will take care of generating the salt and salted password.
func (*State) Authenticate ¶
Authenticate will use a HTTP call to authenticate the user and set the the JWT authentication token string in the command State object.
func (*State) DecryptString ¶
decryptString will decrypt the source base64 encoded string into crypto bytes and then return the result as a string.
func (*State) EncryptString ¶
encryptString will encrypt the source string bytes and then return a base64 encoded string version of the crypto bytes
func (*State) GetAllFileHashes ¶
func (s *State) GetAllFileHashes() ([]filefreezer.FileInfo, error)
GetAllFileHashes returns a slice of FileInfo objects for all files registered to the authenticated user in the command State. A non-nil error value is returned on failure.
func (*State) GetFileInfoByFilename ¶
func (s *State) GetFileInfoByFilename(filename string) (foundFile filefreezer.FileInfo, e error)
GetFileInfoByFilename takes the long way of finding a FileInfo object by scanning all FileInfo objects registered for a given user. If a matching file is found it is returned and the error value will be null; otherwise an error will be set. NOTE: implemented like this to support encrypted filenames.
func (*State) GetFileVersions ¶
func (s *State) GetFileVersions(filename string) (versions []filefreezer.FileVersionInfo, err error)
GetFileVersions will return a slice of global version IDs and a matching slice of version numbers for the filename provided. A non-nil error is returned on error.
func (*State) GetMissingChunksForFile ¶
GetMissingChunksForFile will return a slice of chunk numbers (index starts at zero and is local to the specific file) for a given file located by file ID. A non-nil error is returned on error.
func (*State) GetUserStats ¶
func (s *State) GetUserStats() (stats filefreezer.UserStats, e error)
GetUserStats returns a UserStats object for the authenticated user in the command State. A non-nil error value is returned on failure.
func (*State) ModUser ¶
func (s *State) ModUser(store *filefreezer.Storage, username string, newQuota int, newUsername string, newPassword string) error
ModUser modifies a user in the database. if the newQuota, newUsername or newPassword fields are non-nil then their values are updated in the database.
func (*State) RmFile ¶
RmFile takes the filename and attempts to find it in the list of filenames registered on the storage server for the user. If it does find it, an API method is called to delete the object. If dryRun is set to true the file removal command is never executed. A non-nil error is returned on failure.
func (*State) RmFileByID ¶
RmFileByID takes the file id directly and an API method is called to delete the object. A non-nil error is returned on failure.
func (*State) RmFileVersions ¶
RmFileVersions removes a range of versions (inclusive) from minVersion to maxVersion from storage. A non-nil error is returned on failure.
func (*State) RmRxFileVersions ¶
func (s *State) RmRxFileVersions(pattern string, minVersion int, maxVersionStr string, dryRun bool) error
RmRxFileVersions removes a range of versions (inclusive) from minVersion to maxVersion from storage for all files matching a regexp pattern. A non-nil error is returned on failure.
func (*State) RmRxFiles ¶
RmRxFiles removes files by regular expression matching against the filenames. The dryRun argument controls whether or not the actual removeal request is sent to the server allowing the user to preview the result of the regex match. A non-nil error is returned on failure.
func (*State) RmUser ¶
func (s *State) RmUser(store *filefreezer.Storage, username string) error
RmUser removes a user from the database using the username as akey.
func (*State) RunAuthRequest ¶
func (s *State) RunAuthRequest(target string, method string, token string, reqBody interface{}) ([]byte, error)
RunAuthRequest will build the http client and request then get the response and read the body into a byte array. If reqBody is a []byte array, no transformation is done, but if it's another type than it gets marshalled to a text JSON object.
func (*State) SetCryptoHashForPassword ¶
SetCryptoHashForPassword sets the hash of the hash of the plaintext password on the server for the authenticated user in the command State. This can then be used to ensure the plaintext password entered by a user is the correct one to decrypt the files without actually storing the crypto key (the hashed plaintext password) on the server. A non-nil error value is returned on failure.
func (*State) SetQuiet ¶
SetQuiet will alter the Printf and Println functions to either write or suppress output depending on the quiet flag.
func (*State) SyncDirectory ¶
SyncDirectory will take a localDir and recursively walk the filesystem calling SyncFile for each file encountered. remoteDir can be specified to prefix the remote filepath for each file. The total number of changed chunks is returned and upon error a non-nil error value is returned.
func (*State) SyncFile ¶
func (s *State) SyncFile(localFilename string, remoteFilepath string, versionNum int) (status int, changeCount int, e error)
SyncFile will synchronize the localFilename which is identified as remoteFilepath on the server. A versionNum can also be specified (or left at <=0 for current version) to pick a particular version to sync. A sync status enumeration value is returned indicating if chunks were missing or whether or not the local or remote version were considered newer. The number of chunks changes is also returned and a non-nil error value is returned on error.