utils

package
v19.10.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BaseFolder is the path of the base folder containing safescale data
	BaseFolder = "/opt/safescale"
	// VarFolder ...
	VarFolder = BaseFolder + "/var"
	// LogFolder ...
	LogFolder = VarFolder + "/log"
	// TempFolder ...
	TempFolder = VarFolder + "/tmp"
)
View Source
var (
	// Debug if set to true, work in debug mode
	Debug = false
	// Verbose if set to true, increase verbosity
	Verbose = false
)

Functions

func CIDRToIPv4Range

func CIDRToIPv4Range(cidr string) (string, string, error)

CIDRToIPv4Range converts CIDR to IPv4 range

func CIDRToLongRange

func CIDRToLongRange(cidr string) (uint32, uint32, error)

CIDRToLongRange converts CIDR to IPv4 range

func FromPBHostDefinitionToPBGatewayDefinition

func FromPBHostDefinitionToPBGatewayDefinition(in pb.HostDefinition) pb.GatewayDefinition

FromPBHostDefinitionToPBGatewayDefinition converts a pb.HostDefinition to pb.GatewayDefinition

func FromPBHostSizing

func FromPBHostSizing(src pb.HostSizing) resources.SizingRequirements

FromPBHostSizing converts a protobuf HostSizing message to resources.SizingRequirements

func GetConnection

func GetConnection(host string, port int) *grpc.ClientConn

GetConnection returns a connection to GRPC server

func GetContext

func GetContext(storeUUID bool) (context.Context, error)

GetContext ...

func GetReference

func GetReference(in *pb.Reference) string

GetReference return a reference from the name or id given in the pb.Reference

func GetTimeoutContext

func GetTimeoutContext(timeout time.Duration) (context.Context, context.CancelFunc, error)

GetTimeoutContext return a context for grpc commands

func GetUUID

func GetUUID() string

GetUUID ...

func Hash

func Hash(reader io.Reader) string

Hash will compute and return a SHA-256 hash of the datas of the reader

func IPv4ToLong

func IPv4ToLong(ip string) uint32

IPv4ToLong converts IPv4 to uint32

func IsCIDRRoutable

func IsCIDRRoutable(cidr string) (bool, error)

IsCIDRRoutable tells if the network is routable

func JobCancelUUID

func JobCancelUUID(uuid string)

JobCancelUUID ...

func JobDeregister

func JobDeregister(ctx context.Context)

JobDeregister ...

func JobDeregisterUUID

func JobDeregisterUUID(uuid string)

JobDeregisterUUID ...

func JobList

func JobList() map[string]string

JobList ...

func JobRegister

func JobRegister(ctx context.Context, cancelFunc func(), command string) error

JobRegister ...

func LongToIPv4

func LongToIPv4(value uint32) string

LongToIPv4 converts uint32 to IP

func ToHostStatus

func ToHostStatus(in *resources.Host) *pb.HostStatus

ToHostStatus ...

func ToPBBucketList

func ToPBBucketList(in []string) *pb.BucketList

ToPBBucketList convert a list of string into a *ContainerLsit

func ToPBBucketMountPoint

func ToPBBucketMountPoint(in *resources.Bucket) *pb.BucketMountingPoint

ToPBBucketMountPoint convert a Bucket into a BucketMountingPoint

func ToPBFileList

func ToPBFileList(fileNames []string, uploadDates []string, fileSizes []int64, fileBuckets [][]string) *pb.FileList

ToPBFileList convert a list of file names from api to protocolbuffer FileList format

func ToPBGatewayDefinition

func ToPBGatewayDefinition(in *resources.HostDefinition) *pb.GatewayDefinition

ToPBGatewayDefinition converts a resources.HostDefinition tp .GatewayDefinition

func ToPBHost

func ToPBHost(in *resources.Host) *pb.Host

ToPBHost convert an host from api to protocolbuffer format

func ToPBHostDefinition

func ToPBHostDefinition(in *resources.HostDefinition) *pb.HostDefinition

ToPBHostDefinition ...

func ToPBHostSizing

func ToPBHostSizing(src resources.SizingRequirements) pb.HostSizing

ToPBHostSizing converts a protobuf HostSizing message to resources.SizingRequirements

func ToPBHostTemplate

func ToPBHostTemplate(in *resources.HostTemplate) *pb.HostTemplate

ToPBHostTemplate convert an template from api to protocolbuffer format

func ToPBImage

func ToPBImage(in *resources.Image) *pb.Image

ToPBImage convert an image from api to protocolbuffer format

func ToPBNetwork

func ToPBNetwork(in *resources.Network) *pb.Network

ToPBNetwork convert a network from api to protocolbuffer format

func ToPBShare

func ToPBShare(hostName string, share *propsv1.HostShare) *pb.ShareDefinition

ToPBShare convert a share from model to protocolbuffer format

func ToPBShareMount

func ToPBShareMount(shareName string, hostName string, mount *propsv1.HostRemoteMount) *pb.ShareMountDefinition

ToPBShareMount convert share mount on host to protocolbuffer format

func ToPBShareMountList

func ToPBShareMountList(hostName string, share *propsv1.HostShare, mounts map[string]*propsv1.HostRemoteMount) *pb.ShareMountList

ToPBShareMountList converts share mounts to protocol buffer

func ToPBSshConfig

func ToPBSshConfig(from *system.SSHConfig) *pb.SshConfig

ToPBSshConfig converts a system.SSHConfig into a SshConfig

func ToPBVirtualIP

func ToPBVirtualIP(src resources.VIP) pb.VirtualIp

ToPBVirtualIP converts a resources.VIP to a pb.VirtualIp

func ToPBVolume

func ToPBVolume(in *resources.Volume) *pb.Volume

ToPBVolume converts an api.Volume to a *Volume

func ToPBVolumeAttachment

func ToPBVolumeAttachment(in *resources.VolumeAttachment) *pb.VolumeAttachment

ToPBVolumeAttachment converts an api.Volume to a *Volume

func ToPBVolumeInfo

func ToPBVolumeInfo(volume *resources.Volume, mounts map[string]*propsv1.HostLocalMount) *pb.VolumeInfo

ToPBVolumeInfo converts an api.Volume to a *VolumeInfo

func ToSystemSSHConfig

func ToSystemSSHConfig(from *pb.SshConfig) *system.SSHConfig

ToSystemSSHConfig converts a pb.SshConfig into a system.SSHConfig

Types

type BucketGenerator

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

BucketGenerator ...

func NewBucketGenerator

func NewBucketGenerator(buckets []objectstorage.Bucket) *BucketGenerator

NewBucketGenerator return a bucketGenerator returning the buckets given as parameters

func (*BucketGenerator) Next

Next return the bucket currently pointed by the iterator and then iterate

type ChunkGroup

type ChunkGroup struct {
	FileName    string `json:"filename,omitempty"`
	FileSize    int64  `json:"filsize,omitempty"`
	Date        string `json:"date,omitempty"`
	AesPassword string `json:"aespassword,omitempty"`

	Shards                 []*Shard `json:"shards,omitempty"`
	NbDataShards           int      `json:"nbdatashards,omitempty"`
	NbParityShards         int      `json:"nbparityshards,omitempty"`
	ChunkSize              int      `json:"chunksize,omitempty"`
	NbDataShardsPerBatch   int      `json:"nbdatachunkperbatch,omitempty"`
	NbParityShardsPerBatch int      `json:"nbparitychunkperbatch,omitempty"`
	PaddingSize            int      `json:"paddingsize,omitempty"`

	BucketNames []string `json:"bucketnames,omitempty"`
}

ChunkGroup ...

func DecryptChunkGroup

func DecryptChunkGroup(encrypted []byte, ki *KeyInfo) (*ChunkGroup, error)

DecryptChunkGroup use the keyInfo to decrypt the encryptedChunkGroup, then deserialize it from json, return a chunkGroup

func NewChunkGroup

func NewChunkGroup(fileName string, fileSize int64, bucketNames []string) (*ChunkGroup, error)

NewChunkGroup return a chunk group initialized with a new random aesPassword, buckets, and file infos

func (*ChunkGroup) ComputeShardCheckSum

func (cg *ChunkGroup) ComputeShardCheckSum(shardNum int, reader io.Reader) (string, error)

ComputeShardCheckSum compute the check sum of a given shard, with a reader of the shard datas, return the checksum

func (*ChunkGroup) Encrypt

func (cg *ChunkGroup) Encrypt() ([]byte, *KeyInfo, error)

Encrypt serialize the chunkGroup to JSON then generate a KeyInfo and use it to encrypt the chunkGroup, return the encrypted chunkGroup and the keyInfo

func (*ChunkGroup) GenerateNonce

func (cg *ChunkGroup) GenerateNonce(shardNum int, nonceSize int) ([]byte, error)

GenerateNonce generate a nonce for a given shard, return the nonce

func (*ChunkGroup) GetBatchSizeInfo

func (cg *ChunkGroup) GetBatchSizeInfo() (int, int, int)

GetBatchSizeInfo return the chunkSize, the number of data shards and parity shards per batch

func (*ChunkGroup) GetBucketNames

func (cg *ChunkGroup) GetBucketNames() []string

GetBucketNames return the list of bucket names

func (*ChunkGroup) GetCheckSum

func (cg *ChunkGroup) GetCheckSum(shardNum int) string

GetCheckSum return the checkSum of a given shard

func (*ChunkGroup) GetEncryptedChunkSize

func (cg *ChunkGroup) GetEncryptedChunkSize() int

GetEncryptedChunkSize return the size of an encrypted chunk

func (*ChunkGroup) GetFileInfos

func (cg *ChunkGroup) GetFileInfos() (string, string, int64)

GetFileInfos return the file name, upload date and size

func (*ChunkGroup) GetGCM

func (cg *ChunkGroup) GetGCM() (cipher.AEAD, error)

GetGCM return a gcm initialized with the cg.AesPassword

func (*ChunkGroup) GetNbBatchs

func (cg *ChunkGroup) GetNbBatchs() int

GetNbBatchs return the number of batchs neededs to process all the shards according to the number of shards per batch

func (*ChunkGroup) GetNbShards

func (cg *ChunkGroup) GetNbShards() (int, int)

GetNbShards return the number of data shards and parity shards

func (*ChunkGroup) GetNonce

func (cg *ChunkGroup) GetNonce(shardNum int) []byte

GetNonce return the nonce of a given shard

func (*ChunkGroup) GetPaddingSize

func (cg *ChunkGroup) GetPaddingSize() int

GetPaddingSize return the padding size of the last data shard

func (*ChunkGroup) GetShardNum

func (cg *ChunkGroup) GetShardNum(batchNum int, iterationNum int) int

GetShardNum return the number of the shard in the shard arrays according to the number of the batch and the position of the shard in the batch

func (*ChunkGroup) GetStorageInfo

func (cg *ChunkGroup) GetStorageInfo(shardNum int) (string, string)

GetStorageInfo return the storageInfos of a given shard (fileName, bucketName)

func (*ChunkGroup) InitShards

func (cg *ChunkGroup) InitShards(chunkSize int, maxBatchSize int, ratioNumerator int, ratioDenominator int, bucketGenerator *BucketGenerator) (dataShards int, parityShards int, err error)

InitShards initialize the shard array and return the number of data shards and parity shards

func (*ChunkGroup) IsReconstructible

func (cg *ChunkGroup) IsReconstructible(missingBuckets []string) bool

IsReconstructible return true if the file can be reconstructed even with the given buckets unavailable, false otherwise

func (*ChunkGroup) ToString

func (cg *ChunkGroup) ToString() string

ToString return a string representation on a chunckGroup ready to be displayed

type KeyInfo

type KeyInfo struct {
	AesPassword string `json:"aespassword,omitempty"`
	Nonce       []byte `json:"nonce,omitempty"`
}

KeyInfo ...

func DecryptKeyInfo

func DecryptKeyInfo(encrypted []byte, keyFile string) (*KeyInfo, error)

DecryptKeyInfo use the private RSA Key to decrypt the encryptedKeyInfo, then deserialize it from json, return a KeyInfo

func NewKeyInfo

func NewKeyInfo() (*KeyInfo, error)

NewKeyInfo retrurn a keyInfo struct with a random AES password generated

func (*KeyInfo) Encrypt

func (ki *KeyInfo) Encrypt(keyFile string) ([]byte, error)

Encrypt serialize iKeyInfot to JSON, then use the private RSA Key to encrypt it, return an encrypted KeyInfo

func (*KeyInfo) GetGCM

func (ki *KeyInfo) GetGCM() (cipher.AEAD, error)

GetGCM return a gcm initialized with the keyInfo aesPassword

func (*KeyInfo) GetNonce

func (ki *KeyInfo) GetNonce() []byte

GetNonce return the nonce

func (*KeyInfo) ToString

func (ki *KeyInfo) ToString() string

ToString return a string representation on a keyInfo ready to be displayed

type Shard

type Shard struct {
	//The name the shard have in the object storage
	Name string `json:"name,omitempty"`
	//The name of the bucket where the shard is stored
	BucketName string `json:"bucketName,omitempty"`
	//The shard checkSum (after encryption)
	CheckSum string `json:"checkSum,omitempty"`
	//The Nonce used to encrypt the shard
	Nonce []byte `json:"nonce,omitempty"`
}

Shard ...

func NewShard

func NewShard(bucket objectstorage.Bucket) (*Shard, error)

NewShard return a new Shard

func (*Shard) GenerateNonce

func (s *Shard) GenerateNonce(nonceSize int) ([]byte, error)

GenerateNonce generate, set and return a nonce of the required size

func (*Shard) GetCheckSum

func (s *Shard) GetCheckSum() string

GetCheckSum ...

func (*Shard) GetNonce

func (s *Shard) GetNonce() []byte

GetNonce return the nonce

func (*Shard) GetStorageInfo

func (s *Shard) GetStorageInfo() (string, string)

GetStorageInfo return the name and bucket name of the shard

func (*Shard) SetCheckSum

func (s *Shard) SetCheckSum(reader io.Reader) string

SetCheckSum will hash the file in the reader and store the result as a string

func (*Shard) ToString

func (s *Shard) ToString() string

ToString return a string representation on a shard ready to be displayed

Jump to

Keyboard shortcuts

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