freehold-client: bitbucket.org/tshannon/freehold-client Index | Files

package freeholdclient

import "bitbucket.org/tshannon/freehold-client"

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

Package Files

app.go auth.go backup.go client.go datastore.go error.go file.go log.go property.go session.go settings.go token.go user.go util.go

func IsNotFound Uses

func IsNotFound(err error) bool

IsNotFound returns whether or not the error is a 404

type Application Uses

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 Uses

func (a *Application) Uninstall() error

Uninstall removes the installed application from the freehold instance

type Auth Uses

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 Uses

type AvailableApplication struct {
    Application
    File string `json:"file,omitempty"`
}

AvailableApplication is an application file available for install to a freehold instance

func (*AvailableApplication) Install Uses

func (a *AvailableApplication) Install() (*Application, error)

Install installs the available application

func (*AvailableApplication) Upgrade Uses

func (a *AvailableApplication) Upgrade() (*Application, error)

Upgrade Upgrades a currently installed application

type Backup Uses

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

func (*Backup) WhenTime Uses

func (b *Backup) WhenTime() time.Time

WhenTime is the parsed Time from the Backup

type Client Uses

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 New Uses

func New(rootURL, username, passwordOrToken string) (*Client, error)

New creates a new Freehold Client tlsCfg is optional

func NewFromClient Uses

func NewFromClient(client *http.Client, rootURL, username, passwordOrToken string) (*Client, error)

NewFromClient creates a new freehold client from an existing http Client, which lets you set custom timeouts, tls config, etc

func (*Client) AllApplications Uses

func (c *Client) AllApplications() ([]*Application, error)

AllApplications retrieves all installed applications

func (*Client) AllSessions Uses

func (c *Client) AllSessions() ([]*Session, error)

AllSessions retrieves all sessions for the given user who made the client connection

func (*Client) AllSettings Uses

func (c *Client) AllSettings() (map[string]*Setting, error)

AllSettings retrieves all the current settings for the freehold instance

func (*Client) AllTokens Uses

func (c *Client) AllTokens() ([]*Token, error)

AllTokens retrieves all tokens for the given user who made the client connection

func (*Client) AllUsers Uses

func (c *Client) AllUsers() ([]*User, error)

AllUsers retrieves all Users in the freehold instance

func (*Client) Auth Uses

func (c *Client) Auth() (*Auth, error)

Auth returns authention information about the current user

func (*Client) AvailableApplications Uses

func (c *Client) AvailableApplications() ([]*AvailableApplication, error)

AvailableApplications retrieves all the application files available for install

func (*Client) DefaultSetting Uses

func (c *Client) DefaultSetting(settingName string) error

DefaultSetting sets the given setting's value

func (*Client) GetApplication Uses

func (c *Client) GetApplication(appID string) (*Application, error)

GetApplication retrieves a specific Application

func (*Client) GetBackups Uses

func (c *Client) GetBackups(from, to time.Time) ([]*Backup, error)

GetBackups retrieves the previously generated backups

func (*Client) GetDatastore Uses

func (c *Client) GetDatastore(filePath string) (*Datastore, error)

GetDatastore retrieves a datastore for reading or writing from a freehold instance

func (*Client) GetFile Uses

func (c *Client) GetFile(filePath string) (*File, error)

GetFile retrieves a file for reading or writing from a freehold instance

func (*Client) GetLogs Uses

func (c *Client) GetLogs(iter *LogIter) ([]*Log, error)

GetLogs retrieves the logs that match the passed in Log Iterator

func (*Client) GetSetting Uses

func (c *Client) GetSetting(settingName string) (*Setting, error)

GetSetting gets a specific setting

func (*Client) GetToken Uses

func (c *Client) GetToken(id string) (*Token, error)

GetToken retrieves a specific token identified by the passed in id

func (*Client) GetUser Uses

func (c *Client) GetUser(username string) (*User, error)

GetUser retrieves a User in the freehold instance

func (*Client) NewBackup Uses

func (c *Client) NewBackup(optionalFile string, optionalDSList []string) (string, error)

NewBackup Generates a new freehold instance backup, and returns the path to the backup file

func (*Client) NewDatastore Uses

func (c *Client) NewDatastore(filePath string) (*Datastore, error)

NewDatastore creates a new datastore file at the path, passed in

func (*Client) NewFolder Uses

func (c *Client) NewFolder(folderPath string) error

NewFolder creates a new folder on the freehold instance

func (*Client) NewToken Uses

func (c *Client) NewToken(name, resource, permission string, expires time.Time) (*Token, error)

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) NewUser Uses

func (c *Client) NewUser(username, password, name, homeApp string, isAdmin bool) (*User, error)

NewUser creates a new user

func (*Client) PostAvailableApplication Uses

func (c *Client) PostAvailableApplication(url string) (*AvailableApplication, error)

PostAvailableApplication posts a new available application for install from the passed in URL

func (*Client) RootURL Uses

func (c *Client) RootURL() *url.URL

RootURL returns the Root of this freehold client I.E. the domain + port that all requests will be made with

func (*Client) SetSetting Uses

func (c *Client) SetSetting(settingName string, value interface{}) error

SetSetting sets the given setting's value

func (*Client) UploadDatastore Uses

func (c *Client) UploadDatastore(dsFile *os.File, dest *File) (*Datastore, error)

UploadDatastore uploads a local datstore file to the freehold instance and returns a Datastore Dest must be a Dir

func (*Client) UploadFile Uses

func (c *Client) UploadFile(file *os.File, dest *File) (*File, error)

UploadFile uploads a local file to the freehold instance and returns a File type. Dest must be a Dir

func (*Client) UploadFromReader Uses

func (c *Client) UploadFromReader(fileName string, r io.Reader, size int64, modTime time.Time, dest *File) (*File, error)

UploadFromReader uploads file data from the passed in reader size is required and dest must be a directory on the freehold instance

type Datastore Uses

type Datastore struct {
    Property
}

Datastore is a datastore stored on freehold instance and the properties associated with it

func (*Datastore) Children Uses

func (d *Datastore) Children() ([]*File, error)

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) Delete Uses

func (d *Datastore) Delete(key interface{}) error

Delete deletes the value from the datastore for the passed in key

func (*Datastore) Drop Uses

func (d *Datastore) Drop() error

Drop deletes the datastore file

func (*Datastore) Get Uses

func (d *Datastore) Get(key, returnValue interface{}) error

Get gets a value out of a freehold datastore

func (*Datastore) Iter Uses

func (d *Datastore) Iter(iter *Iter) ([]*KeyValue, error)

Iter returns the list of key / values matched by the passed in interator

func (*Datastore) Max Uses

func (d *Datastore) Max() *KeyValue

Max gets the maximum key / value in the datastore Example:

err := ds.Max().Key(&result)

func (*Datastore) Min Uses

func (d *Datastore) Min() *KeyValue

Min gets the minimum key / value in the datastore Example:

err := ds.Min().Value(&result)

func (*Datastore) Put Uses

func (d *Datastore) Put(key, value interface{}) error

Put puts a new key value pair into the datastore

func (*Datastore) PutObj Uses

func (d *Datastore) PutObj(object interface{}) error

PutObj puts the entire passed in object into the datastore Top level keys become the basis for the key / values object must be able to be marshalled into a json string

type FHError Uses

type FHError struct {
    // contains filtered or unexported fields
}

FHError is an error returned by a freehold instance

func (*FHError) Error Uses

func (e *FHError) Error() string

type File Uses

type File struct {
    Property
}

File is a file stored on freehold instance and the properties associated with it

func (*File) Children Uses

func (f *File) Children() ([]*File, error)

Children returns the child files (if any) of the given folder Calling Children on a non-dir file will not error but return an empty slice

func (*File) Move Uses

func (f *File) Move(to string) error

Move moves a file to a new location

func (*File) Update Uses

func (f *File) Update(r io.Reader, size int64) error

Update overwrites the given file with the bytes read from r Size is the total size to be read from r, and a limitReader is used to enforce this

type Iter Uses

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 Uses

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 Uses

func (kv *KeyValue) Key(result interface{}) error

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

func (*KeyValue) Value Uses

func (kv *KeyValue) Value(result interface{}) error

Value 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().Value(&result) and consolidate your error checking into one call

type Log Uses

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

func (*Log) WhenTime Uses

func (l *Log) WhenTime() time.Time

WhenTime is the parsed Time from the Log

type LogIter Uses

type LogIter struct {
    Iter
    Type string `json:"type,omitempty"`
}

LogIter is used for iterating through freehold logs

type Permission Uses

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 Uses

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 Uses

func (p *Property) Children() ([]Property, error)

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) Close Uses

func (p *Property) Close() error

Close closes the open reader

func (*Property) Delete Uses

func (p *Property) Delete() error

Delete deletes a file / datastore

func (*Property) FullURL Uses

func (p *Property) FullURL() string

FullURL returns the full url of the file / datstore including the root of the freehold instance

func (*Property) ModifiedTime Uses

func (p *Property) ModifiedTime() time.Time

ModifiedTime is the parsed date and time from the modified string value returned from the freehold REST API

func (*Property) Read Uses

func (p *Property) Read(b []byte) (n int, err error)

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 Uses

func (p *Property) SetPermission(prm *Permission) error

SetPermission sets the current file / datastore's permissions to those passed in

type Session Uses

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 Uses

func (s *Session) CreatedTime() time.Time

CreatedTime is the parsed Time from the Session's JSON string response

func (*Session) Delete Uses

func (s *Session) Delete() error

Delete deletes the current session from the freehold instance making it invalid for all future uses

func (*Session) ExpiresTime Uses

func (s *Session) ExpiresTime() time.Time

ExpiresTime is the parsed Time from the Session's JSON string response

type Setting Uses

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 Uses

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 Uses

func (t *Token) CreatedTime() time.Time

CreatedTime is the parsed Time from the Token's JSON string response

func (*Token) Delete Uses

func (t *Token) Delete() error

Delete deletes the current token from the freehold instance making it invalid for all future uses

func (*Token) ExpiresTime Uses

func (t *Token) ExpiresTime() time.Time

ExpiresTime is the parsed Time from the Token's JSON string response

type User Uses

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) Delete Uses

func (u *User) Delete() error

Delete deletes a user

func (*User) SetAdmin Uses

func (u *User) SetAdmin(isAdmin bool) error

SetAdmin sets if the user is an admin or not

func (*User) SetHomeApp Uses

func (u *User) SetHomeApp(newHomeApp string) error

SetHomeApp sets the user's home appliation

func (*User) SetName Uses

func (u *User) SetName(newName string) error

SetName sets the user's name

func (*User) SetPassword Uses

func (u *User) SetPassword(newPassword string) error

SetPassword sets the user's password

Package freeholdclient imports 13 packages (graph). Updated 2016-07-15. Refresh now. Tools for package owners.