common_models

package
v0.0.0-...-4d12b9b Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: AGPL-3.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidField = errors.New("invalid field name")

ErrInvalidField is a field name the event store cannot be asked about.

View Source
var ErrOperatorUnsupported = fmt.Errorf("the event store does not support this operator")

Functions

func Normalize

func Normalize(page, size, defaultSize, maxSize int) (int, int)

Normalize clamps paging values: page >= 1, size defaulted to defaultSize when unset and capped at maxSize (pass maxSize <= 0 for no cap).

func ScopeSQL

func ScopeSQL(query, tenant, logsTable, alertsTable string, page, size int) string

ScopeSQL wraps a caller-supplied SELECT with tenant-scoped logs/alerts CTEs. Both the log explorer's SQL mode and the store.search_sql MCP tool run queries this way, so the scoping lives in one place.

FetchQuery binds no parameters, so the tenant is inlined; sqlQuote escapes the two characters that can end a ClickHouse string literal. Callers must first run the text through the SQL guard (loganalyzer usecase ValidateSQL).

The CTEs only shadow the bare names `logs` and `alerts`. A query that names the physical table, a system table or a table function would walk around them — which is why the guard runs first.

func ToStoreFilters

func ToStoreFilters(in []FilterType) ([]store.Filter, error)

func ValidateField

func ValidateField(field string) error

ValidateField checks a field name that came from a caller before it reaches the store, which writes it into the query text. A dotted name addresses a JSON path, so no segment may be empty. Backticks and backslashes are what quoting has to survive and nothing legitimate uses them; control characters have no place in a name at all. Refusing them here also turns what would be a store error, and a 500, into a 400 the caller can read.

func ValidateTimeBounds

func ValidateTimeBounds(filters []FilterType) error

ValidateTimeBounds refuses a time filter whose value cannot be read. SplitTimeBounds drops such a bound, which leaves the query with no time limit at all: a caller that asked for the last day would get the whole table, and not know.

Types

type AssetSensitivity

type AssetSensitivity struct {
	TenantID        string
	Name            string
	Hostnames       []string
	Ips             []string
	Confidentiality int
	Integrity       int
	Availability    int
}

AssetSensitivity is one asset's CIA rating, projected to the event processor so it can weigh an alert against what the target is worth.

TenantID is what keeps the projection honest: the event processor matches an alert's tenant before it looks at any asset, so an asset that arrives without one is either never applied or applied to somebody else's alerts.

type Base

type Base struct {
	ID        uuid.UUID `gorm:"primaryKey;type:uuid;default:uuid_generate_v4()" json:"id,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	DeleteAt  time.Time `json:"delete_at"`
}

type BulkFailure

type BulkFailure struct {
	TenantID string `json:"tenantId"`
	Error    string `json:"error"`
}

BulkFailure records one per-tenant error so callers can retry just the tenants that failed instead of the whole batch.

type BulkResult

type BulkResult struct {
	Succeeded []string      `json:"succeeded"`
	Failed    []BulkFailure `json:"failed"`
}

BulkResult is what every platform-admin bulk endpoint returns. Partial success is expected — system-owned guards and per-tenant validation errors land in Failed while the rest of the loop continues.

func (*BulkResult) Append

func (r *BulkResult) Append(tenantID string, err error)

Append records an outcome for one tenant. Nil err means success.

type BulkTenantSelector

type BulkTenantSelector struct {
	TenantIDs  []string `json:"tenantIds"`
	AllTenants bool     `json:"allTenants"`
}

BulkTenantSelector picks which tenants a platform-admin bulk op targets. If AllTenants is true, TenantIDs is ignored and the handler enumerates every ACTIVE tenant via the tenant usecase.

type FilterOperator

type FilterOperator string

FilterOperator is the vocabulary a filter is written in, shared by alert tag rules, the dashboards spec and every module that takes a filter list.

const (
	OpEquals      FilterOperator = "IS"
	OpNotEquals   FilterOperator = "IS_NOT"
	OpIn          FilterOperator = "IS_ONE_OF_TERMS"
	OpInOr        FilterOperator = "IS_ONE_OF_TERMS_OR"
	OpLessOrEq    FilterOperator = "IS_LESS_THAN_OR_EQUALS"
	OpGreater     FilterOperator = "IS_GREATER_THAN"
	OpExists      FilterOperator = "EXIST"
	OpNotExists   FilterOperator = "DOES_NOT_EXIST"
	OpNotContains FilterOperator = "NOT_CONTAINS"

	// Extended operators ported from Java OperatorType enum.
	OpContain             FilterOperator = "CONTAIN"
	OpDoesNotContain      FilterOperator = "DOES_NOT_CONTAIN"
	OpContainOneOf        FilterOperator = "CONTAIN_ONE_OF"
	OpDoesNotContainOneOf FilterOperator = "DOES_NOT_CONTAIN_ONE_OF"
	OpIsOneOf             FilterOperator = "IS_ONE_OF"
	OpIsNotOneOf          FilterOperator = "IS_NOT_ONE_OF"
	OpIsBetween           FilterOperator = "IS_BETWEEN"
	OpIsNotBetween        FilterOperator = "IS_NOT_BETWEEN"
	OpIsInFields          FilterOperator = "IS_IN_FIELDS"
	OpIsNotInFields       FilterOperator = "IS_NOT_IN_FIELDS"
	OpEndsWith            FilterOperator = "ENDS_WITH"
	OpNotEndsWith         FilterOperator = "NOT_ENDS_WITH"
	OpStartWith           FilterOperator = "START_WITH"
	OpNotStartWith        FilterOperator = "NOT_START_WITH"
)

func Unsupported

func Unsupported() []FilterOperator

type FilterType

type FilterType struct {
	Field    string         `json:"field"`
	Operator FilterOperator `json:"operator"`
	Value    any            `json:"value,omitempty"`
}

FilterType is one predicate: a field, what to ask about it, and the value.

func SplitTimeBounds

func SplitTimeBounds(scope store.Scope, filters []FilterType) (store.Scope, []FilterType)

type IListRequest

type IListRequest interface {
	GetPageNumber() int
	GetPageSize() int
	GetSearchQuery() string
	GetSortBy() string
}

IListRequest is satisfied by any paginated request — including module filter structs that embed ListRequest — so generic helpers can read paging without knowing the concrete type.

type IListResponse

type IListResponse[T any] interface {
	GetItems() []T
	GetPageNumber() int
	GetPageSize() int
	GetTotalItems() int
	GetTotalPages() int

	SetItems([]T)
	SetPageNumber(int)
	SetPageSize(int)
	SetTotalItems(int)
	SetTotalPages(int)
}

type ListRequest

type ListRequest struct {
	PageNumber  int    `json:"page_number" form:"page_number"`
	PageSize    int    `json:"page_size" form:"page_size"`
	SearchQuery string `json:"search_query" form:"search_query"`
	SortBy      string `json:"sort_by" form:"sort_by"`
}

ListRequest is the common paging/search/sort input. form tags let it bind from query params (GET list endpoints); json tags cover body binding. SearchQuery carries the filter DSL (field.op.value&...), SortBy the sort DSL (field.dir&...).

func (ListRequest) GetPageNumber

func (r ListRequest) GetPageNumber() int

Value receivers so both ListRequest and *ListRequest satisfy IListRequest.

func (ListRequest) GetPageSize

func (r ListRequest) GetPageSize() int

func (ListRequest) GetSearchQuery

func (r ListRequest) GetSearchQuery() string

func (ListRequest) GetSortBy

func (r ListRequest) GetSortBy() string

type ListResponse

type ListResponse[T any] struct {
	Items      []T `json:"items"`
	PageNumber int `json:"page_number"`
	PageSize   int `json:"page_size"`
	TotalItems int `json:"total_items"`
	TotalPages int `json:"total_pages"`
}

func MapList

func MapList[T any, U any](src ListResponse[T], fn func(T) U) ListResponse[U]

MapList converts a ListResponse[T] into a ListResponse[U] by applying fn to each item, preserving the page metadata — e.g. domain entities → DTOs.

func NewListResponse

func NewListResponse[T any](items []T, page, size, totalItems int) ListResponse[T]

NewListResponse builds the envelope and computes TotalPages from size/total. A nil item slice is normalized to an empty slice so the JSON is [] not null.

func (*ListResponse[T]) GetItems

func (lr *ListResponse[T]) GetItems() []T

func (*ListResponse[T]) GetPageNumber

func (lr *ListResponse[T]) GetPageNumber() int

func (*ListResponse[T]) GetPageSize

func (lr *ListResponse[T]) GetPageSize() int

func (*ListResponse[T]) GetTotalItems

func (lr *ListResponse[T]) GetTotalItems() int

func (*ListResponse[T]) GetTotalPages

func (lr *ListResponse[T]) GetTotalPages() int

func (*ListResponse[T]) SetItems

func (lr *ListResponse[T]) SetItems(items []T)

func (*ListResponse[T]) SetPageNumber

func (lr *ListResponse[T]) SetPageNumber(pageNumber int)

func (*ListResponse[T]) SetPageSize

func (lr *ListResponse[T]) SetPageSize(pageSize int)

func (*ListResponse[T]) SetTotalItems

func (lr *ListResponse[T]) SetTotalItems(totalItems int)

func (*ListResponse[T]) SetTotalPages

func (lr *ListResponse[T]) SetTotalPages(totalPages int)

type URL

type URL struct {
	Url string `json:"url"`
}

Jump to

Keyboard shortcuts

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