render

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	UPDATED = iota
	ADDED
	REMOVED
)

Variables

View Source
var (

	// Technically Github allows 66536 characters, which we interpreted as 262144 bytes, but
	// we were still seeing 422 "Body is too long (maximum is 65536 characters)" errors so limit
	// more.
	GitHubMaxMessageSize = 200000 // bytes

	// Azure supports 150000 characters, which for ASCII is 150000 bytes, lets err on the side of caution and
	// limit to 140000 bytes.
	AzureReposMaxMessageSize = 140000 // bytes
)

Functions

func FormatCost2DP

func FormatCost2DP(currency string, d *decimal.Decimal) string

func FormatOutput

func FormatOutput(format string, r Report, opts Options) ([]byte, error)

FormatOutput returns Root r as the format specified. The default format is a table output.

func LoadCommentData

func LoadCommentData(path string) (string, error)

LoadCommentData reads the file at the path into a string.

func ToDiff

func ToDiff(out Report, opts Options) ([]byte, error)

func ToHTML

func ToHTML(out Report, opts Options) ([]byte, error)

func ToJSON

func ToJSON(out Report, opts Options) ([]byte, error)

func ToSlackMessage

func ToSlackMessage(out Report, opts Options) ([]byte, error)

func ToTable

func ToTable(out Report, opts Options) ([]byte, error)

Types

type ActualCosts

type ActualCosts struct {
	ResourceID     string          `json:"resourceId"`
	StartTimestamp time.Time       `json:"startTimestamp"`
	EndTimestamp   time.Time       `json:"endTimestamp"`
	CostComponents []CostComponent `json:"costComponents,omitempty"`
}

type Breakdown

type Breakdown struct {
	Resources             []Resource       `json:"resources"`
	FreeResources         []Resource       `json:"freeResources,omitempty"`
	TotalHourlyCost       *decimal.Decimal `json:"totalHourlyCost"`
	TotalMonthlyCost      *decimal.Decimal `json:"totalMonthlyCost"`
	TotalMonthlyUsageCost *decimal.Decimal `json:"totalMonthlyUsageCost"`
}

func (*Breakdown) HasResources

func (b *Breakdown) HasResources() bool

HasResources returns true if the breakdown has any resources or free resources. This is used to determine if the breakdown should be shown in the output.

func (*Breakdown) TotalMonthlyBaselineCost

func (b *Breakdown) TotalMonthlyBaselineCost() *decimal.Decimal

type CostComponent

type CostComponent struct {
	Name            string           `json:"name"`
	Unit            string           `json:"unit"`
	HourlyQuantity  *decimal.Decimal `json:"hourlyQuantity"`
	MonthlyQuantity *decimal.Decimal `json:"monthlyQuantity"`
	Price           decimal.Decimal  `json:"price"`
	HourlyCost      *decimal.Decimal `json:"hourlyCost"`
	MonthlyCost     *decimal.Decimal `json:"monthlyCost"`
	UsageBased      bool             `json:"usageBased,omitempty"`
	PriceNotFound   bool             `json:"priceNotFound"`
}

type GovernanceFailures

type GovernanceFailures []string

GovernanceFailures defines a list of governance failures that were returned from c3x cloud.

func (GovernanceFailures) Error

func (g GovernanceFailures) Error() string

Error implements the Error interface returning the failures as a single message that can be used in stderr.

type MarkdownCtx

type MarkdownCtx struct {
	Root                         Report
	SkippedProjectCount          int
	ErroredProjectCount          int
	SkippedUnchangedProjectCount int
	DiffOutput                   string
	Options                      Options
	MarkdownOptions              MarkdownOptions
	RunQuotaMsg                  string
	UsageCostsMsg                string
	CostDetailsMsg               string
}

MarkdownCtx holds information that can be used and executed with a go template.

type MarkdownOptions

type MarkdownOptions struct {
	WillUpdate          bool
	WillReplace         bool
	IncludeFeedbackLink bool
	OmitDetails         bool
	BasicSyntax         bool
	MaxMessageSize      int
	Additional          string
}

type MarkdownOutput

type MarkdownOutput struct {
	Msg             []byte
	RuneLen         int
	OriginalMsgSize int
}

MarkdownOutput holds the message converted to markdown with additional information about its length.

func ToMarkdown

func ToMarkdown(out Report, opts Options, markdownOpts MarkdownOptions) (MarkdownOutput, error)

type Metadata

type Metadata struct {
	C3XCommand string `json:"c3xCommand"`

	Branch            string    `json:"vcsBranch"`
	BaseCommitSHA     string    `json:"vcsBaseCommitSha,omitempty"`
	CommitSHA         string    `json:"vcsCommitSha"`
	CommitAuthorName  string    `json:"vcsCommitAuthorName"`
	CommitAuthorEmail string    `json:"vcsCommitAuthorEmail"`
	CommitTimestamp   time.Time `json:"vcsCommitTimestamp"`
	CommitMessage     string    `json:"vcsCommitMessage"`

	VCSRepositoryURL     string   `json:"vcsRepositoryUrl,omitempty"`
	VCSProvider          string   `json:"vcsProvider,omitempty"`
	VCSBaseBranch        string   `json:"vcsBaseBranch,omitempty"`
	VCSPullRequestTitle  string   `json:"vcsPullRequestTitle,omitempty"`
	VCSPullRequestURL    string   `json:"vcsPullRequestUrl,omitempty"`
	VCSPullRequestAuthor string   `json:"vcsPullRequestAuthor,omitempty"`
	VCSPullRequestLabels []string `json:"vcsPullRequestLabels,omitempty"`
	VCSPipelineRunID     string   `json:"vcsPipelineRunId,omitempty"`
	VCSPullRequestID     string   `json:"vcsPullRequestId,omitempty"`

	UsageApiEnabled        bool   `json:"usageApiEnabled,omitempty"`
	UsageFilePath          string `json:"usageFilePath,omitempty"`
	ConfigFilePath         string `json:"configFilePath,omitempty"`
	ConfigFileHasUsageFile bool   `json:"configFileHasUsageFile,omitempty"`
}

Metadata holds common information used to identify the system that C3X is run within.

func NewMetadata

func NewMetadata(ctx *settings.Session) Metadata

NewMetadata returns a Metadata struct filled with information built from the RunContext.

type Options

type Options struct {
	DashboardEndpoint string
	NoColor           bool
	ShowSkipped       bool
	ShowAllProjects   bool
	ShowOnlyChanges   bool
	Fields            []string
	IncludeHTML       bool
	PolicyOutput      PolicyOutput

	CurrencyFormat string
	// contains filtered or unexported fields
}

type PolicyCheck

type PolicyCheck struct {
	Enabled  bool
	Failures PolicyCheckFailures
	Passed   []string
}

PolicyCheck holds information if a given run has any policy checks enabled. This struct is used in templates to create useful cost policy outputs.

func (PolicyCheck) HasFailed

func (p PolicyCheck) HasFailed() bool

HasFailed returns if the PolicyCheck has any cost policy failures

type PolicyCheckFailures

type PolicyCheckFailures []string

PolicyCheckFailures defines a list of policy check failures that can be collected from a policy evaluation.

func (PolicyCheckFailures) Error

func (p PolicyCheckFailures) Error() string

Error implements the Error interface returning the failures as a single message that can be used in stderr.

type PolicyCheckOutput

type PolicyCheckOutput struct {
	Name            string
	Failure         bool
	Warning         bool
	Message         string
	Details         []string
	ResourceDetails []PolicyCheckResourceDetails
	TruncatedCount  int
}

type PolicyCheckResourceDetails

type PolicyCheckResourceDetails struct {
	Address      string
	ResourceType string
	Path         string
	Line         int
	Violations   []PolicyCheckViolations
}

type PolicyCheckViolations

type PolicyCheckViolations struct {
	Details      []string
	ProjectNames []string
}

type PolicyOutput

type PolicyOutput struct {
	HasFailures bool
	HasWarnings bool
	Checks      []PolicyCheckOutput
}

PolicyOutput holds normalized PolicyCheck and TagPolicyCheck data so it can be output in a uniform "Policies" section of the c3x comment.

func NewPolicyOutput

func NewPolicyOutput(pc PolicyCheck) PolicyOutput

NewPolicyOutput normalizes a PolicyCheck suitable for use in the output markdown template.

type Project

type Project struct {
	Name          string                `json:"name"`
	DisplayName   string                `json:"displayName"`
	Metadata      *engine.WorkspaceMeta `json:"metadata"`
	PastBreakdown *Breakdown            `json:"pastBreakdown"`
	Breakdown     *Breakdown            `json:"breakdown"`
	Diff          *Breakdown            `json:"diff"`
	Summary       *Summary              `json:"summary"`
	// contains filtered or unexported fields
}

func (*Project) Label

func (p *Project) Label() string

Label returns the display name of the project

func (*Project) LabelWithMetadata

func (p *Project) LabelWithMetadata() string

LabelWithMetadata returns the display name of the project appended with any distinguishing metadata (Module path or Workspace)

func (*Project) ToSchemaProject

func (p *Project) ToSchemaProject() *engine.Workspace

ToSchemaProject generates a engine.Workspace from a Project. The created engine.Workspace is not suitable to be used outside simple engine.Workspace to engine.Workspace comparisons. It contains missing information that cannot be inferred from a Project.

type Projects

type Projects []Project

func (Projects) IsRunQuotaExceeded

func (projects Projects) IsRunQuotaExceeded() (string, bool)

IsRunQuotaExceeded checks if any of the project metadata have errored with a "run quota exceeded" error. If found it returns the associated message with this diag. This should be used when in any output that notifies the user.

type Report

type Report struct {
	Version                   string           `json:"version"`
	Metadata                  Metadata         `json:"metadata"`
	RunID                     string           `json:"runId,omitempty"`
	ShareURL                  string           `json:"shareUrl,omitempty"`
	CloudURL                  string           `json:"cloudUrl,omitempty"`
	Currency                  string           `json:"currency"`
	Projects                  Projects         `json:"projects"`
	TotalHourlyCost           *decimal.Decimal `json:"totalHourlyCost"`
	TotalMonthlyCost          *decimal.Decimal `json:"totalMonthlyCost"`
	TotalMonthlyUsageCost     *decimal.Decimal `json:"totalMonthlyUsageCost,omitempty"`
	PastTotalHourlyCost       *decimal.Decimal `json:"pastTotalHourlyCost"`
	PastTotalMonthlyCost      *decimal.Decimal `json:"pastTotalMonthlyCost"`
	PastTotalMonthlyUsageCost *decimal.Decimal `json:"pastTotalMonthlyUsageCost,omitempty"`
	DiffTotalHourlyCost       *decimal.Decimal `json:"diffTotalHourlyCost"`
	DiffTotalMonthlyCost      *decimal.Decimal `json:"diffTotalMonthlyCost"`
	DiffTotalMonthlyUsageCost *decimal.Decimal `json:"diffTotalMonthlyUsageCost,omitempty"`
	TimeGenerated             time.Time        `json:"timeGenerated"`
	Summary                   *Summary         `json:"summary"`
	FullSummary               *Summary         `json:"-"`
	IsCIRun                   bool             `json:"-"`
}

func Combine

func Combine(inputs []ReportInput) (Report, error)

func CompareTo

func CompareTo(c *settings.Settings, current, prior Report) (Report, error)

CompareTo generates an output Root using another Root as the base snapshot. Each project in current Root will have all past resources overwritten with the matching projects in the prior Root. If we can't find a matching project then we assume that the project has been newly created and will show a 100% increase in the output Root.

func Load

func Load(p string) (Report, error)

Load reads the file at the location p and the file body into a Root struct. Load naively validates that the C3X JSON body is valid by checking the that the version attribute is within a supported range.

func ToOutputFormat

func ToOutputFormat(c *settings.Settings, projects []*engine.Workspace) (Report, error)

func (*Report) ExampleProjectName

func (r *Report) ExampleProjectName() string

func (*Report) HasDiff

func (r *Report) HasDiff() bool

HasDiff returns true if any project has a difference in monthly cost or resources

func (*Report) HasUnsupportedResources

func (r *Report) HasUnsupportedResources() bool

HasUnsupportedResources returns if the summary has any unsupported resources. This is used to determine if the summary should be shown in different output formats.

type ReportInput

type ReportInput struct {
	Metadata map[string]string
	Root     Report
}

func LoadPaths

func LoadPaths(paths []string) ([]ReportInput, error)

type Resource

type Resource struct {
	Name                                    string                 `json:"name"`
	ResourceType                            string                 `json:"resourceType,omitempty"`
	Tags                                    *map[string]string     `json:"tags,omitempty"`
	DefaultTags                             *map[string]string     `json:"defaultTags,omitempty"`
	TagPropagation                          *TagPropagation        `json:"tagPropagation,omitempty"`
	ProviderSupportsDefaultTags             bool                   `json:"providerSupportsDefaultTags,omitempty"`
	ProviderLink                            string                 `json:"providerLink,omitempty"`
	Metadata                                map[string]interface{} `json:"metadata"`
	HourlyCost                              *decimal.Decimal       `json:"hourlyCost,omitempty"`
	MonthlyCost                             *decimal.Decimal       `json:"monthlyCost,omitempty"`
	MonthlyUsageCost                        *decimal.Decimal       `json:"monthlyUsageCost,omitempty"`
	CostComponents                          []CostComponent        `json:"costComponents,omitempty"`
	ActualCosts                             []ActualCosts          `json:"actualCosts,omitempty"`
	SubResources                            []Resource             `json:"subresources,omitempty"`
	MissingVarsCausingUnknownTagKeys        []string               `json:"missingVarsCausingUnknownTagKeys,omitempty"`
	MissingVarsCausingUnknownDefaultTagKeys []string               `json:"missingVarsCausingUnknownDefaultTagKeys,omitempty"`
}

type Summary

type Summary struct {
	TotalResources            *int `json:"totalResources,omitempty"`
	TotalDetectedResources    *int `json:"totalDetectedResources,omitempty"`
	TotalSupportedResources   *int `json:"totalSupportedResources,omitempty"`
	TotalUnsupportedResources *int `json:"totalUnsupportedResources,omitempty"`
	TotalUsageBasedResources  *int `json:"totalUsageBasedResources,omitempty"`
	TotalNoPriceResources     *int `json:"totalNoPriceResources,omitempty"`

	SupportedResourceCounts   *map[string]int `json:"supportedResourceCounts,omitempty"`
	UnsupportedResourceCounts *map[string]int `json:"unsupportedResourceCounts,omitempty"`
	NoPriceResourceCounts     *map[string]int `json:"noPriceResourceCounts,omitempty"`

	EstimatedUsageCounts   *map[string]int `json:"-"`
	UnestimatedUsageCounts *map[string]int `json:"-"`
	TotalEstimatedUsages   *int            `json:"-"`
	TotalUnestimatedUsages *int            `json:"-"`
}

func BuildSummary

func BuildSummary(resources []*engine.Estimate, opts SummaryOptions) (*Summary, error)

func MergeSummaries

func MergeSummaries(summaries []*Summary) *Summary

type SummaryOptions

type SummaryOptions struct {
	IncludeUnsupportedProviders bool
	OnlyFields                  []string
}

type TagPropagation

type TagPropagation struct {
	To                    string             `json:"to"`
	From                  *string            `json:"from,omitempty"`
	Tags                  *map[string]string `json:"tags,omitempty"`
	Attribute             string             `json:"attribute"`
	HasRequiredAttributes bool               `json:"hasRequiredAttributes,omitempty"`
}

Jump to

Keyboard shortcuts

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