util

package
v0.0.0-...-197f44b Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFileId = errors.New("invalid fileId")
)

Functions

func AddSecretEncryptKeys

func AddSecretEncryptKeys(secret ...string)

AddSecretEncryptKeys adds all history secrets of all storage servers.

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

func ClearList

func ClearList(l *list.List)

ClearList clears the list elements.

func CollectMapKeys

func CollectMapKeys(m map[string]string) []string

func ConvertLogFileSize

func ConvertLogFileSize(s int) int

func ConvertLogLevel

func ConvertLogLevel(levelString string) logger.Level

func ConvertRollInterval

func ConvertRollInterval(rollString string) int

func CreateAlias

func CreateAlias(fid string, instanceId string, isPrivate bool, ts time.Time) string

CreateAlias create an 86 bytes long, self description alias name from file meta info.

Alias name contains file's path, instanceId, private flag, timestamp and a random number, these information combines with '|' and encrypt using AES.

Alias name is a little bit long...

func CreateCRCFileID

func CreateCRCFileID(instanceId string, crc32 string, fileSize uint64) string

CreateCRCFileID creates a file id by instance, crc, file length, timestamp and random int

func CreateCrc32Hash

func CreateCrc32Hash() hash.Hash32

func CreateMD5FileID

func CreateMD5FileID(instanceId string, md5 string) string

CreateCRCFileID creates a file id by instance, md5, timestamp and random int

func CreateMd5Hash

func CreateMd5Hash() hash.Hash

func CreateRandNumber

func CreateRandNumber(max int) int

CreateRandNumber create a random int value.

func DefaultAdvertiseAddress

func DefaultAdvertiseAddress()

func DefaultDataDir

func DefaultDataDir(mode common.BootMode) string

DefaultLogDir returns default system log directory.

func DefaultLogDir

func DefaultLogDir() string

DefaultLogDir returns default system log directory.

func ExchangeEnvValue

func ExchangeEnvValue(key string, then func(envValue string))

if these param exist in system env , then replace it with system env

func ExistsFile

func ExistsFile(fInfo *common.FileInfo) bool

func FixZeros

func FixZeros(i int, width int) string

FixZeros prepends '0's to a int value.

func GenerateDecKey

func GenerateDecKey(secret string)

GenerateDecKey generates aes encrypt key for current usage.

func GenerateToken

func GenerateToken(fileId, secret string, expireTimestamp string) string

GenerateToken generates token for http file download.

func GetCrc32HashString

func GetCrc32HashString(h hash.Hash32) string

func GetEnv

func GetEnv(key string) string

func GetMd5HashString

func GetMd5HashString(h hash.Hash) string

func GetSecrets

func GetSecrets() (map[string]string, error)

func HttpFileNotFoundError

func HttpFileNotFoundError(w http.ResponseWriter)

func HttpForbiddenError

func HttpForbiddenError(w http.ResponseWriter, message string)

func HttpInternalServerError

func HttpInternalServerError(w http.ResponseWriter, message string)

func HttpWriteResponse

func HttpWriteResponse(writer http.ResponseWriter, statusCode int, message string)

HttpWriteResponse writes error response.

func InitialConfigMap

func InitialConfigMap(path string)

func LoadConfig

func LoadConfig(c string, mode common.BootMode, container interface{}) error

LoadConfig loads config from config file.

func LoadInstanceData

func LoadInstanceData() string

LoadInstanceData load old instance id from data dir. If there is no old instance id before, create a new instance id for this data dir.

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

func ParseAlias

func ParseAlias(alias, currentSecret string) (fileInfo *common.FileInfo, secret string, err error)

ParseAlias parses file info from file alias name, and returns *common.FileInfo

func ParseServer

func ParseServer(s string) (*common.Server, error)

func ParseServers

func ParseServers(servers string) ([]*common.Server, error)

ParseServers parses server infos from a string.

func PrepareDirs

func PrepareDirs(tmpDir string) error
func PrintLogo()

func StoreSecrets

func StoreSecrets(instanceId string, secret ...string) error

StoreSecrets stores secrets to config bucket.

func StringListExists

func StringListExists(list *list.List, ele string) bool

StringListExists checks if a string list contains the string.

func ValidateAgentConfig

func ValidateAgentConfig(c *common.AgentConfig) error

ValidateAgentConfig validates agent config.

func ValidateClientConfig

func ValidateClientConfig(c *common.ClientConfig) error

ValidateStorageConfig validates storage config.

func ValidateStorageConfig

func ValidateStorageConfig(c *common.StorageConfig) error

ValidateStorageConfig validates storage config.

func ValidateTrackerConfig

func ValidateTrackerConfig(c *common.TrackerConfig) error

ValidateTrackerConfig validates tracker config.

func WriteConfig

func WriteConfig(c string, container interface{}) error

WriteConfig writes config to file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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