libdatamanager

package module
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: Apache-2.0 Imports: 25 Imported by: 6

README

libDataManager

A go package implementing the DataManager protocol

Documentation

Index

Constants

View Source
const (
	// KeystoreDBFile the sqlite DB containing the file-key associations
	KeystoreDBFile = ".keys.db"

	// KeyringService the servicename for the keyring
	KeyringService = "DataManagerCLI-keystore"
)
View Source
const (
	// Ping
	EPPing Endpoint = "/ping"

	// User
	EPUser     Endpoint = "/user"
	EPLogin    Endpoint = EPUser + "/login"
	EPRegister Endpoint = EPUser + "/register"

	// Files
	EPFile Endpoint = "/file"

	EPFileList    Endpoint = EPFile + "s"
	EPFileUpdate  Endpoint = EPFile + "/update"
	EPFileDelete  Endpoint = EPFile + "/delete"
	EPFileGet     Endpoint = EPFile + "/get"
	EPFilePublish Endpoint = EPFile + "/publish"

	// Upload
	EPFileUpload Endpoint = "/upload" + EPFile

	// Attributes
	EPAttribute Endpoint = "/attribute"
	// Tags
	EPAttributeTag = EPAttribute + "/tag"
	EPTagUpdate    = EPAttributeTag + "/update"
	EPTagDelete    = EPAttributeTag + "/delete"
	EPTags         = EPAttributeTag + "/get"
	// Group
	EPAttributeGroup = EPAttribute + "/group"
	EPGroupUpdate    = EPAttributeGroup + "/update"
	EPGroupDelete    = EPAttributeGroup + "/delete"
	EPGroups         = EPAttributeGroup + "/get"

	// Namespace
	EPNamespace       Endpoint = "/namespace"
	EPNamespaceCreate          = EPNamespace + "/create"
	EPNamespaceUpdate          = EPNamespace + "/update"
	EPNamespaceDelete          = EPNamespace + "/delete"
	EPNamespaceList            = EPNamespace + "s"
)

Remote endpoints

View Source
const (
	// HeaderStatus headername for status in response
	HeaderStatus string = "X-Response-Status"

	// HeaderStatusMessage headername for status in response
	HeaderStatusMessage string = "X-Response-Message"

	// HeaderContentType contenttype of response
	HeaderContentType string = "Content-Type"

	// HeaderFileName filename header
	HeaderFileName string = "X-Filename"

	// HeaderRequest request content
	HeaderRequest string = "Request"

	// HeaderEncryption encryption header
	HeaderEncryption string = "X-Encryption"

	// HeaderContentLength request content length
	HeaderContentLength string = "ContentLength"

	// HeaderFileID fileid header
	HeaderFileID string = "X-FileID"

	// HeaderChecksum files checksum
	HeaderChecksum string = "Checksum"
)

Variables

View Source
var (
	// ErrInvalidResponseHeaders error on missing or malformed response headers
	ErrInvalidResponseHeaders = errors.New("Invalid response headers")
	// ErrResponseError response returned an error
	ErrResponseError = errors.New("response returned an error")
	// ErrResponseFilenameInvalid if server returns no filename
	ErrResponseFilenameInvalid = errors.New("invalid filename received")
)
View Source
var (
	// ErrKeyUnavailable if keystore key is unavailable
	ErrKeyUnavailable = errors.New("keyring key is unavailable")
	// ErrKeystoreNoDir error if keystore is no directory
	ErrKeystoreNoDir = errors.New("Keystore is not a directory")
)
View Source
var Boundary = "MachliJalKiRaniHaiJeevanUskaPaaniHai"

Boundary boundary for the part

View Source
var EncryptionCiphers = []string{
	"aes",
}

EncryptionCiphers supported encryption chipers

View Source
var (
	// ErrChecksumNotMatch error if the checksum of the downloaded
	// file doesn't match with the checksum of the remote file
	ErrChecksumNotMatch = errors.New("generated checksum not match")
)
View Source
var NoProxyWriter = func(w io.Writer) io.Writer {
	return w
}

NoProxyWriter use to fill proxyWriter arg in UpdloadFile

Functions

func ChiperToInt

func ChiperToInt(c string) int32

ChiperToInt cipter to int

func ChiperToString

func ChiperToString(i int32) string

ChiperToString cipter to int

func Decrypt added in v1.1.10

func Decrypt(in io.Reader, out, hashwriter io.Writer, keyAes, buff []byte) (err error)

Decrypt decrypt stuff

func Encrypt added in v1.0.6

func Encrypt(in io.Reader, out io.Writer, keyAes, buff []byte) (err error)

Encrypt encrypts input stream and writes it to out

func EncryptionIValid

func EncryptionIValid(i int32) bool

EncryptionIValid return true if encryption i is valid

func FileUploader

func FileUploader(f *os.File, proxyWriter func(io.Writer) io.Writer, encryption, encryptionKey string, done chan string) (r *io.PipeReader, contentType string, size int64)

FileUploader upload a file directly

func GetFilesizeFromDownloadRequest added in v1.1.10

func GetFilesizeFromDownloadRequest(resp *http.Response) int64

GetFilesizeFromDownloadRequest returns the filesize from a file from the response headers

func IsValidCipher

func IsValidCipher(c string) bool

IsValidCipher return true if given cipher is valid

Types

type Attribute

type Attribute string

Attribute attribute for file (tag/group)

const (
	TagAttribute   Attribute = "tag"
	GroupAttribute Attribute = "group"
)

Attributes

type Authorization

type Authorization struct {
	Type    AuthorizationType
	Palyoad string
}

Authorization the authorization params for a server request

type AuthorizationType

type AuthorizationType string

AuthorizationType authorization type

const (
	Bearer AuthorizationType = "Bearer"
	Basic  AuthorizationType = "Basic"
)

Authorizanion types

type BulkPublishResponse

type BulkPublishResponse struct {
	Files []UploadResponse `json:"files"`
}

BulkPublishResponse response for publishing a file

type ContentType

type ContentType string

ContentType contenttype header of request

const (
	JSONContentType ContentType = "application/json"
)

Content types

type CountResponse

type CountResponse struct {
	Count uint32 `json:"count"`
}

CountResponse response containing a count of changed items

type CredentialsRequest

type CredentialsRequest struct {
	MachineID string `json:"mid,omitempty"`
	Username  string `json:"username"`
	Password  string `json:"pass"`
}

CredentialsRequest request containing credentials

type Endpoint

type Endpoint string

Endpoint a remote url-path

type FileAttributes

type FileAttributes struct {
	Tags      []string `json:"tags,omitempty"`
	Groups    []string `json:"groups,omitempty"`
	Namespace string   `json:"ns"`
}

FileAttributes attributes for a file

type FileChanges

type FileChanges struct {
	NewName                  string
	NewNamespace             string
	AddTags, AddGroups       []string
	RemoveTags, RemoveGroups []string
	SetPublic, SetPrivate    bool
}

FileChanges file changes for updating a file

type FileListRequest

type FileListRequest struct {
	FileID         uint                     `json:"fid"`
	Name           string                   `json:"name"`
	AllNamespaces  bool                     `json:"allns"`
	OptionalParams OptionalRequetsParameter `json:"opt"`
	Order          string                   `json:"order,omitempty"`
	Attributes     FileAttributes           `json:"attributes"`
}

FileListRequest contains file info (and a file)

type FileListResponse

type FileListResponse struct {
	Files []FileResponseItem
}

FileListResponse response for listing files

type FileRequest

type FileRequest struct {
	FileID     uint           `json:"fid"`
	Name       string         `json:"name,omitempty"`
	PublicName string         `json:"pubname,omitempty"`
	Updates    FileUpdateItem `json:"updates,omitempty"`
	All        bool           `json:"all"`
	Attributes FileAttributes `json:"attributes"`
}

FileRequest contains data to update a file

type FileResponseItem

type FileResponseItem struct {
	ID           uint           `json:"id"`
	Size         int64          `json:"size"`
	CreationDate time.Time      `json:"creation"`
	Name         string         `json:"name"`
	IsPublic     bool           `json:"isPub"`
	PublicName   string         `json:"pubname"`
	Attributes   FileAttributes `json:"attrib"`
	Encryption   string         `json:"e"`
	Checksum     string         `json:"checksum"`
}

FileResponseItem file item for file response

type FileUpdateItem

type FileUpdateItem struct {
	IsPublic     string   `json:"ispublic,omitempty"`
	NewName      string   `json:"name,omitempty"`
	NewNamespace string   `json:"namespace,omitempty"`
	RemoveTags   []string `json:"rem_tags,omitempty"`
	RemoveGroups []string `json:"rem_groups,omitempty"`
	AddTags      []string `json:"add_tags,omitempty"`
	AddGroups    []string `json:"add_groups,omitempty"`
}

FileUpdateItem lists changes to a file

type IDsResponse added in v1.1.2

type IDsResponse struct {
	IDs []uint `json:"ids"`
}

IDsResponse response containing a list of ids

type Keystore added in v1.1.1

type Keystore struct {
	Path string
	DB   *gorm.DB
	// contains filtered or unexported fields
}

Keystore a place to store keys

func NewKeystore added in v1.1.1

func NewKeystore(path string) *Keystore

NewKeystore create a new keystore

func (*Keystore) AddKey added in v1.1.1

func (store *Keystore) AddKey(fileID uint, keyPath string) error

AddKey Inserts key into keystore

func (*Keystore) Close added in v1.1.1

func (store *Keystore) Close()

Close closes the keystore

func (*Keystore) DeleteKey added in v1.1.1

func (store *Keystore) DeleteKey(fileID uint) (*KeystoreFile, error)

DeleteKey Inserts key into keystore

func (*Keystore) GetFileInfo added in v1.1.7

func (store *Keystore) GetFileInfo() *os.FileInfo

GetFileInfo returns fileinfo for the keystore

func (*Keystore) GetFiles added in v1.1.7

func (store *Keystore) GetFiles() ([]KeystoreFile, error)

GetFiles returns a slice containing all keystore Files

func (*Keystore) GetKey added in v1.1.1

func (store *Keystore) GetKey(fileID uint) ([]byte, error)

GetKey returns the key assigned to the fileID. If FileID or key was not found, error is not nil

func (*Keystore) GetKeyFile added in v1.1.1

func (store *Keystore) GetKeyFile(fileID uint) (*KeystoreFile, error)

GetKeyFile returns a keyfile with assigned to the fileID

func (*Keystore) GetKeystoreDataFile added in v1.1.1

func (store *Keystore) GetKeystoreDataFile() string

GetKeystoreDataFile returns the keystore db filepath

func (*Keystore) GetKeystoreFile added in v1.1.1

func (store *Keystore) GetKeystoreFile(file string) string

GetKeystoreFile returns the full path of file

func (*Keystore) GetValidKeyCount added in v1.1.7

func (store *Keystore) GetValidKeyCount() (int, error)

GetValidKeyCount reutrns count of valid keys

func (*Keystore) Open added in v1.1.1

func (store *Keystore) Open() error

Open opens the keystore

type KeystoreFile added in v1.1.1

type KeystoreFile struct {
	gorm.Model
	FileID uint
	Key    string
}

KeystoreFile the keystore row

type LibDM

type LibDM struct {
	Config *RequestConfig
}

LibDM data required in all requests

func NewLibDM

func NewLibDM(config *RequestConfig) *LibDM

NewLibDM create new libDM "class"

func (LibDM) CreateNamespace

func (libdm LibDM) CreateNamespace(name string, customNS bool) (*StringResponse, error)

CreateNamespace creates a namespace

func (LibDM) DeleteAttribute

func (libdm LibDM) DeleteAttribute(attribute Attribute, namespace, name string) (*RestRequestResponse, error)

DeleteAttribute update an attribute

func (LibDM) DeleteFile

func (libdm LibDM) DeleteFile(name string, id uint, all bool, attributes FileAttributes) (*IDsResponse, error)

DeleteFile deletes the desired file(s)

func (LibDM) DeleteNamespace

func (libdm LibDM) DeleteNamespace(name string) (*StringResponse, error)

DeleteNamespace update a namespace

func (LibDM) DownloadFile

func (libdm LibDM) DownloadFile(name string, id uint, namespace, localFilePath string, appendFilename ...bool) error

DownloadFile downloads and saves a file to the given localFilePath. If the file exists, it will be overwritten

func (LibDM) GetFile added in v1.0.1

func (libdm LibDM) GetFile(name string, id uint, namespace string) (*http.Response, string, string, error)

GetFile requests a filedownload and returns the response -> response, serverfilename, checksum, error The response body must be closed

func (LibDM) GetGroups added in v1.0.7

func (libdm LibDM) GetGroups(namespace string) ([]Attribute, error)

GetGroups returns an array of attributes containing groups available in given namespace

func (LibDM) GetNamespaces

func (libdm LibDM) GetNamespaces() (*StringSliceResponse, error)

GetNamespaces get all namespaces

func (LibDM) GetTags added in v1.0.7

func (libdm LibDM) GetTags(namespace string) ([]Attribute, error)

GetTags returns an array of attributes containing tags available in given namespace

func (LibDM) ListFiles

func (libdm LibDM) ListFiles(name string, id uint, allNamespaces bool, attributes FileAttributes, verbose uint8) (*FileListResponse, error)

ListFiles lists the files corresponding to the args

func (LibDM) Login

func (libdm LibDM) Login(username, password string) (*LoginResponse, error)

Login login into the server

func (LibDM) PublishFile

func (libdm LibDM) PublishFile(name string, id uint, publicName string, all bool, attributes FileAttributes) (interface{}, error)

PublishFile publishs a file. If "all" is true, the response object is BulkPublishResponse. Else it is PublishResponse

func (LibDM) Register

func (libdm LibDM) Register(username, password string) (*RestRequestResponse, error)

Register create a new account. Return true on success

func (LibDM) Request

func (libdm LibDM) Request(ep Endpoint, payload, response interface{}, authorized bool) (*RestRequestResponse, error)

Request do a request using libdm

func (LibDM) UpdateAttribute

func (libdm LibDM) UpdateAttribute(attribute Attribute, namespace, name, newName string) (*RestRequestResponse, error)

UpdateAttribute update an attribute

func (LibDM) UpdateFile

func (libdm LibDM) UpdateFile(name string, id uint, namespace string, all bool, changes FileChanges) (*CountResponse, error)

UpdateFile updates a file on the server

func (LibDM) UpdateNamespace

func (libdm LibDM) UpdateNamespace(name, newName string, customNS bool) (*StringResponse, error)

UpdateNamespace update a namespace

func (LibDM) UploadFile

func (libdm LibDM) UploadFile(path, name string, public bool, replaceFile uint, attributes FileAttributes, proxyWriter func(w io.Writer) io.Writer, fsDetermined chan int64, done chan string, strArgs ...string) (*UploadResponse, error)

UploadFile uploads the given file to the server and set's its affiliations strargs: [0] public name [1] encryption [2] encryptionKey

type LoginResponse

type LoginResponse struct {
	Token     string `json:"token"`
	Namespace string `json:"ns"`
}

LoginResponse response for login

type Method

type Method string

Method http request method

const (
	GET    Method = "GET"
	POST   Method = "POST"
	DELETE Method = "DELETE"
	PUT    Method = "PUT"
)

Requests

type NamespaceRequest

type NamespaceRequest struct {
	Namespace string        `json:"ns"`
	NewName   string        `json:"newName,omitempty"`
	Type      NamespaceType `json:"nstype"`
}

NamespaceRequest namespace action request

type NamespaceType

type NamespaceType uint8

NamespaceType type of namespace

const (
	UserNamespaceType NamespaceType = iota
	CustomNamespaceType
)

Namespace types

type OptionalRequetsParameter

type OptionalRequetsParameter struct {
	Verbose uint8 `json:"verb"`
}

OptionalRequetsParameter optional request parameter

type PingRequest

type PingRequest struct {
	Payload string
}

PingRequest a ping request content

type PublishResponse

type PublishResponse struct {
	PublicFilename string `json:"pubName"`
}

PublishResponse response for publishing a file

type Request

type Request struct {
	RequestType   RequestType
	Endpoint      Endpoint
	Payload       interface{}
	Config        *RequestConfig
	Method        Method
	ContentType   ContentType
	Authorization *Authorization
	Headers       map[string]string
	BenchChan     chan time.Time
}

Request a rest server request

func NewRequest

func NewRequest(endpoint Endpoint, payload interface{}, config *RequestConfig) *Request

NewRequest creates a new post request

func (*Request) BuildClient

func (request *Request) BuildClient() *http.Client

BuildClient return client

func (Request) Do

func (request Request) Do(retVar interface{}) (*RestRequestResponse, error)

Do a better request method

func (*Request) DoHTTPRequest

func (request *Request) DoHTTPRequest() (*http.Response, error)

DoHTTPRequest do plain http request

func (*Request) WithAuth

func (request *Request) WithAuth(a Authorization) *Request

WithAuth with authorization

func (*Request) WithAuthFromConfig

func (request *Request) WithAuthFromConfig() *Request

WithAuthFromConfig with authorization

func (*Request) WithBenchCallback

func (request *Request) WithBenchCallback(c chan time.Time) *Request

WithBenchCallback with bench

func (*Request) WithContentType

func (request *Request) WithContentType(ct ContentType) *Request

WithContentType with contenttype

func (*Request) WithHeader

func (request *Request) WithHeader(name string, value string) *Request

WithHeader add header to request

func (*Request) WithMethod

func (request *Request) WithMethod(m Method) *Request

WithMethod use a different method

func (*Request) WithRequestType

func (request *Request) WithRequestType(rType RequestType) *Request

WithRequestType use different request type

type RequestConfig

type RequestConfig struct {
	IgnoreCert   bool
	URL          string
	MachineID    string
	Username     string
	SessionToken string
}

RequestConfig configurations for requests

func (RequestConfig) GetBearerAuth

func (rc RequestConfig) GetBearerAuth() Authorization

GetBearerAuth returns bearer authorization from config

type RequestType

type RequestType uint8

RequestType type of request

const (
	JSONRequestType RequestType = iota
	RawRequestType
)

Request types

type ResponseErr

type ResponseErr struct {
	Response *RestRequestResponse
	Err      error
}

ResponseErr response error

func NewErrorFromResponse

func NewErrorFromResponse(r *RestRequestResponse, err ...error) *ResponseErr

NewErrorFromResponse return error from response

func (*ResponseErr) Error

func (reserr *ResponseErr) Error() string

type ResponseStatus

type ResponseStatus uint8

ResponseStatus the status of response

const (
	// ResponseError if there was an error
	ResponseError ResponseStatus = 0
	// ResponseSuccess if the response is successful
	ResponseSuccess ResponseStatus = 1
)

type RestRequestResponse

type RestRequestResponse struct {
	HTTPCode int
	Status   ResponseStatus
	Message  string
	Headers  *http.Header
}

RestRequestResponse the response of a rest call

type StringResponse

type StringResponse struct {
	String string `json:"content"`
}

StringResponse response containing only one string

type StringSliceResponse

type StringSliceResponse struct {
	Slice []string `json:"slice"`
}

StringSliceResponse response containing only one string slice

type UpdateAttributeRequest

type UpdateAttributeRequest struct {
	Name      string `json:"name"`
	NewName   string `json:"newname"`
	Namespace string `json:"namespace"`
}

UpdateAttributeRequest contains data to update a tag

type UploadRequest

type UploadRequest struct {
	UploadType  UploadType     `json:"type"`
	URL         string         `json:"url,omitempty"`
	Name        string         `json:"name"`
	Public      bool           `json:"pb,omitempty"`
	PublicName  string         `json:"pbname,omitempty"`
	Attributes  FileAttributes `json:"attr,omitempty"`
	Encryption  string         `json:"e,omitempty"`
	ReplaceFile uint           `json:"r,omitempty"`
	Size        int64          `json:"s"`
}

UploadRequest contains file info (and a file)

type UploadResponse

type UploadResponse struct {
	FileID         uint   `json:"fileID"`
	Filename       string `json:"filename"`
	PublicFilename string `json:"publicFilename,omitempty"`
	Checksum       string `json:"checksum"`
}

UploadResponse response for uploading file

type UploadType

type UploadType uint8

UploadType type of upload

const (
	FileUploadType UploadType = iota
	URLUploadType
)

Available upload types

Directories

Path Synopsis
config module

Jump to

Keyboard shortcuts

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