Lei.OCI.Annotations (LowEndInsight v0.9.1)

Copy Markdown View Source

Generates OCI image annotations from LowEndInsight analysis reports.

Annotations follow the dev.lowendinsight.* namespace using OCI annotation conventions (reverse-DNS prefix, hyphenated keys, string values).

See docs/OCI_ANNOTATION_SCHEMA.md for the full schema specification.

Summary

Functions

Generates a map of OCI annotation key-value pairs from a single-repo LEI report.

Generates OCI annotations directly from a results map, repo URL, and timestamp.

Returns annotations as a list of --annotation key=value CLI flag strings, suitable for passing to docker buildx build or oras push.

Encodes annotations as a JSON string suitable for --annotation-file flags in OCI tooling (crane, oras, docker buildx).

Functions

from_report(report)

@spec from_report(map()) :: {:ok, map()} | {:error, String.t()}

Generates a map of OCI annotation key-value pairs from a single-repo LEI report.

Returns {:ok, map} where all keys are dev.lowendinsight.* strings and all values are strings (per OCI spec). Returns {:error, reason} for unsupported formats.

Examples

iex> report = %{header: %{start_time: "2024-01-01T00:00:00Z"}, data: %{repo: "https://github.com/org/repo", results: %{risk: "critical", contributor_count: 1}}}
iex> {:ok, annotations} = Lei.OCI.Annotations.from_report(report)
iex> annotations["dev.lowendinsight.risk"]
"critical"

from_results(results, repo_url, analyzed_at)

@spec from_results(map(), String.t(), String.t()) :: {:ok, map()}

Generates OCI annotations directly from a results map, repo URL, and timestamp.

Useful when you already have extracted analysis results and don't need to parse a full report structure.

to_cli_flags(annotations)

@spec to_cli_flags(map()) :: [String.t()]

Returns annotations as a list of --annotation key=value CLI flag strings, suitable for passing to docker buildx build or oras push.

to_json(annotations)

@spec to_json(map()) :: {:ok, String.t()}

Encodes annotations as a JSON string suitable for --annotation-file flags in OCI tooling (crane, oras, docker buildx).