handler

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseIntervalListQueryParam

func ParseIntervalListQueryParam(intervalQuery string, def []time.Duration) ([]time.Duration, error)

func RegisterHandlers

func RegisterHandlers(server *api.Server, logger *zap.SugaredLogger, db *gorm.DB, config *config.Config)

Types

type EvidenceActivity

type EvidenceActivity struct {
	UUID        uuid.UUID
	Title       string
	Description string
	Remarks     string
	Props       []oscalTypes_1_1_3.Property
	Links       []oscalTypes_1_1_3.Link
	Steps       []EvidenceActivityStep
}

type EvidenceActivityStep

type EvidenceActivityStep struct {
	UUID        uuid.UUID
	Title       string
	Description string
	Remarks     string
	Props       []oscalTypes_1_1_3.Property
	Links       []oscalTypes_1_1_3.Link
}

type EvidenceComponent

type EvidenceComponent struct {
	// components/common/ssh
	// components/common/github-repository
	// components/common/github-organisation
	// components/common/ubuntu-22
	// components/internal/auth-policy
	Identifier string

	// Software
	// Service
	Type        string
	Title       string
	Description string
	Remarks     string
	Purpose     string
	Protocols   []oscalTypes_1_1_3.Protocol
	Props       []oscalTypes_1_1_3.Property
	Links       []oscalTypes_1_1_3.Link
}

type EvidenceCreateRequest

type EvidenceCreateRequest struct {
	// UUID needs to remain consistent for a piece of evidence being collected periodically.
	// It represents the "stream" of the same observation being made over time.
	// For the same checks, performed on the same machine, the UUID for each check should remain the same.
	// For the same check, performed on two different machines, the UUID should differ.
	UUID        uuid.UUID
	Title       string
	Description string
	Remarks     *string

	// Assigning labels to Evidence makes it searchable and easily usable in the UI
	Labels map[string]string

	// When did we start collecting the evidence, and when did the process end, and how long is it valid for ?
	Start   time.Time
	End     time.Time
	Expires *time.Time

	Props      []oscalTypes_1_1_3.Property
	Links      []oscalTypes_1_1_3.Link
	BackMatter *oscalTypes_1_1_3.BackMatter `json:"back-matter,omitempty"`

	// Who or What is generating this evidence
	Origins []oscalTypes_1_1_3.Origin
	// What steps did we take to create this evidence
	Activities     []EvidenceActivity
	InventoryItems []EvidenceInventoryItem
	// Which components of the subject are being observed. A tool, user, policy etc.
	Components []EvidenceComponent
	// Who or What are we providing evidence for. What's under test.
	Subjects []EvidenceSubject
	// Did we satisfy what was being tested for, or did we fail ?
	Status oscalTypes_1_1_3.ObjectiveStatus
}

type EvidenceHandler

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

func NewEvidenceHandler

func NewEvidenceHandler(sugar *zap.SugaredLogger, db *gorm.DB) *EvidenceHandler

func (*EvidenceHandler) ComplianceByControl

func (h *EvidenceHandler) ComplianceByControl(ctx echo.Context) error

ComplianceByControl godoc

@Summary		Get compliance counts by control
@Description	Retrieves the count of evidence statuses for filters associated with a specific Control ID.
@Tags			Evidence
@Produce		json
@Param			id	path		string	true	"Control ID"
@Success		200	{object}	GenericDataListResponse[handler.ComplianceByControl.StatusCount]
@Failure		500	{object}	api.Error
@Router			/evidence/compliance-by-control/{id} [get]

func (*EvidenceHandler) ComplianceByFilter added in v0.5.0

func (h *EvidenceHandler) ComplianceByFilter(ctx echo.Context) error

ComplianceByFilter godoc

@Summary		Get compliance status counts by filter/dashboard ID
@Description	Retrieves the count of evidence statuses for a specific filter/dashboard.
@Tags			Evidence
@Produce		json
@Param			id	path		string	true	"Filter/Dashboard ID (UUID)"
@Success		200	{object}	GenericDataListResponse[handler.ComplianceByControl.StatusCount]
@Failure		400	{object}	api.Error	"Invalid UUID"
@Failure		404	{object}	api.Error
@Failure		500	{object}	api.Error
@Router			/evidence/compliance-by-filter/{id} [get]

func (*EvidenceHandler) Create

func (h *EvidenceHandler) Create(ctx echo.Context) error

Create godoc

@Summary		Create new Evidence
@Description	Creates a new Evidence record including activities, inventory items, components, and subjects.
@Tags			Evidence
@Accept			json
@Produce		json
@Param			evidence	body		EvidenceCreateRequest	true	"Evidence create request"
@Success		201			{object}	GenericDataResponse[relational.Evidence]
@Failure		400			{object}	api.Error
@Failure		500			{object}	api.Error
@Security		OAuth2Password
@Router			/evidence [post]

func (*EvidenceHandler) ForControl

func (h *EvidenceHandler) ForControl(ctx echo.Context) error

ForControl godoc

@Summary		List Evidence for a Control
@Description	Retrieves Evidence records associated with a specific Control ID, including related activities, inventory items, components, subjects, and labels.
@Tags			Evidence
@Produce		json
@Param			id	path		string	true	"Control ID"
@Success		200	{object}	handler.ForControl.EvidenceDataListResponse
@Failure		400	{object}	api.Error
@Failure		404	{object}	api.Error
@Failure		500	{object}	api.Error
@Router			/evidence/for-control/{id} [get]

func (*EvidenceHandler) Get

func (h *EvidenceHandler) Get(ctx echo.Context) error

Get godoc

@Summary		Get Evidence by ID
@Description	Retrieves a single Evidence record by its unique ID, including associated activities, inventory items, components, subjects, and labels.
@Tags			Evidence
@Produce		json
@Param			id	path		string	true	"Evidence ID"
@Success		200	{object}	GenericDataResponse[OscalLikeEvidence]
@Failure		400	{object}	api.Error
@Failure		404	{object}	api.Error
@Failure		500	{object}	api.Error
@Router			/evidence/{id} [get]

func (*EvidenceHandler) History

func (h *EvidenceHandler) History(ctx echo.Context) error

History godoc

@Summary		Get Evidence history by UUID
@Description	Retrieves a the history for a Evidence record by its UUID, including associated activities, inventory items, components, subjects, and labels.
@Tags			Evidence
@Produce		json
@Param			id	path		string	true	"Evidence ID"
@Success		200	{object}	GenericDataListResponse[OscalLikeEvidence]
@Failure		400	{object}	api.Error
@Failure		404	{object}	api.Error
@Failure		500	{object}	api.Error
@Router			/evidence/history/{id} [get]

func (*EvidenceHandler) Register

func (h *EvidenceHandler) Register(api *echo.Group)

func (*EvidenceHandler) Search

func (h *EvidenceHandler) Search(ctx echo.Context) error

Search godoc

@Summary		Search Evidence
@Description	Searches Evidence records by label filters.
@Tags			Evidence
@Accept			json
@Produce		json
@Param			filter	body		labelfilter.Filter	true	"Label filter"
@Success		200		{object}	GenericDataListResponse[relational.Evidence]
@Failure		422		{object}	api.Error
@Failure		500		{object}	api.Error
@Router			/evidence/search [post]

func (*EvidenceHandler) StatusOverTime

func (h *EvidenceHandler) StatusOverTime(ctx echo.Context) error

StatusOverTime godoc

@Summary		Evidence status metrics over intervals
@Description	Retrieves counts of evidence statuses at various time intervals based on a label filter.
@Tags			Evidence
@Accept			json
@Produce		json
@Param			filter		body		labelfilter.Filter	true	"Label filter"
@Param			intervals	query		string				false	"Comma-separated list of duration intervals (e.g., '10m,1h,24h')"
@Success		200			{object}	handler.GenericDataListResponse[StatusInterval]
@Failure		400			{object}	api.Error
@Failure		422			{object}	api.Error
@Failure		500			{object}	api.Error
@Router			/evidence/status-over-time [post]

func (*EvidenceHandler) StatusOverTimeByUUID

func (h *EvidenceHandler) StatusOverTimeByUUID(ctx echo.Context) error

StatusOverTimeByUUID godoc

@Summary		Evidence status metrics over intervals by UUID
@Description	Retrieves counts of evidence statuses at various time intervals for a specific evidence stream identified by UUID.
@Tags			Evidence
@Produce		json
@Param			id			path		string	true	"Evidence UUID"
@Param			intervals	query		string	false	"Comma-separated list of duration intervals (e.g., '10m,1h,24h')"
@Success		200			{object}	handler.GenericDataListResponse[StatusInterval]
@Failure		400			{object}	api.Error
@Failure		422			{object}	api.Error
@Failure		500			{object}	api.Error
@Router			/evidence/status-over-time/{id} [get]

type EvidenceInventoryItem

type EvidenceInventoryItem struct {
	// user/chris@linguine.tech
	// operating-system/ubuntu/22.4
	// web-server/ec2/i-12345
	Identifier string

	// "operating-system"	description="System software that manages computer hardware, software resources, and provides common services for computer programs."
	// "database"			description="An electronic collection of data, or information, that is specially organized for rapid search and retrieval."
	// "web-server"			description="A system that delivers content or services to end users over the Internet or an intranet."
	// "dns-server"			description="A system that resolves domain names to internet protocol (IP) addresses."
	// "email-server"		description="A computer system that sends and receives electronic mail messages."
	// "directory-server"	description="A system that stores, organizes and provides access to directory information in order to unify network resources."
	// "pbx"				description="A private branch exchange (PBX) provides a a private telephone switchboard."
	// "firewall"			description="A network security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules."
	// "router"				description="A physical or virtual networking device that forwards data packets between computer networks."
	// "switch"				description="A physical or virtual networking device that connects devices within a computer network by using packet switching to receive and forward data to the destination device."
	// "storage-array"		description="A consolidated, block-level data storage capability."
	// "appliance"			description="A physical or virtual machine that centralizes hardware, software, or services for a specific purpose."
	Type                  string
	Title                 string
	Description           string
	Remarks               string
	Props                 []oscalTypes_1_1_3.Property
	Links                 []oscalTypes_1_1_3.Link
	ImplementedComponents []struct {
		Identifier string
	}
}

type EvidenceSubject

type EvidenceSubject struct {
	Identifier string

	// InventoryItem
	// Component
	Type string

	Description string
	Remarks     string
	Props       []oscalTypes_1_1_3.Property
	Links       []oscalTypes_1_1_3.Link
}

type FilterHandler

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

FilterHandler handles CRUD operations for filters.

func NewFilterHandler

func NewFilterHandler(sugar *zap.SugaredLogger, db *gorm.DB) *FilterHandler

func (*FilterHandler) Create

func (h *FilterHandler) Create(ctx echo.Context) error

Create godoc

@Summary		Create a new filter
@Description	Creates a new filter.
@Tags			Filters
@Accept			json
@Produce		json
@Param			filter	body		createFilterRequest	true	"Filter to add"
@Success		201		{object}	GenericDataResponse[relational.Filter]
@Failure		400		{object}	api.Error
@Failure		422		{object}	api.Error
@Failure		500		{object}	api.Error
@Router			/filters [post]

func (*FilterHandler) Delete

func (h *FilterHandler) Delete(ctx echo.Context) error

Delete godoc

@Summary		Delete a filter
@Description	Deletes a filter.
@Tags			Filters
@Param			id	path	string	true	"Filter ID"
@Success		204	"No Content"
@Failure		400	{object}	api.Error
@Failure		404	{object}	api.Error
@Failure		500	{object}	api.Error
@Router			/filters/{id} [delete]

func (*FilterHandler) Get

func (h *FilterHandler) Get(ctx echo.Context) error

Get godoc

@Summary		Get a filter
@Description	Retrieves a single filter by its unique ID.
@Tags			Filters
@Produce		json
@Param			id	path		string	true	"Filter ID"
@Success		200	{object}	GenericDataResponse[FilterWithControlsResponse]
@Failure		400	{object}	api.Error
@Failure		404	{object}	api.Error
@Failure		500	{object}	api.Error
@Router			/filters/{id} [get]

func (*FilterHandler) List

func (h *FilterHandler) List(ctx echo.Context) error

List godoc

@Summary		List filters
@Description	Retrieves all filters.
@Tags			Filters
@Produce		json
@Success		200	{object}	GenericDataListResponse[FilterWithControlsResponse]
@Failure		500	{object}	api.Error
@Router			/filters [get]

func (*FilterHandler) Register

func (h *FilterHandler) Register(api *echo.Group)

Register registers the filter endpoints.

func (*FilterHandler) Update

func (h *FilterHandler) Update(ctx echo.Context) error

Update godoc

@Summary		Update a filter
@Description	Updates an existing filter.
@Tags			Filters
@Accept			json
@Produce		json
@Param			id		path		string				true	"Filter ID"
@Param			filter	body		createFilterRequest	true	"Filter to update"
@Success		200		{object}	GenericDataResponse[relational.Filter]
@Failure		400		{object}	api.Error
@Failure		404		{object}	api.Error
@Failure		500		{object}	api.Error
@Router			/filters/{id} [put]

type FilterWithControlsResponse

type FilterWithControlsResponse struct {
	relational.Filter
	Controls []oscalTypes_1_1_3.Control `json:"controls"`
}

type GenericDataListResponse

type GenericDataListResponse[T any] struct {
	// Items from the list response
	Data []T `json:"data" yaml:"data"`
}

type GenericDataResponse

type GenericDataResponse[T any] struct {
	// Items from the list response
	Data T `json:"data" yaml:"data"`
}

type HealthHandler added in v0.5.0

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

func NewHealthHandler added in v0.5.0

func NewHealthHandler(sugar *zap.SugaredLogger, db *gorm.DB) *HealthHandler

func (*HealthHandler) Health added in v0.5.0

func (h *HealthHandler) Health(ctx echo.Context) error

func (*HealthHandler) Ready added in v0.5.0

func (h *HealthHandler) Ready(ctx echo.Context) error

func (*HealthHandler) Register added in v0.5.0

func (h *HealthHandler) Register(api *echo.Group)

type HeartbeatCreateRequest

type HeartbeatCreateRequest struct {
	UUID      uuid.UUID `json:"uuid,omitempty" validate:"required"`
	CreatedAt time.Time `json:"created_at,omitempty" validate:"required"`
}

type HeartbeatHandler

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

func NewHeartbeatHandler

func NewHeartbeatHandler(sugar *zap.SugaredLogger, db *gorm.DB) *HeartbeatHandler

func (*HeartbeatHandler) Create

func (h *HeartbeatHandler) Create(ctx echo.Context) error

Create godoc

@Summary		Create Heartbeat
@Description	Creates a new heartbeat record for monitoring.
@Tags			Heartbeat
@Accept			json
@Produce		json
@Param			heartbeat	body	HeartbeatCreateRequest	true	"Heartbeat payload"
@Success		201			"Created"
@Failure		400			{object}	api.Error
@Failure		500			{object}	api.Error
@Router			/agent/heartbeat [post]

func (*HeartbeatHandler) OverTime

func (h *HeartbeatHandler) OverTime(ctx echo.Context) error

OverTime godoc

@Summary		Get Heartbeat Metrics Over Time
@Description	Retrieves heartbeat counts aggregated by 2-minute intervals.
@Tags			Heartbeat
@Produce		json
@Success		200	{object}	handler.GenericDataListResponse[handler.OverTime.HeartbeatInterval]
@Failure		500	{object}	api.Error
@Router			/agent/heartbeat/over-time [get]

func (*HeartbeatHandler) Register

func (h *HeartbeatHandler) Register(api *echo.Group)

type OscalLikeEvidence

type OscalLikeEvidence struct {
	relational.Evidence
	BackMatter     *oscalTypes_1_1_3.BackMatter         `json:"back-matter,omitempty"`
	Props          []oscalTypes_1_1_3.Property          `json:"props"`
	Links          []oscalTypes_1_1_3.Link              `json:"links"`
	Origins        []oscalTypes_1_1_3.Origin            `json:"origins,omitempty"`
	Activities     []oscalTypes_1_1_3.Activity          `json:"activities,omitempty"`
	InventoryItems []oscalTypes_1_1_3.InventoryItem     `json:"inventory-items,omitempty"`
	Components     []oscalTypes_1_1_3.SystemComponent   `json:"components,omitempty"`
	Subjects       []oscalTypes_1_1_3.AssessmentSubject `json:"subjects,omitempty"`
	Status         oscalTypes_1_1_3.ObjectiveStatus     `json:"status"`
}

func (*OscalLikeEvidence) FromEvidence

func (o *OscalLikeEvidence) FromEvidence(evidence *relational.Evidence) error

type PlanResponse

type PlanResponse struct {
	domain.Plan
}

type StatusCount

type StatusCount struct {
	Count  int64  `json:"count"`
	Status string `json:"status"`
}

type StatusInterval

type StatusInterval struct {
	Interval time.Time     `json:"interval"`
	Statuses []StatusCount `json:"statuses"`
}

type SubjectResponse

type SubjectResponse struct {
	domain.SubjectType
}

type UserHandler added in v0.4.2

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

func NewUserHandler added in v0.4.2

func NewUserHandler(sugar *zap.SugaredLogger, db *gorm.DB) *UserHandler

func (*UserHandler) ChangeLoggedInUserPassword added in v0.4.2

func (h *UserHandler) ChangeLoggedInUserPassword(ctx echo.Context) error

ChangeLoggedInUserPassword godoc

@Summary		Change password for logged-in user
@Description	Changes the password for the currently logged-in user
@Tags			Users
@Accept			json
@Produce		json
@Param			changePasswordRequest	body		handler.UserHandler.ChangeLoggedInUserPassword.changePasswordRequest	true	"Change Password Request"
@Success		204						{object}	nil
@Failure		400						{object}	api.Error
@Failure		401						{object}	api.Error
@Failure		500						{object}	api.Error
@Security		OAuth2Password
@Router			/users/me/change-password [post]

func (*UserHandler) ChangePassword added in v0.4.2

func (h *UserHandler) ChangePassword(ctx echo.Context) error

ChangePassword godoc

@Summary		Change password for a specific user
@Description	Changes the password for a user by ID
@Tags			Users
@Accept			json
@Produce		json
@Param			id						path		string														true	"User ID"
@Param			changePasswordRequest	body		handler.UserHandler.ChangePassword.changePasswordRequest	true	"Change Password Request"
@Success		204						{object}	nil
@Failure		400						{object}	api.Error
@Failure		401						{object}	api.Error
@Failure		404						{object}	api.Error
@Failure		500						{object}	api.Error
@Security		OAuth2Password
@Router			/users/{id}/change-password [post]

func (*UserHandler) CreateUser added in v0.4.2

func (h *UserHandler) CreateUser(ctx echo.Context) error

CreateUser godoc

@Summary		Create a new user
@Description	Creates a new user in the system
@Tags			Users
@Accept			json
@Produce		json
@Param			user	body		handler.UserHandler.CreateUser.createUserRequest	true	"User details"
@Success		201		{object}	handler.GenericDataResponse[relational.User]
@Failure		400		{object}	api.Error
@Failure		401		{object}	api.Error
@Failure		409		{object}	api.Error
@Failure		500		{object}	api.Error
@Security		OAuth2Password
@Router			/admin/users [post]

func (*UserHandler) DeleteUser added in v0.4.2

func (h *UserHandler) DeleteUser(ctx echo.Context) error

DeleteUser godoc

@Summary		Delete a user
@Description	Deletes a user from the system
@Tags			Users
@Param			id	path		string	true	"User ID"
@Success		204	{object}	nil
@Failure		400	{object}	api.Error
@Failure		401	{object}	api.Error
@Failure		404	{object}	api.Error
@Failure		500	{object}	api.Error
@Security		OAuth2Password
@Router			/admin/users/{id} [delete]

func (*UserHandler) GetMe added in v0.4.2

func (h *UserHandler) GetMe(ctx echo.Context) error

GetMe godoc

@Summary		Get logged-in user details
@Description	Retrieves the details of the currently logged-in user
@Tags			Users
@Produce		json
@Success		200	{object}	handler.GenericDataResponse[relational.User]
@Failure		401	{object}	api.Error
@Failure		404	{object}	api.Error
@Failure		500	{object}	api.Error
@Security		OAuth2Password
@Router			/users/me [get]

func (*UserHandler) GetUser added in v0.4.2

func (h *UserHandler) GetUser(ctx echo.Context) error

GetUser godoc

@Summary		Get user by ID
@Description	Get user details by user ID
@Tags			Users
@Produce		json
@Param			id	path		string	true	"User ID"
@Success		200	{object}	handler.GenericDataResponse[relational.User]
@Failure		400	{object}	api.Error
@Failure		401	{object}	api.Error
@Failure		404	{object}	api.Error
@Failure		500	{object}	api.Error
@Security		OAuth2Password
@Router			/admin/users/{id} [get]

func (*UserHandler) ListUsers added in v0.4.2

func (h *UserHandler) ListUsers(ctx echo.Context) error

ListUsers godoc

@Summary		List all users
@Description	Lists all users in the system
@Tags			Users
@Produce		json
@Success		200	{object}	handler.GenericDataListResponse[relational.User]
@Failure		401	{object}	api.Error
@Failure		500	{object}	api.Error
@Security		OAuth2Password
@Router			/admin/users [get]

func (*UserHandler) Register added in v0.4.2

func (h *UserHandler) Register(api *echo.Group)

func (*UserHandler) RegisterSelfRoutes added in v0.5.0

func (h *UserHandler) RegisterSelfRoutes(api *echo.Group)

func (*UserHandler) UpdateUser added in v0.4.2

func (h *UserHandler) UpdateUser(ctx echo.Context) error

UpdateUser godoc

@Summary		Update user details
@Description	Updates the details of an existing user
@Tags			Users
@Accept			json
@Produce		json
@Param			id		path		string												true	"User ID"
@Param			user	body		handler.UserHandler.UpdateUser.updateUserRequest	true	"User details"
@Success		200		{object}	handler.GenericDataResponse[relational.User]
@Failure		400		{object}	api.Error
@Failure		401		{object}	api.Error
@Failure		404		{object}	api.Error
@Failure		500		{object}	api.Error
@Security		OAuth2Password
@Router			/admin/users/{id} [put]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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