util

package
v0.0.0-...-5d04527 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HYBRID_DOMAIN     = ".axt.aliyuncs.com"
	HYBRID_DOMAIN_VPC = ".axt.aliyun.com"
)
View Source
const (
	UserAgentHeader = "User-Agent"
)

Variables

View Source
var (
	UserAgentValue string
	CrtPath        string
	NilRequest     *atomicutil.AtomicBoolean
	CaCertPool     *x509.CertPool
)
View Source
var (
	ErrHTTPCode = errors.New("http code error")
)
View Source
var G_IsWindows bool

Functions

func CallApi

func CallApi(httpMethod, url string, parameters map[string]interface{}, respObj interface{}, apiTimeout time.Duration, noLog bool) error

func CheckFileIsExist

func CheckFileIsExist(filename string) bool

func ComputeBinMd5

func ComputeBinMd5(bin []byte) string

func ComputeMd5

func ComputeMd5(filePath string) (string, error)

func ComputeStrMd5

func ComputeStrMd5(str string) string

func CopyDir

func CopyDir(srcPath string, destPath string) error

copy srcPath/* to destPath/, srcPath,destPath need exist

func ExeCmd

func ExeCmd(cmd string) (error, string, string)

func ExeCmdNoWait

func ExeCmdNoWait(cmd string) (error, int)

func FileExist

func FileExist(path string) bool

func GetAzoneId

func GetAzoneId() string

func GetCachePath

func GetCachePath() (string, error)

func GetClientReportService

func GetClientReportService() string

func GetConfigPath

func GetConfigPath() (string, error)

func GetConnectDetectService

func GetConnectDetectService() string

func GetCrossVersionConfigPath

func GetCrossVersionConfigPath() (string, error)

func GetCurrentPath

func GetCurrentPath() (string, error)

func GetDeRegisterService

func GetDeRegisterService() string

func GetDeamonUrl

func GetDeamonUrl() string

func GetErrorOutputService

func GetErrorOutputService() string

func GetFetchSessionTaskListService

func GetFetchSessionTaskListService() string

func GetFetchTaskListService

func GetFetchTaskListService() string

func GetFinishOutputService

func GetFinishOutputService() string

func GetGshellCheckService

func GetGshellCheckService() string

func GetHTTPTransport

func GetHTTPTransport() *http.Transport

func GetHybridPath

func GetHybridPath() (string, error)

func GetInstanceId

func GetInstanceId() string

func GetInvalidTaskService

func GetInvalidTaskService() string

New version 1.0

func GetMachineID

func GetMachineID() (string, error)

func GetMetricsService

func GetMetricsService() string

func GetParam

func GetParam(name string) (string, error)

func GetPingService

func GetPingService() string

func GetPluginHealthService

func GetPluginHealthService() string

func GetPluginListService

func GetPluginListService() string

func GetPluginPath

func GetPluginPath() (string, error)

func GetPluginUpdateCheckService

func GetPluginUpdateCheckService() string

func GetProxyFunc

func GetProxyFunc() func(*http.Request) (*url.URL, error)

func GetPutInstanceStateReportService

func GetPutInstanceStateReportService() string

func GetPutInventoryService

func GetPutInventoryService() string

func GetRegionId

func GetRegionId() string

GetRegionId should be always successful since InitRegionId should be called before. However, it's hard to terminate the agent under this case since even panic could only terminate the calling goroutine

func GetRoleName

func GetRoleName() (string, error)

func GetRunningOutputService

func GetRunningOutputService() string

func GetScriptPath

func GetScriptPath() (string, error)

func GetSecretParam

func GetSecretParam(name string) (string, error)

func GetSelfhostedPath

func GetSelfhostedPath() (string, error)

func GetServerHost

func GetServerHost() string

GetServerHost returns empty string when region id is invalid as error handling

func GetSessionStatusService

func GetSessionStatusService() string

func GetStateConfigService

func GetStateConfigService() string

func GetStoppedOutputService

func GetStoppedOutputService() string

func GetTempPath

func GetTempPath() (string, error)

func GetTemplateService

func GetTemplateService() string

func GetTimeoutOutputService

func GetTimeoutOutputService() string

func GetUpdateService

func GetUpdateService() string

func GetVerifiedTaskService

func GetVerifiedTaskService() string

func HasCmdInLinux

func HasCmdInLinux(cmd string) bool

func HttpDownloadWithTimeout

func HttpDownloadWithTimeout(url string, filePath string, timeout time.Duration) error

HttpDownloadWithTimeout downloads a file from url to filePath with specified timeout. Check if returned error is of type *url.Error and whether url.Error.Timeout method returns true for timeout request.

func HttpDownlod

func HttpDownlod(url string, FilePath string) error

func HttpGet

func HttpGet(url string) (error, string)

func HttpGetWithTimeout

func HttpGetWithTimeout(url string, timeout time.Duration, noLog bool) (error, string)

func HttpPost

func HttpPost(url string, data string, contentType string) (string, error)

func HttpPostWithTimeout

func HttpPostWithTimeout(url string, data string, contentType string, timeout time.Duration, noLog bool) (string, error)

func InitUserAgentValue

func InitUserAgentValue()

func IsDirectory

func IsDirectory(path string) bool

func IsFile

func IsFile(path string) bool

func IsHybrid

func IsHybrid() bool

func IsSelfHosted

func IsSelfHosted() bool

func IsServiceExist

func IsServiceExist(ServiceName string) bool

func IsServiceRunning

func IsServiceRunning(ServiceName string) bool

func IsSysVLinux

func IsSysVLinux() bool

func IsSystemdLinux

func IsSystemdLinux() bool

func IsUpstartLinux

func IsUpstartLinux() bool

func IsVerboseMode

func IsVerboseMode() bool

func MakeSurePath

func MakeSurePath(path string) error

func MockMetaServer

func MockMetaServer(region_id string)

func ReplaceAllParameterStore

func ReplaceAllParameterStore(param string) (string, error)

func RsaSign

func RsaSign(data string, keyBytes string) string

func RsaSignWithMD5

func RsaSignWithMD5(data []byte, keyBytes []byte) []byte

func SetCurrentEnvPath

func SetCurrentEnvPath() bool

func SetScriptPath

func SetScriptPath(path string)

func SetVerboseMode

func SetVerboseMode(mode bool)

func StartService

func StartService(ServiceName string) error

func StopService

func StopService(ServiceName string) error

func Unzip

func Unzip(zipFile string, destDir string) error

func WriteStringToFile

func WriteStringToFile(path string, content string) error

Types

type CancelFlag

type CancelFlag interface {
	// Canceled returns true if a cancel or Shutdown has been requested, false otherwise.
	// This method should be called periodically in the job.
	Canceled() bool

	// Set sets the state of this flag and wakes up waiting callers.
	Set(state State)

	// ShutDown returns true if a ShutDown has been requested, false otherwise.
	// This method should be called periodically in the job.
	ShutDown() bool

	// State returns the current flag state
	State() State

	// Wait blocks the caller until either a cancel has been requested or the
	// task has completed normally. Returns Canceled if cancel has been requested,
	// or Completed if the task completed normally.
	// This is intended to be used to wake up a job that may be waiting on some resources, as follows:
	// The main job starts a go routine that calls Wait. The main job then does its processing.
	// During processing the job may be waiting on certain events/conditions.
	// In the go routine, once Wait returns, if the return value indicates that a cancel
	// request has been received, the go routine wakes up the running job.
	Wait() (state State)
}

CancelFlag is an object that is passed to any job submitted to a task in order to communicated job cancellation. Job cancellation has to be cooperative.

type ChanneledCancelFlag

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

ChanneledCancelFlag is a default implementation of the task.CancelFlag interface.

func NewChanneledCancelFlag

func NewChanneledCancelFlag() *ChanneledCancelFlag

NewChanneledCancelFlag creates a new instance of ChanneledCancelFlag.

func (*ChanneledCancelFlag) Canceled

func (t *ChanneledCancelFlag) Canceled() bool

Canceled returns true if this flag has been set to Cancel state, false otherwise.

func (*ChanneledCancelFlag) Set

func (t *ChanneledCancelFlag) Set(state State)

Set sets the state of this flag and wakes up waiting callers.

func (*ChanneledCancelFlag) ShutDown

func (t *ChanneledCancelFlag) ShutDown() bool

ShutDown returns true if this flag has been set to ShutDown state, false otherwise.

func (*ChanneledCancelFlag) State

func (t *ChanneledCancelFlag) State() State

State returns the current flag state.

func (*ChanneledCancelFlag) Wait

func (t *ChanneledCancelFlag) Wait() (state State)

Wait blocks until the flag is set to either Cancel or Completed state. Returns the state.

type HttpErrorCode

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

func (*HttpErrorCode) Error

func (e *HttpErrorCode) Error() string

func (*HttpErrorCode) GetCode

func (e *HttpErrorCode) GetCode() int

type State

type State int

State represents the state of a job.

const (
	// Canceled indicates a job for which cancellation has been requested.
	Canceled State = 1

	// Completed indicates a completed job.
	Completed State = 2

	// ShutDown indicates a job for which ShutDown has been requested.
	ShutDown State = 3
)

Jump to

Keyboard shortcuts

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