rai

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PathDatabase     = "/database"
	PathEngine       = "/compute"
	PathOAuthClients = "/oauth-clients"
	PathTransaction  = "/transaction"
	PathTransactions = "/transactions"
	PathUsers        = "/users"
)
View Source
const DefaultConfigFile = "~/.rai/config"
View Source
const DefaultConfigProfile = "default"
View Source
const DefaultHost = "azure.relationalai.com"
View Source
const DefaultPort = "443"
View Source
const DefaultRegion = "us-east"
View Source
const DefaultScheme = "https"
View Source
const Version = "0.0.1"

Variables

View Source
var ErrMissingFilterValue = errors.New("missing filter value")
View Source
var ErrNotFound = newHTTPError(http.StatusNotFound, "")

Functions

func Encode

func Encode(w io.Writer, item interface{}, indent int) error

Encode the given item as JSON to the given writer.

func LoadConfig

func LoadConfig(cfg *Config) error

Load settings from the default profile of the default config file.

func LoadConfigFile

func LoadConfigFile(fname, profile string, cfg *Config) error

Load settings from the given profile of the named config file.

func LoadConfigProfile

func LoadConfigProfile(profile string, cfg *Config) error

Load settings from the given profile in the default config file.

func LoadConfigString

func LoadConfigString(source, profile string, cfg *Config) error

Load settings from the given profile of the provided config source.

func Print

func Print(item interface{}, indent int) error

Print the given item as JSON to stdout.

Types

type AccessToken

type AccessToken struct {
	Token     string `json:"access_token"`
	Scope     string `json:"scope"`
	ExpiresIn int    `json:"expires_in"` // token lifetime in seconds
	CreatedOn int64  `json:"created_on"` // epoch seconds
}

todo: make sure CreatedOn is persisted as epoch seconds

func (*AccessToken) ExpiresOn

func (a *AccessToken) ExpiresOn() int64

Instant the token expires in epoch seconds.

func (*AccessToken) IsExpired

func (a *AccessToken) IsExpired() bool

Anticipate access token expiration by 5 seconds

func (*AccessToken) Load

func (a *AccessToken) Load(r io.Reader) error

func (*AccessToken) String

func (a *AccessToken) String() string

type AccessTokenHandler

type AccessTokenHandler interface {
	GetAccessToken() (string, error)
}

type ArrowRelation

type ArrowRelation struct {
	RelationID string
	Table      []interface{}
}

type CSVOptions

type CSVOptions struct {
	Schema     map[string]string
	HeaderRow  *int
	Delim      rune
	EscapeChar rune
	QuoteChar  rune
}

func NewCSVOptions

func NewCSVOptions() *CSVOptions

func (*CSVOptions) WithDelim

func (opts *CSVOptions) WithDelim(delim rune) *CSVOptions

func (*CSVOptions) WithEscapeChar

func (opts *CSVOptions) WithEscapeChar(escapeChar rune) *CSVOptions

func (*CSVOptions) WithHeaderRow

func (opts *CSVOptions) WithHeaderRow(headerRow int) *CSVOptions

func (*CSVOptions) WithQuoteChar

func (opts *CSVOptions) WithQuoteChar(quoteChar rune) *CSVOptions

func (*CSVOptions) WithSchema

func (opts *CSVOptions) WithSchema(schema map[string]string) *CSVOptions

type Client

type Client struct {
	Region string
	Scheme string
	Host   string
	Port   string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, opts *ClientOptions) *Client

func NewClientFromConfig

func NewClientFromConfig(profile string) (*Client, error)

Returns a new client using the background context and config settings from the named profile.

func NewDefaultClient

func NewDefaultClient() (*Client, error)

Returns a new client using the background context and config settings from the default profile.

func (*Client) AccessToken

func (c *Client) AccessToken() (string, error)

Returns the current access token

func (*Client) CancelTransaction added in v0.1.1

func (c *Client) CancelTransaction(id string) (*TransactionAsyncCancelResponse, error)

func (*Client) CloneDatabase

func (c *Client) CloneDatabase(database, source string) (*Database, error)

func (*Client) Context

func (c *Client) Context() context.Context

func (*Client) CreateDatabase

func (c *Client) CreateDatabase(database string) (*Database, error)

func (*Client) CreateEngine

func (c *Client) CreateEngine(engine, size string) (*Engine, error)

Request the creation of an engine, and wait for the opeartion to complete. This can block the caller for up to a minute.

func (*Client) CreateEngineAsync

func (c *Client) CreateEngineAsync(engine, size string) (*Engine, error)

Request the creation of an engine, and immediately return. The process of provisioning a new engine can take up to a minute.

func (*Client) CreateOAuthClient

func (c *Client) CreateOAuthClient(
	name string, perms []string,
) (*OAuthClientExtra, error)

func (*Client) CreateUser

func (c *Client) CreateUser(email string, roles []string) (*User, error)

func (*Client) Delete

func (c *Client) Delete(path string, args url.Values, data, result interface{}) error

func (*Client) DeleteDatabase

func (c *Client) DeleteDatabase(database string) error

func (*Client) DeleteEngine

func (c *Client) DeleteEngine(engine string) error

Request the deletion of an engine and wait for the operation to complete.

func (*Client) DeleteEngineAsync

func (c *Client) DeleteEngineAsync(engine string) (*Engine, error)

func (*Client) DeleteModel

func (c *Client) DeleteModel(
	database, engine, name string,
) (*TransactionResult, error)

func (*Client) DeleteModels

func (c *Client) DeleteModels(
	database, engine string, models []string,
) (*TransactionResult, error)

func (*Client) DeleteOAuthClient

func (c *Client) DeleteOAuthClient(id string) (*DeleteOAuthClientResponse, error)

func (*Client) DeleteUser

func (c *Client) DeleteUser(id string) (*DeleteUserResponse, error)

func (*Client) DisableUser

func (c *Client) DisableUser(id string) (*User, error)

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Execute the given request and return the response or error.

func (*Client) EnableUser

func (c *Client) EnableUser(id string) (*User, error)

func (*Client) Execute

func (c *Client) Execute(
	database, engine, source string,
	inputs map[string]string,
	readonly bool,
) (*TransactionAsyncResult, error)

func (*Client) ExecuteAsync

func (c *Client) ExecuteAsync(
	database, engine, source string,
	inputs map[string]string,
	readonly bool,
) (*TransactionAsyncResult, error)

func (*Client) ExecuteV1 added in v0.2.0

func (c *Client) ExecuteV1(
	database, engine, source string,
	inputs map[string]string,
	readonly bool,
) (*TransactionResult, error)

Execute the given query, with the given optional query inputs.

func (*Client) FindOAuthClient

func (c *Client) FindOAuthClient(name string) (*OAuthClient, error)

Returns the OAuth client with the given name or nil if it does not exist.

func (*Client) FindUser

func (c *Client) FindUser(email string) (*User, error)

Returns the User with the given email or nil if it does not exist.

func (*Client) Get

func (c *Client) Get(path string, args url.Values, result interface{}) error

func (*Client) GetAccessToken

func (c *Client) GetAccessToken(creds *ClientCredentials) (*AccessToken, error)

Fetch a new access token using the given client credentials.

func (*Client) GetDatabase

func (c *Client) GetDatabase(database string) (*Database, error)

func (*Client) GetEngine

func (c *Client) GetEngine(engine string) (*Engine, error)

func (*Client) GetModel

func (c *Client) GetModel(database, engine, model string) (*Model, error)

func (*Client) GetOAuthClient

func (c *Client) GetOAuthClient(id string) (*OAuthClientExtra, error)

func (*Client) GetTransaction

func (c *Client) GetTransaction(id string) (*TransactionAsyncSingleResponse, error)

func (*Client) GetTransactionMetadata

func (c *Client) GetTransactionMetadata(id string) ([]TransactionAsyncMetadataResponse, error)

func (*Client) GetTransactionProblems

func (c *Client) GetTransactionProblems(id string) ([]interface{}, error)

func (*Client) GetTransactionResults

func (c *Client) GetTransactionResults(id string) ([]ArrowRelation, error)

func (*Client) GetTransactions

func (c *Client) GetTransactions() (*TransactionAsyncMultipleResponses, error)

func (*Client) GetUser

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

func (*Client) ListDatabases

func (c *Client) ListDatabases(filters ...interface{}) ([]Database, error)

func (*Client) ListEDBs

func (c *Client) ListEDBs(database, engine string) ([]EDB, error)

func (*Client) ListEngines

func (c *Client) ListEngines(filters ...interface{}) ([]Engine, error)

func (*Client) ListModelNames

func (c *Client) ListModelNames(database, engine string) ([]string, error)

Returns a list of model names for the given database.

func (*Client) ListModels

func (c *Client) ListModels(database, engine string) ([]Model, error)

Returns the names of models installed in the given database.

func (*Client) ListOAuthClients

func (c *Client) ListOAuthClients() ([]OAuthClient, error)

func (*Client) ListUsers

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

func (*Client) LoadCSV

func (c *Client) LoadCSV(
	database, engine, relation string, r io.Reader, opts *CSVOptions,
) (*TransactionResult, error)

func (*Client) LoadJSON

func (c *Client) LoadJSON(
	database, engine, relation string, r io.Reader,
) (*TransactionResult, error)

func (*Client) LoadModel

func (c *Client) LoadModel(
	database, engine, name string, r io.Reader,
) (*TransactionResult, error)

func (*Client) LoadModels

func (c *Client) LoadModels(
	database, engine string, models map[string]io.Reader,
) (*TransactionResult, error)

func (*Client) Patch

func (c *Client) Patch(path string, args url.Values, data, result interface{}) error

func (*Client) Post

func (c *Client) Post(path string, args url.Values, data, result interface{}) error

func (*Client) Put

func (c *Client) Put(path string, args url.Values, data, result interface{}) error

func (*Client) SetAccessTokenHandler

func (c *Client) SetAccessTokenHandler(handler AccessTokenHandler)

func (*Client) SetContext

func (c *Client) SetContext(ctx context.Context)

func (*Client) UpdateUser

func (c *Client) UpdateUser(id string, req UpdateUserRequest) (*User, error)

func (*Client) Url

func (c *Client) Url(path string) string

Returns a URL constructed from given path.

type ClientCredentials

type ClientCredentials struct {
	ClientID             string `json:"clientId"`
	ClientSecret         string `json:"-"`
	ClientCredentialsUrl string `json:"clientCredentialsUrl"`
}

type ClientCredentialsHandler

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

func NewClientCredentialsHandler

func NewClientCredentialsHandler(
	c *Client, creds *ClientCredentials,
) ClientCredentialsHandler

This handler uses the given OAuth client credentials to retrieve access tokens, as needed, and caches them locally in ~/.rai/tokens.json.

func (ClientCredentialsHandler) GetAccessToken

func (h ClientCredentialsHandler) GetAccessToken() (string, error)

type ClientOptions

type ClientOptions struct {
	Config
	HTTPClient         *http.Client
	AccessTokenHandler AccessTokenHandler
}

func NewClientOptions

func NewClientOptions(cfg *Config) *ClientOptions

type ClientProblem

type ClientProblem struct {
	Type        string `json:"type"`
	ErrorCode   string `json:"error_code"`
	IsError     bool   `json:"is_error"`
	IsException bool   `json:"is_exception"`
	Message     string `json:"message"`
	Report      string `json:"report"`
}

type Config

type Config struct {
	Region      string             `json:"region"`
	Scheme      string             `json:"scheme"`
	Host        string             `json:"host"`
	Port        string             `json:"port"`
	Credentials *ClientCredentials `json:"credentials"`
}

type Database

type Database struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Region      string `json:"region"`
	AccountName string `json:"account_name"`
	CreatedBy   string `json:"created_by"`
	DeletedOn   string `json:"deleted_on"`
	DeletedBy   string `json:"deleted_by,omitempty"`
	State       string `json:"state"`
}

type DbAction

type DbAction map[string]interface{}

type DeleteEngineStatus

type DeleteEngineStatus struct {
	Name    string `json:"name"`
	State   string `json:"state"`
	Message string `json:"message"`
}

type DeleteOAuthClientResponse

type DeleteOAuthClientResponse struct {
	ID      string `json:"client_id"`
	Message string `json:"message"`
}

type DeleteUserResponse

type DeleteUserResponse struct {
	ID      string `json:"user_id"`
	Message string `json:"message"`
}

type EDB

type EDB struct {
	Name   string   `json:"name"`
	Keys   []string `json:"keys"`
	Values []string `json:"values"`
}

type Engine

type Engine struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Region      string `json:"region"`
	AccountName string `json:"account_name"`
	CreatedBy   string `json:"created_by"`
	CreatedOn   string `json:"created_on,omitempty"` // todo: required?
	DeletedOn   string `json:"deleted_on,omitempty"`
	Size        string `json:"size"`
	State       string `json:"state"`
}

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
}

func (HTTPError) Error

func (e HTTPError) Error() string

type IntegrityConstraintViolation

type IntegrityConstraintViolation struct {
	Type    string   `json:"type"`
	Sources []Source `json:"sources"`
}

type Model

type Model struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type NopAccessTokenHandler

type NopAccessTokenHandler struct{}

This handler always returns an empty token, which results in requests not being authenticated.

func NewNopAccessTokenHandler

func NewNopAccessTokenHandler() NopAccessTokenHandler

func (NopAccessTokenHandler) GetAccessToken

func (h NopAccessTokenHandler) GetAccessToken() (string, error)

type OAuthClient

type OAuthClient struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	AccountName string    `json:"account_name"`
	CreatedBy   string    `json:"created_by"`
	CreatedOn   time.Time `json:"created_on"`
}

type OAuthClientExtra

type OAuthClientExtra struct {
	OAuthClient
	Permissions []string `json:"permissions"`
	Secret      string   `json:"secret"`
}

type RelKey

type RelKey struct {
	Name   string   `json:"name"`
	Keys   []string `json:"keys"`
	Values []string `json:"values"`
}

type Relation

type Relation struct {
	RelKey  RelKey          `json:"rel_key"`
	Columns [][]interface{} `json:"columns"`
}

func (*Relation) GetRow

func (r *Relation) GetRow(n int) []interface{}

func (*Relation) Name

func (r *Relation) Name() string

func (*Relation) RowCount

func (r *Relation) RowCount() int

func (*Relation) Schema

func (r *Relation) Schema() string

func (*Relation) Show

func (r *Relation) Show()

type Showable

type Showable interface {
	Show()
}

type Source

type Source struct {
	RelKey RelKey `json:"rel_key"`
	Source string `json:"source"`
	Type   string `json:"type"`
}

type Transaction

type Transaction struct {
	Region        string
	Database      string
	Engine        string
	Mode          string
	Source        string
	Abort         bool
	Readonly      bool
	NoWaitDurable bool
	Version       int
}

The transaction "request" envelope

func NewTransaction

func NewTransaction(region, database, engine, mode string) *Transaction

func (*Transaction) Payload

func (tx *Transaction) Payload(actions ...DbAction) map[string]interface{}

Constructs a transaction request payload.

func (*Transaction) QueryArgs

func (tx *Transaction) QueryArgs() url.Values

type TransactionAsync

type TransactionAsync struct {
	Database string
	Engine   string
	Source   string
	Readonly bool
}

TransactionAsync is the envelope for an async transaction

func NewTransactionAsync

func NewTransactionAsync(database, engine string) *TransactionAsync

func (*TransactionAsync) QueryArgs

func (tx *TransactionAsync) QueryArgs() url.Values

type TransactionAsyncCancelResponse added in v0.1.1

type TransactionAsyncCancelResponse struct {
	Message string `json:"message"`
}

type TransactionAsyncFile

type TransactionAsyncFile struct {
	Name        string
	Filename    string
	ContentType string
	Data        []byte
}

type TransactionAsyncMetadataResponse

type TransactionAsyncMetadataResponse struct {
	RelationId string   `json:"relationId"`
	Types      []string `json:"types"`
}

type TransactionAsyncMultipleResponses

type TransactionAsyncMultipleResponses struct {
	Transactions []TransactionAsyncResponse `json:"transactions"`
}

type TransactionAsyncResponse

type TransactionAsyncResponse struct {
	ID                    string `json:"id"`
	State                 string `json:"state"`
	AccountName           string `json:"account_name,omitempty"`
	CreatedBy             string `json:"created_by,omitempty"`
	CreatedOn             int64  `json:"created_on,omitempty"`
	FinishedAt            int64  `json:"finished_at,omitempty"`
	DatabaseName          string `json:"database_name,omitempty"`
	ReadOnly              bool   `json:"read_only,omitempty"`
	UserAgent             string `json:"user_agent,omitempty"`
	Query                 string `json:"query,omitempty"`
	LastRequestedInterval int64  `json:"last_requested_interval,omitempty"`
}

type TransactionAsyncResult

type TransactionAsyncResult struct {
	// If !GotCompleteResult, keep polling until Transaction reaches terminal State.
	GotCompleteResult bool
	Transaction       TransactionAsyncResponse
	Results           []ArrowRelation
	Metadata          []TransactionAsyncMetadataResponse
	Problems          []interface{}
}

type TransactionAsyncSingleResponse

type TransactionAsyncSingleResponse struct {
	Transaction TransactionAsyncResponse `json:"transaction"`
}

type TransactionResult

type TransactionResult struct {
	Aborted  bool            `json:"aborted"`
	Output   []Relation      `json:"output"`
	Problems []ClientProblem `json:"problems"`
}

func (*TransactionResult) Show

func (tx *TransactionResult) Show()

type UpdateUserRequest

type UpdateUserRequest struct {
	Status string   `json:"status,omitempty"`
	Roles  []string `json:"roles,omitempty"`
}

type User

type User struct {
	AccountName string   `json:"account_name"`
	Email       string   `json:"email"`
	ID          string   `json:"id"`
	IDProviers  []string `json:"id_providers"`
	Roles       []string `json:"roles"`
	Status      string   `json:"status"`
}

Jump to

Keyboard shortcuts

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