util

package
v0.0.0-...-61e8f65 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyNameAndTags is returned when both name and tags are not given.
	ErrEmptyNameAndTags = errors.New("please provide name or tags of the node you want to operate")

	// ErrTooManyArguments is returned when both name and tags are given.
	ErrTooManyArguments = errors.New("too many arguments, cannot have both name and tags")

	// ErrEmptyName is returned when user gives an empty node name.
	ErrEmptyName = errors.New("node name cannot be empty")
)
View Source
var Directory = filepath.Join(os.Getenv("HOME"), ".nodectl")

Directory is the directory address of the cli and all nodes data.

View Source
var Terraform = filepath.Join(os.Getenv("HOME"), ".nodectl", "bin", "terraform")

Terraform is the path of the terraform binary.

Functions

func BackUpConfig

func BackUpConfig(name string) error

BackUpConfig copies the config file of the node to the backup folder under .darknode directory in case something unexpected happens.

func CaptureGroups

func CaptureGroups(regEx, input string) (paramsMap map[string]string)

CaptureGroups returns a map which parses all the capture groups.

func CheckWSL

func CheckWSL() bool

CheckWSL if the linux system is a Subsystem of window.

func CommandOutput

func CommandOutput(commands string) (string, error)

CommandOutput runs a series of commands with bash

func ErrsText

func ErrsText(errs []error, sep string) string

func FindSelfAddress

func FindSelfAddress(options renvm.Options) (wire.Address, int, error)

func GenerateSshKeyAndWriteToDir

func GenerateSshKeyAndWriteToDir(name string) error

GenerateSshKeyAndWriteToDir generates a new ssh key and write it to the given path.

func GenesisURL

func GenesisURL(network multichain.Network) string

GenesisURL returns the url of the genesis file on the given network.

func GetFileURL

func GetFileURL(network multichain.Network, name string) string

GetFileURL returns the URL of the requested file in s3, the network input must be a valid network, otherwise function will panic.

func GetNodesByTags

func GetNodesByTags(tags string) ([]string, error)

GetNodesByTags return the names of the nodes which have the given tags.

func GithubClient

func GithubClient(ctx context.Context) *github.Client

GithubClient initialize the Github client. If an access token has been set as an environment, it will use it for oauth to avoid rate limiting.

func HandleErrs

func HandleErrs(errs []error) error

HandleErrs checks a list of errors, return the first error encountered, nil otherwise.

func LatestRelease

func LatestRelease(network multichain.Network) (string, error)

LatestRelease fetches the name of the latest Darknode release of given network.

func NodeConfigPath

func NodeConfigPath(name string) string

NodeConfigPath return the absolute path of the given darknode's config file.

func NodeEthereumAddr

func NodeEthereumAddr(pk *id.PrivKey) common.Address

NodeEthereumAddr gets the ethereum address of the node with given name.

func NodeExistence

func NodeExistence(name string) error

NodeExistence checks if there exists a node with given name. It returns nil if node exists.

func NodeIP

func NodeIP(name string) (string, error)

NodeIP gets the IP address of the node with given name.

func NodeInstanceUser

func NodeInstanceUser(name string) string

func NodeOptions

func NodeOptions(name string) (renvm.Options, error)

NodeOptions returns the config of the node with given name.

func NodePath

func NodePath(name string) string

NodePath return the absolute directory of the node with given name.

func NodeProvider

func NodeProvider(name string) (string, error)

NodeProvider returns the provider of the node with given name.

func OpenInBrowser

func OpenInBrowser(url string) error

OpenInBrowser tries to open the url with system default browser. It ignores the error if failing.

func OptionsURL

func OptionsURL(network multichain.Network) string

OptionsURL returns the url of the options template.

func ParseNodesFromNameAndTags

func ParseNodesFromNameAndTags(name, tags string) ([]string, error)

ParseNodesFromNameAndTags returns the darknode names which satisfies the name requirements or the tag requirements.

func ParseSshPrivateKey

func ParseSshPrivateKey(name string) (ssh.Signer, error)

func RateLimit

func RateLimit(ctx context.Context, client *github.Client) (int, error)

RateLimit checks if we get rate-limited by the Github API. It will return how many remaining requests we can make before getting rate-limited

func RemoteOutput

func RemoteOutput(name, script string) ([]byte, error)

RemoteOutput runs the script on the instance which host the darknode of given name and returns the output of the script.

func RemoteRun

func RemoteRun(name, script, username string) error

RemoteRun runs the script on the instance which host the darknode of given name.

func Run

func Run(name string, args ...string) error

run the command and pipe the output to the stdout

func SilentRun

func SilentRun(name string, args ...string) error

SilentRun runs the commands with no output

func SnapshotURL

func SnapshotURL(network multichain.Network, name string) string

SnapshotURL returns the url of the latest snapshot file on the given network.

func StringInSlice

func StringInSlice(target string, list []string) bool

StringInSlice checks whether the string is in the slice

func StringifySshPubKey

func StringifySshPubKey(key ssh.PublicKey) string

func ValidateName

func ValidateName(name string) error

ValidateName validates the given name. It should 1) Only contains letter, number, "-" and "_". 2) No more than 32 characters 3) Not start or end with a whitespace.

func ValidateTags

func ValidateTags(have, required string) bool

func VerifyStatusCode

func VerifyStatusCode(response *http.Response, expected int) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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