utils

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Copyright 2022 Nethermind

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNoTag           = errors.New("no tag found on Github")
	ErrorCheckingVersion = errors.New("error while checking for new Version, please check your internet connection")
)
View Source
var Version string

Version represents the current version of Sedge

Functions

func AssignPorts

func AssignPorts(host string, defaults map[string]uint16) (ports map[string]uint16, err error)

AssignPorts : Checks if port is occupied in a given host

params :- a. host string Host which port is to be checked b. port string Port to be checked

returns :- a. bool True if <port> is available. False otherwise

func CheckContainers

func CheckContainers(cmdRunner commands.CommandRunner, generationPath string) (string, error)

CheckContainers : Check if containers of generated docker-compose script are running

params :- a. generationPath string Path to the generated docker-compose script

returns :- a. string Output of 'docker ps --services --filter status=running' b. error Error if any

func CheckErr

func CheckErr(descr string, isErr bool, err error) error

CheckErr : Helper function for tests. Check if a given error was expected.

params :- a. desc string Description of the error in case of failure b. isError bool Whether the error was expected or not c. err error Error to check

returns :- a. error Error if any

func CheckUrlOrPath

func CheckUrlOrPath(src string) error

CheckUrlOrPath : Verifies if provided source string is an url or filepath returning relevant error if neither

params :- a. string Source that will be tried to convert to url or path

returns :- a. error if provided source is neither file or url.

func Contains

func Contains(list []string, str string) bool

Contains : Checks if a string slice contains a string

params :- a. list []string String slice to be checked b. str string String to be checked

returns :- a. bool True if str is in list, false otherwise

func ContainsOnly

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

ContainsOnly : Checks if a string slice contains only strings of a given string slice

params :- a. list []string String slice to be checked b. target []string String slice to be checked

returns :- a. bool True if every string in list is in target, false otherwise

func CopyFile

func CopyFile(src, dst string) error

CopyFile: Copies the file from src to dst, if the directory of the dst doesn't exist then is created before the copy.

params :- a. src string Source path b. dst string Destination path

func CurrentVersion

func CurrentVersion() string

CurrentVersion : Export the current version of Sedge

params :- None

returns :- a. string Return the current version of Sedge

func DownloadOrCopy

func DownloadOrCopy(src, dest string, autoremove bool) error

DownloadOrCopy : Get content of the source url or filepath provided

params :- a. string Source that will be used as url or filepath b. string Destination filepath to downloaded or copied file c. bool Delete existing file in the destination filepath

returns :- a. error if any

func ENRValidator

func ENRValidator(bootNodes []string) error

ENRValidator validates a list of CL boot nodes and returns an error if any of them is invalid.

func ENodesValidator

func ENodesValidator(bootNodes []string) error

ENodesValidator validates a list of EL boot nodes and returns an error if any of them is invalid.

func Filter

func Filter[T any](list []T, filter func(T) bool) (ret []T)

Filter : Filter a slice given a predicate

params :- a. list []K List to be filtered b. filter func(K) bool Predicate to be applied to each element of the list

returns :- a. []K Filtered list

func GetDistroName

func GetDistroName() (_ string, err error)

GetDistroName : Get the name and version of the linux distribution of the host machine.

params :- None

returns :- a. string "<Distribution_Name> <Distribution_Version>" a. error Error if any

func GetRequest

func GetRequest(url string, retryDuration time.Duration) (*http.Response, error)

GetRequest : Make a GET request to the given URL. Uses exponential retries with backoff.

params :- a. url string URL to make the request to b. retryDuration time.Duration Duration to wait between retries

returns :- a. http.Response Response from the request b. error Error if any

func GetUrlOrPathContent

func GetUrlOrPathContent(src string) (string, error)

GetUrlOrPathContent : Get content of the source url or filepath provided

params :- a. string Source that will be used as url or filepath

returns :- a. error if any

func HandleUrlOrPath

func HandleUrlOrPath(
	src string,
	handleUrl func(url string) error,
	handlePath func(path string) error,
) error

HandleUrlOrPath : Get a source string and call related handler if the source

params :- a. string Source that will be tried to convert to url or path b. func(url string) error Handler function to call if source is an url c. func(path string) error Handler function to call if source is a filepath

returns :- a. error occurred during any of the handlers if any or if provided source is neither file or url.

func IsAddress

func IsAddress(a string) bool

IsAddress : Checks if a string is an Ethereum address

params :- a. a string String to be checked

returns :- a. bool True if <a> is a valid Ethereum address. False otherwise

func IsLatestVersion

func IsLatestVersion() (bool, error)

IsLatestVersion : Check if we are running the latest version that was released on GitHub

params :- None

returns :- a. bool Returns true if we are on the latest version, but false if we have a different version that latest on Github. a. err error Error if any

func LoadDockerComposeServices

func LoadDockerComposeServices(path string) ([]string, error)

TODO: Add unit tests LoadDockerComposeServices get the services from a Sedge valid docker-compose script

func ParseEnv

func ParseEnv(path string) (map[string]string, error)

ParseEnv parse a .env file and return a map of the environment variables

func SetUmask

func SetUmask(mask int)

func SkipLines

func SkipLines(content string, symbol string) string

SkipLines : Skips lines starting with `symbol`

params :- a. content string String to be processed b. symbol string Symbol to be skipped

returns :- a. string Processed string

func SupportedNetworks

func SupportedNetworks() (networkNames []string, err error)

SupportedNetworks : Get supported networks names. A network is supported if it has a folder with the network name in either templates/envs or templates/services forder.

params :- none

returns :- a. []string List of supported network names b. error Error if any

func UriValidator

func UriValidator(input []string) (string, bool)

UriValidator validates a URI and returns true if it is valid.

func ValidateCompose

func ValidateCompose(path string) error

ValidateCompose validate a docker-compose script according to the docker-compose specification

func ZipString

func ZipString(lists ...[]string) ([][]string, error)

ZipString : Zip string slices

params :- a. lists ...[]string String slices to be zipped

returns :- a. [][]string Zipped string slices b. error Error if any

Types

type DepositCLI

type DepositCLI struct {
	// Network : Network name, e.g. "mainnet", "goerli"
	Network string
	// Path : Path to the keystore folder
	Path string
	// Password : Keystore password
	Password string
	// LenPass : Slice used to hide password in template
	LenPass []struct{}
	// Image : staking-deposit-cli docker image
	Image string
	// Eth1WithdrawalAddress : Address to be used to create withdrawal credentials
	Eth1WithdrawalAddress string
}

DepositCLI : Struct Data for eth2.0-deposit-cli command template

type DistroInfo

type DistroInfo struct {
	Name         string
	Architecture string
	Version      string
}

DistroInfo : Struct Contains name, architecture and version of the linux distribution of the host machine

type ValidatorKeyData

type ValidatorKeyData struct {
	// Existing: True if a existing mnemonic is being used. False to create and use a new one.
	Existing bool
	// Network : Target network
	Network string
	// Path : Path to the keystore folder
	Path string
	// Password : Keystore password
	Password string
	// Eth1WithdrawalAddress : Address to be used to create withdrawal credentials
	Eth1WithdrawalAddress string
}

ValidatorKeyData : Struct Data for Keystore generation

Jump to

Keyboard shortcuts

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