presenters

package
v0.0.0-...-6a59c2e Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SnykDocsURL is the base URL for Snyk's documentation.
	SnykDocsURL = "https://docs.snyk.io"
	// SnykDocsErrorCatalogPath is the path to the error catalog on Snyk's documentation website.
	SnykDocsErrorCatalogPath = "/scan-with-snyk/error-catalog"
)
View Source
const ApplicationJSONMimeType = "application/json"

ApplicationJSONMimeType is the mime type for application/json.

View Source
const ConfigJSONStripWhitespaces = "internal_json_no_whitespaces"

ConfigJSONStripWhitespaces is the configuration key to strip whitespaces from JSON output.

View Source
const DefaultMimeType = "text/cli"

DefaultMimeType is the default mime type for the presenter.

View Source
const NoneMimeType = "unknown"

NoneMimeType is the mime type for when no mime type is specified.

Variables

View Source
var DefaultTemplateFiles = []string{
	"templates/unified_finding.tmpl",
	"templates/finding.component.tmpl",
}

DefaultTemplateFiles is an instance of TemplatePathsStruct with the template paths.

Functions

func FilterSeverityASC

func FilterSeverityASC(original []string, severityMinLevel string) []string

FilterSeverityASC filters a slice of severities based on a minimum level.

func HTMLToAnsi

func HTMLToAnsi(_, cssClass, originalContent string) string

HTMLToAnsi converts HTML content to ANSI formatted text.

func IsHTML

func IsHTML(str string) bool

IsHTML checks if a string contains HTML content.

func NewJSONWriter

func NewJSONWriter(next io.Writer, stripWhitespaces bool) io.Writer

NewJSONWriter creates a new JSON writer that can optionally strip whitespaces.

func RenderDivider

func RenderDivider() string

RenderDivider renders a horizontal line.

func RenderError

func RenderError(ctx context.Context, err *snyk_errors.Error) string

RenderError renders a snyk_errors.Error to a string.

func RenderLink(str string) string

RenderLink renders a string as a hyperlink.

func RenderTip

func RenderTip(str string) string

RenderTip renders a string as a tip.

func RenderTitle

func RenderTitle(str string) string

RenderTitle renders a string as a title.

Types

type ElementCallback

type ElementCallback func(tagName, cssClass, originalContent string) string

ElementCallback is a function that can be used to transform an HTML element.

type HTMLpresenter

type HTMLpresenter struct {
	Callback ElementCallback
}

HTMLpresenter is a presenter that can convert HTML to plain text.

func NewHTMLPresenter

func NewHTMLPresenter(callback ElementCallback) *HTMLpresenter

NewHTMLPresenter creates a new HTML presenter with the given callback.

func (*HTMLpresenter) Present

func (p *HTMLpresenter) Present(htmlString string) (string, error)

Present processes HTML content and returns plain text.

type JSONWriter

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

JSONWriter is a writer that can optionally strip whitespaces from JSON output.

func (*JSONWriter) Write

func (w *JSONWriter) Write(p []byte) (n int, err error)

type SummaryPayload

type SummaryPayload struct {
	Summary              *json_schemas.TestSummary `json:"summary"`
	DependencyCount      int                       `json:"dependencyCount"`
	PackageManager       string                    `json:"packageManager"`
	ProjectName          string                    `json:"projectName"`
	DisplayTargetFile    string                    `json:"displayTargetFile"`
	UniqueCount          int32                     `json:"uniqueCount"`
	VulnerablePathsCount int                       `json:"vulnerablePathsCount"`
}

SummaryPayload is a wrapper for the test summary and additional metadata needed for the unified output.

type TemplateImplFunction

type TemplateImplFunction func() (*template.Template, template.FuncMap, error)

TemplateImplFunction is a function that returns a template, a function map, and an error.

type UnifiedFindingPresenter

type UnifiedFindingPresenter struct {
	Input []*UnifiedProjectResult
	// contains filtered or unexported fields
}

UnifiedFindingPresenter is responsible for rendering unified findings data.

func NewUnifiedFindingsRenderer

func NewUnifiedFindingsRenderer(
	unifiedFindingsDoc []*UnifiedProjectResult,
	config configuration.Configuration,
	writer io.Writer,
	options ...UnifiedFindingPresenterOptions,
) *UnifiedFindingPresenter

NewUnifiedFindingsRenderer creates a new presenter for unified findings. Note: This new renderer works directly with the testapi.FindingData model. The templates used will need to be compatible with this data structure.

func (*UnifiedFindingPresenter) RenderTemplate

func (p *UnifiedFindingPresenter) RenderTemplate(templateFiles []string, mimeType string) error

RenderTemplate renders the template with the given files and MIME type.

type UnifiedFindingPresenterOptions

type UnifiedFindingPresenterOptions func(presentation *UnifiedFindingPresenter)

UnifiedFindingPresenterOptions configures the UnifiedFindingPresenter.

func WithUnifiedRuntimeInfo

func WithUnifiedRuntimeInfo(ri runtimeinfo.RuntimeInfo) UnifiedFindingPresenterOptions

WithUnifiedRuntimeInfo adds runtime information to the presenter.

type UnifiedProjectResult

type UnifiedProjectResult struct {
	Findings             []testapi.FindingData
	Summary              *json_schemas.TestSummary
	DependencyCount      int
	PackageManager       string
	ProjectName          string
	DisplayTargetFile    string
	UniqueCount          int
	VulnerablePathsCount int
}

UnifiedProjectResult holds the findings and summary for a single project from the unified flow.

Jump to

Keyboard shortcuts

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