apiclient

package
v0.10.35 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorCodeExceededQuota = "above_quota"
	ErrorCodeAPIKeyInvalid = "invalid_api_key"
)

Functions

func ReportCLIError

func ReportCLIError(ctx *config.RunContext, cliErr error, replacePath bool) error

Types

type APIClient

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

func (*APIClient) AddAuthHeaders

func (c *APIClient) AddAuthHeaders(req *http.Request)

func (*APIClient) AddDefaultHeaders

func (c *APIClient) AddDefaultHeaders(req *http.Request)

func (*APIClient) DoQueries added in v0.10.34

func (c *APIClient) DoQueries(queries []GraphQLQuery) ([]gjson.Result, error)

type APIError

type APIError struct {

	// Msg defines a human-readable string that is safe to show to the user
	// to give more context about an error.
	Msg string
	// Code is the original StatusCode of the error.
	Code int
	// ErrorCode is the internal error code that can accompany errors from different status codes.
	ErrorCode string
	// contains filtered or unexported fields
}

APIError defines an api error that is designed to be showed to the user in a output form (comment/stdout/html).

func (*APIError) Error

func (e *APIError) Error() string

type APIErrorResponse

type APIErrorResponse struct {
	Error     string `json:"error"`
	ErrorCode string `json:"error_code"`
}

type ActualCostComponent added in v0.10.12

type ActualCostComponent struct {
	UsageType       string
	Description     string
	MonthlyCost     string
	MonthlyQuantity string
	Price           string
	Unit            string
	Currency        string
}

ActualCostComponent represents an individual line item of actual costs for a resource

type ActualCostsQueryVariables added in v0.10.12

type ActualCostsQueryVariables struct {
	RepoURL              string `json:"repoUrl"`
	ProjectWithWorkspace string `json:"project"`
	Address              string `json:"address"`
	Currency             string `json:"currency"`
}

type ActualCostsResult added in v0.10.12

type ActualCostsResult struct {
	Address        string
	ResourceID     string
	StartTimestamp time.Time
	EndTimestamp   time.Time
	CostComponents []ActualCostComponent
}

ActualCostsResult contains the cost information of actual costs retrieved from the Infracost Cloud Usage API

type AddRunResponse added in v0.9.16

type AddRunResponse struct {
	RunID              string                    `json:"id"`
	ShareURL           string                    `json:"shareUrl"`
	CloudURL           string                    `json:"cloudUrl"`
	PullRequestURL     string                    `json:"pullRequestUrl"`
	GovernanceFailures output.GovernanceFailures `json:"governanceFailures"`
	GovernanceComment  string                    `json:"governanceComment"`
	GovernanceResults  []GovernanceResult        `json:"governanceResults"`
}

type AuthClient added in v0.10.3

type AuthClient struct {
	Host string
}

AuthClient represents a client for Infracost's authentication process.

func (AuthClient) Login added in v0.10.3

func (a AuthClient) Login(contextVals map[string]interface{}) (string, string, error)

Login opens a browser with authentication URL and starts a HTTP server to wait for a callback request.

type BatchRequest added in v0.10.25

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

type CloudResourceIDVariables added in v0.10.13

type CloudResourceIDVariables struct {
	RepoURL              string              `json:"repoUrl"`
	ProjectWithWorkspace string              `json:"project"`
	ResourceIDAddresses  []ResourceIDAddress `json:"addressResourceIds"`
}

type CommentFormat added in v0.10.30

type CommentFormat string
var (
	CommentFormatMarkdownHTML CommentFormat = "MARKDOWN_HTML"
	CommentFormatMarkdown     CommentFormat = "MARKDOWN"
)

type CreateAPIKeyResponse

type CreateAPIKeyResponse struct {
	APIKey string `json:"apiKey"`
	Error  string `json:"error"`
}

type DashboardAPIClient

type DashboardAPIClient struct {
	APIClient
}

func NewDashboardAPIClient

func NewDashboardAPIClient(ctx *config.RunContext) *DashboardAPIClient

func (*DashboardAPIClient) AddRun

func (c *DashboardAPIClient) AddRun(ctx *config.RunContext, out output.Root, commentFormat CommentFormat) (AddRunResponse, error)

func (*DashboardAPIClient) QueryCLISettings added in v0.10.7

func (c *DashboardAPIClient) QueryCLISettings() (QueryCLISettingsResponse, error)

type GovernanceResult added in v0.10.30

type GovernanceResult struct {
	Type      string   `json:"govType"`
	Checked   int64    `json:"checked"`
	Warnings  []string `json:"warnings"`
	Failures  []string `json:"failures"`
	Unblocked []string `json:"unblocked"`
}

type GraphQLQuery

type GraphQLQuery struct {
	Query     string                 `json:"query"`
	Variables map[string]interface{} `json:"variables"`
}

type LeveledLogger added in v0.10.17

type LeveledLogger struct {
	Logger zerolog.Logger
}

LeveledLogger is a wrapper around logrus.Entry that implements the retryablehttp.LeveledLogger interface.

func (*LeveledLogger) Debug added in v0.10.17

func (l *LeveledLogger) Debug(msg string, keysAndValues ...interface{})

func (*LeveledLogger) Error added in v0.10.17

func (l *LeveledLogger) Error(msg string, keysAndValues ...interface{})

func (*LeveledLogger) Info added in v0.10.17

func (l *LeveledLogger) Info(msg string, keysAndValues ...interface{})

func (*LeveledLogger) Warn added in v0.10.17

func (l *LeveledLogger) Warn(msg string, keysAndValues ...interface{})

type PolicyAPIClient added in v0.10.30

type PolicyAPIClient struct {
	APIClient
	// contains filtered or unexported fields
}

func NewPolicyAPIClient added in v0.10.30

func NewPolicyAPIClient(ctx *config.RunContext) (*PolicyAPIClient, error)

NewPolicyAPIClient retrieves resource allow-list info from Infracost Cloud and returns a new policy client

func (*PolicyAPIClient) UploadPolicyData added in v0.10.30

func (c *PolicyAPIClient) UploadPolicyData(project *schema.Project, rds, pastRds []*schema.ResourceData) error

UploadPolicyData sends a filtered set of a project's resource information to Infracost Cloud and potentially adds PolicySha and PastPolicySha to the project's metadata.

type PriceQueryKey

type PriceQueryKey struct {
	Resource      *schema.Resource
	CostComponent *schema.CostComponent
}

type PriceQueryResult

type PriceQueryResult struct {
	PriceQueryKey
	Result gjson.Result
	// contains filtered or unexported fields
}

type PricingAPIClient

type PricingAPIClient struct {
	APIClient
	Currency       string
	EventsDisabled bool
	// contains filtered or unexported fields
}

func GetPricingAPIClient added in v0.10.29

func GetPricingAPIClient(ctx *config.RunContext) *PricingAPIClient

GetPricingAPIClient initializes and returns an instance of PricingAPIClient using the given RunContext configuration. If an instance of PricingAPIClient has already been created, it will return the existing instance. This is done to ensure that the client cache is global across the application.

func NewPricingAPIClient

func NewPricingAPIClient(ctx *config.RunContext) *PricingAPIClient

NewPricingAPIClient creates a new instance of PricingAPIClient using the given RunContext configuration. Most callers should use GetPricingAPIClient instead of this function to ensure that the client cache is global across the application. This function is useful for creating isolated pricing clients which do not share the global cache.

func (*PricingAPIClient) AddEvent added in v0.9.5

func (c *PricingAPIClient) AddEvent(name string, env map[string]interface{}) error

func (*PricingAPIClient) BatchRequests added in v0.10.25

func (c *PricingAPIClient) BatchRequests(resources []*schema.Resource, batchSize int) []BatchRequest

BatchRequests batches all the queries for these resources so we can use less GraphQL requests Use PriceQueryKeys to keep track of which query maps to which sub-resource and price component.

func (*PricingAPIClient) FlushCache added in v0.10.29

func (c *PricingAPIClient) FlushCache() error

FlushCache writes the in memory cache to the filesystem. This allows the cache to be persisted between runs. FlushCache should only be called once, at program termination.

func (*PricingAPIClient) PerformRequest added in v0.10.25

func (c *PricingAPIClient) PerformRequest(req BatchRequest) ([]PriceQueryResult, error)

PerformRequest sends a batch request to the Pricing API endpoint to fetch pricing details for the provided queries. It optimizes the API call by checking a local cache for previous results. If the results of a given query are cached, they are used directly; otherwise, a request to the API is made.

type QueryCLISettingsResponse added in v0.10.7

type QueryCLISettingsResponse struct {
	CloudEnabled       bool `json:"cloudEnabled"`
	ActualCostsEnabled bool `json:"actualCostsEnabled"`
	UsageAPIEnabled    bool `json:"usageApiEnabled"`
	TagsAPIEnabled     bool `json:"tagsApiEnabled"`
	PoliciesAPIEnabled bool `json:"policiesApiEnabled"`
}

type ResourceIDAddress added in v0.10.13

type ResourceIDAddress struct {
	Address    string `json:"address"`
	ResourceID string `json:"resourceId"`
}

type UsageAPIClient added in v0.10.12

type UsageAPIClient struct {
	APIClient
	Currency string
}

func NewUsageAPIClient added in v0.10.12

func NewUsageAPIClient(ctx *config.RunContext) *UsageAPIClient

NewUsageAPIClient returns a new Infracost Cloud Usage API Client configured from the RunContext

func (*UsageAPIClient) ListActualCosts added in v0.10.12

func (c *UsageAPIClient) ListActualCosts(vars ActualCostsQueryVariables) ([]ActualCostsResult, error)

ListActualCosts queries the Infracost Cloud Usage API to retrieve any cloud provider reported costs associated with the resource.

func (*UsageAPIClient) ListUsageQuantities added in v0.10.12

func (c *UsageAPIClient) ListUsageQuantities(vars []*UsageQuantitiesQueryVariables) ([]*schema.UsageData, error)

ListUsageQuantities queries the Infracost Cloud Usage API to retrieve usage estimates derived from cloud provider reported usage and costs.

func (*UsageAPIClient) UploadCloudResourceIDs added in v0.10.13

func (c *UsageAPIClient) UploadCloudResourceIDs(vars CloudResourceIDVariables) error

UploadCloudResourceIDs uploads cloud resource IDs to the Infracost Cloud Usage API, so they may be used to calculate usage estimates.

type UsageQuantitiesQueryVariables added in v0.10.12

type UsageQuantitiesQueryVariables struct {
	RepoURL              string              `json:"repoUrl"`
	ProjectWithWorkspace string              `json:"project"`
	ResourceType         string              `json:"resourceType"`
	Address              string              `json:"address"`
	UsageKeys            []string            `json:"usageKeys"`
	UsageParams          []schema.UsageParam `json:"usageParams"`
}

Jump to

Keyboard shortcuts

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