utils

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: Apache-2.0 Imports: 32 Imported by: 18

Documentation

Index

Constants

View Source
const (
	TimeStampLayout          = "2006-01-02T15:04:05.000000-07:00"
	TimeLayoutYYYYMMDDHHMMSS = "20060102150405"
	RetriesFactor            = 3
)
View Source
const VERSION = "0.8.0"

Variables

This section is empty.

Functions

func CheckError

func CheckError(err error)

TODO remove after migration

func CheckRequiredFlags

func CheckRequiredFlags(c *cli.Context, flags []string)

CheckRequiredFlags checks for required flags, and show usage if requirements not met

func CheckReturnCode

func CheckReturnCode(res int, mesg []byte)

func CheckStandardStatus

func CheckStandardStatus(status int, mesg []byte) error

CheckStandardStatus return error if status is not OK

func Contains added in v0.8.0

func Contains(s []string, x string) bool

Contains evaluates whether s contains x.

func ExecCode

func ExecCode(code string, path string, filename string) (output string, exitCode int, startedAt time.Time, finishedAt time.Time)

func FileExists

func FileExists(name string) bool

FileExists checks file existence

func FlagConvertParams

func FlagConvertParams(c *cli.Context) *map[string]interface{}

FlagConvertParams converts cli parameters in API callable params

func FlagConvertParamsJSON

func FlagConvertParamsJSON(c *cli.Context, jsonFlags []string) (*map[string]interface{}, error)

FlagConvertParamsJSON converts cli parameters in API callable params, and encodes JSON parameters

func FlagsRequired

func FlagsRequired(c *cli.Context, flags []string)

TODO remove after migration

func GetDefaultCaCertFilePath

func GetDefaultCaCertFilePath() string

GetDefaultCaCertFilePath returns default concerto configuration path file

func GetDefaultCertFilePath

func GetDefaultCertFilePath() string

GetDefaultCertFilePath returns default concerto configuration path file

func GetDefaultKeyFilePath

func GetDefaultKeyFilePath() string

GetDefaultKeyFilePath returns default concerto configuration path file

func GetDefaultLogFilePath

func GetDefaultLogFilePath() string

GetDefaultLogFilePath returns default concerto configuration path file

func GetProcessIdFromFile

func GetProcessIdFromFile(pidFileName string) (int, error)

GetProcessIdFromFile reads the process id previously stored in the file

func ItemConvertParams

func ItemConvertParams(item interface{}) (*map[string]interface{}, error)

ItemConvertParams converts API items into map of interface

func JSONParam

func JSONParam(param string) (interface{}, error)

JSONParam parses parameter as json structure

func RandomString

func RandomString(strlen int) string

RandomString generates a random string from lowercase letters and numbers

func RemoveDuplicates added in v0.8.0

func RemoveDuplicates(elements []string) []string

RemoveDuplicates returns the slice removing duplicates if exist

func RemoveFileInfo added in v0.8.0

func RemoveFileInfo(fileInfo os.FileInfo, fileInfoName string) error

func Retry added in v0.8.0

func Retry(attempts int, sleep time.Duration, fn func() error) error

func RunCmd

func RunCmd(command string) (output string, exitCode int, startedAt time.Time, finishedAt time.Time)

func RunContinuousCmd

func RunContinuousCmd(fn func(chunk string) error, command string, thresholdTime int, thresholdLines int) (int, error)

thresholdTime > 0 continuous report thresholdLines > 0 bootstrapping

func RunFile

func RunFile(command string) (output string, exitCode int, startedAt time.Time, finishedAt time.Time)

func RunTracedCmd

func RunTracedCmd(command string) (exitCode int, stdOut string, stdErr string, startedAt time.Time, finishedAt time.Time)

RunTracedCmd executes the received command and manages two output pipes (output and error) It shouldn't throw any exception/error or stop the process.

func ScrapeErrorMessage

func ScrapeErrorMessage(message string, regExpression string) string

func SetProcessIdToFile

func SetProcessIdToFile(pidFileName string) error

SetProcessIdToFile obtains the process id and save it inside a file

func StopProcess

func StopProcess(pidFileName string) error

StopProcess reads the process id from given file and stops the process

func StopProcessId

func StopProcessId(pid int) error

StopProcessId stops the process by the given id

func Subset added in v0.8.0

func Subset(s1, s2 []string) bool

Subset returns true if the first slice is completely contained in the second slice. There must be at least the same number of duplicate values in second as there are in first.

func Untar added in v0.8.0

func Untar(ctx context.Context, source, target string) error

func Unzip

func Unzip(archive, target string) error

Types

type Cert

type Cert struct {
	Cert string `xml:"cert,attr"`
	Key  string `xml:"key,attr"`
	Ca   string `xml:"server_ca,attr"`
}

Cert stores cert files location

type ConcertoService

type ConcertoService interface {
	Post(path string, payload *map[string]interface{}) ([]byte, int, error)
	Put(path string, payload *map[string]interface{}) ([]byte, int, error)
	Delete(path string) ([]byte, int, error)
	Get(path string) ([]byte, int, error)
	GetFile(path string, filePath string) (string, int, error)
}

ConcertoService defines actions to be performed by web service manager

type Config

type Config struct {
	XMLName             xml.Name `xml:"concerto"`
	APIEndpoint         string   `xml:"server,attr"`
	LogFile             string   `xml:"log_file,attr"`
	LogLevel            string   `xml:"log_level,attr"`
	Certificate         Cert     `xml:"ssl"`
	ConfLocation        string
	ConfFile            string
	IsHost              bool
	ConcertoURL         string
	BrownfieldToken     string
	CommandPollingToken string
	ServerID            string
	CurrentUserName     string
	CurrentUserIsAdmin  bool
}

Config stores configuration file contents

func GetConcertoConfig

func GetConcertoConfig() (*Config, error)

GetConcertoConfig returns concerto configuration

func InitializeConcertoConfig

func InitializeConcertoConfig(c *cli.Context) (*Config, error)

InitializeConcertoConfig creates the concerto configuration structure

func (*Config) IsAgentMode added in v0.7.0

func (config *Config) IsAgentMode() bool

IsAgentMode returns whether CLI is acting as Server Or Client mode

func (*Config) IsConfigReady

func (config *Config) IsConfigReady() bool

IsConfigReady returns whether configurations items are filled

func (*Config) IsConfigReadyBrownfield

func (config *Config) IsConfigReadyBrownfield() bool

IsConfigReadyBrownfield returns whether config is ready for brownfield token authentication

func (*Config) IsConfigReadyCommandPolling

func (config *Config) IsConfigReadyCommandPolling() bool

IsConfigReadyCommandPolling returns whether config is ready for polling token authentication

func (*Config) IsConfigReadySetup

func (config *Config) IsConfigReadySetup() bool

IsConfigReadySetup returns whether we can use setup command

type HTTPConcertoservice

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

HTTPConcertoservice web service manager.

func NewHTTPConcertoService

func NewHTTPConcertoService(config *Config) (hcs *HTTPConcertoservice, err error)

NewHTTPConcertoService creates new http Concerto client based on config

func NewHTTPConcertoServiceWithBrownfieldToken

func NewHTTPConcertoServiceWithBrownfieldToken(config *Config) (hcs *HTTPConcertoservice, err error)

NewHTTPConcertoService creates new http Concerto client based on config

func NewHTTPConcertoServiceWithCommandPolling

func NewHTTPConcertoServiceWithCommandPolling(config *Config) (hcs *HTTPConcertoservice, err error)

func (*HTTPConcertoservice) Delete

func (hcs *HTTPConcertoservice) Delete(path string) ([]byte, int, error)

Delete sends DELETE request to Concerto API

func (*HTTPConcertoservice) Get

func (hcs *HTTPConcertoservice) Get(path string) ([]byte, int, error)

Get sends GET request to Concerto API

func (*HTTPConcertoservice) GetFile

func (hcs *HTTPConcertoservice) GetFile(path string, filePath string) (string, int, error)

GetFile sends GET request to Concerto API and receives a file

func (*HTTPConcertoservice) Post

func (hcs *HTTPConcertoservice) Post(path string, payload *map[string]interface{}) ([]byte, int, error)

Post sends POST request to Concerto API

func (*HTTPConcertoservice) Put

func (hcs *HTTPConcertoservice) Put(path string, payload *map[string]interface{}) ([]byte, int, error)

Put sends PUT request to Concerto API

type MockConcertoService

type MockConcertoService struct {
	mock.Mock
}

MockConcertoService service manager.

func (*MockConcertoService) Delete

func (m *MockConcertoService) Delete(path string) ([]byte, int, error)

Delete mocks DELETE request to Concerto API

func (*MockConcertoService) Get

func (m *MockConcertoService) Get(path string) ([]byte, int, error)

Get mocks GET request to Concerto API

func (*MockConcertoService) GetFile

func (m *MockConcertoService) GetFile(path string, filePath string) (string, int, error)

GetFile sends GET request to Concerto API and receives a file

func (*MockConcertoService) Post

func (m *MockConcertoService) Post(path string, payload *map[string]interface{}) ([]byte, int, error)

Post mocks POST request to Concerto API

func (*MockConcertoService) Put

func (m *MockConcertoService) Put(path string, payload *map[string]interface{}) ([]byte, int, error)

Put mocks PUT request to Concerto API

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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