e3db

package module
v0.0.2-0...-385794c Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2017 License: MIT Imports: 22 Imported by: 0

README

Build Status Coverage Status

Overview

The Tozny End-to-End Encrypted Database (E3DB) is a storage platform with powerful sharing and consent management features. Read more on our blog.

E3DB provides a familiar JSON-based NoSQL-style API for reading, writing, and querying data stored securely in the cloud.

This repository contains a client library and command-line tool E3DB.

Build Prerequisites

e3db uses Glide for dependency management. For more information and installation instructions, see the Glide Web Site. Binaries for many platforms can be downloaded from the GitHub Releases Page.

Command-Line Interface

The E3DB command-line interface (CLI) is a powerful tool for administrating and interacting with the E3DB service. Binary releases for many platforms are available from this project's Releases page.

Building the CLI

To build a local version of the command-line interface, check out the sources into the appropriate location within $GOPATH, install dependencies using Glide, and build the github.com/tozny/e3db/cmd/e3db package:

git clone https://github.com/tozny/e3db-go $GOPATH/src/github.com/tozny/e3db-go
cd $GOPATH/src/github.com/tozny/e3db-go
glide install
go install ./cmd/e3db

Client Library

Installation

If your project uses Glide for managing dependencies and reproducible builds, add the E3DB client library to your glide.yaml by running:

$ glide get github.com/tozny/e3db-go

If you aren't using Glide and want to depend on the latest version of E3DB, check out the repository to the correct location within $GOPATH and install dependencies using Glide.

git clone https://github.com/tozny/e3db-go $GOPATH/src/github.com/tozny/e3db-go
cd $GOPATH/src/github.com/tozny/e3db-go
glide install

Usage

Here is some simple example code to connect and list records:

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/tozny/e3db-go"
)

func main() {
	client, err := e3db.GetDefaultClient()
	if err != nil {
		fmt.Fprint(os.Stderr, err)
		return
	}

	cursor := client.Query(context.Background(), e3db.Q{})
	for {
		record, err := cursor.Next()
		if err == e3db.Done {
			break
		} else if err != nil {
			log.Fatal(err)
		}
		fmt.Println(record.Meta.RecordID)
	}
}

Reading and Writing Records

To write new records to the database, first create a blank record of the correct type with NewRecord. Then fill in the fields of the record's Data field. Finally, write the record to the database with Write, which returns the unique ID of the newly created record.

record := client.NewRecord("contact")
record.Data["first_name"] = "Jon"
record.Data["last_name"]  = "Snow"
record.Data["phone"]      = "555-555-1212"
recordID, err := client.Write(context.Background(), record)
fmt.Println("Wrote record: " + recordID)
// Read it back out:
newRecord, err := client.Read(context.Background(), recordID)
fmt.Println (newRecord.Data["first_name"])

Documentaton

Comprehensive documentation for the SDK can be found online via GoDoc.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Done = errors.New("iteration complete")

Done is returned by Next when iteration is complete.

Functions

func ProfileExists

func ProfileExists(profile string) bool

ProfileExists returns true if a configuration exists for the given profile name.

func SaveConfig

func SaveConfig(profile string, opts *ClientOpts) error

SaveConfig writes an E3DB client configuration to a profile.

func SaveDefaultConfig

func SaveDefaultConfig(opts *ClientOpts) error

SaveDefaultConfig writes an E3DB client configuration to a profile.

Types

type Channel

type Channel struct {
	Application string `json:"application"`
	Type        string `json:"type"`
	Subject     string `json:"subject"`
}

Channel contains information defining the channel to which a client wishes to connect.

type Client

type Client struct {
	Options ClientOpts
	// contains filtered or unexported fields
}

Client is an authenticated connection to the E3DB service, providing access to end-to-end encrypted data stored in the database.

func GetClient

func GetClient(opts ClientOpts) (*Client, error)

GetClient creates an E3DB client given a custom set of options. Use 'GetConfig' to load options from a configuration profile.

func GetDefaultClient

func GetDefaultClient() (*Client, error)

GetDefaultClient loads the default E3DB configuration profile and creates a client using those options.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, recordID string) error

Delete deletes a record given a record ID.

func (*Client) GetClientInfo

func (c *Client) GetClientInfo(ctx context.Context, clientID string) (*ClientInfo, error)

GetClientInfo queries the E3DB server for a client's public information given its client UUID or email (if enabled).

func (*Client) GetIncomingSharing

func (c *Client) GetIncomingSharing(ctx context.Context) ([]IncomingSharingPolicy, error)

GetIncomingSharing returns a list of writers and types of records that are currently shared with me.

func (*Client) GetOutgoingSharing

func (c *Client) GetOutgoingSharing(ctx context.Context) ([]OutgoingSharingPolicy, error)

GetOutgoingSharing returns a list of readers and types of records that I am currently sharing.

func (*Client) NewEventSource

func (c *Client) NewEventSource(ctx context.Context) (*EventSource, error)

NewEventSource is a factory that creates a new EventSource object for the given client, allowing for incoming events from the e3db server to be ingested by a client application.

func (*Client) Query

func (c *Client) Query(ctx context.Context, q Q) *Cursor

Query executes a database query given a set of search parameters, returning a cursor that can be iterated over to loop through the result set.

func (*Client) Read

func (c *Client) Read(ctx context.Context, recordID string) (*Record, error)

Read reads a record given a record ID, decrypts it, and returns the result.

func (*Client) ReadRaw

func (c *Client) ReadRaw(ctx context.Context, recordID string) (*Record, error)

ReadRaw reads a record given a record ID and returns the record without decrypting data fields.

func (*Client) Share

func (c *Client) Share(ctx context.Context, recordType string, readerID string) error

Share grants another e3db client permission to read records of the specified record type.

func (*Client) Unshare

func (c *Client) Unshare(ctx context.Context, recordType string, readerID string) error

Unshare revokes another e3db client's permission to read records of the given record type.

func (*Client) Update

func (c *Client) Update(ctx context.Context, record *Record) error

Updates a record, if the version field matches the version stored by E3DB.

Returns HTTP 409 (Conflict) in error if the record cannot be updated.

func (*Client) Write

func (c *Client) Write(ctx context.Context, recordType string, data map[string]string, plain map[string]string) (*Record, error)

Write writes a new encrypted record to the database. Returns the new record (with the original, unencrypted data)

type ClientInfo

type ClientInfo struct {
	ClientID  string    `json:"client_id"`
	PublicKey clientKey `json:"public_key"`
	Validated bool      `json:"validated"`
}

ClientInfo contains information sent by the E3DB service about a client.

type ClientOpts

type ClientOpts struct {
	ClientID    string
	ClientEmail string
	APIKeyID    string
	APISecret   string
	PublicKey   publicKey
	PrivateKey  privateKey
	APIBaseURL  string
	Logging     bool
}

ClientOpts contains options for configuring an E3DB client.

func DefaultConfig

func DefaultConfig() (*ClientOpts, error)

DefaultConfig loads the default E3DB configuration.

func GetConfig

func GetConfig(profile string) (*ClientOpts, error)

GetConfig loads an E3DB client configuration from a configuration file given the name of the profile.

type Cursor

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

Cursor represents an iterator into a recordset returned by 'e3db.Query'.

func (*Cursor) Next

func (c *Cursor) Next() (*Record, error)

Next returns the item at the current iterator position (if one is available).

type Event

type Event struct {
	Time        time.Time         `json:"time"`
	Application string            `json:"application"`
	Type        string            `json:"type"`
	Action      string            `json:"action"`
	Subject     string            `json:"subject"`
	Producer    string            `json:"producer"`
	Context     map[string]string `json:"context"`
}

Event is an object representing the JSON blob dispatched from e3db in response to serverside events.

type EventSource

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

EventSource represents an open socket to the e3db Event source.

func (*EventSource) Close

func (c *EventSource) Close() error

Close the underlying websocket connection

func (*EventSource) Events

func (c *EventSource) Events() <-chan Event

Events produces a one-way version of the event-bearing channel

func (*EventSource) Subscribe

func (c *EventSource) Subscribe(channel Channel)

Subscribe to a specific event stream

func (*EventSource) Unsubscribe

func (c *EventSource) Unsubscribe(channel Channel)

Unsubscribe from a specific event stream

type IncomingSharingPolicy

type IncomingSharingPolicy struct {
	WriterID   string `json:"writer_id"`
	Type       string `json:"record_type"`
	WriterName string `json:"writer_name"`
}

IncomingSharingPolicy contains information about who has shared what type of records with me.

type Meta

type Meta struct {
	RecordID     string            `json:"record_id,omitempty"`
	WriterID     string            `json:"writer_id"`
	UserID       string            `json:"user_id"`
	Type         string            `json:"type"`
	Plain        map[string]string `json:"plain"`
	Created      time.Time         `json:"created"`
	LastModified time.Time         `json:"last_modified"`
	Version      string            `json:"version,omitempty"`
}

Meta contains meta-information about an E3DB record, such as who wrote it, when it was written, and the type of the data stored.

type OutgoingSharingPolicy

type OutgoingSharingPolicy struct {
	ReaderID   string `json:"reader_id"`
	Type       string `json:"record_type"`
	ReaderName string `json:"reader_name"`
}

OutgoingSharingPolicy contains information about who and what types of records I have shared with.

type Q

type Q struct {
	Count             int               `json:"count"`
	IncludeData       bool              `json:"include_data,omitempty"`
	WriterIDs         []string          `json:"writer_ids,omitempty"`
	UserIDs           []string          `json:"user_ids,omitempty"`
	RecordIDs         []string          `json:"record_ids,omitempty"`
	ContentTypes      []string          `json:"content_types,omitempty"`
	AfterIndex        int               `json:"after_index,omitempty"`
	Plain             map[string]string `json:"plain,omitempty"`
	IncludeAllWriters bool              `json:"include_all_writers,omitempty"`
}

Q contains options for querying a set of records in the database.

type Record

type Record struct {
	Meta Meta              `json:"meta"`
	Data map[string]string `json:"data"`
}

Record contains a plaintext 'Meta' object containing record metadata, along with decrypted fields in 'Data'. All data will be encrypted before it is stored in the E3DB service.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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