utils

package
v0.0.0-...-f97e583 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const GRPCErrorPrefix string = "rpc error: code = Unknown desc ="
View Source
const UnitValidationRegex string = `\b(\d+(\.\d+)?)((ns|us|ms|s|m|h))\b`

Variables

View Source
var ErrorDescriptions = map[AppError]string{
	ErrDocumentExists: "This mongo document is already exist in the collection",
}

ErrorDescriptions holds detailed error description for every AppError

View Source
var ErrorStatusCodes = map[AppError]int{
	ErrDocumentExists: 401,
}

ErrorStatusCodes holds the http status codes for every AppError

View Source
var (
	SupportedPrivateGitRepository = []string{"github", "gitlab"}
)

Functions

func AddRootIndent

func AddRootIndent(b []byte, n int) []byte

func CheckEmptyFields

func CheckEmptyFields(v interface{}) error

func ContainsString

func ContainsString(s []string, str string) bool

ContainsString checks if a string is present in an array of strings

func DirSize

func DirSize(path string) (int64, error)

DirSize returns the size of directory

func GenerateAccessKey

func GenerateAccessKey(length int) (string, error)

GenerateAccessKey generates an access key by leveraging crypto/rand package

func GenerateUUID

func GenerateUUID() string

GenerateUUID : Generate a unique string id based on google/uuid

func IsFileExisting

func IsFileExisting(path string) (bool, error)

IsFileExisting checks if a file or directory exists in the system

func MatchInfrastructureType

func MatchInfrastructureType(infras []*model.InfrastructureType, infra model.InfrastructureType) bool

func ParseGRPCError

func ParseGRPCError(err error) error

func RandomString

func RandomString(n int) string

RandomString generates random strings, can be used to create ids

func RestCall

func RestCall(method string, url string, payload []byte, opt ...func(option *RestCallOption)) (int, []byte, error)

func Split

func Split(str, before, after string) string

Split returns the string in between a before sub-string and an after sub-string

func StringPtrToString

func StringPtrToString(val *string) string

func TransformProbe

func TransformProbe(probeList []v1alpha1.ProbeAttributes) []v1alpha1.ProbeAttributes

func Truncate

func Truncate(num float64) float64

Truncate a float to two levels of precision

func WithHeaders

func WithHeaders(headers map[string]string) func(*RestCallOption)

func WithMaxRetries

func WithMaxRetries(maxRetries int) func(*RestCallOption)

func WithRetryInterval

func WithRetryInterval(retryInterval time.Duration) func(*RestCallOption)

func WithTimeout

func WithTimeout(timeout time.Duration) func(*RestCallOption)

func WriteHeaders

func WriteHeaders(w *gin.ResponseWriter, statusCode int)

WriteHeaders adds important headers to API responses

Types

type AppError

type AppError error

AppError defines general error's throughout the system

var (
	ErrDocumentExists AppError = errors.New("mongo_document_exists")
)

type Configuration

type Configuration struct {
	Version                     string `required:"true"`
	InfraDeployments            string `required:"true" split_words:"true"`
	DbServer                    string `required:"true" split_words:"true"`
	JwtSecret                   string `required:"true" split_words:"true"`
	LitmusPortalNamespace       string `required:"true" split_words:"true"`
	DbUser                      string `required:"true" split_words:"true"`
	DbPassword                  string `required:"true" split_words:"true"`
	ChaosCenterScope            string `required:"true" split_words:"true"`
	SubscriberImage             string `required:"true" split_words:"true"`
	EventTrackerImage           string `required:"true" split_words:"true"`
	ArgoWorkflowControllerImage string `required:"true" split_words:"true"`
	ArgoWorkflowExecutorImage   string `required:"true" split_words:"true"`
	LitmusChaosOperatorImage    string `required:"true" split_words:"true"`
	LitmusChaosRunnerImage      string `required:"true" split_words:"true"`
	LitmusChaosExporterImage    string `required:"true" split_words:"true"`
	ContainerRuntimeExecutor    string `required:"true" split_words:"true"`
	WorkflowHelperImageVersion  string `required:"true" split_words:"true"`
	ServerServiceName           string `split_words:"true"`
	NodeName                    string `split_words:"true"`
	Ingress                     string `split_words:"true"`
	IngressName                 string `split_words:"true"`
	ChaosCenterUiEndpoint       string `split_words:"true" default:"localhost:8080"`
	TlsCertB64                  string `split_words:"true"`
	TlsSecretName               string `split_words:"true"`
	LitmusAuthGrpcEndpoint      string `split_words:"true" default:"localhost"`
	LitmusAuthGrpcPort          string `split_words:"true" default:":3030"`
	KubeConfigFilePath          string `split_words:"true"`
	RemoteHubMaxSize            string `split_words:"true"`
	SkipSslVerify               string `split_words:"true"`
	SelfInfraNodeSelector       string `split_words:"true"`
	SelfInfraTolerations        string `split_words:"true"`
	HttpPort                    string `split_words:"true" default:"8080"`
	RpcPort                     string `split_words:"true" default:"8000"`
	InfraCompatibleVersions     string `required:"true" split_words:"true"`
	DefaultHubGitURL            string `required:"true" default:"https://github.com/litmuschaos/chaos-charts"`
	DefaultHubBranchName        string `required:"true" split_words:"true"`
	CustomChaosHubPath          string `split_words:"true" default:"/tmp/"`
	DefaultChaosHubPath         string `split_words:"true" default:"/tmp/default/"`
}
var Config Configuration

type RestCallOption

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

Jump to

Keyboard shortcuts

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