zetabase

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: BSD-3-Clause Imports: 22 Imported by: 0

README

Zetabase Go client

This package provides:

  1. the zb tool, used to manage accounts and databases; and
  2. a client library for managing Zetabase data, settings, and users from Go code.

Documentation

Notes

This package should be considered the reference implementation for the Zetabase protocol.

Release v0.1 (Curry)
  • Initial release

Documentation

Overview

Package zetabase provides a Go client library for the Zetabase cloud database along with a command-line tool for managing data and users.

Most users will only require the ZetabaseClient class; other exposed functions are primarily of use for working at the protocol layer, e.g. for performance fine-tuning.

The client library communicates using a protocol based on gRPC/Protocol Buffers.

This code and the included command-line tool are licensed under the Modified BSD License included in the attached LICENSE file.

Index

Constants

View Source
const (
	ClientVersion     = "0.1.1"
	ClientVersionCode = "Curry"
)
View Source
const (
	DoSaveCertificates = false
)
View Source
const (
	GrpcMaxBytes = 4000000
)

Variables

This section is empty.

Functions

func ConfirmUserIdentity

func ConfirmUserIdentity(ctx context.Context, uid string, parentId *string, verifyStr string, client zbprotocol.ZetabaseProviderClient) error

Function ConfirmUserIdentity confirms a new user ID with the SMS confirmation code they received.

func DecodeEcdsaPrivateKey

func DecodeEcdsaPrivateKey(pemEncoded string) (*ecdsa.PrivateKey, error)

func DecodeEcdsaPublicKey

func DecodeEcdsaPublicKey(pemEncodedPub string) (*ecdsa.PublicKey, error)

func EmptySignature

func EmptySignature() *zbprotocol.EcdsaSignature

func EncodeEcdsaPrivateKey

func EncodeEcdsaPrivateKey(privateKey *ecdsa.PrivateKey) ([]byte, error)

func EncodeEcdsaPublicKey

func EncodeEcdsaPublicKey(publicKey *ecdsa.PublicKey) ([]byte, error)

func GenerateKeyPair

func GenerateKeyPair() (*ecdsa.PrivateKey, *ecdsa.PublicKey)

func IsSemVerVersionAtLeast

func IsSemVerVersionAtLeast(userVersion, minVersion string) bool

func MakeCredentialEcdsa

func MakeCredentialEcdsa(nonce int64, uid string, relBytes []byte, pk *ecdsa.PrivateKey) *zbprotocol.ProofOfCredential

func MakeCredentialJwt

func MakeCredentialJwt(tok string) *zbprotocol.ProofOfCredential

func MakeEmptyCredentials

func MakeEmptyCredentials() *zbprotocol.ProofOfCredential

func MakeGetPages

func MakeGetPages(client *ZetabaseClient, dataKeys []string, maxItemSize int64, tableOwnerId, tableId string) *getPages

func MakeZetabaseSignature

func MakeZetabaseSignature(uid string, nonce int64, relData []byte, pk *ecdsa.PrivateKey) (string, string)

func MultiPutExtraSigningBytesMd5

func MultiPutExtraSigningBytesMd5(pairs []*zbprotocol.DataPair) []byte

Get extra signing bytes for a list of data pairs (PutMulti).

func PermissionsEntrySigningBytes

func PermissionsEntrySigningBytes(perm *zbprotocol.PermissionsEntry) []byte

func TableCreateSigningBytes

func TableCreateSigningBytes(tblId string, perms []*zbprotocol.PermissionsEntry) []byte

func TablePutExtraSigningBytes

func TablePutExtraSigningBytes(key string, valu []byte) []byte

Get extra signing bytes for a single table put

func ValidatePhoneNumber

func ValidatePhoneNumber(s string) bool

func ValidateZetabaseSignature

func ValidateZetabaseSignature(uid string, nonce int64, relData []byte, pk *ecdsa.PublicKey, r, s string) bool

Types

type BQClause

type BQClause struct {
	Subexpression *BQRootQ `"(" @@ ")"`
	Comparison    *BQCompQ ` | @@`
}

A "clause": a subexpression in parentheses OR a single field comparison

func (*BQClause) ToQuery

func (b *BQClause) ToQuery() SubQueryConvertible

type BQCompQ

type BQCompQ struct {
	Field    string   `@Ident`
	Operator string   `@("=" | ">" | "<" | ">=" | "<=" | "~" | "!=" | "not")`
	Value    *BQValue `@@`
}

Base comparison: an identifier then a comparison operator then a literal

func (*BQCompQ) ToQuery

func (b *BQCompQ) ToQuery() SubQueryConvertible

type BQLogicalQ

type BQLogicalQ struct {
	Operation string    `@("and" | "or")`
	Query     *BQClause `@@`
}

A "logical": an operator with a second clause

type BQParser

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

func NewBQParser

func NewBQParser(s string) *BQParser

func (*BQParser) Parse

func (b *BQParser) Parse() (*BQRootQ, error)

type BQRootQ

type BQRootQ struct {
	Clause       *BQClause     `@@`
	Conjunctions []*BQLogicalQ `@@*`
}

Root (expression): a comparison followed by one or more logical conjunctions...

func (*BQRootQ) ToQuery

func (b *BQRootQ) ToQuery() SubQueryConvertible

type BQValue

type BQValue struct {
	String  *string  `   @String`
	Number  *float64 ` | @Float`
	Integer *int64   ` | @Int`
}

A value: string or number literal

func (*BQValue) Value

func (b *BQValue) Value() interface{}

type IndexedField

type IndexedField struct {
	FieldName string
	LangCode  string
	IndexType zbprotocol.QueryOrdering
}

func NewIndexedField

func NewIndexedField(fieldName string, indexTyp zbprotocol.QueryOrdering) *IndexedField

func (*IndexedField) SetLanguageCode

func (f *IndexedField) SetLanguageCode(code string)

func (*IndexedField) ToProtocol

func (f *IndexedField) ToProtocol() *zbprotocol.TableIndexField

type NewRootUserInfo added in v0.1.5

type NewRootUserInfo struct {
	Id             string `json:"uid"`
	PubKeyEncoded  string `json:"pub_key"`
	PrivKeyEncoded string `json:"priv_key"`
}

Information on newly created root users

type NonceMaker

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

func NewNonceMaker

func NewNonceMaker() *NonceMaker

func (*NonceMaker) Get

func (n *NonceMaker) Get() int64

type PaginationHandler

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

Type PaginationHandler manages pagination of Zetabase responses.

func StandardPaginationHandlerFor

func StandardPaginationHandlerFor(f func(int64) (map[string][]byte, bool, error)) *PaginationHandler

Build a PaginationHandler given a function that takes as input a page index and returns the page data

func (*PaginationHandler) Data

func (p *PaginationHandler) Data() (map[string][]byte, error)

Get data fetched so far (for data retrieval responses)

func (*PaginationHandler) DataAll

func (p *PaginationHandler) DataAll() (map[string][]byte, error)

Get all data from all pages (for data retrieval responses)

func (*PaginationHandler) Keys

func (p *PaginationHandler) Keys() ([]string, error)

Get keys fetched so far

func (*PaginationHandler) KeysAll

func (p *PaginationHandler) KeysAll() ([]string, error)

Get all keys from all pages (for data retrieval responses)

func (*PaginationHandler) Next

func (p *PaginationHandler) Next()

Fetch next page worth of data

type PermConstraint

type PermConstraint struct {
	Field    string
	ReqValue string
}

func NewPermConstraintCustom added in v0.1.2

func NewPermConstraintCustom(field, reqValue string) *PermConstraint

func NewPermConstraintOrder added in v0.1.2

func NewPermConstraintOrder(field string) *PermConstraint

func NewPermConstraintRandom added in v0.1.2

func NewPermConstraintRandom(field string) *PermConstraint

func NewPermConstraintTime added in v0.1.2

func NewPermConstraintTime(field string) *PermConstraint

func NewPermConstraintUserId

func NewPermConstraintUserId(field string) *PermConstraint

func NewPermissionConstraint

func NewPermissionConstraint(field, reqValue string) *PermConstraint

type PermEntry

type PermEntry struct {
	Level        zbprotocol.PermissionLevel
	AudienceType zbprotocol.PermissionAudienceType
	AudienceId   string
	Constraints  []*PermConstraint
}

func (*PermEntry) AddConstraint

func (p *PermEntry) AddConstraint(c *PermConstraint)

func (*PermEntry) ToProtocol

func (p *PermEntry) ToProtocol(uid, tblId string) *zbprotocol.PermissionsEntry

type QueryAnd

type QueryAnd struct {
	Left  SubQueryConvertible
	Right SubQueryConvertible
}

func QAnd

func QAnd(l, r SubQueryConvertible) *QueryAnd

func (*QueryAnd) ToSubQuery

func (q *QueryAnd) ToSubQuery(tblOwnerId, tblId string) *zbprotocol.TableSubQuery

type QueryEquals

type QueryEquals struct {
	Field     string
	CompValue interface{}
}

func QEq

func QEq(field string, valu interface{}) *QueryEquals

func (*QueryEquals) ToSubQuery

func (q *QueryEquals) ToSubQuery(a, b string) *zbprotocol.TableSubQuery

type QueryGreaterThan

type QueryGreaterThan struct {
	Field     string
	CompValue interface{}
}

func QGt

func QGt(field string, valu interface{}) *QueryGreaterThan

func (*QueryGreaterThan) ToSubQuery

func (q *QueryGreaterThan) ToSubQuery(a, b string) *zbprotocol.TableSubQuery

type QueryGreaterThanEqual

type QueryGreaterThanEqual struct {
	Field     string
	CompValue interface{}
}

func QGte

func QGte(field string, valu interface{}) *QueryGreaterThanEqual

func (*QueryGreaterThanEqual) ToSubQuery

type QueryLessThan

type QueryLessThan struct {
	Field     string
	CompValue interface{}
}

func QLt

func QLt(field string, valu interface{}) *QueryLessThan

func (*QueryLessThan) ToSubQuery

func (q *QueryLessThan) ToSubQuery(a, b string) *zbprotocol.TableSubQuery

type QueryLessThanEqual

type QueryLessThanEqual struct {
	Field     string
	CompValue interface{}
}

func QLte

func QLte(field string, valu interface{}) *QueryLessThanEqual

func (*QueryLessThanEqual) ToSubQuery

func (q *QueryLessThanEqual) ToSubQuery(a, b string) *zbprotocol.TableSubQuery

type QueryNotEquals

type QueryNotEquals struct {
	Field     string
	CompValue interface{}
}

func QNEq

func QNEq(field string, valu interface{}) *QueryNotEquals

func (*QueryNotEquals) ToSubQuery

func (q *QueryNotEquals) ToSubQuery(a, b string) *zbprotocol.TableSubQuery

type QueryOr

type QueryOr struct {
	Left  SubQueryConvertible
	Right SubQueryConvertible
}

func QOr

func QOr(l, r SubQueryConvertible) *QueryOr

func (*QueryOr) ToSubQuery

func (q *QueryOr) ToSubQuery(tblOwnerId, tblId string) *zbprotocol.TableSubQuery

type QueryTextSearch

type QueryTextSearch struct {
	Field     string
	CompValue interface{}
}

func QText

func QText(field string, queryStr string) *QueryTextSearch

func (*QueryTextSearch) ToSubQuery

func (q *QueryTextSearch) ToSubQuery(a, b string) *zbprotocol.TableSubQuery

type SubQueryConvertible

type SubQueryConvertible interface {
	ToSubQuery(tblOwnerId, tblId string) *zbprotocol.TableSubQuery
}

type ZetabaseClient

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

Type ZetabaseClient represents a long-lived Zetabase connection for a particular identity.

func NewZetabaseClient

func NewZetabaseClient(uid string) *ZetabaseClient

Creates a new client for a given user ID uid. The user ID should be in UUID form.

func NewZetabaseUserClient added in v0.1.2

func NewZetabaseUserClient(parentId string) *ZetabaseClient

func (*ZetabaseClient) AddPermission

func (z *ZetabaseClient) AddPermission(tblOwnerId, tblId string, perm *PermEntry) error

Method AddPermission adds permission perm to the given table tblId.

func (*ZetabaseClient) CheckVersion

func (z *ZetabaseClient) CheckVersion() (bool, *zbprotocol.VersionDetails, error)

Checks version compatibility between client and server

func (*ZetabaseClient) ConfirmNewRootUser added in v0.1.5

func (z *ZetabaseClient) ConfirmNewRootUser(userId, verificationCode string) error

Confirm new given user ID and verification code

func (*ZetabaseClient) ConfirmNewSubUser

func (z *ZetabaseClient) ConfirmNewSubUser(subuserId, verificationCode string) error

Confirm new subuser given subuser ID and verification code

func (*ZetabaseClient) Connect

func (z *ZetabaseClient) Connect() error

Connect to Zetabase with the provided credentials.

func (*ZetabaseClient) CreateTable

func (z *ZetabaseClient) CreateTable(tblId string, dataType zbprotocol.TableDataFormat, indexedFields []*IndexedField, perms []*PermEntry, allowJwt bool) error

Create a new table tblId with the given data format, indexed fields, and permissions

func (*ZetabaseClient) DeleteKey

func (z *ZetabaseClient) DeleteKey(tableOwnerId, tableId, key string) error

Delete a given key-value pair from a table

func (*ZetabaseClient) DeleteTable

func (z *ZetabaseClient) DeleteTable(tableOwnerId, tableId string) error

Delete a table and all its contents

func (*ZetabaseClient) Get

func (z *ZetabaseClient) Get(tableOwnerId, tableId string, keys []string) *getPages

func (*ZetabaseClient) GetSubIdentities

func (z *ZetabaseClient) GetSubIdentities() ([]*zbprotocol.NewSubIdentityRequest, error)

Method GetSubIdentities lists subusers of the authenticated user.

func (*ZetabaseClient) GrpcClient

Return the underlying gRPC client

func (*ZetabaseClient) Id

func (z *ZetabaseClient) Id() string

Get user ID

func (*ZetabaseClient) JwtTokens added in v0.1.5

func (z *ZetabaseClient) JwtTokens() (string, string)

func (*ZetabaseClient) ListKeys

func (z *ZetabaseClient) ListKeys(tableOwnerId, tableId string) *PaginationHandler

Method ListKeys lists the keys for a given table

func (*ZetabaseClient) ListKeysWithPattern

func (z *ZetabaseClient) ListKeysWithPattern(tableOwnerId, tableId, pattern string) *PaginationHandler

Method ListKeysWithPattern lists keys with a given prefix pattern, where the suffix wildcard operator is represented by %.

func (*ZetabaseClient) ListTables added in v0.1.2

func (z *ZetabaseClient) ListTables() ([]string, error)

Method ListTables lists the tables associated with the ZetabaseClient's account

func (*ZetabaseClient) ModifySubIdentity

func (z *ZetabaseClient) ModifySubIdentity(subUserId string, newHandle *string, newEmail *string, newMobile *string, newPass *string, newPubKey *string) error

Method ModifySubIdentity modifies an existing subuser. Non-nil fields will be updated.

func (*ZetabaseClient) NewRootUser added in v0.1.5

func (z *ZetabaseClient) NewRootUser(handle, email, mobile, password string, pubKey0 *ecdsa.PublicKey) (*NewRootUserInfo, error)

Create a new root user with the given attributes

func (*ZetabaseClient) NewSubUser

func (z *ZetabaseClient) NewSubUser(handle, email, mobile, password, signupCode, groupId string, pubKey *ecdsa.PublicKey) (string, error)

Create a new subuser with the given attributes

func (*ZetabaseClient) PutData

func (z *ZetabaseClient) PutData(tableOwnerId, tableId, key string, valu []byte, overwrite bool) error

Put a given key-value pair into a table

func (*ZetabaseClient) PutMulti

func (z *ZetabaseClient) PutMulti(tableOwnerId, tableId string, keys []string, valus [][]byte, overwrite bool) error

Method PutMulti puts multiple key-value pairs into a table at once

func (*ZetabaseClient) Query

func (z *ZetabaseClient) Query(tableOwnerId, tableId string, qry0 SubQueryConvertible) *PaginationHandler

func (*ZetabaseClient) QueryData

func (z *ZetabaseClient) QueryData(tbldOwnerId, tblId string, qry SubQueryConvertible) (*getPages, error)

func (*ZetabaseClient) RefreshToken added in v0.1.5

func (z *ZetabaseClient) RefreshToken() error

func (*ZetabaseClient) SetCertVerify

func (z *ZetabaseClient) SetCertVerify(b bool)

Toggle certificate verification

func (*ZetabaseClient) SetDebugMode

func (z *ZetabaseClient) SetDebugMode()

Toggle debug mode

func (*ZetabaseClient) SetIdKey

func (z *ZetabaseClient) SetIdKey(priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey)

Set the private and public keys corresponding to this identity

func (*ZetabaseClient) SetIdPassword

func (z *ZetabaseClient) SetIdPassword(loginId, pwd string)

Set a handle and password as authentication credentials (for JWT authentication mode)

func (*ZetabaseClient) SetInsecure

func (z *ZetabaseClient) SetInsecure()

Toggle insecure (plaintext) connection

func (*ZetabaseClient) SetMaxItemSize

func (z *ZetabaseClient) SetMaxItemSize(newSize int64)

func (*ZetabaseClient) SetParent

func (z *ZetabaseClient) SetParent(id string)

Set parent user ID (when connecting as a subuser) to id. This parent ID should be in UUID form.

func (*ZetabaseClient) SetServerAddr

func (z *ZetabaseClient) SetServerAddr(addr string)

Set a customer server address (for on-premises installations only)

func (*ZetabaseClient) SetThirdPartyAuthToken added in v0.1.4

func (z *ZetabaseClient) SetThirdPartyAuthToken(handle, token, source string)

Set third-party authentication credentials

func (*ZetabaseClient) StringDump added in v0.1.3

func (z *ZetabaseClient) StringDump() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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