onpremise

package
v4.4.36 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: EUPL-1.2 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoDataFileProvided = errors.New("no data file provided")
	ErrTooManyRetries     = errors.New("too many retries to pull data file")
	ErrFileNotModified    = errors.New("data file not modified")
	ErrLicenseKeyRequired = errors.New("auto update set to true, no custom URL specified, license key is required, set it using WithLicenseKey")
)

Functions

This section is empty.

Types

type Engine

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

Engine is an implementation of the on-premise (based on a local data file) device detection. It encapsulates the automatic data file updates feature - to periodically fetch and reload the new data file. File system watcher feature allows to monitor for changes to the local data file and reload it when it changes. Custom URL can be used to fetch data files, the polling interval is configurable The 51degrees distributor service can also be used with a licenseKey For more information see With... options and examples

func New

func New(opts ...EngineOptions) (*Engine, error)

New creates an instance of the on-premise device detection engine. WithDataFile must be provided to specify the path to the data file, otherwise initialization will fail

func (*Engine) GetHttpHeaderKeys

func (e *Engine) GetHttpHeaderKeys() []dd.EvidenceKey

GetHttpHeaderKeys returns all HTTP headers that can be used as evidence for device detection

func (*Engine) Process

func (e *Engine) Process(evidenceList []Evidence) (*dd.ResultsHash, error)

Process detects the device from the provided evidence list returns the dd.ResultsHash object from which various device properties are retrieved

func (*Engine) Stop

func (e *Engine) Stop()

Stop has to be called to free all the resources of the engine before the instance goes out of scope

type EngineOptions

type EngineOptions func(cfg *Engine) error

func WithAutoUpdate

func WithAutoUpdate(enabled bool) EngineOptions

WithAutoUpdate enables or disables auto update default is true if enabled, engine will automatically pull the data file from the distributor or custom URL if disabled options like WithDataUpdateUrl, WithLicenseKey will be ignored

func WithConfigHash added in v4.4.33

func WithConfigHash(configHash *dd.ConfigHash) EngineOptions

WithConfigHash allows to configure the Hash matching algorithm. See dd.ConfigHash type for all available settings: PerformanceProfile, Drift, Difference, Concurrency By default initialized with dd.Balanced performance profile dd.NewConfigHash(dd.Balanced)

func WithCustomLogger

func WithCustomLogger(logger LogWriter) EngineOptions

WithCustomLogger sets a custom logger

func WithDataFile

func WithDataFile(path string) EngineOptions

WithDataFile sets the path to the local data file, this parameter is required to start the engine

func WithDataUpdateUrl

func WithDataUpdateUrl(urlStr string) EngineOptions

WithDataUpdateUrl sets a custom URL to download the data file from

func WithFileWatch

func WithFileWatch(enabled bool) EngineOptions

WithFileWatch enables or disables file watching in case 3rd party updates the data file engine will automatically reload the data file. Default is true

func WithLicenseKey

func WithLicenseKey(key string) EngineOptions

WithLicenseKey sets the license key to use when pulling the data file this option can only be used when using the default data file url from 51Degrees, it will be appended as a query parameter

func WithLogging

func WithLogging(enabled bool) EngineOptions

WithLogging enables or disables the logger

func WithMaxRetries

func WithMaxRetries(retries int) EngineOptions

WithMaxRetries sets the maximum number of retries to pull the data file if request fails

func WithPollingInterval

func WithPollingInterval(seconds int) EngineOptions

WithPollingInterval sets the interval in seconds to pull the data file

func WithProduct

func WithProduct(product string) EngineOptions

WithProduct sets the product to use when pulling the data file when distributor service is used licenseKey has to be provided using WithLicenseKey

func WithProperties added in v4.4.33

func WithProperties(properties []string) EngineOptions

WithProperties sets properties that the engine retrieves from the data file for each device detection result instance default is "" which will include all possible properties

func WithRandomization

func WithRandomization(seconds int) EngineOptions

WithRandomization sets the randomization time in seconds default is 10 minutes if set, when scheduling the file pulling, it will add randomization time to the interval this is useful to avoid multiple engines pulling the data file at the same time in case of multiple engines/instances

func WithTempDataCopy

func WithTempDataCopy(enabled bool) EngineOptions

WithTempDataCopy enables or disables creating a temp copy of the data file default is true if enabled, engine will create a temp copy of the data file and use it for detection rather than original data file if disabled, engine will use the original data file to initialize the manager this is useful when 3rd party updates the data file on the file system

func WithTempDataDir added in v4.4.33

func WithTempDataDir(dir string) EngineOptions

WithTempDataDir sets the directory to store the temp data file default is system temp directory

func WithUpdateOnStart

func WithUpdateOnStart(enabled bool) EngineOptions

WithUpdateOnStart enables or disables update on start if enabled, engine will pull the data file from the distributor (or custom URL) once initialized default is false

type Evidence

type Evidence struct {
	Prefix dd.EvidencePrefix
	Key    string
	Value  string
}

Evidence struct encapsulates the evidence provided as input to the Process function Evidence is usually an HTTP header, thus Prefix would be dd.HttpHeaderString, but can also be a query param (dd.HttpEvidenceQuery) or a cookie (dd.HttpEvidenceCookie)

type FileResponse

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

type FileWatcher

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

type LogWriter

type LogWriter interface {
	Printf(format string, v ...interface{})
}
var DefaultLogger LogWriter = log.New(os.Stdout, "\r\n", log.LstdFlags)

type Watcher added in v4.4.34

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

func (*Watcher) Changed added in v4.4.34

func (fw *Watcher) Changed() <-chan os.FileInfo

func (*Watcher) Errors added in v4.4.34

func (fw *Watcher) Errors() <-chan error

func (*Watcher) IsStopped added in v4.4.34

func (fw *Watcher) IsStopped() <-chan bool

func (*Watcher) Start added in v4.4.34

func (fw *Watcher) Start() error

func (*Watcher) Stop added in v4.4.34

func (fw *Watcher) Stop() error

Jump to

Keyboard shortcuts

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