freeholdclient

package module
v0.0.0-...-515de08 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2015 License: MIT Imports: 13 Imported by: 0

README

Freehold Client

Freehold Client is a Go specific client API for interacting with a given freehold instance.

GoDoc API reference can be found here.

Usage is as follows:

	client, err := freeholdclient.New("https://freeholdinstance.org", "username", "passwordortoken", nil)
	if err != nil {
		panic(err)
	}

If you are running your freehold instance with a self-signed cert, you may want to specify your own cert handling using the optional tls config.

	client, err := freeholdclient.New("https://freeholdinstance.org", "username", "passwordortoken", 
		&tls.Config{InsecureSkipVerify: true}, //Ideally you'd setup proper cert authority validation
	)
	if err != nil {
		panic(err)
	}

It is recommended that when using the client that you generate a security token, and access the freehold instance, rather than storing the end user's password locally on the machine.

	client, err := freeholdclient.New(rootURL, username, password, tlsCfg)
	if err != nil {
		return err
	}

	token, err := client.NewToken("Token Name", "", "", time.Now().AddDate(0, 6, 0))
	if err != nil {
		return err
	}

	client, err = freeholdclient.New(rootURL, username, token.Token, tlsCfg)
	if err != nil {
		return err
	}

	//store token.Token for use later, and forget password

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

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

func (*Backup) WhenTime

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

WhenTime is the parsed Time from the 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 New

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

New creates a new Freehold Client tlsCfg is optional

func NewFromClient

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

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

AllApplications retrieves all installed applications

func (*Client) AllSessions

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

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

func (*Client) AllSettings

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

AllSettings retrieves all the current settings for the freehold instance

func (*Client) AllTokens

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

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

func (*Client) AllUsers

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

AllUsers retrieves all Users in the freehold instance

func (*Client) Auth

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

Auth returns authention information about the current user

func (*Client) AvailableApplications

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

AvailableApplications retrieves all the application files available for install

func (*Client) DefaultSetting

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

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

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

GetBackups retrieves the previously generated backups

func (*Client) GetDatastore

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

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

func (*Client) GetFile

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

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

func (*Client) GetLogs

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

GetLogs retrieves the logs that match the passed in Log Iterator

func (*Client) GetSetting

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

GetSetting gets a specific setting

func (*Client) GetToken

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

GetToken retrieves a specific token identified by the passed in id

func (*Client) GetUser

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

GetUser retrieves a User in the freehold instance

func (*Client) NewBackup

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

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

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

func (*Client) NewFolder

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

NewFolder creates a new folder on the freehold instance

func (*Client) NewToken

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

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

NewUser creates a new user

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

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

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

SetSetting sets the given setting's value

func (*Client) UploadDatastore

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

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

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

type Datastore struct {
	Property
}

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

func (*Datastore) Children

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

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

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

func (*Datastore) Drop

func (d *Datastore) Drop() error

Drop deletes the datastore file

func (*Datastore) Get

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

Get gets a value out of a freehold datastore

func (*Datastore) Iter

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

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

func (*Datastore) Max

func (d *Datastore) Max() *KeyValue

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

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

func (*Datastore) Min

func (d *Datastore) Min() *KeyValue

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

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

func (*Datastore) Put

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

Put puts a new key value pair into the datastore

func (*Datastore) PutObj

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

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

FHError is an error returned by a freehold instance

func (*FHError) Error

func (e *FHError) Error() string

type File

type File struct {
	Property
}

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

func (*File) Children

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

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

Move moves a file to a new location

func (*File) Update

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

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

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

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

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

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

WhenTime is the parsed Time from the Log

type LogIter

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

LogIter is used for iterating through freehold logs

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

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

func (p *Property) Close() error

Close closes the open reader

func (*Property) Delete

func (p *Property) Delete() error

Delete deletes a file / datastore

func (*Property) FullURL

func (p *Property) FullURL() string

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

func (*Property) ModifiedTime

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

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

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

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

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

func (*Session) Delete

func (s *Session) Delete() error

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

func (*Session) ExpiresTime

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

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

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

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

func (*Token) Delete

func (t *Token) Delete() error

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

func (*Token) ExpiresTime

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

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

func (u *User) Delete() error

Delete deletes a user

func (*User) SetAdmin

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

SetAdmin sets if the user is an admin or not

func (*User) SetHomeApp

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

SetHomeApp sets the user's home appliation

func (*User) SetName

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

SetName sets the user's name

func (*User) SetPassword

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

SetPassword sets the user's password

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL