utils

package
v1.5.3-rc.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: BSD-3-Clause Imports: 32 Imported by: 0

Documentation

Overview

Copyright (C) 2022, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2022, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2023, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2022, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2023, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2022, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2023, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2023, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSingleQuotes added in v1.5.0

func AddSingleQuotes(s []string) []string

AddSingleQuotes adds single quotes to each string in the given slice.

func Any added in v1.4.0

func Any[T any](input []T, f func(T) bool) bool

func ArchSupported added in v1.5.0

func ArchSupported(arch string) bool

func ContainsIgnoreCase added in v1.3.6

func ContainsIgnoreCase(s, substr string) bool

containsIgnoreCase checks if the given string contains the specified substring, ignoring case.

func ConvertInterfaceToMap added in v1.3.4

func ConvertInterfaceToMap(value interface{}) (map[string]interface{}, error)

ConvertInterfaceToMap converts a given value to a map[string]interface{}.

func DirectoryExists added in v1.3.7

func DirectoryExists(dirName string) bool

func Download added in v1.4.0

func Download(url string) ([]byte, error)

func DownloadStr added in v1.4.0

func DownloadStr(url string) (string, error)

func DownloadWithTee added in v1.4.0

func DownloadWithTee(url string, path string) ([]byte, error)

func E2EDocker added in v1.4.0

func E2EDocker() bool

E2EDocker checks if docker and docker-compose are available.

func ExpandHome added in v1.5.0

func ExpandHome(path string) string

ExpandHome expands ~ symbol to home directory

func FileCopy added in v1.5.0

func FileCopy(src string, dst string) error

FileCopy copies a file from src to dst.

func FileExists added in v1.3.4

func FileExists(filename string) bool

FileExists checks if a file exists.

func Filter added in v1.3.4

func Filter[T any](input []T, f func(T) bool) []T

func Find added in v1.4.0

func Find[T any](input []T, f func(T) bool) *T

func GenDockerComposeFile added in v1.4.0

func GenDockerComposeFile(nodes int, ubuntuVersion string, networkPrefix string, sshPubKey string) (string, error)

GenDockerComposeFile generates a Docker Compose file with the specified number of nodes and Ubuntu version.

func GenerateDockerHostIDs added in v1.4.0

func GenerateDockerHostIDs(numNodes int) []string

GenerateDockerHostIDs generates a list of Docker host IDs.

func GenerateDockerHostIPs added in v1.4.0

func GenerateDockerHostIPs(numNodes int) []string

func GetANRContext added in v1.3.4

func GetANRContext() (context.Context, context.CancelFunc)

Context for ANR network operations

func GetAPIContext added in v1.3.4

func GetAPIContext() (context.Context, context.CancelFunc)

Context for API requests

func GetAPILargeContext added in v1.5.1

func GetAPILargeContext() (context.Context, context.CancelFunc)

Context for API requests with large timeout

func GetCodespaceURL added in v1.5.1

func GetCodespaceURL(url string) (string, error)

func GetGitCommit added in v1.5.0

func GetGitCommit(gitRepoURL string) string

GetGitCommit takes a Git repository URL that contains commit ID and returns the commit ID Example: https://github.com/ava-labs/hypersdk/pull/772/commits/b88acfb370f5aeb83a000aece2d72f28154410a5 Should return b88acfb370f5aeb83a000aece2d72f28154410a5

func GetIndexInSlice added in v1.5.0

func GetIndexInSlice[T comparable](list []T, element T) (int, error)

func GetRealFilePath added in v1.3.4

func GetRealFilePath(path string) string

func GetRepoFromCommitURL added in v1.5.0

func GetRepoFromCommitURL(gitRepoURL string) (string, string)

GetRepoFromCommitURL takes a Git repository URL that contains commit ID and returns the cloneable Git Repo URL (ends in .git) and the repo directory name Example: https://github.com/ava-labs/hypersdk/pull/772/commits/b88acfb370f5aeb83a000aece2d72f28154410a5 Should return https://github.com/ava-labs/hypersdk

func GetSHA256FromDisk added in v1.0.3

func GetSHA256FromDisk(binPath string) (string, error)

func GetSSHConnectionString added in v1.3.3

func GetSSHConnectionString(publicIP, certFilePath string) string

GetSSHConnectionString returns the SSH connection string for the given public IP and certificate file path.

func GetURIHostPortAndPath added in v1.5.1

func GetURIHostPortAndPath(uri string) (string, uint32, string, error)

Get the host, port and path from a URL.

func GetUserIPAddress added in v1.4.0

func GetUserIPAddress() (string, error)

GetUserIPAddress retrieves the IP address of the user.

func InsideCodespace added in v1.5.1

func InsideCodespace() bool

func IsE2E added in v1.4.0

func IsE2E() bool

IsE2E checks if the environment variable "RUN_E2E" is set and returns true if it is, false otherwise.

func IsExecutable added in v1.3.4

func IsExecutable(filename string) bool

IsExecutable checks if a file is executable.

func IsSSHAgentAvailable added in v1.3.7

func IsSSHAgentAvailable() bool

isSSHAgentAvailable checks if the SSH agent is available.

func IsSSHAgentIdentityValid added in v1.3.7

func IsSSHAgentIdentityValid(identity string) (bool, error)

func IsSSHPubKey added in v1.5.0

func IsSSHPubKey(pubkey string) bool

IsSSHPubKey checks if the given string is a valid SSH public key.

func IsUnsignedSlice added in v1.3.5

func IsUnsignedSlice(n []int) bool

IsUnsignedSlice returns true if all elements in the slice are unsigned integers.

func IsValidIP added in v1.4.0

func IsValidIP(ipStr string) bool

func IsValidURL added in v1.5.1

func IsValidURL(urlString string) bool

IsValidURL checks if a URL is valid.

func ListSSHAgentIdentities added in v1.3.7

func ListSSHAgentIdentities() ([]string, error)

ListSSHAgentIdentity returns a list of SSH identities from ssh-agent.

func Map added in v1.3.4

func Map[T, U any](input []T, f func(T) U) []U

func MapWithError added in v1.3.4

func MapWithError[T, U any](input []T, f func(T) (U, error)) ([]U, error)

func NewBlsSecretKeyBytes added in v1.3.4

func NewBlsSecretKeyBytes() ([]byte, error)

func RandomString added in v1.4.0

func RandomString(length int) string

RandomString generates a random string of the specified length.

func ReadFile added in v1.5.3

func ReadFile(filePath string) (string, error)

ReadFile reads a file and returns the contents as a string

func ReadLongString added in v1.5.0

func ReadLongString(msg string, args ...interface{}) (string, error)

ReadLongString reads a long string from the user input.

func ReadSSHAgentIdentityPublicKey added in v1.3.7

func ReadSSHAgentIdentityPublicKey(identityName string) (string, error)

func RemoveLineCleanChars added in v1.4.0

func RemoveLineCleanChars(s string) string

func SaveDockerComposeFile added in v1.4.0

func SaveDockerComposeFile(fileName string, nodes int, ubuntuVersion string, sshPubKey string) (string, error)

SaveDockerComposeFile saves the Docker Compose file with the specified number of nodes and Ubuntu version.

func ScriptLog added in v1.4.0

func ScriptLog(nodeID string, msg string, args ...interface{}) string

func SearchSHA256File added in v1.0.3

func SearchSHA256File(file []byte, toSearch string) (string, error)

func SetupRealtimeCLIOutput added in v1.2.7

func SetupRealtimeCLIOutput(cmd *exec.Cmd, redirectStdout bool, redirectStderr bool) (*bytes.Buffer, *bytes.Buffer)

func SortUint32 added in v1.3.5

func SortUint32(arr []uint32)

func SplitComaSeparatedInt added in v1.3.5

func SplitComaSeparatedInt(s string) []int

SplitComaSeparatedInt splits a comma-separated string into a slice of integers.

func SplitComaSeparatedString added in v1.3.5

func SplitComaSeparatedString(s string) []string

SplitComaSeparatedString splits and trims a comma-separated string into a slice of strings.

func SplitKeyValueStringToMap added in v1.3.3

func SplitKeyValueStringToMap(str string, delimiter string) (map[string]string, error)

SplitKeyValueStringToMap splits a string with multiple key-value pairs separated by delimiter. Delimiter must be a single character

func SplitSliceAt added in v1.4.0

func SplitSliceAt[T any](slice []T, index int) ([]T, []T)

SplitSliceAt splits a slice at the given index and returns two new slices.func SplitSliceAt[T any](slice []T, index int) ([]T, []T) {

func SplitStringWithQuotes added in v1.3.3

func SplitStringWithQuotes(str string, r rune) []string

SplitString split string with a rune comma ignore quoted

func StartDockerCompose added in v1.4.0

func StartDockerCompose(filePath string) error

StartDockerCompose is a function that starts Docker Compose.

func StopDockerCompose added in v1.4.0

func StopDockerCompose(filePath string) error

StopDockerCompose stops the Docker Compose services defined in the specified file.

func Sum added in v1.4.0

func Sum(s []int) int

Sum calculates the sum of all the elements in the given slice of integers.

func SupportedAvagoArch added in v1.5.0

func SupportedAvagoArch() []string

func TimedFunction added in v1.3.4

func TimedFunction(f func() (interface{}, error), name string, timeout time.Duration) (interface{}, error)

TimedFunction is a function that executes the given function `f` within a specified timeout duration.

func ToNodeID added in v1.3.4

func ToNodeID(certBytes []byte) (ids.NodeID, error)

func Unique added in v1.3.5

func Unique(slice []string) []string

Unique returns a new slice containing only the unique elements from the input slice.

func UserHomePath added in v1.3.4

func UserHomePath(filePath ...string) string

UserHomePath returns the absolute path of a file located in the user's home directory.

func ValidateJSON

func ValidateJSON(path string) ([]byte, error)

ValidateJSON takes a json string and returns it's byte representation if it contains valid JSON

func WriteStringToFile added in v1.5.3

func WriteStringToFile(filePath string, data string) error

WriteStringToFile writes a string to a file

Types

type Config added in v1.4.0

type Config struct {
	IPs           []string
	UbuntuVersion string
	NetworkPrefix string
	SSHPubKey     string
}

Config holds the information needed for the template

Jump to

Keyboard shortcuts

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