core

package
v0.0.0-...-797ef38 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DELETE = "DELETE"
	PUT    = "PUT"
	GET    = "GET"
	POST   = "POST"
)
View Source
const (
	MetricHistogramBoundKeyV2              = "le"
	MetricHistogramCountSuffix             = "_count"
	MetricHistogramSumSuffix               = "_sum"
	MetricHistogramBucketSuffix            = "_bucket"
	MetricSummaryQuantileKeyV2             = "quantile"
	MetricSummaryCountSuffix               = "_count"
	MetricSummarySumSuffix                 = "_sum"
	AttributeInstrumentationLibraryName    = "otel.library.name"
	AttributeInstrumentationLibraryVersion = "otel.library.version"
)

Variables

View Source
var Version = "0.0.0.0"

Version placeholder variable for the version number displayed on cli this value gets overridden at build time with the correct version in the build file

Functions

func DKey

func DKey(key string) string

func HttpRequest

func HttpRequest(client *http.Client, uri, method, user, pwd string, resultCode int) ([]byte, error)

func Key

func Key(iType, name string) string

func Retry

func Retry(attempts int, sleep time.Duration, f func(input interface{}) error, input interface{}) error

Retry the execution of a function if an error is returned to provide an easy way to increase resiliency. This is especially useful when making HTTP requests or doing anything else that has to reach out across the network. There are two options for stopping the retry loop before all the attempts are made:

  1. return nil; or
  2. return a wrapped error: stop{err}

Choose option #2 when an error occurs where retrying would be futile. Consider most 4XX HTTP status codes. They indicate that the client has done something wrong and subsequent retries, without any modification to the request will result in the same response. In this case we still want to return an error, so we wrap the error in the stop type. The actual error that is returned by the retry function will be the original non-wrapped error. This allows for later checks like err == ErrUnauthorized.

func SaveInfo

func SaveInfo(f multipart.File) (string, error)

func SyncPath

func SyncPath() string

func SyncTemp

func SyncTemp() string

Types

type API

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

API backend services API

func Api

func Api() *API

func NewAPI

func NewAPI(cfg *Conf) (*API, error)

func (*API) AdmitRegistered

func (r *API) AdmitRegistered(macAddress, hostUUID string) error

AdmitRegistered admits a host that has been registered with a mac-address after confirmation of activation

func (*API) Augment

func (r *API) Augment(events *Events) (*Events, error)

func (*API) AuthenticateActivationSvc

func (r *API) AuthenticateActivationSvc(request http.Request) (*h.UserPrincipal, error)

func (*API) AuthenticatePilot

func (r *API) AuthenticatePilot(token string) (*h.UserPrincipal, error)

AuthenticatePilot authenticates pilot requests

func (*API) AuthenticateUser

func (r *API) AuthenticateUser(request http.Request) (*h.UserPrincipal, error)

AuthenticateUser authenticate user requests

func (*API) CompleteJob

func (r *API) CompleteJob(status *JobResult) error

func (*API) CreateJobBatch

func (r *API) CreateJobBatch(info JobBatchInfo) (int64, error)

func (*API) DecommissionHost

func (r *API) DecommissionHost(hostUUID string) error

func (*API) DeleteCommand

func (r *API) DeleteCommand(cmdName string) (string, error)

func (*API) DeleteDictionary

func (r *API) DeleteDictionary(key string) (string, error)

func (*API) GetAllCommands

func (r *API) GetAllCommands() ([]Cmd, error)

func (*API) GetAreas

func (r *API) GetAreas(orgGroup string) ([]Area, error)

func (*API) GetCVEBaseline

func (r *API) GetCVEBaseline(score float64, label []string) ([]CvePackage, error)

func (*API) GetCommand

func (r *API) GetCommand(cmdName string) (*Cmd, error)

func (*API) GetCommandValue

func (r *API) GetCommandValue(fxKey string) (*CmdInfo, error)

func (*API) GetDictionaries

func (r *API) GetDictionaries(values bool) ([]*Dictionary, error)

func (*API) GetDictionary

func (r *API) GetDictionary(key string) (*Dictionary, error)

func (*API) GetHost

func (r *API) GetHost(uuid string) (*Host, error)

func (*API) GetHosts

func (r *API) GetHosts(oGroup, or, ar, loc string, label []string) ([]Host, error)

GetHosts get a list of hosts filtered by oGroup: organisation group key or: organisation key ar: area key loc: location key

func (*API) GetHostsAtLocations

func (r *API) GetHostsAtLocations(locations []string) ([]Host, error)

func (*API) GetJobBatches

func (r *API) GetJobBatches(name, owner *string, from, to *time.Time, label *[]string) ([]JobBatch, error)

func (*API) GetJobs

func (r *API) GetJobs(oGroup, or, ar, loc string, batchId *int64) ([]Job, error)

func (*API) GetLocations

func (r *API) GetLocations(area string) ([]Location, error)

func (*API) GetOrgGroups

func (r *API) GetOrgGroups() ([]Org, error)

func (*API) GetOrgs

func (r *API) GetOrgs(orgGroup string) ([]Org, error)

func (*API) GetPackageAPI

func (r *API) GetPackageAPI(name string) ([]*data.FxInfo, error)

func (*API) GetPackages

func (r *API) GetPackages() ([]PackageInfo, error)

GetPackages get a list of packages in the backing Artisan registry

func (*API) Login

func (r *API) Login(username string) (h.Controls, error)

Login if the user is authenticated returns a list of access controls otherwise an error is returned

func (*API) Ping

func (r *API) Ping() (jobId int64, fxKey string, fxVersion int64, err error)

func (*API) PingInterval

func (r *API) PingInterval() time.Duration

func (*API) PutCommand

func (r *API) PutCommand(cmd *Cmd) error

PutCommand put the command in the Onix database

func (*API) Register

func (r *API) Register(reg *RegistrationRequest) (*RegistrationResponse, error)

func (*API) SetAdmission

func (r *API) SetAdmission(admission Admission) error

func (*API) SetDictionary

func (r *API) SetDictionary(dictionary Dictionary) (string, error)

func (*API) SetRegistration

func (r *API) SetRegistration(registration Registration) error

func (*API) SubmitLogs

func (r *API) SubmitLogs(channel string, content []byte) ConnResult

SubmitLogs post the logs to a backend using a connector TODO: use file buffer to pass logs to connector as done in SubmitMetrics

func (*API) SubmitMetrics

func (r *API) SubmitMetrics(channel string, content []byte) ConnResult

SubmitMetrics post the metrics to a backend using a connector

func (*API) UndoRegistration

func (r *API) UndoRegistration(mac string) error

func (*API) UpsertCVE

func (r *API) UpsertCVE(hostUUID string, rep *CveReport) error

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Client REM HTTP client

func NewClient

func NewClient(conf *ClientConf) (*Client, error)

NewClient creates a new Onix Web API client

func (*Client) Delete

func (c *Client) Delete(url string, processor HttpRequestProcessor) (*http.Response, error)

Delete Make a DELETE HTTP request to the specified URL

func (*Client) Get

func (c *Client) Get(url string, processor HttpRequestProcessor) (*http.Response, error)

Get Make a GET HTTP request to the specified URL

func (*Client) MakeRequest

func (c *Client) MakeRequest(method string, url string, payload Serializable, processor HttpRequestProcessor) (*http.Response, error)

MakeRequest Make a generic HTTP request

func (*Client) Post

func (c *Client) Post(url string, payload Serializable, processor HttpRequestProcessor) (*http.Response, error)

Post Make a POST HTTP request to the specified URL

func (*Client) Put

func (c *Client) Put(url string, payload Serializable, processor HttpRequestProcessor) (*http.Response, error)

Put Make a PUT HTTP request to the specified URL

type ClientConf

type ClientConf struct {
	// the base URI for the service
	BaseURI string
	// disables TLS certificate verification
	InsecureSkipVerify bool
	// the user username for Basic and OpenId user authentication
	Username string
	// the user password for Basic and OpenId user authentication
	Password string
	// time out
	Timeout time.Duration
	// client proxy
	Proxy func(*http.Request) (*url.URL, error)
}

ClientConf client configuration information

type Conf

type Conf struct {
}

func NewConf

func NewConf() *Conf

func (*Conf) GetActivationPwd

func (c *Conf) GetActivationPwd() string

func (*Conf) GetActivationURI

func (c *Conf) GetActivationURI() string

func (*Conf) GetActivationUser

func (c *Conf) GetActivationUser() string

func (*Conf) GetArtRegPackageFilter

func (c *Conf) GetArtRegPackageFilter() string

func (*Conf) GetCorsHeaders

func (c *Conf) GetCorsHeaders() string

func (*Conf) GetCorsOrigin

func (c *Conf) GetCorsOrigin() string

func (*Conf) GetTenant

func (c *Conf) GetTenant() string

func (*Conf) PingIntervalSecs

func (c *Conf) PingIntervalSecs() time.Duration

PingIntervalSecs the pilot ping interval

type ConfKey

type ConfKey string
const (
	ConfDbName                  ConfKey = "PILOT_CTL_DB_NAME"
	ConfDbHost                  ConfKey = "PILOT_CTL_DB_HOST"
	ConfDbPort                  ConfKey = "PILOT_CTL_DB_PORT"
	ConfDbUser                  ConfKey = "PILOT_CTL_DB_USER"
	ConfDbPwd                   ConfKey = "PILOT_CTL_DB_PWD"
	ConfPingIntervalSecs        ConfKey = "PILOT_CTL_PING_INTERVAL_SECS"
	ConfILinkUri                ConfKey = "PILOT_CTL_ILINK_URI"
	ConfILinkUser               ConfKey = "PILOT_CTL_ILINK_USER"
	ConfILinkPwd                ConfKey = "PILOT_CTL_ILINK_PWD"
	ConfILinkInsecureSkipVerify ConfKey = "PILOT_CTL_ILINK_INSECURE_SKIP_VERIFY"
	ConfArtRegURI               ConfKey = "PILOT_CTL_ART_REG_URI"
	ConfArtRegUser              ConfKey = "PILOT_CTL_ART_REG_USER"
	ConfArtRegPwd               ConfKey = "PILOT_CTL_ART_REG_PWD"
	ConfArtRegPackageFilter     ConfKey = "PILOT_CTL_ART_REG_PACKAGE_FILTER"
	ConfActURI                  ConfKey = "PILOT_CTL_ACTIVATION_URI"
	ConfActUser                 ConfKey = "PILOT_CTL_ACTIVATION_USER"
	ConfActPwd                  ConfKey = "PILOT_CTL_ACTIVATION_PWD"
	ConfTenant                  ConfKey = "PILOT_CTL_TENANT"
	ConfDbMaxConn               ConfKey = "PILOT_CTL_DB_MAXCONN"
	ConfCorsOrigin              ConfKey = "PILOT_CTL_CORS_ORIGIN"
	ConfCorsHeaders             ConfKey = "PILOT_CTL_CORS_HEADERS"
	ConfSyncPath                ConfKey = "PILOT_CTL_SYNC_PATH"
	ConfTelemBufferPath         ConfKey = "PILOT_CTL_TELEM_BUFFER_PATH"
	ConfTelemConnectors         ConfKey = "PILOT_CTL_TELEM_CONN"
)

type ConnResult

type ConnResult struct {
	Error             string `json:"e,omitempty"`
	TotalEntries      int    `json:"t,omitempty"`
	SuccessfulEntries int    `json:"s,omitempty"`
}

ConnResult the result of the connector execution

type DataPoint

type DataPoint struct {
	Measure string
	Tags    map[string]string
	Fields  map[string]interface{}
	Time    time.Time
	Type    string
}

type Db

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

func NewDb

func NewDb(host, port, db, uname, pwd string, maxConn int) (*Db, error)

func (*Db) Query

func (db *Db) Query(query string, args ...interface{}) (pgx.Rows, error)

func (*Db) RunCommand

func (db *Db) RunCommand(script string, arguments ...interface{}) error

type Diff

type Diff struct {
	OG    *DiffReport     `json:"org_groups" yaml:"org_groups"`
	OR    *DiffReport     `json:"orgs" yaml:"orgs"`
	AR    *DiffReport     `json:"areas" yaml:"areas"`
	LO    *DiffReport     `json:"locations" yaml:"locations"`
	LINKS *DiffLinkReport `json:"links" yaml:"links"`
}

func SyncInfo

func SyncInfo(file string, api *API, dryRun bool) (diff *Diff, err error)

SyncInfo syncs the content of the input spreadsheet file compares the logistics information in the spreadsheet and commits any differences to Onix CMDB

type DiffLinkReport

type DiffLinkReport struct {
	Added   []linkInfo `json:"added,omitempty" yaml:"added,omitempty"`
	Removed []linkInfo `json:"removed" yaml:"removed,omitempty"`
}

type DiffReport

type DiffReport struct {
	Added   *infoList `json:"added,omitempty" yaml:"added,omitempty"`
	Removed *infoList `json:"removed" yaml:"removed,omitempty"`
	Updated *infoList `json:"updated" yaml:"updated,omitempty"`
}

type EventPublisher

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

func NewEventPublisher

func NewEventPublisher() *EventPublisher

func (*EventPublisher) Publish

func (p *EventPublisher) Publish(payload *types.Events)

type HttpRequestProcessor

type HttpRequestProcessor func(req *http.Request, payload Serializable) error

HttpRequestProcessor modify the http request for example by adding any relevant http headers payload is provided for example, in case a Content-MD5 header has to be added to the request

type Logger

type Logger interface {
	Debug(msg string, kv ...interface{})
}

type MetricValueType

type MetricValueType uint8
const (
	MetricValueTypeUntyped MetricValueType = iota
	MetricValueTypeGauge
	MetricValueTypeSum
	MetricValueTypeHistogram
	MetricValueTypeSummary
)

func (MetricValueType) String

func (vType MetricValueType) String() string

type OtelDataPointConverter

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

func NewOtelDataPointConverter

func NewOtelDataPointConverter() OtelDataPointConverter

func (*OtelDataPointConverter) Convert

type Result

type Result struct {
	Error   bool   `json:"error"`
	Message string `json:"message"`
}

Result data retrieved by PUT and DELETE WAPI resources

type Row

type Row []string

Row a row in the table

type Serializable

type Serializable interface {
	Reader() (*bytes.Reader, error)
	Bytes() (*[]byte, error)
}

Serializable all entities interface for payload serialisation

type StopRetry

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

StopRetry is a wrapper for an error to tell the Retry function that the retry loop should finish before it has reached the total number of retries

type Table

type Table struct {
	Header Row   `json:"header,omitempty"`
	Rows   []Row `json:"row,omitempty"`
}

Table generic table used as a serializable result set for queries

Jump to

Keyboard shortcuts

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