rest

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package rest implements the HTTP presentation layer for ScanVault. Controllers, routes, and request/response types all live here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(router *gin.Engine, h *ScanController, disableLocalSave bool, jsonPath string) *fuego.Engine

RegisterRoutes wires all HTTP routes and returns the fuego Engine (for OpenAPI generation).

Types

type AffectedImageDTO

type AffectedImageDTO struct {
	ImageName    string    `json:"image_name"`
	ImageTag     string    `json:"image_tag"`
	PkgName      string    `json:"pkg_name"`
	PkgVersion   string    `json:"pkg_version,omitempty"`
	FixedVersion string    `json:"fixed_version,omitempty"`
	ScannedAt    time.Time `json:"scanned_at"`
}

AffectedImageDTO is one image affected by a specific CVE.

type CVEAffectedImagesResponseDTO

type CVEAffectedImagesResponseDTO struct {
	CVEID  string             `json:"cve_id"`
	Count  int                `json:"count"`
	Images []AffectedImageDTO `json:"images"`
}

CVEAffectedImagesResponseDTO is the API response DTO for CVE affected images.

type FixableSummaryResponseDTO

type FixableSummaryResponseDTO struct {
	Image        string                    `json:"image,omitempty"`
	TotalVulns   int64                     `json:"total_vulns"`
	Fixable      int64                     `json:"fixable"`
	NotFixable   int64                     `json:"not_fixable"`
	FixablePct   float64                   `json:"fixable_pct"`
	FixableItems []FixableVulnerabilityDTO `json:"fixable_items"`
}

FixableSummaryResponseDTO is the API response DTO for fixable analytics.

type FixableVulnerabilityDTO

type FixableVulnerabilityDTO struct {
	CVEID        string `json:"cve_id"`
	PkgName      string `json:"pkg_name"`
	PkgVersion   string `json:"pkg_version,omitempty"`
	FixedVersion string `json:"fixed_version"`
	Severity     string `json:"severity"`
	Title        string `json:"title,omitempty"`
	ImageName    string `json:"image_name"`
	ImageTag     string `json:"image_tag"`
}

FixableVulnerabilityDTO is one vulnerability with a known fix.

type HealthResponse

type HealthResponse struct {
	Status string `json:"status"`
}

HealthResponse is the response envelope for health checks.

type ScanController

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

ScanController handles scan CRUD HTTP endpoints.

func NewScanController

func NewScanController(uc *usecases.ScanUseCases, logger zerolog.Logger) *ScanController

NewScanController creates a new ScanController.

func (*ScanController) CreateScan

func (h *ScanController) CreateScan(c *gin.Context)

CreateScan handles POST /scans.

func (*ScanController) GetCVEAffectedImages

func (h *ScanController) GetCVEAffectedImages(c *gin.Context)

GetCVEAffectedImages handles GET /analytics/vulnerabilities/cve/:cve_id/images.

func (*ScanController) GetFixableSummary

func (h *ScanController) GetFixableSummary(c *gin.Context)

GetFixableSummary handles GET /analytics/vulnerabilities/fixable.

func (*ScanController) GetLatestScan

func (h *ScanController) GetLatestScan(c *gin.Context)

GetLatestScan handles GET /scans/latest?image=<name>.

func (*ScanController) GetScanVulnerabilities

func (h *ScanController) GetScanVulnerabilities(c *gin.Context)

GetScanVulnerabilities handles GET /scans/:id/vulnerabilities.

func (*ScanController) GetTopCVEs

func (h *ScanController) GetTopCVEs(c *gin.Context)

GetTopCVEs handles GET /analytics/vulnerabilities/top-cves.

func (*ScanController) GetVulnerabilitySummary

func (h *ScanController) GetVulnerabilitySummary(c *gin.Context)

GetVulnerabilitySummary handles GET /analytics/vulnerabilities/summary.

func (*ScanController) GetVulnerabilityTrends

func (h *ScanController) GetVulnerabilityTrends(c *gin.Context)

GetVulnerabilityTrends handles GET /analytics/vulnerabilities/trends.

func (*ScanController) HealthCheck

func (h *ScanController) HealthCheck(c *gin.Context)

HealthCheck handles GET /health.

func (*ScanController) ListAllScans

func (h *ScanController) ListAllScans(c *gin.Context)

ListAllScans handles GET /scans/all.

func (*ScanController) ListScans

func (h *ScanController) ListScans(c *gin.Context)

ListScans handles GET /scans?tag=<tag> or GET /scans?image=<name>[&severity=<level>].

type ScanResponseDTO

type ScanResponseDTO struct {
	ID           string         `json:"id"`
	ImageName    string         `json:"image_name"`
	ImageTag     string         `json:"image_tag"`
	ImageDigest  string         `json:"image_digest"`
	ScanResult   TrivyReportDTO `json:"scan_result"`
	CreatedAt    time.Time      `json:"created_at"`
	VulnCritical int            `json:"vuln_critical"`
	VulnHigh     int            `json:"vuln_high"`
	VulnMedium   int            `json:"vuln_medium"`
	VulnLow      int            `json:"vuln_low"`
	VulnUnknown  int            `json:"vuln_unknown"`
}

ScanResponseDTO is the API response DTO for one scan.

type ScanVulnerabilitiesResponseDTO

type ScanVulnerabilitiesResponseDTO struct {
	ScanID    string                     `json:"scan_id"`
	ImageName string                     `json:"image_name"`
	ImageTag  string                     `json:"image_tag"`
	Severity  string                     `json:"severity,omitempty"`
	Pkg       string                     `json:"pkg,omitempty"`
	Count     int                        `json:"count"`
	Items     []ScanVulnerabilityItemDTO `json:"items"`
}

ScanVulnerabilitiesResponseDTO is the API response DTO for GET /scans/:id/vulnerabilities.

type ScanVulnerabilityItemDTO

type ScanVulnerabilityItemDTO struct {
	Target        string                `json:"target"`
	Class         string                `json:"class,omitempty"`
	Type          string                `json:"type,omitempty"`
	Vulnerability TrivyVulnerabilityDTO `json:"vulnerability"`
}

ScanVulnerabilityItemDTO is one vulnerability item in a scan vulnerability response.

type ScansListResponseDTO

type ScansListResponseDTO struct {
	Image    string            `json:"image,omitempty"`
	Tag      string            `json:"tag,omitempty"`
	Severity string            `json:"severity,omitempty"`
	Count    int               `json:"count"`
	Limit    int               `json:"limit,omitempty"`
	Offset   int               `json:"offset,omitempty"`
	Items    []ScanResponseDTO `json:"items"`
}

ScansListResponseDTO is the API response DTO for scan lists.

type Server

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

Server wraps the HTTP server and its dependencies.

func NewServer

func NewServer(c *infra.Container) *Server

NewServer builds the gin router, wires controllers, and returns a ready Server.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start begins serving HTTP and starts the cleanup worker (if enabled). It blocks until ctx is cancelled, then performs a graceful shutdown.

type SeverityCountDTO

type SeverityCountDTO struct {
	Severity string `json:"severity"`
	Count    int64  `json:"count"`
}

SeverityCountDTO is one aggregate severity bucket for analytics.

type TopCVEDTO

type TopCVEDTO struct {
	CVEID      string `json:"cve_id"`
	Severity   string `json:"severity"`
	Title      string `json:"title,omitempty"`
	ImageCount int64  `json:"image_count"`
	Fixable    bool   `json:"fixable"`
}

TopCVEDTO is a CVE aggregated across latest scans.

type TopCVEsResponseDTO

type TopCVEsResponseDTO struct {
	Image    string      `json:"image,omitempty"`
	Severity string      `json:"severity,omitempty"`
	Limit    int         `json:"limit"`
	From     *time.Time  `json:"from,omitempty"`
	To       *time.Time  `json:"to,omitempty"`
	Count    int         `json:"count"`
	CVEs     []TopCVEDTO `json:"cves"`
}

TopCVEsResponseDTO is the API response DTO for top CVE analytics.

type TrivyMetadataDTO

type TrivyMetadataDTO struct {
	ImageID     string   `json:"ImageID,omitempty"`
	RepoTags    []string `json:"RepoTags,omitempty"`
	RepoDigests []string `json:"RepoDigests,omitempty"`
}

TrivyMetadataDTO represents image metadata included by Trivy.

type TrivyReportDTO

type TrivyReportDTO struct {
	ArtifactName string           `json:"ArtifactName,omitempty"`
	ArtifactType string           `json:"ArtifactType,omitempty"`
	Metadata     TrivyMetadataDTO `json:"Metadata,omitempty"`
	Results      []TrivyResultDTO `json:"Results,omitempty"`
}

TrivyReportDTO represents the request payload accepted by POST /scans.

type TrivyResultDTO

type TrivyResultDTO struct {
	Target          string                  `json:"Target,omitempty"`
	Class           string                  `json:"Class,omitempty"`
	Type            string                  `json:"Type,omitempty"`
	Vulnerabilities []TrivyVulnerabilityDTO `json:"Vulnerabilities,omitempty"`
}

TrivyResultDTO represents one Trivy result section.

type TrivyVulnerabilityDTO

type TrivyVulnerabilityDTO struct {
	VulnerabilityID string `json:"VulnerabilityID"`
	PkgName         string `json:"PkgName"`
	PkgVersion      string `json:"PkgVersion,omitempty"`
	FixedVersion    string `json:"FixedVersion,omitempty"`
	Severity        string `json:"Severity"`
	Title           string `json:"Title,omitempty"`
}

TrivyVulnerabilityDTO represents one vulnerability item in a Trivy report.

type VulnerabilitySummaryResponseDTO

type VulnerabilitySummaryResponseDTO struct {
	Image                string             `json:"image,omitempty"`
	From                 *time.Time         `json:"from,omitempty"`
	To                   *time.Time         `json:"to,omitempty"`
	TotalScans           int64              `json:"total_scans"`
	TotalVulnerabilities int64              `json:"total_vulnerabilities"`
	SeverityCounts       []SeverityCountDTO `json:"severity_counts"`
	TopCVEs              []TopCVEDTO        `json:"top_cves,omitempty"`
}

VulnerabilitySummaryResponseDTO is the API response DTO for summary analytics.

type VulnerabilityTrendPointDTO

type VulnerabilityTrendPointDTO struct {
	Bucket   time.Time `json:"bucket"`
	Severity string    `json:"severity"`
	Count    int64     `json:"count"`
}

VulnerabilityTrendPointDTO is one bucketed vulnerability count.

type VulnerabilityTrendsResponseDTO

type VulnerabilityTrendsResponseDTO struct {
	Image    string                       `json:"image,omitempty"`
	Interval string                       `json:"interval"`
	From     *time.Time                   `json:"from,omitempty"`
	To       *time.Time                   `json:"to,omitempty"`
	Count    int                          `json:"count"`
	Points   []VulnerabilityTrendPointDTO `json:"points"`
}

VulnerabilityTrendsResponseDTO is the API response DTO for trends analytics.

Jump to

Keyboard shortcuts

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