Documentation ¶
Index ¶
- Constants
- Variables
- func ConfigNameFromPath(fullpath string) string
- func ConfigPathFromName(backendPath, backendName string) string
- func CreateFileRow(bk Backend, pairs types.TagPairs, filename string, plaintags []string) (*types.Row, error)
- func CreateJSONRow(bk Backend, pairs types.TagPairs, obj interface{}, plaintags []string) (*types.Row, error)
- func CreateRow(bk Backend, pairs types.TagPairs, rowData []byte, plaintags []string) (*types.Row, error)
- func CreateTag(bk Backend, plaintag string) (*types.TagPair, error)
- func CreateTagsFromPlain(bk Backend, plaintags []string, pairs types.TagPairs) (newPairs types.TagPairs, err error)
- func DeleteRows(bk Backend, pairs types.TagPairs, plaintags cryptag.PlainTags) error
- func DropboxConfigToMap(cfg DropboxConfig) map[string]interface{}
- func GetMaker(bkType string) (maker, error)
- func IsDefaultBackendSet(backendPath string) (bool, error)
- func ListRowsFromPlainTags(bk Backend, pairs types.TagPairs, plaintags cryptag.PlainTags) (types.Rows, error)
- func NewTagPair(key *[32]byte, plaintag string) (*types.TagPair, error)
- func PopulateRowBeforeSave(bk Backend, row *types.Row, pairs types.TagPairs) (newPairs types.TagPairs, err error)
- func RegisterMaker(bkType string, f maker) error
- func RowsFromPlainTags(bk Backend, pairs types.TagPairs, plaintags cryptag.PlainTags) (types.Rows, error)
- func SandstormWebKeyToMap(webkey string) map[string]interface{}
- func Save(bk Backend) error
- func SetDefaultBackend(backendPath, newDefault string) error
- func UpdateFileRow(bk Backend, pairs types.TagPairs, prevIDTag string, newFilename string) (*types.Row, error)
- func UpdateKey(bk Backend, newKey interface{}) error
- func UpdateRow(bk Backend, pairs types.TagPairs, prevIDTag string, newData []byte) (*types.Row, error)
- func UpdateRowAdvanced(bk Backend, pairs types.TagPairs, oldRow *types.Row, newData []byte, ...) (*types.Row, error)
- func WebserverConfigToMap(cfg WebserverConfig) map[string]interface{}
- type Backend
- func Create(bkType, bkName string, args []string) (Backend, error)
- func CreateFromConfig(bkPath string, cfg *Config) (Backend, error)
- func LoadBackend(backendPath, backendName string) (Backend, error)
- func New(cfg *Config) (Backend, error)
- func ReadBackends(backendPath, bkPattern string) ([]Backend, error)
- type Config
- type DropboxConfig
- type DropboxRemote
- func (db *DropboxRemote) AllTagPairs(oldPairs types.TagPairs) (types.TagPairs, error)
- func (db *DropboxRemote) DeleteRows(randTags cryptag.RandomTags) error
- func (db *DropboxRemote) GetTagCursor() string
- func (db *DropboxRemote) Key() *[32]byte
- func (db *DropboxRemote) ListRows(randtags cryptag.RandomTags) (types.Rows, error)
- func (db *DropboxRemote) Name() string
- func (db *DropboxRemote) RowsFromRandomTags(randtags cryptag.RandomTags) (types.Rows, error)
- func (db *DropboxRemote) SaveRow(row *types.Row) error
- func (db *DropboxRemote) SaveTagPair(pair *types.TagPair) error
- func (db *DropboxRemote) SetHTTPClient(c *http.Client)
- func (db *DropboxRemote) SetTagCursor(cursor string)
- func (db *DropboxRemote) TagPairsFromRandomTags(randtags cryptag.RandomTags) (types.TagPairs, error)
- func (db *DropboxRemote) ToConfig() (*Config, error)
- func (db *DropboxRemote) UseTor() error
- type FileSystem
- func (fs *FileSystem) AllTagPairs(oldPairs types.TagPairs) (types.TagPairs, error)
- func (fs *FileSystem) DeleteRows(randTags cryptag.RandomTags) error
- func (fs *FileSystem) Key() *[32]byte
- func (fs *FileSystem) ListRows(randtags cryptag.RandomTags) (types.Rows, error)
- func (fs *FileSystem) Name() string
- func (fs *FileSystem) RowsFromRandomTags(randtags cryptag.RandomTags) (types.Rows, error)
- func (fs *FileSystem) SaveRow(row *types.Row) error
- func (fs *FileSystem) SaveTagPair(pair *types.TagPair) error
- func (fs *FileSystem) TagPairsFromRandomTags(randtags cryptag.RandomTags) (types.TagPairs, error)
- func (fs *FileSystem) ToConfig() (*Config, error)
- type WebserverBackend
- func CreateSandstormWebserver(key []byte, bkName, webkey string) (*WebserverBackend, error)
- func CreateWebserver(key []byte, backendName, baseURL, authToken string) (*WebserverBackend, error)
- func LoadWebserverBackend(backendPath, backendName string) (*WebserverBackend, error)
- func NewWebserverBackend(key []byte, serverName, serverBaseUrl, authToken string) (*WebserverBackend, error)
- func SandstormFromConfig(cfg *Config) (*WebserverBackend, error)
- func WebserverFromConfig(conf *Config) (*WebserverBackend, error)
- func (wb *WebserverBackend) AllTagPairs(oldPairs types.TagPairs) (types.TagPairs, error)
- func (wb *WebserverBackend) DeleteRows(randtags cryptag.RandomTags) error
- func (wb *WebserverBackend) Key() *[32]byte
- func (wb *WebserverBackend) ListRows(randtags cryptag.RandomTags) (types.Rows, error)
- func (wb *WebserverBackend) Name() string
- func (wb *WebserverBackend) RowsFromRandomTags(randtags cryptag.RandomTags) (types.Rows, error)
- func (wb *WebserverBackend) SaveRow(row *types.Row) error
- func (wb *WebserverBackend) SaveTagPair(pair *types.TagPair) error
- func (wb *WebserverBackend) SetHTTPClient(client *http.Client)
- func (wb *WebserverBackend) TagPairsFromRandomTags(randtags cryptag.RandomTags) (types.TagPairs, error)
- func (wb *WebserverBackend) ToConfig() (*Config, error)
- func (wb *WebserverBackend) UseTor() error
- type WebserverConfig
Constants ¶
const ( TypeDropboxRemote = "dropbox" TypeFileSystem = "filesystem" TypeWebserver = "webserver" TypeSandstorm = "sandstorm" // Uses webserver + WebserverBackend code )
Variables ¶
var ( RANDOM_TAG_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789" RANDOM_TAG_LENGTH = 9 ErrBackendExists = errors.New("Backend already exists") )
var (
ErrConfigExists = errors.New("Backend config already exists")
)
var (
ErrMakerNotFound = errors.New("Backend maker func not found")
)
var (
ErrNilConfig = errors.New("Backend Config is nil")
)
var (
ErrNilCustom = errors.New("Field 'Custom' cannot be nil!")
)
var (
ErrNoDefaultBackend = errors.New("backend: no default backend set;" +
" specify a backend explicitly or set a default to use")
)
var (
ErrWrongBackendType = errors.New("backend: wrong Backend type")
)
var (
HttpGetTimeout = 300 * time.Second
)
Functions ¶
func ConfigNameFromPath ¶
func ConfigPathFromName ¶
func CreateFileRow ¶
func CreateJSONRow ¶
func CreateTag ¶
CreateTag uses NewTagPair to create a new TagPair, then saves said TagPair in backend.
func CreateTagsFromPlain ¶
func CreateTagsFromPlain(bk Backend, plaintags []string, pairs types.TagPairs) (newPairs types.TagPairs, err error)
CreateTagsFromPlain concurrently creates new TagPairs for each plaintag that doesn't already have a corresponding PlainTag in pairs. (Be sure that pairs contains the latest TagPairs contained in backend.)
func DeleteRows ¶
func DropboxConfigToMap ¶
func DropboxConfigToMap(cfg DropboxConfig) map[string]interface{}
func GetMaker ¶
GetMaker returns a Backend maker function that will make a Backend of the specified type. If no such Backend has been registered, ErrMakerNotFound is returned.
func IsDefaultBackendSet ¶
Checks if a default backend is set. Returns true if so, false otherwise.
func ListRowsFromPlainTags ¶
func NewTagPair ¶
NewTagPair creates a (cryptographically secure pseudorandom) RandomTag that corresponds to the given PlainTag, generates a new nonce, encrypts the PlainTag, then creates and returns the newly allocated TagPair.
func PopulateRowBeforeSave ¶
func PopulateRowBeforeSave(bk Backend, row *types.Row, pairs types.TagPairs) (newPairs types.TagPairs, err error)
PopulateRowBeforeSave creates a new TagPair for each plaintag unique to row, sets row.RandomTags, and sets row.Encrypted. row is now ready to be saved to a Backend.
func RegisterMaker ¶
RegisterMaker registers a new Backend maker function by type. Suitable for placing in an init() function in the file where a new Backend type has been defined.
func RowsFromPlainTags ¶
func SandstormWebKeyToMap ¶
func SetDefaultBackend ¶
SetDefaultBackend sets the default Backend to newDefault by creating a symlink from (newDefault).json to default.json
func UpdateFileRow ¶
func UpdateFileRow(bk Backend, pairs types.TagPairs, prevIDTag string, newFilename string) (*types.Row, error)
UpdateFileRow finds the Row uniquely picked out by prevIDTag then creates a new Row consisting of the contents of newFilename and the tags from the Row being updated (after replacing id:..., created:..., and filename:..., and adding a origversionrow:... tag).
func UpdateKey ¶
newKey can be of type *[32]byte, []byte (with length 32), or a string to be parsed with keyutil.Parse.
func UpdateRow ¶
func UpdateRow(bk Backend, pairs types.TagPairs, prevIDTag string, newData []byte) (*types.Row, error)
UpdateRow creates a new version of the Row whose ID tag is prevIDTag, but replaces the "id:..." and "created:..." tags. It then adds an "origversionrow:..." tag if one does not already exist which points to the ID tag of the original Row being versioned here.
func UpdateRowAdvanced ¶
func UpdateRowAdvanced(bk Backend, pairs types.TagPairs, oldRow *types.Row, newData []byte, newishTags []string) (*types.Row, error)
UpdateRowAdvanced creates a new version of oldRow but with updated tags that begin with newishTags, remove the "id:...", "created:...", and "all" tags, and will add an "origversionrow:..." tag that points to the ID tag of the original Row being versioned here (or keep the existing "origversionrow:..." tag).
If the plaintags that the new, updated row should have doesn't require any pre-processing, newishTags can simply be oldRow.PlainTags(). (You may want your pre-processing step to add tags like `prevversionrow:...` or user-specified tags.)
func WebserverConfigToMap ¶
func WebserverConfigToMap(cfg WebserverConfig) map[string]interface{}
Types ¶
type Backend ¶
type Backend interface { Name() string Key() *[32]byte AllTagPairs(oldPairs types.TagPairs) (types.TagPairs, error) TagPairsFromRandomTags(randtags cryptag.RandomTags) (types.TagPairs, error) SaveTagPair(pair *types.TagPair) error ListRows(randtags cryptag.RandomTags) (types.Rows, error) RowsFromRandomTags(randtags cryptag.RandomTags) (types.Rows, error) SaveRow(row *types.Row) error DeleteRows(randtags cryptag.RandomTags) error ToConfig() (*Config, error) }
Backend is an interface that represents a type of storage location for data, such as a filesystem or remote API.
func Create ¶
Create persists a new Backend Config to disk. DEPRECATED; use CreateFromConfig instead.
func CreateFromConfig ¶
CreateFromConfig persists a new Backend Config to disk using cfg, then returns a new Backend based on cfg.
func LoadBackend ¶
func ReadBackends ¶
ReadBackends reads all the Backend Configs at backendPath whose names match the pattern bkPattern, turns them into Backends, then returns all the successfully created Backends.
type Config ¶
type Config struct { Name string Type string // Should be one of: backend.Type* New bool `json:"-"` Key *[32]byte Local bool DataPath string // Used by backend.FileSystem, other local backends Custom map[string]interface{} `json:",omitempty"` // Used by Dropbox, Webserver, other backends }
Config represents the configuration info for a Backend. Configs store things like which type of Backend this is the config for (e.g., filesystem or webserver), the base URL of the Backend (if it's remote), API tokens, etc.
func ReadConfig ¶
ReadConfig reads, parses, and unmarshals the Backend Config file with the name backendName and returns it.
func ReadConfigs ¶
ReadConfigs reads, parses, and unmarshals the Backend Config files located in backendPath (defaults to cryptag.BackendPath) and that matches the pattern bkPattern.
func (*Config) Backup ¶
Backup creates a backup of this Config to (backendsDir)/(conf.Name).json-$timestamp
func (*Config) Canonicalize ¶
Canonicalize makes changes to this Config to ensure that it is valid and returns an error when this cannot be ensured and no correction can be safely made (e.g., if conf.Name is empty). Useful while ensuring correctness of a new-created Config and right before saving one.
func (*Config) GetType ¶
GetType returns the type of conf. Preferable to using .Type directly because this detects legacy Backend Configs with type TypeFileSystem, TypeWebserver, and TypeDropboxRemote.
type DropboxConfig ¶
type DropboxConfig struct { AppKey string AppSecret string AccessToken string BasePath string // e.g., "/cryptag_folder_in_dropbox_root" }
func DropboxConfigFromMap ¶
func DropboxConfigFromMap(m map[string]interface{}) (DropboxConfig, error)
func (*DropboxConfig) Valid ¶
func (dc *DropboxConfig) Valid() error
type DropboxRemote ¶
type DropboxRemote struct {
// contains filtered or unexported fields
}
DropboxRemote represents a Dropbox folder that is being used to store data in. Implements backend.Backend.
func DropboxRemoteFromConfig ¶
func DropboxRemoteFromConfig(conf *Config) (*DropboxRemote, error)
DropboxRemoteFromConfig turns conf into a DropboxRemote Backend.
func LoadDropboxRemote ¶
func LoadDropboxRemote(backendPath, backendName string) (*DropboxRemote, error)
LoadDropboxRemote tries to load a DropboxRemote Backend named backendName. For legacy reasons, if backendName is empty, uses "dropbox"-$(hostname).
func NewDropboxRemote ¶
func NewDropboxRemote(key []byte, name string, cfg DropboxConfig) (*DropboxRemote, error)
NewDropboxRemote creates a new DropboxRemote using the given attributes and returns it.
For legacy reasons, will save this backend to disk if len(key) == 0 or name == "".
func (*DropboxRemote) AllTagPairs ¶
func (*DropboxRemote) DeleteRows ¶
func (db *DropboxRemote) DeleteRows(randTags cryptag.RandomTags) error
func (*DropboxRemote) GetTagCursor ¶
func (db *DropboxRemote) GetTagCursor() string
GetTagCursor gets the cursor for the remote tags directory used for incremental TagPair fetching.
func (*DropboxRemote) Key ¶
func (db *DropboxRemote) Key() *[32]byte
func (*DropboxRemote) ListRows ¶
func (db *DropboxRemote) ListRows(randtags cryptag.RandomTags) (types.Rows, error)
func (*DropboxRemote) Name ¶
func (db *DropboxRemote) Name() string
func (*DropboxRemote) RowsFromRandomTags ¶
func (db *DropboxRemote) RowsFromRandomTags(randtags cryptag.RandomTags) (types.Rows, error)
func (*DropboxRemote) SaveTagPair ¶
func (db *DropboxRemote) SaveTagPair(pair *types.TagPair) error
func (*DropboxRemote) SetHTTPClient ¶
func (db *DropboxRemote) SetHTTPClient(c *http.Client)
SetHTTPClient sets the underlying HTTP client used. Probably most useful for using a custom client that does proxied requests, perhaps through Tor.
func (*DropboxRemote) SetTagCursor ¶
func (db *DropboxRemote) SetTagCursor(cursor string)
SetTagCursor sets the cursor for the remote tags directory incremental TagPair fetching so it can be used for incremental TagPair fetching.
func (*DropboxRemote) TagPairsFromRandomTags ¶
func (db *DropboxRemote) TagPairsFromRandomTags(randtags cryptag.RandomTags) (types.TagPairs, error)
func (*DropboxRemote) ToConfig ¶
func (db *DropboxRemote) ToConfig() (*Config, error)
ToConfig converts db to a Backend Config. If db.key is nil, returns error.
func (*DropboxRemote) UseTor ¶
func (db *DropboxRemote) UseTor() error
UseTor sets db's HTTP client to one that uses Tor.
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
func LoadOrCreateDefaultFileSystemBackend ¶
func LoadOrCreateDefaultFileSystemBackend(backendPath, backendName string) (*FileSystem, error)
LoadOrCreateDefaultFileSystemBackend calls LoadOrCreateFileSystem then, if the returned FileSystem was just created anew, makes it the default Backend.
func LoadOrCreateFileSystem ¶
func LoadOrCreateFileSystem(backendPath, backendName string) (*FileSystem, error)
func NewFileSystem ¶
func NewFileSystem(conf *Config) (*FileSystem, error)
func (*FileSystem) AllTagPairs ¶
func (*FileSystem) DeleteRows ¶
func (fs *FileSystem) DeleteRows(randTags cryptag.RandomTags) error
func (*FileSystem) Key ¶
func (fs *FileSystem) Key() *[32]byte
func (*FileSystem) ListRows ¶
func (fs *FileSystem) ListRows(randtags cryptag.RandomTags) (types.Rows, error)
func (*FileSystem) Name ¶
func (fs *FileSystem) Name() string
func (*FileSystem) RowsFromRandomTags ¶
func (fs *FileSystem) RowsFromRandomTags(randtags cryptag.RandomTags) (types.Rows, error)
func (*FileSystem) SaveTagPair ¶
func (fs *FileSystem) SaveTagPair(pair *types.TagPair) error
func (*FileSystem) TagPairsFromRandomTags ¶
func (fs *FileSystem) TagPairsFromRandomTags(randtags cryptag.RandomTags) (types.TagPairs, error)
func (*FileSystem) ToConfig ¶
func (fs *FileSystem) ToConfig() (*Config, error)
type WebserverBackend ¶
type WebserverBackend struct {
// contains filtered or unexported fields
}
func CreateSandstormWebserver ¶
func CreateSandstormWebserver(key []byte, bkName, webkey string) (*WebserverBackend, error)
func CreateWebserver ¶
func CreateWebserver(key []byte, backendName, baseURL, authToken string) (*WebserverBackend, error)
CreateWebserver is a high-level function that creates a new WebserverBackend and saves its config to disk. (Useful for config init and more.)
func LoadWebserverBackend ¶
func LoadWebserverBackend(backendPath, backendName string) (*WebserverBackend, error)
func NewWebserverBackend ¶
func NewWebserverBackend(key []byte, serverName, serverBaseUrl, authToken string) (*WebserverBackend, error)
func SandstormFromConfig ¶
func SandstormFromConfig(cfg *Config) (*WebserverBackend, error)
func WebserverFromConfig ¶
func WebserverFromConfig(conf *Config) (*WebserverBackend, error)
func (*WebserverBackend) AllTagPairs ¶
func (*WebserverBackend) DeleteRows ¶
func (wb *WebserverBackend) DeleteRows(randtags cryptag.RandomTags) error
func (*WebserverBackend) Key ¶
func (wb *WebserverBackend) Key() *[32]byte
func (*WebserverBackend) ListRows ¶
func (wb *WebserverBackend) ListRows(randtags cryptag.RandomTags) (types.Rows, error)
func (*WebserverBackend) Name ¶
func (wb *WebserverBackend) Name() string
func (*WebserverBackend) RowsFromRandomTags ¶
func (wb *WebserverBackend) RowsFromRandomTags(randtags cryptag.RandomTags) (types.Rows, error)
func (*WebserverBackend) SaveTagPair ¶
func (wb *WebserverBackend) SaveTagPair(pair *types.TagPair) error
func (*WebserverBackend) SetHTTPClient ¶
func (wb *WebserverBackend) SetHTTPClient(client *http.Client)
SetHTTPClient sets the underlying HTTP client used. Useful for using a custom client that does proxied requests, perhaps through Tor.
func (*WebserverBackend) TagPairsFromRandomTags ¶
func (wb *WebserverBackend) TagPairsFromRandomTags(randtags cryptag.RandomTags) (types.TagPairs, error)
func (*WebserverBackend) ToConfig ¶
func (wb *WebserverBackend) ToConfig() (*Config, error)
func (*WebserverBackend) UseTor ¶
func (wb *WebserverBackend) UseTor() error
UseTor sets wb's HTTP client to one that uses Tor and records that Tor should be used.
type WebserverConfig ¶
func WebserverConfigFromMap ¶
func WebserverConfigFromMap(m map[string]interface{}) (WebserverConfig, error)
func (*WebserverConfig) Valid ¶
func (wc *WebserverConfig) Valid() error