core

package module
v0.0.0-...-9c4f1a3 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NONE  = ""
	SLASH = string(os.PathSeparator)
)

Variables

View Source
var (
	Log             = nfo.Log
	Fatal           = nfo.Fatal
	Notice          = nfo.Notice
	Flash           = nfo.Flash
	Stdout          = nfo.Stdout
	Warn            = nfo.Warn
	Defer           = nfo.Defer
	Debug           = nfo.Debug
	Exit            = nfo.Exit
	PleaseWait      = nfo.PleaseWait
	Stderr          = nfo.Stderr
	ProgressBar     = nfo.ProgressBar
	Path            = filepath.Clean
	TransferCounter = nfo.TransferCounter
	NewLimitGroup   = xsync.NewLimitGroup
	FormatPath      = filepath.FromSlash
	GetPath         = filepath.ToSlash
	Info            = nfo.Aux
)

Import from go-nfo.

View Source
var ErrNoUploadID = errors.New("Upload ID not found.")
View Source
var ErrNotFound = errors.New("Requested item not found.")
View Source
var ErrUploadNoResp = errors.New("Unexpected empty resposne from server.")
View Source
var SetPath = fmt.Sprintf

SetPath shortcut.

Functions

func CombinePath

func CombinePath(name ...string) string

func Critical

func Critical(err error)

Fatal Error Check

func DateString

func DateString(input time.Time) string

Create standard date YY-MM-DD out of time.Time.

func DefaultPleaseWait

func DefaultPleaseWait()

Returns please wait prompt back to default setting.

func Dequote

func Dequote(input *string)

func Err

func Err(input ...interface{})

func ErrCount

func ErrCount() uint32

Returns amount of times Err has been triggered.

func HumanSize

func HumanSize(bytes int64) string

Provides human readable file sizes.

func IsAPIError

func IsAPIError(err error, code ...string) bool

Search for KWAPIErrorCode, if multiple codes are given return true if we find one.

func IsBlank

func IsBlank(input ...string) bool

func KVLiteStore

func KVLiteStore(input Database) *kvLiteStore

Wraps KVLite Databse as a auth token store.

func MD5Sum

func MD5Sum(filename string) (sum string, err error)

MD5Sum function for checking files against appliance.

func MkDir

func MkDir(name ...string) (err error)

Creates folders.

func RandBytes

func RandBytes(sz int) []byte

Generates a random byte slice of length specified.

func ReadKWTime

func ReadKWTime(input string) (time.Time, error)

Parse Timestamps from kiteworks

func Rename

func Rename(oldpath, newpath string) error

func SetParams

func SetParams(vars ...interface{}) (output []interface{})

Creates Param for API post

func SplitPath

func SplitPath(path string) (folder_path []string)

Splits path up

func StringDate

func StringDate(input string) (output time.Time, err error)

Converts string to date.

func WriteKWTime

func WriteKWTime(input time.Time) string

Write timestamps for kiteworks.

Types

type APIClient

type APIClient struct {
	Server         string        // kiteworks host name.
	ApplicationID  string        // Application ID set for kiteworks custom app.
	RedirectURI    string        // Redirect URI for kiteworks custom app.
	AgentString    string        // Agent-String header for calls to kiteworks.
	VerifySSL      bool          // Verify certificate for connections.
	ProxyURI       string        // Proxy for outgoing https requests.
	Snoop          bool          // Flag to snoop API calls
	RequestTimeout time.Duration // Timeout for request to be answered from kiteworks server.
	ConnectTimeout time.Duration // Timeout for TLS connection to kiteworks server.
	MaxChunkSize   int64         // Max Upload Chunksize in bytes, min = 1M, max = 68M
	Retries        uint          // Max retries on a failed call
	TokenStore     TokenStore    // TokenStore for reading and writing auth tokens securely.

	NewToken        func(username string) (*Auth, error) // Provides new access_token.
	ErrorScanner    func(body []byte) APIError           // Reads body of response and interprets any errors.
	RetryErrorCodes []string                             // Error codes ("ERR_INTERNAL_SERVER_ERROR"), that should induce a retry. (will automatically try TokenErrorCodes as well)
	TokenErrorCodes []string                             // Error codes ("ERR_INVALID_GRANT"), that should indicate a problem with the current access token.
	// contains filtered or unexported fields
}

func (APIClient) BackoffTimer

func (s APIClient) BackoffTimer(retry uint)

Backs off subsequent attempts generating a pause between requests.

func (APIClient) Call

func (s APIClient) Call(username string, api_req APIRequest) (err error)

kiteworks API Call Wrapper

func (*APIClient) Chunks

func (K *APIClient) Chunks(total_size int64) (total_chunks int64)

Returns chunk_size, total number of chunks and last chunk size.

func (*APIClient) ClientSecret

func (K *APIClient) ClientSecret(client_secret_key string)

Sets client secret key.

func (APIClient) DecodeJSON

func (K APIClient) DecodeJSON(resp *http.Response, output interface{}) (err error)

Decodes JSON response body to provided interface.

func (APIClient) Do

func (s APIClient) Do(req *http.Request) (resp *http.Response, err error)

func (*APIClient) Download

func (S *APIClient) Download(req *http.Request, reqs ...*http.Request) ReadSeekCloser

Perform External Download from a remote request.

func (APIClient) GetClientSecret

func (K APIClient) GetClientSecret() string

func (APIClient) GetSignature

func (K APIClient) GetSignature() string

func (*APIClient) GetTransferLimit

func (K *APIClient) GetTransferLimit() int

func (APIClient) NewAPIError

func (C APIClient) NewAPIError() *apiError

func (APIClient) NewRequest

func (s APIClient) NewRequest(username, method, path string) (req *http.Request, err error)

New API Client Request.

func (APIClient) PageCall

func (s APIClient) PageCall(username string, req APIRequest, offset, limit int) (err error)

Call handler which allows for easier getting of multiple-object arrays. An offset of -1 will provide all results, any positive offset will only return the requested results.

func (*APIClient) SetLimiter

func (K *APIClient) SetLimiter(max_calls int)

Configures maximum number of simultaneous api calls.

func (*APIClient) SetTransferLimiter

func (K *APIClient) SetTransferLimiter(max_transfers int)

Configures maximum number of simultaneous file transfers.

func (*APIClient) Signature

func (K *APIClient) Signature(signature_key string)

Sets signature key.

type APIError

type APIError interface {
	Register(code, message string)
	NoErrors() bool
	Error() string
}

type APIRequest

type APIRequest struct {
	Version int
	Header  http.Header
	Method  string
	Path    string
	Params  []interface{}
	Output  interface{}
}

APIRequest model

type Auth

type Auth struct {
	AccessToken  string `json:"access_token"`
	Scope        string `json:"scope"`
	RefreshToken string `json:"refresh_token"`
	Expires      int64  `json:"expires_in"`
}

Auth token.

type BitFlag

type BitFlag = xsync.BitFlag

type ConfigStore

type ConfigStore = cfg.Store

type DBase

type DBase struct {
	Store kvlite.Store
}

Wrapper around go-kvlite.

func OpenCache

func OpenCache() *DBase

Open a memory-only go-kvlite store.

func (DBase) Close

func (d DBase) Close()

Closes go-kvlite database.

func (DBase) CountKeys

func (d DBase) CountKeys(table string) int

Count keys in table.

func (DBase) CryptSet

func (d DBase) CryptSet(table, key string, value interface{})

Encrypt value to go-kvlie, fatal on error.

func (DBase) Drop

func (d DBase) Drop(table string)

DB Wrappers to perform fatal error checks on each call.

func (DBase) Get

func (d DBase) Get(table, key string, output interface{}) bool

Retrieve value from go-kvlite.

func (DBase) Keys

func (d DBase) Keys(table string) []string

List keys in go-kvlite.

func (DBase) Set

func (d DBase) Set(table, key string, value interface{})

Save value to go-kvlite.

func (*DBase) Shared

func (d *DBase) Shared(table string) SubStore

Spins off a new shared table.

func (*DBase) Sub

func (d *DBase) Sub(prefix string) SubStore

func (DBase) Table

func (d DBase) Table(table string) Table

func (DBase) Tables

func (d DBase) Tables() []string

List Tables in DB

func (DBase) Unset

func (d DBase) Unset(table, key string)

Delete value from go-kvlite.

type Database

type Database interface {
	Sub(prefix string) SubStore
	Shared(table string) SubStore
	Drop(table string)
	CryptSet(table, key string, value interface{})
	Set(table, key string, value interface{})
	Unset(table, key string)
	Get(table, key string, output interface{}) bool
	Keys(table string) []string
	CountKeys(table string) int
	Tables() []string
	Table(table string) Table
}

type Error

type Error string

Error handler for const errors.

func (Error) Error

func (e Error) Error() string

type FileInfo

type FileInfo interface {
	Name() string
	Size() int64
	ModTime() time.Time
}

type FlagSet

type FlagSet struct {
	FlagArgs []string
	*eflag.EFlagSet
}

Menu item flags

func (*FlagSet) Parse

func (f *FlagSet) Parse() (err error)

Parse flags assocaited with task.

type GetUsers

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

Get Users

func (*GetUsers) Next

func (T *GetUsers) Next() (users []KiteUser, err error)

Return a set of users to process.

type KWAPI

type KWAPI struct {
	*APIClient
}

KWAPI Wrapper for kiteworks.

func (*KWAPI) Authenticate

func (K *KWAPI) Authenticate(username string) (*KWSession, error)

Authenticate with server.

func (*KWAPI) KWNewToken

func (K *KWAPI) KWNewToken(username string) (auth *Auth, err error)

func (*KWAPI) Login

func (K *KWAPI) Login(username string) (*KWSession, error)

Login to server

func (*KWAPI) Session

func (K *KWAPI) Session(username string) KWSession

Wraps a session for specfiied user.

type KWProfile

type KWProfile struct {
	Features struct {
		AllowSFTP    bool  `json:"allowSftp"`
		MaxStorage   int64 `json:"maxStorage"`
		SendExternal bool  `json:"sendExternal`
		FolderCreate int   `json:"folderCreate"`
	} `json:"features"`
}

type KWSession

type KWSession struct {
	Username string
	*KWAPI
}

kiteworks Session.

func (KWSession) Admin

func (s KWSession) Admin() kw_rest_admin

func (KWSession) Call

func (K KWSession) Call(api_req APIRequest) (err error)

Wrapper around Call to provide username.

func (KWSession) DataCall

func (s KWSession) DataCall(req APIRequest, offset, limit int) (err error)

Call handler which allows for easier getting of multiple-object arrays. An offset of -1 will provide all results, any positive offset will only return the requested results.

func (KWSession) File

func (s KWSession) File(file_id int) kw_rest_file

func (KWSession) FileDownload

func (s KWSession) FileDownload(file *KiteObject) (ReadSeekCloser, error)

Downloads a file to a specific path

func (KWSession) Folder

func (s KWSession) Folder(folder_id int) kw_rest_folder

func (KWSession) MyUser

func (s KWSession) MyUser() (user KiteUser, err error)

Retrieve my user info.

func (KWSession) Profile

func (K KWSession) Profile(profile_id int) kw_profile

func (KWSession) RunTask

func (T KWSession) RunTask(input Task, db Database, report *TaskReport, args ...map[string]interface{}) (err error)

Allows a KitebrokerTask to launch another KiteBrokerTask.

func (KWSession) TopFolders

func (s KWSession) TopFolders(params ...interface{}) (folders []KiteObject, err error)

Get list of all top folders

func (KWSession) Upload

func (s KWSession) Upload(filename string, upload_id int, source_reader ReadSeekCloser) (*KiteObject, error)

Uploads file from specific local path, uploads in chunks, allows resume.

type KiteBrokerTask

type KiteBrokerTask struct {
	Flags  FlagSet
	DB     SubStore
	Report *TaskReport
	KW     KWSession
}

Required for each task object.

func (*KiteBrokerTask) KiteBrokerTask_report_summary

func (T *KiteBrokerTask) KiteBrokerTask_report_summary(errors uint32)

Provides summary of the task after completion.

func (*KiteBrokerTask) KiteBrokerTask_set_db

func (T *KiteBrokerTask) KiteBrokerTask_set_db(DB SubStore)

Initializes the task's database

func (*KiteBrokerTask) KiteBrokerTask_set_flags

func (T *KiteBrokerTask) KiteBrokerTask_set_flags(Flags FlagSet)

Sets the flags for the task.

func (*KiteBrokerTask) KiteBrokerTask_set_report

func (T *KiteBrokerTask) KiteBrokerTask_set_report(input *TaskReport)

Sets a report for the task.

func (*KiteBrokerTask) KiteBrokerTask_set_session

func (T *KiteBrokerTask) KiteBrokerTask_set_session(user KWSession)

Sets the kw api session for the task

type KiteLinks struct {
	Relationship string `json:"rel"`
	Entity       string `json:"entity"`
	ID           int    `json:"id"`
	URL          string `json:"href"`
}

Kiteworks Links Data

type KiteMember

type KiteMember struct {
	ID     int            `json:"objectId"`
	RoleID int            `json:"roleId`
	User   KiteUser       `json:"user"`
	Role   KitePermission `json:"role"`
}

type KiteObject

type KiteObject struct {
	Type                  string         `json:"type"`
	Status                string         `json:"status"`
	ID                    int            `json:"id"`
	Name                  string         `json:"name"`
	Description           string         `json:"description"`
	Created               string         `json:"created"`
	Modified              string         `json:"modified"`
	ClientCreated         string         `json:"clientCreated"`
	ClientModified        string         `json:"clientModified"`
	Deleted               bool           `json:"deleted"`
	PermDeleted           bool           `json:"permDeleted"`
	Expire                interface{}    `json:"expire"`
	Path                  string         `json:"path"`
	ParentID              int            `json:"parentId"`
	UserID                int            `json:"userId"`
	Permalink             string         `json:"permalink"`
	Secure                bool           `json:"secure"`
	LockUser              int            `json:"lockUser"`
	Fingerprint           string         `json:"fingerprint"`
	ProfileID             int            `json:"typeID`
	Size                  int64          `json:"size"`
	Mime                  string         `json:"mime"`
	AVStatus              string         `json:"avStatus"`
	DLPStatus             string         `json:"dlpStatus"`
	AdminQuarantineStatus string         `json:"adminQuarantineStatus`
	Quarantined           bool           `json:"quarantined"`
	DLPLocked             bool           `json:"dlpLocked"`
	FileLifetime          int            `json:"fileLifetime"`
	MailID                int            `json:"mail_id"`
	Links                 []KiteLinks    `json:"links"`
	CurrentUserRole       KitePermission `json:"currentUserRole"`
}

KiteFile/Folder/Attachment

func (*KiteObject) Expiry

func (K *KiteObject) Expiry() time.Time

Returns the Expiration in time.Time.

type KitePermission

type KitePermission struct {
	ID         int    `json:"id"`
	Name       string `json:"name"`
	Rank       int    `json:"rank"`
	Modifiable bool   `json:"modifiable"`
	Disabled   bool   `json:"disabled"`
}

Permission information

type KiteUser

type KiteUser struct {
	ID          int    `json:"id"`
	Active      bool   `json:"active"`
	Deactivated bool   `json:"deactivated"`
	Suspended   bool   `json:"suspended"`
	BaseDirID   int    `json:"basedirId"`
	Deleted     bool   `json:"deleted"`
	Email       string `json:"email"`
	MyDirID     int    `json:"mydirId"`
	Name        string `json:"name"`
	SyncDirID   int    `json:"syncdirId"`
	UserTypeID  int    `json:"userTypeId"`
	Verified    bool   `json:"verified"`
	Internal    bool   `json:"internal"`
}

Kiteworks User Data

type LimitGroup

type LimitGroup = xsync.LimitGroup

type PostForm

type PostForm map[string]interface{}

Form POST to API.

type PostJSON

type PostJSON map[string]interface{}

Post JSON to API.

type Query

type Query map[string]interface{}

Add Query params to KWAPI request.

type ReadSeekCloser

type ReadSeekCloser = nfo.ReadSeekCloser

type SubStore

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

SubStore is a TaskStore, a database with a prefix in the table.

func (SubStore) CountKeys

func (d SubStore) CountKeys(table string) int

Count keys in table.

func (SubStore) CryptSet

func (d SubStore) CryptSet(table, key string, value interface{})

Encrypt value to go-kvlie, fatal on error.

func (SubStore) Drop

func (d SubStore) Drop(table string)

DB Wrappers to perform fatal error checks on each call.

func (SubStore) Get

func (d SubStore) Get(table, key string, output interface{}) bool

Retrieve value from go-kvlite.

func (SubStore) Keys

func (d SubStore) Keys(table string) []string

List keys in go-kvlite.

func (SubStore) Set

func (d SubStore) Set(table, key string, value interface{})

Save value to go-kvlite.

func (SubStore) Shared

func (d SubStore) Shared(table string) SubStore

Spins off a new shared table.

func (SubStore) Sub

func (d SubStore) Sub(prefix string) SubStore

Applies additional prefix to table.

func (SubStore) Table

func (d SubStore) Table(table string) Table

Drill in to specific table.

func (SubStore) Tables

func (d SubStore) Tables() []string

List Tables in DB

func (SubStore) Unset

func (d SubStore) Unset(table, key string)

Delete value from go-kvlite.

type Table

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

func (Table) CountKeys

func (t Table) CountKeys() int

func (Table) CryptSet

func (t Table) CryptSet(key string, value interface{})

func (Table) Drop

func (t Table) Drop()

func (Table) Get

func (t Table) Get(key string, value interface{}) bool

func (Table) Keys

func (t Table) Keys() []string

func (Table) Set

func (t Table) Set(key string, value interface{})

func (Table) Unset

func (t Table) Unset(key string)

type Tally

type Tally struct {
	Format func(val int64) string
	// contains filtered or unexported fields
}

Tally for TaskReport.

func (Tally) Add

func (c Tally) Add(num int64)

Add to Tally

func (Tally) Name

func (c Tally) Name() string

Gets name from Tally

func (Tally) Value

func (c Tally) Value() int64

Get the value of the Tally

type Task

type Task interface {
	New() Task
	Name() string
	Desc() string
	Init() error
	Main() error
	KiteBrokerTask_set_flags(Flags FlagSet)
	KiteBrokerTask_set_db(DB SubStore)
	KiteBrokerTask_set_report(*TaskReport)
	KiteBrokerTask_set_session(user KWSession)
	KiteBrokerTask_report_summary(error uint32)
}

Task Interface

type TaskArgs

type TaskArgs map[string]interface{}

type TaskReport

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

TraskReport

func NewTaskReport

func NewTaskReport(name string, file string, flags *FlagSet) *TaskReport

Create New Task Report.

func (*TaskReport) Summary

func (t *TaskReport) Summary(errors uint32)

Generates Summary Report

func (*TaskReport) Tally

func (r *TaskReport) Tally(name string, format ...func(val int64) string) (new_tally Tally)

Generates a new Tally for the TaskReport

type TokenStore

type TokenStore interface {
	Save(username string, auth *Auth) error
	Load(username string) (*Auth, error)
	Delete(username string) error
}

TokenStore interface for saving and retrieving auth tokens. Errors should only be underlying issues reading/writing to the store itself.

Jump to

Keyboard shortcuts

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