Skip to content

Commit

Permalink
Merge pull request #26 from tozny/quality/E3DB-1133-review-update-sdk
Browse files Browse the repository at this point in the history
[E3DB-1133] Ensure Go SDK has that modern look and feel/is go developer friendly.
  • Loading branch information
galxy25 committed Nov 27, 2018
2 parents 376af0c + ad8377c commit 5355fcf
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 191 deletions.
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
language: go

go:
- 1.7
- 1.8
- 1.11
- tip

install:
- go get -v github.com/Masterminds/glide
- cd $GOPATH/src/github.com/Masterminds/glide && git checkout 84607742b10f492430762d038e954236bbaf23f7 && go install && cd -
- glide install
- go build
- go get github.com/mattn/goveralls
- ./travis-install-configfile.sh

script:
- go test -v -covermode=count -coverprofile=coverage.out --tags integration
- $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN
- goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN

env:
global:
secure: BE18nJ2H83YDxR/afzVhqepLjbVf3GotMAmBMg4eNw66jnBN9CQqaBNZyxHkp2QuMXRq0QRREZTSe/GZbLeS4LSYiTHvU9IYbW48E/m0AOLzeDYsH9DxCQjDp36qXqlPNbIslxXjqErkZHUSp5oGiSSZa+oDmJYsUnXT4AUJbJE7Itgnzb1MxF0l2uLdx1KG3P8V4XrqPkFoCSkjM3nXl6A9d07dQv1zFqjcOSHmVgehwl9v5kW6ejPZS4esyrh5C80PKs3Sr5aWCEIwR+ualFJLJjbLpGzMCS9hZy5PXNFiGlO517dUEyAb2s44cmaHKhoCFjGnS+LgAxrZ/xZ7s9jKYKReiEa8mO+GYXzd+/tJKvfduGohd0Lc29Cx8J3SEMhbTdo58yJXXIciof/2jnZhyHaSbHxoZkNsp8KQAteQxv+lhFW06rTD65x4LP/3jGbSLz7Vg2G0z9JLDopdqZej/duiH632QqJMP1ABPjgh/adI3oyQz7omilCswpJyuN7as2az8B224R+atnjgiFQH/DbpjpCdhRdjcwBhg1jlQ/hA1Eglh/c3H3ZlPbsgsHZqjstksNxFJTfIIh3wG3PZsji9YWsw+T2ZSfjcEvhEpi4psl0dIgKlGfIJm3joeSLrHGcQkRO9DnyNgAYYP7ppsWkRBnAVfMuzYycrCYI=
- secure: BE18nJ2H83YDxR/afzVhqepLjbVf3GotMAmBMg4eNw66jnBN9CQqaBNZyxHkp2QuMXRq0QRREZTSe/GZbLeS4LSYiTHvU9IYbW48E/m0AOLzeDYsH9DxCQjDp36qXqlPNbIslxXjqErkZHUSp5oGiSSZa+oDmJYsUnXT4AUJbJE7Itgnzb1MxF0l2uLdx1KG3P8V4XrqPkFoCSkjM3nXl6A9d07dQv1zFqjcOSHmVgehwl9v5kW6ejPZS4esyrh5C80PKs3Sr5aWCEIwR+ualFJLJjbLpGzMCS9hZy5PXNFiGlO517dUEyAb2s44cmaHKhoCFjGnS+LgAxrZ/xZ7s9jKYKReiEa8mO+GYXzd+/tJKvfduGohd0Lc29Cx8J3SEMhbTdo58yJXXIciof/2jnZhyHaSbHxoZkNsp8KQAteQxv+lhFW06rTD65x4LP/3jGbSLz7Vg2G0z9JLDopdqZej/duiH632QqJMP1ABPjgh/adI3oyQz7omilCswpJyuN7as2az8B224R+atnjgiFQH/DbpjpCdhRdjcwBhg1jlQ/hA1Eglh/c3H3ZlPbsgsHZqjstksNxFJTfIIh3wG3PZsji9YWsw+T2ZSfjcEvhEpi4psl0dIgKlGfIJm3joeSLrHGcQkRO9DnyNgAYYP7ppsWkRBnAVfMuzYycrCYI=
- GO111MODULE=on
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN mkdir -p /go/src/github.com/tozny/e3db-go/
COPY . /go/src/github.com/tozny/e3db-go/
WORKDIR /go/src/github.com/tozny/e3db-go/

RUN glide install && \
RUN CGO_ENABLED=0 go build && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./cmd/e3db && \
mv e3db /bin/

Expand Down
31 changes: 9 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ 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](https://glide.sh).
Binaries for many platforms can be downloaded from the
[GitHub Releases Page](https://github.com/Masterminds/glide/releases).
e3db uses native go modules for dependency management, which requires a version of go >= 1.11.

# Command-Line Interface

Expand All @@ -27,36 +24,26 @@ 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:
sources locally, install
dependencies, and build the `github.com/tozny/e3db/cmd/e3db` package:

```shell
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
git clone https://github.com/tozny/e3db-go
cd e3db-go
go build
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`
If your project uses go modules for managing dependencies and
reproducible builds, add the E3DB client library to your `go.mod`
by running:

```shell
$ 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.

```shell
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 get github.com/tozny/e3db-go/v2
```

## Registering a client
Expand Down
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ fi
rm -rf build
mkdir -p build

glide install
export XDG_CACHE_HOME="/tmp/.cache"
CGO_ENABLED=0 go build

for os in darwin linux windows; do
for arch in 386 amd64; do
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build ./cmd/e3db
case $os in
case $os in
windows)
mv e3db.exe build/e3db-$os-$arch$suffix.exe
;;
Expand Down
23 changes: 17 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
// All Rights Reserved.
//

/*
Package e3db provides programmatic access to the e3db API/Innovault service for the secure transmission and storage of arbitrary data encrypted locally using this SDK.
Official documentation for e3db can be found at https://tozny.com/documentation/e3db/
If not using go mod command for your project:
import "github.com/tozny/e3db-go"
Otherwise
import "github.com/tozny/e3db-go/v2"
*/
package e3db

import (
Expand Down Expand Up @@ -56,6 +66,7 @@ type Client struct {
akCache map[akCacheKey]secretKey
}

// ClientKey contains a cryptographic key for use in client operations.
type ClientKey struct {
Curve25519 string `json:"curve25519"`
}
Expand Down Expand Up @@ -465,7 +476,7 @@ func (c *Client) Update(ctx context.Context, record *Record) error {
return nil
}

// Delete removes a record, with optional optimistic locking
// Delete removes a record, with optional optimistic locking.
func (c *Client) Delete(ctx context.Context, recordID string, version string) error {
u := fmt.Sprintf("%s/v1/storage/records/%s", c.apiURL(), url.QueryEscape(recordID))

Expand All @@ -487,7 +498,7 @@ func (c *Client) Delete(ctx context.Context, recordID string, version string) er
return nil
}

// Backup backs up the client's credentials to an account with which it's registered
// Backup backs up the client's credentials to an account with which it's registered.
func (c *Client) Backup(ctx context.Context, clientID string, registrationToken string) error {
credentials := make(map[string]string)
credentials["version"] = "1"
Expand Down Expand Up @@ -719,7 +730,7 @@ func (c *Client) NewEventSource(ctx context.Context) (*EventSource, error) {
return &source, nil
}

// Subscribe to a specific event stream
// Subscribe to a specific event stream.
func (c *EventSource) Subscribe(channel Channel) {
command := subscription{
Action: "attach",
Expand All @@ -729,7 +740,7 @@ func (c *EventSource) Subscribe(channel Channel) {
c.commands <- command
}

// Unsubscribe from a specific event stream
// Unsubscribe from a specific event stream.
func (c *EventSource) Unsubscribe(channel Channel) {
command := subscription{
Action: "detach",
Expand All @@ -739,12 +750,12 @@ func (c *EventSource) Unsubscribe(channel Channel) {
c.commands <- command
}

// Close the underlying websocket connection
// Close the underlying websocket connection.
func (c *EventSource) Close() error {
return c.conn.Close()
}

// Events produces a one-way version of the event-bearing channel
// Events produces a one-way version of the event-bearing channel.
func (c *EventSource) Events() <-chan Event {
return c.events
}
2 changes: 1 addition & 1 deletion cmd/e3db/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"golang.org/x/crypto/nacl/box"

"github.com/jawher/mow.cli"
"github.com/tozny/e3db-go"
"github.com/tozny/e3db-go/v2"
)

type cliOptions struct {
Expand Down
12 changes: 6 additions & 6 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ func secretBoxDecryptFromBase64(ciphertext, nonce string, key secretKey) ([]byte
const publicKeySize = 32
const privateKeySize = 32

// PublicKey is an alias of a 32-byte array representing the public key component
// PublicKey is an alias of a 32-byte array representing the public key component.
type PublicKey *[publicKeySize]byte

// PrivateKey is an alias of a 32-byte array representing the private key component
// PrivateKey is an alias of a 32-byte array representing the private key component.
type PrivateKey *[privateKeySize]byte

// GenerateKeyPair creates a new Curve25519 keypair for cryptographic operations
// GenerateKeyPair creates a new Curve25519 keypair for cryptographic operations.
func GenerateKeyPair() (string, string, error) {
pub, priv, err := box.GenerateKey(rand.Reader)
if err != nil {
Expand All @@ -139,7 +139,7 @@ func GenerateKeyPair() (string, string, error) {
return encodePublicKey(pub), encodePrivateKey(priv), nil
}

// MakePublicKey converts a byte array to a PublicKey type
// MakePublicKey converts a byte array to a PublicKey type.
func MakePublicKey(b []byte) PublicKey {
key := [publicKeySize]byte{}
copy(key[:], b)
Expand All @@ -162,7 +162,7 @@ func encodePublicKey(k PublicKey) string {
return base64Encode(k[:])
}

// MakePrivateKey converts a byte array to a PrivateKey type
// MakePrivateKey converts a byte array to a PrivateKey type.
func MakePrivateKey(b []byte) PrivateKey {
key := [privateKeySize]byte{}
copy(key[:], b)
Expand Down Expand Up @@ -403,7 +403,7 @@ func (c *Client) decryptRecordWithKey(record *Record, ak secretKey) error {
return nil
}

// encryptRecord mencrypting all data fields in a record
// encryptRecord encrypts all data fields in a record
// using an access key granted by the authorizer, returning
// a new record.
func (c *Client) encryptRecord(ctx context.Context, record *Record) (*Record, error) {
Expand Down
81 changes: 0 additions & 81 deletions example/feedback.go

This file was deleted.

Loading

0 comments on commit 5355fcf

Please sign in to comment.