Documentation
¶
Overview ¶
Package freeholdclient is a Go client for interacting with a freehold instance. When using the freehold client it is recommended to generate a token and use that rather than storing a users password locally in cleartext
Index ¶
- func IsNotFound(err error) bool
- type Application
- type Auth
- type AvailableApplication
- type Backup
- type Client
- func (c *Client) AllApplications() ([]*Application, error)
- func (c *Client) AllSessions() ([]*Session, error)
- func (c *Client) AllSettings() (map[string]*Setting, error)
- func (c *Client) AllTokens() ([]*Token, error)
- func (c *Client) AllUsers() ([]*User, error)
- func (c *Client) Auth() (*Auth, error)
- func (c *Client) AvailableApplications() ([]*AvailableApplication, error)
- func (c *Client) DefaultSetting(settingName string) error
- func (c *Client) GetApplication(appID string) (*Application, error)
- func (c *Client) GetBackups(from, to time.Time) ([]*Backup, error)
- func (c *Client) GetDatastore(filePath string) (*Datastore, error)
- func (c *Client) GetFile(filePath string) (*File, error)
- func (c *Client) GetLogs(iter *LogIter) ([]*Log, error)
- func (c *Client) GetSetting(settingName string) (*Setting, error)
- func (c *Client) GetToken(id string) (*Token, error)
- func (c *Client) GetUser(username string) (*User, error)
- func (c *Client) NewBackup(optionalFile string, optionalDSList []string) (string, error)
- func (c *Client) NewDatastore(filePath string) (*Datastore, error)
- func (c *Client) NewFolder(folderPath string) error
- func (c *Client) NewToken(name, resource, permission string, expires time.Time) (*Token, error)
- func (c *Client) NewUser(username, password, name, homeApp string, isAdmin bool) (*User, error)
- func (c *Client) PostAvailableApplication(url string) (*AvailableApplication, error)
- func (c *Client) RootURL() *url.URL
- func (c *Client) SetSetting(settingName string, value interface{}) error
- func (c *Client) UploadDatastore(dsFile *os.File, dest *File) (*Datastore, error)
- func (c *Client) UploadFile(file *os.File, dest *File) (*File, error)
- func (c *Client) UploadFromReader(fileName string, r io.Reader, size int64, modTime time.Time, dest *File) (*File, error)
- type Datastore
- func (d *Datastore) Children() ([]*File, error)
- func (d *Datastore) Delete(key interface{}) error
- func (d *Datastore) Drop() error
- func (d *Datastore) Get(key, returnValue interface{}) error
- func (d *Datastore) Iter(iter *Iter) ([]*KeyValue, error)
- func (d *Datastore) Max() *KeyValue
- func (d *Datastore) Min() *KeyValue
- func (d *Datastore) Put(key, value interface{}) error
- func (d *Datastore) PutObj(object interface{}) error
- type FHError
- type File
- type Iter
- type KeyValue
- type Log
- type LogIter
- type Permission
- type Property
- func (p *Property) Children() ([]Property, error)
- func (p *Property) Close() error
- func (p *Property) Delete() error
- func (p *Property) FullURL() string
- func (p *Property) ModifiedTime() time.Time
- func (p *Property) Read(b []byte) (n int, err error)
- func (p *Property) SetPermission(prm *Permission) error
- type Session
- type Setting
- type Token
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶
IsNotFound returns whether or not the error is a 404
Types ¶
type Application ¶
type Application struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` Author string `json:"author,omitempty"` Root string `json:"root,omitempty"` Icon string `json:"icon,omitempty"` Version string `json:"version,omitempty"` // contains filtered or unexported fields }
Application is the structure of an Application Install
func (*Application) Uninstall ¶
func (a *Application) Uninstall() error
Uninstall removes the installed application from the freehold instance
type Auth ¶
type Auth struct { AuthType string `json:"type"` Username string `json:"user,omitempty"` *User *Token }
Auth contains the type and identity of a user in Freehold if user == nil, then auth is public access
type AvailableApplication ¶
type AvailableApplication struct { Application File string `json:"file,omitempty"` }
AvailableApplication is an application file available for install to a freehold instance
func (*AvailableApplication) Install ¶
func (a *AvailableApplication) Install() (*Application, error)
Install installs the available application
func (*AvailableApplication) Upgrade ¶
func (a *AvailableApplication) Upgrade() (*Application, error)
Upgrade Upgrades a currently installed application
type Backup ¶
type Backup struct { When string `json:"when"` File string `json:"file"` Who string `json:"who"` Datastores []string `json:"datastores"` // contains filtered or unexported fields }
Backup is the structure of a freehold backup
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is used for interacting with a Freehold Instance A Client needs a url, username, and password or token After the client is initialized, all requests should be run against the path of the file, ds, etc in question /v1/file/test.txt instead of the full url https://freeholdinstance/v1/file/test.txt
It is highly encouraged to not store a user's password, and instead use a Security Token generated for this specific client
func NewFromClient ¶
NewFromClient creates a new freehold client from an existing http Client, which lets you set custom timeouts, tls config, etc
func (*Client) AllApplications ¶
func (c *Client) AllApplications() ([]*Application, error)
AllApplications retrieves all installed applications
func (*Client) AllSessions ¶
AllSessions retrieves all sessions for the given user who made the client connection
func (*Client) AllSettings ¶
AllSettings retrieves all the current settings for the freehold instance
func (*Client) AllTokens ¶
AllTokens retrieves all tokens for the given user who made the client connection
func (*Client) AvailableApplications ¶
func (c *Client) AvailableApplications() ([]*AvailableApplication, error)
AvailableApplications retrieves all the application files available for install
func (*Client) DefaultSetting ¶
DefaultSetting sets the given setting's value
func (*Client) GetApplication ¶
func (c *Client) GetApplication(appID string) (*Application, error)
GetApplication retrieves a specific Application
func (*Client) GetBackups ¶
GetBackups retrieves the previously generated backups
func (*Client) GetDatastore ¶
GetDatastore retrieves a datastore for reading or writing from a freehold instance
func (*Client) GetSetting ¶
GetSetting gets a specific setting
func (*Client) NewBackup ¶
NewBackup Generates a new freehold instance backup, and returns the path to the backup file
func (*Client) NewDatastore ¶
NewDatastore creates a new datastore file at the path, passed in
func (*Client) NewToken ¶
NewToken generates a new token with the passed in values. Only Name is required. Depending on the freehold settings this call may need to be made from a client which has a users password specified instead of another token
func (*Client) PostAvailableApplication ¶
func (c *Client) PostAvailableApplication(url string) (*AvailableApplication, error)
PostAvailableApplication posts a new available application for install from the passed in URL
func (*Client) RootURL ¶
RootURL returns the Root of this freehold client I.E. the domain + port that all requests will be made with
func (*Client) SetSetting ¶
SetSetting sets the given setting's value
func (*Client) UploadDatastore ¶
UploadDatastore uploads a local datstore file to the freehold instance and returns a Datastore Dest must be a Dir
func (*Client) UploadFile ¶
UploadFile uploads a local file to the freehold instance and returns a File type. Dest must be a Dir
type Datastore ¶
type Datastore struct {
Property
}
Datastore is a datastore stored on freehold instance and the properties associated with it
func (*Datastore) Children ¶
Children returns the child datastores (if any) of the given folder Calling Children on a non-dir file will not error but return an empty slice
func (*Datastore) Max ¶
Max gets the maximum key / value in the datastore Example:
err := ds.Max().Key(&result)
func (*Datastore) Min ¶
Min gets the minimum key / value in the datastore Example:
err := ds.Min().Value(&result)
type FHError ¶
type FHError struct {
// contains filtered or unexported fields
}
FHError is an error returned by a freehold instance
type File ¶
type File struct {
Property
}
File is a file stored on freehold instance and the properties associated with it
type Iter ¶
type Iter struct { From interface{} `json:"from,omitempty"` To interface{} `json:"to,omitempty"` Skip int `json:"skip,omitempty"` Limit int `json:"limit,omitempty"` Regexp string `json:"regexp,omitempty"` Order string `json:"order,omitempty"` }
Iter is for iterating through a datastore
type KeyValue ¶
type KeyValue struct { K *json.RawMessage `json:"key,omitempty"` V *json.RawMessage `json:"value,omitempty"` // contains filtered or unexported fields }
KeyValue is a key value pair returned from a datastore
func (*KeyValue) Key ¶
Key is a convience function for unmarshalling the key from the KeyValue, will return any errors from the retrieval of this key first So you can run requests like err := ds.Min().Key(&result) and consolidate your error checking into one call
type Log ¶
type Log struct { When string `json:"when"` Type string `json:"type"` Log string `json:"log"` // contains filtered or unexported fields }
Log is the storage stucture for a log entry
type Permission ¶
type Permission struct { Owner string `json:"owner,omitempty"` Public string `json:"public,omitempty"` Friend string `json:"friend,omitempty"` Private string `json:"private,omitempty"` }
Permission is the client side definition of a Freehold Permission
type Property ¶
type Property struct { Name string `json:"name,omitempty"` URL string `json:"url,omitempty"` Permissions *Permission `json:"permissions,omitempty"` Size int64 `json:"size,omitempty"` Modified string `json:"modified,omitempty"` IsDir bool `json:"isDir,omitempty"` // contains filtered or unexported fields }
Property is a set of datastore or file properties from a freehold instance
func (*Property) Children ¶
Children returns the child files / datastores (if any) of the given folder Calling Children on a non-dir file will not error but return an empty slice
func (*Property) FullURL ¶
FullURL returns the full url of the file / datstore including the root of the freehold instance
func (*Property) ModifiedTime ¶
ModifiedTime is the parsed date and time from the modified string value returned from the freehold REST API
func (*Property) Read ¶
Reads data from the freehold instance on the given file or datastore (GET file data) Close() needs to be called when read is completed
func (*Property) SetPermission ¶
func (p *Property) SetPermission(prm *Permission) error
SetPermission sets the current file / datastore's permissions to those passed in
type Session ¶
type Session struct { ID string `json:"id,omitempty"` Expires string `json:"expires,omitempty"` CSRFToken string `json:"CSRFToken,omitempty"` IPAddress string `json:"ipAddress,omitempty"` Created string `json:"created,omitempty"` UserAgent string `json:"userAgent,omitempty"` // contains filtered or unexported fields }
Session is a freehold session, tracked by a cookie
func (*Session) CreatedTime ¶
CreatedTime is the parsed Time from the Session's JSON string response
func (*Session) Delete ¶
Delete deletes the current session from the freehold instance making it invalid for all future uses
func (*Session) ExpiresTime ¶
ExpiresTime is the parsed Time from the Session's JSON string response
type Setting ¶
type Setting struct { Description string `json:"description,omitempty"` Value interface{} `json:"value,omitempty"` }
Setting is a value that changes how the freehold instance operates
type Token ¶
type Token struct { Token string `json:"token,omitempty"` // Unique identifier used for authentication ID string `json:"id,omitempty"` //Unique identifier used for identification Name string `json:"name,omitempty"` Expires string `json:"expires,omitempty"` Resource string `json:"resource,omitempty"` Permission string `json:"permission,omitempty"` Created string `json:"created,omitempty"` // contains filtered or unexported fields }
Token is the client side defintion to hold the Token data returned from a freehold instance. a Token is a unique identifier which can grant access to a specific resource, or to everything a user has
func (*Token) CreatedTime ¶
CreatedTime is the parsed Time from the Token's JSON string response
func (*Token) Delete ¶
Delete deletes the current token from the freehold instance making it invalid for all future uses
func (*Token) ExpiresTime ¶
ExpiresTime is the parsed Time from the Token's JSON string response
type User ¶
type User struct { Username string `json:"-"` Name string `json:"name,omitempty"` Password string `json:"password,omitempty"` HomeApp string `json:"homeApp,omitempty"` Admin bool `json:"admin,omitempty"` // contains filtered or unexported fields }
User is a user in a freehold instance
func (*User) SetHomeApp ¶
SetHomeApp sets the user's home appliation
func (*User) SetPassword ¶
SetPassword sets the user's password