export

package
v5.5.9 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExportNotificationStarted  = 0
	ExportNotificationArchived = 1 // happens when
	ExportNotificationDeleted  = 2 // happens when the export is deleted from archive
)
View Source
const (
	CodeUserAdded  = 1
	CodeAdded      = 0
	CodeUserExists = -1
	CodeQueueFull  = -2

	// WrapperItem statuses
	StatusPending   = 0
	StatusRunning   = 1
	StatusDone      = 2
	StatusError     = 3
	StatusCanceled  = 4
	StatusCanceling = 5

	// Delete return codes
	DeleteExportNotFound    = 0
	DeleteExportDeleted     = 1
	DeleteExportUserDeleted = 2
	DeleteExportCanceled    = 3
)

Variables

This section is empty.

Functions

func ConvertHitsToCSV

func ConvertHitsToCSV(hits []reader.Hit, params CSVParameters, writeHeader bool) ([]byte, error)

ConvertHitsToCSV converts hits to CSV

func ExportFactHits

func ExportFactHits(ti time.Time, f engine.Fact, placeholders map[string]string, nhit int, offset int) ([]reader.Hit, error)

ExportFactHits export data from ElasticSearch and returns a slice of Hits

func ExportFactHitsFull

func ExportFactHitsFull(f engine.Fact) ([]reader.Hit, error)

func WriteConvertHitsToCSV added in v5.3.6

func WriteConvertHitsToCSV(w *csv.Writer, hits []reader.Hit, params CSVParameters, writeHeader bool) error

WriteConvertHitsToCSV writes hits to CSV

Types

type CSVParameters added in v5.3.6

type CSVParameters struct {
	Columns       []Column `json:"columns"`
	Separator     string   `json:"separator"`
	Limit         int64    `json:"limit"`
	ListSeparator string   `json:"listSeparator"`
}

func (CSVParameters) Equals added in v5.3.6

func (p CSVParameters) Equals(params CSVParameters) bool

Equals compares two CSVParameters

func (CSVParameters) GetColumnsLabel added in v5.3.6

func (p CSVParameters) GetColumnsLabel() []string

GetColumnsLabel returns the label of the columns

type Column added in v5.3.6

type Column struct {
	Name   string `json:"name"`
	Label  string `json:"label"`
	Format string `json:"format" default:""`
}

func (Column) Equals added in v5.3.6

func (p Column) Equals(column Column) bool

Equals compares two Column

type ElasticParams added in v5.5.1

type ElasticParams struct {
	Indices           string
	Client            string
	Limit             int64
	IgnoreUnavailable bool
	AllowNoIndices    string
}

type ExportNotification added in v5.3.6

type ExportNotification struct {
	notification.BaseNotification
	Export WrapperItem `json:"export"`
	Status int         `json:"status"`
}

func NewExportNotification added in v5.3.6

func NewExportNotification(id int64, export WrapperItem, status int) *ExportNotification

func (ExportNotification) Equals added in v5.3.6

func (e ExportNotification) Equals(notification notification.Notification) bool

Equals returns true if the two notifications are equals

func (ExportNotification) IsPersistent added in v5.3.6

func (e ExportNotification) IsPersistent() bool

IsPersistent returns whether the notification is persistent (saved to a database)

func (ExportNotification) NewInstance added in v5.3.6

func (e ExportNotification) NewInstance(id int64, data []byte, isRead bool) (notification.Notification, error)

NewInstance returns a new instance of a ExportNotification

func (ExportNotification) SetId added in v5.3.6

SetId set the notification ID

func (ExportNotification) SetPersistent added in v5.3.6

func (e ExportNotification) SetPersistent(persistent bool) notification.Notification

SetPersistent sets whether the notification is persistent (saved to a database)

func (ExportNotification) ToBytes added in v5.3.6

func (e ExportNotification) ToBytes() ([]byte, error)

ToBytes convert a notification in a json byte slice to be sent through any required channel

type ExportWorker added in v5.3.6

type ExportWorker struct {
	Mutex    sync.Mutex
	Id       int
	Success  chan<- int
	Cancel   chan bool // channel to cancel the worker
	BasePath string    // base path where the file will be saved
	// critical fields
	Available bool
	QueueItem WrapperItem
}

func NewExportWorker added in v5.3.6

func NewExportWorker(id int, basePath string, success chan<- int) *ExportWorker

func (*ExportWorker) DrainCancelChannel added in v5.3.6

func (e *ExportWorker) DrainCancelChannel()

DrainCancelChannel drains the cancel channel

func (*ExportWorker) IsAvailable added in v5.3.6

func (e *ExportWorker) IsAvailable() bool

IsAvailable returns the availability of the worker

func (*ExportWorker) SetError added in v5.3.6

func (e *ExportWorker) SetError(error error)

SetError sets the error and the status of the worker

func (*ExportWorker) SetStatus added in v5.3.6

func (e *ExportWorker) SetStatus(status int)

SetStatus sets the status of the worker

func (*ExportWorker) Start added in v5.3.6

func (e *ExportWorker) Start(item WrapperItem, ctx context.Context)

Start starts the export task It handles one queueItem at a time and when finished it stops the goroutine

func (*ExportWorker) SwapAvailable added in v5.3.6

func (e *ExportWorker) SwapAvailable(available bool) (old bool)

SwapAvailable swaps the availability of the worker

type StreamedExport added in v5.2.10

type StreamedExport struct {
	Data chan []reader.Hit
}

func NewStreamedExport added in v5.2.10

func NewStreamedExport() *StreamedExport

NewStreamedExport returns a pointer to a new StreamedExport instance One instance per StreamedExport since the channel Data will be closed after export is finished

func (StreamedExport) DrainChannel added in v5.2.10

func (export StreamedExport) DrainChannel()

DrainChannel Drains the Data channel without processing the remaining values

func (StreamedExport) ProcessStreamedExport added in v5.5.0

func (export StreamedExport) ProcessStreamedExport(ctx context.Context, searchRequest *search.Request, params ElasticParams) error

ProcessStreamedExport export data from ElasticSearch to a channel using a given elastic client, request and indices to query Please note that the channel is not closed when this function is executed

func (StreamedExport) StreamedExportFactHitsFull added in v5.2.10

func (export StreamedExport) StreamedExportFactHitsFull(ctx context.Context, f engine.Fact, limit int64, factParameters map[string]string) error

StreamedExportFactHitsFull export data from ElasticSearch to a channel Please note that the channel is not closed when this function is executed it is building the searchRequest generated by the fact, and the indices

type Wrapper added in v5.3.6

type Wrapper struct {
	BasePath string // public for export_handlers
	// contains filtered or unexported fields
}

func NewWrapper added in v5.3.6

func NewWrapper(basePath string, workersCount, diskRetentionDays, queueMaxSize int) *Wrapper

NewWrapper creates a new export wrapper

func (*Wrapper) AddToQueue added in v5.3.6

func (ew *Wrapper) AddToQueue(facts []engine.Fact, title string, params CSVParameters, user users.User, factParameters map[string]string, addHashPrefix bool) (*WrapperItem, int)

AddToQueue Adds a new export to the export worker queue

addHashPrefix adds a hash as prefix to resulting files, to avoid duplicates

func (*Wrapper) AddToQueueCustom added in v5.5.0

func (ew *Wrapper) AddToQueueCustom(title string, esParams ElasticParams, searchRequests []search.Request, params CSVParameters, user users.User, addHashPrefix bool) (*WrapperItem, int)

AddToQueueCustom Adds a new export with a custom elastic connection and a custom search request

addHashPrefix adds a hash as prefix to resulting files, to avoid duplicates

func (*Wrapper) DeleteExport added in v5.3.6

func (ew *Wrapper) DeleteExport(id string, user users.User) int

DeleteExport removes an export from the queue / archive, or cancels it if it is running returns : DeleteExportNotFound (0): if the export was not found DeleteExportDeleted (1): if the export was found and deleted DeleteExportUserDeleted (2): if the export was found and the user was removed DeleteExportCanceled (3): if the export was found and the cancellation request was made this function is similar to GetUserExport, but it avoids iterating over all exports, thus it is faster

func (*Wrapper) FindArchive added in v5.3.6

func (ew *Wrapper) FindArchive(id string, user users.User) (WrapperItem, bool)

FindArchive returns the archive item for the given id and user

func (*Wrapper) GetUserExport added in v5.3.6

func (ew *Wrapper) GetUserExport(id string, user users.User) (item WrapperItem, ok bool)

GetUserExport returns the export item for the given id and user this function is similar to GetUserExports, but it avoids iterating over all exports, thus it is faster

func (*Wrapper) GetUserExports added in v5.3.6

func (ew *Wrapper) GetUserExports(user users.User) []WrapperItem

func (*Wrapper) Init added in v5.3.6

func (ew *Wrapper) Init(ctx context.Context)

Init initializes the export wrapper

type WrapperItem added in v5.3.6

type WrapperItem struct {
	Id             string            `json:"id"`      // unique id that represents an export demand
	FactIDs        []int64           `json:"factIds"` // list of fact ids that are part of the export (for archive and json)
	Facts          []engine.Fact     `json:"-"`
	Error          string            `json:"error"`
	Status         int               `json:"status"`
	FileName       string            `json:"fileName"`
	Title          string            `json:"title"`
	Date           time.Time         `json:"date"`
	Users          []string          `json:"-"`
	Params         CSVParameters     `json:"-"`
	FactParameters map[string]string `json:"factParameters"`

	// For custom export requests
	Custom            bool             `json:"custom"`
	ElasticName       string           `json:"elasticName"`
	Indices           string           `json:"-"`
	SearchRequests    []search.Request `json:"-"`
	AllowNoIndices    string           `json:"-"`
	IgnoreUnavailable bool             `json:"-"`
}

WrapperItem represents an export demand

func NewWrapperItem added in v5.3.6

func NewWrapperItem(facts []engine.Fact, title string, params CSVParameters, user users.User, factParameters map[string]string, addHashPrefix bool) *WrapperItem

NewWrapperItem creates a new export wrapper item

addHashPrefix adds a hash as prefix to resulting files, to avoid duplicates

func (*WrapperItem) ContainsFact added in v5.3.6

func (it *WrapperItem) ContainsFact(factID int64) bool

ContainsFact checks if fact is part of the WrapperItem data

func (*WrapperItem) ContainsUser added in v5.3.6

func (it *WrapperItem) ContainsUser(user users.User) bool

ContainsUser checks if user is in item

Jump to

Keyboard shortcuts

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