common

package
v0.0.0-...-7c21e21 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TimeFormat
	TimeFormat = "2006-01-02T15:04:05Z"
	// KeyContextNamespace the key of namespace in context
	KeyContextNamespace = "namespace"

	// ResourceName resource name
	ResourceName = "resourceName"
	// ResourceVersion resource version
	ResourceVersion = "resourceVersion"
	// Application application resource
	Application Resource = "application"
	// App alias of application resource
	APP Resource = "app"
	// Configuration configuration resource
	Configuration Resource = "configuration"
	// Config config resource
	Config Resource = "config"
	// Secret secret resource
	Secret Resource = "secret"
	// Deprecated
	// Deployment deployment resource
	Deployment Resource = "deployment"
	// Node node resource
	Node Resource = "node"
	// Shadow shadow resource
	Shadow Resource = "shadow"
	// NodeDesire nodedesire resource
	NodeDesire Resource = "nodedesire"
	// NodeReport nodereport resource
	NodeReport Resource = "nodereport"
	// Batch batch resource
	Batch Resource = "batch"
	// Index index resource
	Index Resource = "index"
	// !deprecated
	// DefaultConfigDir default host dir of config
	DefaultConfigDir = "var/db/baetyl"
	// DefaultLibDir lib dir of the service by default
	DefaultLibDir = "var/lib/baetyl"
	// DefaultBinDir the file path of master binary
	DefaultBinDir = "bin"
	// DefaultBinFile the file of master binary
	DefaultBinFile = "baetyl"
	// DefaultActiveWebPort the port of web active
	DefaultActiveWebPort = 30007 // The range of valid ports is 30000-32767
	// AppConfFileName application config file name
	AppConfFileName = "application.yml"
	// DefaultSetupFile
	DefaultSetupFile = "setup.sh"
	// DefaultOffActivationFile
	DefaultOffActivationFile = "offlineActivation.sh"
	// DefaultOnActivationFile
	DefaultOnActivationFile = "onlineActivation.sh"
	// DefaultMasterConfDir master config dir by default
	DefaultMasterConfDir = "etc/baetyl"
	// DefaultMasterConfFile master config file by default
	DefaultMasterConfFile = "conf.yml"
	// DefaultMasterPlistFile
	DefaultMasterPlistFile = "baetyl.plist"
	// DefaultMasterDaemonFile
	DefaultMasterDaemonFile = "baetyl.service"
	// ComposeVersion compose version
	ComposeVersion = "3"
	// Bind bind
	Bind VolumeType = "bind"
	// Volume volume
	Volume VolumeType = "volume"

	DesiredApplications    = "apps"
	DesiredSysApplications = "sysapps"

	// Receive receive
	Receive State = "RECEIVE"
	// Deploy deploy
	Deploy State = "DEPLOYED"
	// Updating updating
	Updating State = "UPDATING"
	// Updated updated
	Updated State = "UPDATED"
	// Timeout timeout
	Timeout State = "TIMEOUT"
	// Failure failure
	Failure State = "FAILURE"

	// Secret type
	SecretRegistry = "registry"
	SecretConfig   = "config"
	MaxRetryNum    = 20

	// LabelKeyFunction tag of function
	LabelKeyFunction = "baetyl-function"
	LabelNodeName    = "baetyl-node-name"
	LabelAppName     = "baetyl-app-name"
	LabelSystem      = "baetyl-cloud-system"
	LabelBatch       = "baetyl-batch"
)
View Source
const (
	BaetylCloud      = "baetyl-cloud"
	BaetylCloudGroup = "cloud.baetyl.io"
	Description      = "description"
	UpdateTimestamp  = "updateTimestamp"
	Metadata         = "matadata"
	PkiCertID        = "pkiCertID"

	AnnotationDescription     = BaetylCloudGroup + "/" + Description
	AnnotationUpdateTimestamp = BaetylCloudGroup + "/" + UpdateTimestamp
	AnnotationMetadata        = BaetylCloudGroup + "/" + Metadata
	AnnotationPkiCertID       = BaetylCloudGroup + "/" + PkiCertID
)
View Source
const (
	None                    Security = "None"
	Token                   Security = "Token"
	Cert                    Security = "Cert"
	Dongle                  Security = "Dongle"
	DefaultActiveTime                = 1167580800 //todo avoid mysql ERROR 1292. "2007-01-01 00:00:00" s
	DefaultSN                        = "agent-sn"
	DefaultSNPath                    = "/var/lib/baetyl/sn"
	DefaultSNFile                    = "fingerprint.txt"
	DefaultInputField                = "sn"
	DefaultAgentConfigMount          = "/etc/baetyl"
	FingerprintSN                    = 0x1
	FingerprintInput                 = 0x2
	FingerprintHostName              = 0x4
	FingerprintBootID                = 0x8
	FingerprintSystemUUID            = 0x10
	FingerprintMachineID             = 0x20

	FilenameYamlService       = "service.yml"
	PageSize                  = 20
	Online                    = "online"
	Offline                   = "offline"
	Success             Event = "success"
	Nothing             Event = "nothing"
	Failed              Event = "failed"
	Inactivated               = 0x0
	Activated                 = 0x1
	DisableWhitelist          = 0x0
	EnableWhitelist           = 0x1
)
View Source
const (
	DefaultBaetylEdgeNamespace       = "baetyl-edge"
	DefaultBaetylEdgeSystemNamespace = "baetyl-edge-system"

	BaetylModule                            = "baetyl-module"
	BaetylFunctionRuntime                   = "baetyl-function-runtime"
	BaetylInit            SystemApplication = "baetyl-init"
	BaetylCore            SystemApplication = "baetyl-core"
	BaetylBroker          SystemApplication = "baetyl-broker"
	BaetylFunction        SystemApplication = "baetyl-function"
	BaetylState           SystemApplication = "baetyl-state"

	TemplateJsonAppCore        = "app-core.json"
	TemplateJsonAppFunction    = "app-function.json"
	TemplateJsonConfigCore     = "config-core.json"
	TemplateJsonConfigFunction = "config-function.json"

	Sync     CertType = "sync"
	Internal CertType = "internal"
	External CertType = "external"

	ResourceMetrics          = "metrics.yml"
	ResourceLocalPathStorage = "local-path-storage.yml"
	ResourceSetup            = "setup.sh"
	ResourceInitYaml         = "baetyl-init.yml"

	AddressServer = "server-address"
	AddressNode   = "node-address"
	AddressActive = "active-address"

	ObjectSource = "object-source"
)
View Source
const (
	AWSS3ReadPermission    = "public-read"
	AWSS3WritePermission   = "public-read-write"
	AWSS3PrivatePermission = "private"
)
View Source
const (
	ContainerApp = "container"
	FunctionApp  = "function"
)
View Source
const (
	KeyConfFile      = "ConfFile"
	ValueConfFile    = "etc/baetyl/cloud.yml"
	KeyTraceKey      = "TraceKey"
	ValueTraceKey    = "requestId"
	KeyTraceHeader   = "TraceHeader"
	ValueTraceHeader = "x-bce-request-id" // TODO: change to x-baetyl-request-id when support configuration
	KeyEasyPack      = "EasyPack"
	ValueEasyPack    = "baidueasypack"
)
View Source
const (
	// * plugin
	ErrPluginNotFound Code = "ErrPluginNotFound"
	ErrPluginInvalid       = "ErrPluginInvalid"

	// * request
	ErrRequestAccessDenied   = "ErrRequestAccessDenied"
	ErrRequestMethodNotFound = "ErrRequestMethodNotFound"
	ErrRequestParamInvalid   = "ErrRequestParamInvalid"
	// * resource
	ErrResourceNotFound        = "ErrResourceNotFound"
	ErrResourceAccessForbidden = "ErrResourceAccessForbidden"
	ErrResourceConflict        = "ErrResourceConflict"
	ErrResourceHasBeenUsed     = "ErrResourceHasBeenUsed"
	ErrNodeNotReady            = "ErrNodeNotReady"

	// * volumes
	ErrVolumeType = "ErrVolumeType"
	// * unknown
	ErrUnknown = "UnknownError"
	// * application
	ErrAppNameConflict         = "ErrAppNameConflict"
	ErrVolumeNotFoundWhenMount = "ErrVolumeNotFoundWhenMount"
	ErrAppReferencedByNode     = "ErrAppReferencedByNode"
	// * node
	ErrNodeNumMaxLimit       = "ErrNodeNumMaxLimit"
	ErrNodeNumQueryException = "ErrNodeNumQueryException"

	// * config
	ErrConfigInUsed = "ErrConfigInUsed"
	// * register
	ErrRegisterQuotaNumOut     = "ErrRegisterQuotaNumOut"
	ErrRegisterDeleteRecord    = "ErrRegisterDeleteRecord"
	ErrRegisterDeleteCallback  = "ErrRegisterDeleteCallback"
	ErrRegisterPackage         = "ErrRegisterPackage"
	ErrRegisterRecordActivated = "ErrRegisterRecordActivated"
	// * db
	ErrDatabase = "ErrDatabase"
	// * k8s
	ErrK8S = "ErrK8S"
	// * ceph
	ErrCeph = "ErrCeph"
	// * io
	ErrIO = "ErrIO"
	// * template
	ErrTemplate = "ErrTemplate"
	// * function
	ErrFunction = "ErrFunction"
	// * resourceName
	ErrInvalidResourceName = "resourceName"
	ErrInvalidLabels       = "validLabels"
	ErrInvalidRequired     = "required"
	// * fingerprintValue
	ErrInvalidFingerprintValue = "fingerprintValue"
	// * memory
	ErrInvalidMemory = "memory"
	// * duration
	ErrInvalidDuration = "duration"
	// * setcpus
	ErrInvalidSetcpus = "setcpus"
	// * nonBaetyl
	ErrInvalidName = "nonBaetyl"
	// * license
	ErrLicenseQuota = "ErrLicenseQuota"
	// * third server error
	ErrThirdServer = "ErrThirdServer"
)

all codes

View Source
const (
	ConfigObjectPrefix = "_object_"
)
View Source
const (
	UnpackTypeZip = "zip"
)

Variables

View Source
var (
	// Todo use global.go
	Cache          map[string]string
	FingerprintMap = map[int]string{
		0x1:  "sn",
		0x2:  "input",
		0x4:  "hostName",
		0x8:  "bootID",
		0x10: "systemUUID",
		0x20: "machineID",
	}
)

Functions

func AddSystemLabel

func AddSystemLabel(labels map[string]string, infos map[string]string) map[string]string

func CompareNumericalString

func CompareNumericalString(a, b string) int

func Error

func Error(c Code, fs ...*F) error

Error returns an error with code and fields

func GetConfFile

func GetConfFile() string

func GetEasyPack

func GetEasyPack() string

func GetTraceHeader

func GetTraceHeader() string

func GetTraceKey

func GetTraceKey() string

func LoadConfig

func LoadConfig(cfg interface{}, files ...string) error

func LogDirtyData

func LogDirtyData(err error, fields ...log.Field)

func PackageResponse

func PackageResponse(res interface{}) (int, interface{})

PackageResponse PackageResponse

func PopulateFailedResponse

func PopulateFailedResponse(cc *Context, err error, abort bool)

PopulateFailedResponse PopulateFailedResponse

func RandString

func RandString(n int) string

RandString

  • param n: suggest at least 10 to avoid conflict

referred to https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go

func SetConfFile

func SetConfFile(v string)

func SetEasyPack

func SetEasyPack()

func SetTraceHeader

func SetTraceHeader(v string)

func SetTraceKey

func SetTraceKey(v string)

func UUID

func UUID() string

UUID generate uuid

func UUIDPrune

func UUIDPrune() string

UUIDPrune generate uuid without '-'

func Wrapper

func Wrapper(handler HandlerFunc) func(c *gin.Context)

Wrapper Wrapper TODO: to use gin.HandlerFunc ?

func WrapperRaw

func WrapperRaw(handler HandlerFunc) func(c *gin.Context)

Types

type CertType

type CertType string

type Code

type Code string

Code code

func (Code) String

func (c Code) String() string

type Context

type Context struct {
	*gin.Context
}

Context context

func NewContext

func NewContext(inner *gin.Context) *Context

NewContext create a new context with gin context

func NewContextEmpty

func NewContextEmpty() *Context

NewContextEmpty create a new empty context

func (*Context) GetName

func (c *Context) GetName() string

GetName gets name from context if exists

func (*Context) GetNameFromParam

func (c *Context) GetNameFromParam() string

GetNameFromParam gets name from param if exists

func (*Context) GetNamespace

func (c *Context) GetNamespace() string

GetNamespace gets namespace from context if exists

func (*Context) GetTrace

func (c *Context) GetTrace() (k string, v string)

GetTrace gets the trace key and value

func (*Context) GetUser

func (c *Context) GetUser() User

GetUser gets user from context if exists

func (*Context) LoadBody

func (c *Context) LoadBody(obj interface{}) error

LoadBody loads json data from body into object and set defaults

func (*Context) SetName

func (c *Context) SetName(n string)

SetName sets name into context

func (*Context) SetNamespace

func (c *Context) SetNamespace(ns string)

SetNamespace sets namespace into context

func (*Context) SetTrace

func (c *Context) SetTrace()

SetTrace set the trace key and value

func (*Context) SetUser

func (c *Context) SetUser(user User)

SetUser sets user into context

type Event

type Event string

type F

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

Field field

func Field

func Field(k string, v interface{}) *F

Field returns a field

type HandlerFunc

type HandlerFunc func(c *Context) (interface{}, error)

HandlerFunc HandlerFunc

type Resource

type Resource string

type Security

type Security string

type State

type State string

type SystemApplication

type SystemApplication string

type User

type User struct {
	ID string
}

type VolumeType

type VolumeType string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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