cmd

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: ISC Imports: 62 Imported by: 0

Documentation

Overview

Package cmd is the front-end interface for the application as a command-line utility.

KeyStoreAuthenticator

KeyStoreAuthenticator prompts the user for their password, which is used to unlock their keystore file to interact with the Ethereum blockchain. Since multiple keystore files can exist at the configured directory, the KeyStoreAuthenticator will try the password on all keystore files present.

Client

Client is how the application is invoked from the command line. When you run the binary, for example `./seerlink n`, client.RunNode is called to start the Seerlink core. Similarly, running `./seerlink j` returns information on all jobs in the node, and `./seerlink s` with another argument as a JobID gives information specific to that job.

Renderer

Renderer helps format and display data (based on the kind of data it is) to the command line.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorNoAPICredentialsAvailable is returned when not run from a terminal
	// and no API credentials have been provided
	ErrorNoAPICredentialsAvailable = errors.New("API credentials must be supplied")
)

Functions

func NewApp

func NewApp(client *Client) *cli.App

NewApp returns the command-line parser/function-router for the given client

Types

type APIInitializer

type APIInitializer interface {
	// Initialize creates a new user for API access, or does nothing if one exists.
	Initialize(store *store.Store) (models.User, error)
}

APIInitializer is the interface used to create the API User credentials needed to access the API. Does nothing if API user already exists.

func NewFileAPIInitializer

func NewFileAPIInitializer(file string) APIInitializer

NewFileAPIInitializer creates a concrete instance of APIInitializer that pulls API user credentials from the passed file path.

func NewPromptingAPIInitializer

func NewPromptingAPIInitializer(prompter Prompter) APIInitializer

NewPromptingAPIInitializer creates a concrete instance of APIInitializer that uses the terminal to solicit credentials from the user.

type AppFactory

type AppFactory interface {
	NewApplication(*orm.Config, ...func(seerlink.Application)) seerlink.Application
}

AppFactory implements the NewApplication method.

type ChangePasswordPrompter

type ChangePasswordPrompter interface {
	Prompt() (models.ChangePasswordRequest, error)
}

ChangePasswordPrompter is an interface primarily used for DI to obtain a password change request from the User.

func NewChangePasswordPrompter

func NewChangePasswordPrompter() ChangePasswordPrompter

NewChangePasswordPrompter returns the production password change request prompter

type Client

type Client struct {
	Renderer
	Config                         *orm.Config
	AppFactory                     AppFactory
	KeyStoreAuthenticator          KeyStoreAuthenticator
	FallbackAPIInitializer         APIInitializer
	Runner                         Runner
	HTTP                           HTTPClient
	CookieAuthenticator            CookieAuthenticator
	FileSessionRequestBuilder      SessionRequestBuilder
	PromptingSessionRequestBuilder SessionRequestBuilder
	ChangePasswordPrompter         ChangePasswordPrompter
	PasswordPrompter               PasswordPrompter
}

Client is the shell for the node, local commands and remote commands.

func (*Client) ArchiveJobSpec

func (cli *Client) ArchiveJobSpec(c *clipkg.Context) error

ArchiveJobSpec soft deletes a job and its associated runs.

func (*Client) CancelJobRun

func (cli *Client) CancelJobRun(c *clipkg.Context) error

CancelJob cancels a running job

func (*Client) ChangePassword

func (cli *Client) ChangePassword(c *clipkg.Context) (err error)

ChangePassword prompts the user for the old password and a new one, then posts it to Seerlink to change the password.

func (*Client) CreateAndExportWeakVRFKey

func (cli *Client) CreateAndExportWeakVRFKey(c *clipkg.Context) error

CreateAndExportWeakVRFKey creates a key in the VRF keystore, protected by the password in the password file, but with weak key-derivation-function parameters, which makes it cheaper for testing, but also more vulnerable to bruteforcing of the encrypted key material. For testing purposes only!

The key is only stored at the specified file location, not stored in the DB.

func (*Client) CreateBridge

func (cli *Client) CreateBridge(c *clipkg.Context) (err error)

CreateBridge adds a new bridge to the seerlink node

func (*Client) CreateETHKey

func (cli *Client) CreateETHKey(c *clipkg.Context) (err error)

CreateETHKey creates a new ethereum key with the same password as the one used to unlock the existing key.

func (*Client) CreateExternalInitiator

func (cli *Client) CreateExternalInitiator(c *clipkg.Context) (err error)

CreateExternalInitiator adds an external initiator

func (*Client) CreateJobRun

func (cli *Client) CreateJobRun(c *clipkg.Context) (err error)

CreateJobRun creates job run based on SpecID and optional JSON

func (*Client) CreateJobSpec

func (cli *Client) CreateJobSpec(c *clipkg.Context) (err error)

CreateJobSpec creates a JobSpec based on JSON input

func (*Client) CreateJobV2

func (cli *Client) CreateJobV2(c *clipkg.Context) (err error)

CreateJobV2 creates a V2 job Valid input is a TOML string or a path to TOML file

func (*Client) CreateOCRKeyBundle

func (cli *Client) CreateOCRKeyBundle(c *clipkg.Context) error

CreateOCRKeyBundle creates a key and inserts it into encrypted_ocr_key_bundles, protected by the password in the password file

func (*Client) CreateP2PKey

func (cli *Client) CreateP2PKey(c *clipkg.Context) (err error)

func (*Client) CreateServiceAgreement

func (cli *Client) CreateServiceAgreement(c *clipkg.Context) (err error)

CreateServiceAgreement creates a ServiceAgreement based on JSON input

func (*Client) CreateVRFKey

func (cli *Client) CreateVRFKey(c *clipkg.Context) error

CreateVRFKey creates a key in the VRF keystore, protected by the password in the password file

func (*Client) DeleteETHKey

func (cli *Client) DeleteETHKey(c *clipkg.Context) (err error)

func (*Client) DeleteExternalInitiator

func (cli *Client) DeleteExternalInitiator(c *clipkg.Context) (err error)

DeleteExternalInitiator removes an external initiator

func (*Client) DeleteJobV2

func (cli *Client) DeleteJobV2(c *clipkg.Context) error

func (*Client) DeleteOCRKeyBundle

func (cli *Client) DeleteOCRKeyBundle(c *clipkg.Context) error

DeleteOCRKeyBundle creates a key and inserts it into encrypted_ocr_keys, protected by the password in the password file

func (*Client) DeleteP2PKey

func (cli *Client) DeleteP2PKey(c *clipkg.Context) (err error)

func (*Client) DeleteUser

func (cli *Client) DeleteUser(c *clipkg.Context) (err error)

DeleteUser is run locally to remove the User row from the node's database.

func (*Client) DeleteVRFKey

func (cli *Client) DeleteVRFKey(c *clipkg.Context) error

DeleteVRFKey soft-deletes the VRF key with given public key from the db

Since this runs in an independent process from any seerlink node, it cannot cause running nodes to forget the key, if they already have it unlocked.

func (*Client) ExportETHKey

func (cli *Client) ExportETHKey(c *clipkg.Context) (err error)

func (*Client) ExportOCRKey

func (cli *Client) ExportOCRKey(c *clipkg.Context) (err error)

func (*Client) ExportP2PKey

func (cli *Client) ExportP2PKey(c *clipkg.Context) (err error)

func (*Client) ExportVRFKey

func (cli *Client) ExportVRFKey(c *clipkg.Context) error

ExportVRFKey saves encrypted copy of VRF key with given public key to requested file path.

func (*Client) GetConfiguration

func (cli *Client) GetConfiguration(c *clipkg.Context) (err error)

GetConfiguration gets the nodes environment variables

func (*Client) HardReset

func (cli *Client) HardReset(c *clipkg.Context) error

HardReset will remove all non-started transactions if any are found.

func (*Client) ImportETHKey

func (cli *Client) ImportETHKey(c *clipkg.Context) (err error)

func (*Client) ImportKey

func (cli *Client) ImportKey(c *clipkg.Context) error

ImportKey imports a key to be used with the seerlink node

func (*Client) ImportOCRKey

func (cli *Client) ImportOCRKey(c *clipkg.Context) (err error)

func (*Client) ImportP2PKey

func (cli *Client) ImportP2PKey(c *clipkg.Context) (err error)

func (*Client) ImportVRFKey

func (cli *Client) ImportVRFKey(c *clipkg.Context) error

ImportVRFKey reads a file into an EncryptedVRFKey in the db

func (*Client) IndexBridges

func (cli *Client) IndexBridges(c *clipkg.Context) (err error)

IndexBridges returns all bridges.

func (*Client) IndexJobRuns

func (cli *Client) IndexJobRuns(c *clipkg.Context) error

IndexJobRuns returns the list of all job runs for a specific job if no jobid is passed, defaults to returning all jobruns

func (*Client) IndexJobSpecs

func (cli *Client) IndexJobSpecs(c *clipkg.Context) error

IndexJobSpecs returns all job specs.

func (*Client) IndexTransactions

func (cli *Client) IndexTransactions(c *clipkg.Context) error

IndexTransactions returns the list of transactions in descending order, taking an optional page parameter

func (*Client) IndexTxAttempts

func (cli *Client) IndexTxAttempts(c *clipkg.Context) error

IndexTxAttempts returns the list of transactions in descending order, taking an optional page parameter

func (*Client) ListETHKeys

func (cli *Client) ListETHKeys(c *clipkg.Context) (err error)

ListETHKeys renders a table containing the active account address with its ETH & LINK balance

func (*Client) ListJobsV2

func (cli *Client) ListJobsV2(c *clipkg.Context) (err error)

ListJobsV2 lists all v2 jobs

func (*Client) ListKeys

func (cli *Client) ListKeys(c *clipkg.Context) error

ListKeys Lists the keys in the db

func (*Client) ListOCRKeyBundles

func (cli *Client) ListOCRKeyBundles(c *clipkg.Context) error

ListOCRKeyBundles lists the available OCR Key Bundles

func (*Client) ListP2PKeys

func (cli *Client) ListP2PKeys(c *clipkg.Context) (err error)

func (*Client) PrepareTestDatabase

func (cli *Client) PrepareTestDatabase(c *clipkg.Context) error

PrepareTestDatabase calls ResetDatabase then loads fixtures required for tests

func (*Client) RebroadcastTransactions

func (cli *Client) RebroadcastTransactions(c *clipkg.Context) (err error)

RebroadcastTransactions run locally to force manual rebroadcasting of transactions in a given nonce range.

func (*Client) RemoteLogin

func (cli *Client) RemoteLogin(c *clipkg.Context) error

RemoteLogin creates a cookie session to run remote commands.

func (*Client) RemoveBridge

func (cli *Client) RemoveBridge(c *clipkg.Context) (err error)

RemoveBridge removes a specific Bridge by name.

func (*Client) ResetDatabase

func (cli *Client) ResetDatabase(c *clipkg.Context) error

ResetDatabase drops, creates and migrates the database specified by DATABASE_URL This is useful to setup the database for testing

func (*Client) RunNode

func (cli *Client) RunNode(c *clipkg.Context) error

RunNode starts the Seerlink core.

func (*Client) SendEther

func (cli *Client) SendEther(c *clipkg.Context) (err error)

SendEther transfers ETH from the node's account to a specified address.

func (*Client) SetMinimumGasPrice

func (cli *Client) SetMinimumGasPrice(c *clipkg.Context) (err error)

SetMinimumGasPrice specifies the minimum gas price to use for outgoing transactions

func (*Client) SetNextNonce

func (cli *Client) SetNextNonce(c *clipkg.Context) error

SetNextNonce manually updates the keys.next_nonce field for the given key with the given nonce value

func (*Client) ShowBridge

func (cli *Client) ShowBridge(c *clipkg.Context) (err error)

ShowBridge returns the info for the given Bridge name.

func (*Client) ShowJobRun

func (cli *Client) ShowJobRun(c *clipkg.Context) (err error)

ShowJobRun returns the status of the given Jobrun.

func (*Client) ShowJobSpec

func (cli *Client) ShowJobSpec(c *clipkg.Context) (err error)

ShowJobSpec returns the status of the given JobID.

func (*Client) ShowTransaction

func (cli *Client) ShowTransaction(c *clipkg.Context) (err error)

ShowTransaction returns the info for the given transaction hash

func (*Client) TriggerPipelineRun

func (cli *Client) TriggerPipelineRun(c *clipkg.Context) error

TriggerPipelineRun triggers a V2 job run based on a job ID

type CookieAuthenticator

type CookieAuthenticator interface {
	Cookie() (*http.Cookie, error)
	Authenticate(models.SessionRequest) (*http.Cookie, error)
}

CookieAuthenticator is the interface to generating a cookie to authenticate future HTTP requests.

func NewSessionCookieAuthenticator

func NewSessionCookieAuthenticator(config *orm.Config, store CookieStore) CookieAuthenticator

NewSessionCookieAuthenticator creates a SessionCookieAuthenticator using the passed config and builder.

type CookieStore

type CookieStore interface {
	Save(cookie *http.Cookie) error
	Retrieve() (*http.Cookie, error)
}

CookieStore is a place to store and retrieve cookies.

type DirectRequestSpec

type DirectRequestSpec struct {
	ContractAddress  string    `json:"contractAddress"`
	OnChainJobSpecID string    `json:"OnChainJobSpecID"`
	CreatedAt        time.Time `json:"createdAt"`
	UpdatedAt        time.Time `json:"updatedAt"`
}

DirectRequestSpec defines the spec details of a DirectRequest Job

type DiskCookieStore

type DiskCookieStore struct {
	Config *orm.Config
}

DiskCookieStore saves a single cookie in the local cli working directory.

func (DiskCookieStore) Retrieve

func (d DiskCookieStore) Retrieve() (*http.Cookie, error)

Retrieve returns any Saved cookies.

func (DiskCookieStore) Save

func (d DiskCookieStore) Save(cookie *http.Cookie) error

Save stores a cookie.

type FluxMonitorSpec

type FluxMonitorSpec struct {
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

FluxMonitorSpec defines the spec details of a FluxMonitor Job

type HTTPClient

type HTTPClient interface {
	Get(string, ...map[string]string) (*http.Response, error)
	Post(string, io.Reader) (*http.Response, error)
	Put(string, io.Reader) (*http.Response, error)
	Patch(string, io.Reader, ...map[string]string) (*http.Response, error)
	Delete(string) (*http.Response, error)
}

HTTPClient encapsulates all methods used to interact with a seerlink node API.

func NewAuthenticatedHTTPClient

func NewAuthenticatedHTTPClient(config orm.ConfigReader, cookieAuth CookieAuthenticator) HTTPClient

NewAuthenticatedHTTPClient uses the CookieAuthenticator to generate a sessionID which is then used for all subsequent HTTP API requests.

type JAID

type JAID struct {
	ID string `json:"-"`
}

JAID represents a JSON API ID. It implements the api2go MarshalIdentifier and UnmarshalIdentitier interface.

func (JAID) GetID

func (jaid JAID) GetID() string

GetID implements the api2go MarshalIdentifier interface.

func (*JAID) SetID

func (jaid *JAID) SetID(value string) error

SetID implements the api2go UnmarshalIdentitier interface.

type Job

type Job struct {
	JAID
	Name                  string                 `json:"name"`
	Type                  JobType                `json:"type"`
	DirectRequestSpec     *DirectRequestSpec     `json:"DirectRequestSpec"`
	FluxMonitorSpec       *FluxMonitorSpec       `json:"fluxMonitorSpec"`
	OffChainReportingSpec *OffChainReportingSpec `json:"offChainReportingOracleSpec"`
	PipelineSpec          PipelineSpec           `json:"pipelineSpec"`
}

Job represents a V2 Job

func (Job) FriendlyCreatedAt

func (j Job) FriendlyCreatedAt() string

FriendlyCreatedAt returns the created at timestamp of the spec which matches the type in RFC3339 format.

func (Job) FriendlyTasks

func (j Job) FriendlyTasks() []string

FriendlyTasks returns the tasks

func (Job) GetName

func (j Job) GetName() string

GetName implements the api2go EntityNamer interface

func (Job) GetTasks

func (j Job) GetTasks() ([]string, error)

GetTasks extracts the tasks from the dependency graph

TODO - Remove dependency on the pipeline package

func (Job) ToRow

func (j Job) ToRow() [][]string

ToRow returns the job as a multiple rows per task

type JobType

type JobType string

JobType defines the the job type

const (
	// DirectRequestJob defines a Direct Request Job
	DirectRequestJob JobType = "directrequest"
	// FluxMonitorJob defines a Flux Monitor Job
	FluxMonitorJob JobType = "fluxmonitor"
	// OffChainReportingJob defines an OCR Job
	OffChainReportingJob JobType = "offchainreporting"
)

func (JobType) String

func (t JobType) String() string

type KeyStoreAuthenticator

type KeyStoreAuthenticator interface {
	Authenticate(*store.Store, string) (string, error)
	AuthenticateVRFKey(*store.Store, string) error
	AuthenticateOCRKey(store *store.Store, password string) error
}

KeyStoreAuthenticator implements the Authenticate method for the store and a password string.

type MemoryCookieStore

type MemoryCookieStore struct {
	Cookie *http.Cookie
}

MemoryCookieStore keeps a single cookie in memory

func (*MemoryCookieStore) Retrieve

func (m *MemoryCookieStore) Retrieve() (*http.Cookie, error)

Retrieve returns any Saved cookies.

func (*MemoryCookieStore) Save

func (m *MemoryCookieStore) Save(cookie *http.Cookie) error

Save stores a cookie.

type OffChainReportingSpec

type OffChainReportingSpec struct {
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

OffChainReportingSpec defines the spec details of a OffChainReporting Job

type PasswordPrompter

type PasswordPrompter interface {
	Prompt() string
}

PasswordPrompter is an interface primarily used for DI to obtain a password from the User.

func NewPasswordPrompter

func NewPasswordPrompter() PasswordPrompter

NewPasswordPrompter returns the production password change request prompter

type PipelineSpec

type PipelineSpec struct {
	ID           int32  `json:"ID"`
	DotDAGSource string `json:"dotDagSource"`
}

PipelineSpec defines the spec details of the pipeline

type Prompter

type Prompter interface {
	Prompt(string) string
	PasswordPrompt(string) string
	IsTerminal() bool
}

Prompter implements the Prompt function to be used to display at the console.

func NewTerminalPrompter

func NewTerminalPrompter() Prompter

NewTerminalPrompter prompts the user via terminal.

type Renderer

type Renderer interface {
	Render(interface{}) error
}

Renderer implements the Render method.

type RendererJSON

type RendererJSON struct {
	io.Writer
}

RendererJSON is used to render JSON data.

func (RendererJSON) Render

func (rj RendererJSON) Render(v interface{}) error

Render writes the given input as a JSON string.

type RendererTable

type RendererTable struct {
	io.Writer
}

RendererTable is used for data to be rendered as a table.

func (RendererTable) Render

func (rt RendererTable) Render(v interface{}) error

Render returns a formatted table of text for a given Job or presenter and relevant information.

type Runner

type Runner interface {
	Run(seerlink.Application) error
}

Runner implements the Run method.

type SeerlinkAppFactory

type SeerlinkAppFactory struct{}

SeerlinkAppFactory is used to create a new Application.

func (SeerlinkAppFactory) NewApplication

func (n SeerlinkAppFactory) NewApplication(config *orm.Config, onConnectCallbacks ...func(seerlink.Application)) seerlink.Application

NewApplication returns a new instance of the node with the given config.

type SeerlinkRunner

type SeerlinkRunner struct{}

SeerlinkRunner is used to run the node application.

func (SeerlinkRunner) Run

Run sets the log level based on config and starts the web router to listen for input and return data.

type SessionCookieAuthenticator

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

SessionCookieAuthenticator is a concrete implementation of CookieAuthenticator that retrieves a session id for the user with credentials from the session request.

func (*SessionCookieAuthenticator) Authenticate

func (t *SessionCookieAuthenticator) Authenticate(sessionRequest models.SessionRequest) (*http.Cookie, error)

Authenticate retrieves a session ID via a cookie and saves it to disk.

func (*SessionCookieAuthenticator) Cookie

func (t *SessionCookieAuthenticator) Cookie() (*http.Cookie, error)

Cookie Returns the previously saved authentication cookie.

type SessionRequestBuilder

type SessionRequestBuilder interface {
	Build(flag string) (models.SessionRequest, error)
}

SessionRequestBuilder is an interface that returns a SessionRequest, abstracting how session requests are generated, whether they be from the prompt or from a file.

func NewFileSessionRequestBuilder

func NewFileSessionRequestBuilder() SessionRequestBuilder

NewFileSessionRequestBuilder pulls credentials from a file to generate a SessionRequest.

func NewPromptingSessionRequestBuilder

func NewPromptingSessionRequestBuilder(prompter Prompter) SessionRequestBuilder

NewPromptingSessionRequestBuilder uses a prompter, often via terminal, to solicit information from a user to generate the SessionRequest.

type TerminalKeyStoreAuthenticator

type TerminalKeyStoreAuthenticator struct {
	Prompter Prompter
}

TerminalKeyStoreAuthenticator contains fields for prompting the user and an exit code.

func (TerminalKeyStoreAuthenticator) Authenticate

func (auth TerminalKeyStoreAuthenticator) Authenticate(store *store.Store, password string) (string, error)

Authenticate checks to see if there are accounts present in the KeyStore, and if there are none, a new account will be created by prompting for a password. If there are accounts present, all accounts will be unlocked.

func (TerminalKeyStoreAuthenticator) AuthenticateOCRKey

func (auth TerminalKeyStoreAuthenticator) AuthenticateOCRKey(store *store.Store, password string) error

func (TerminalKeyStoreAuthenticator) AuthenticateVRFKey

func (auth TerminalKeyStoreAuthenticator) AuthenticateVRFKey(store *store.Store, password string) error

AuthenticateVRFKey creates an encrypted VRF key protected by password in store's db if db store has no extant keys. It unlocks at least one VRF key with given password, or returns an error. password must be non-trivial, as an empty password signifies that the VRF oracle functionality is disabled.

Directories

Path Synopsis
testscript

Jump to

Keyboard shortcuts

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