apiclient

package
v0.0.0-...-a2d4d4d Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 36 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

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

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

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

type ActualCostsResult

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 Diginfra Cloud Usage API

type AddRunResponse

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

type AuthClient

type AuthClient struct {
	Host string
}

AuthClient represents a client for Diginfra's authentication process.

func (AuthClient) Login

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

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

type CloudResourceIDVariables

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

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 (*DashboardAPIClient) QueryCLISettings

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

func (*DashboardAPIClient) SavePostedPrComment

func (c *DashboardAPIClient) SavePostedPrComment(ctx *config.RunContext, runId, comment string) error

type GovernanceResult

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

type LeveledLogger struct {
	Logger zerolog.Logger
}

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

func (*LeveledLogger) Debug

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

func (*LeveledLogger) Error

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

func (*LeveledLogger) Info

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

func (*LeveledLogger) Warn

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

type PolicyAPIClient

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

func NewPolicyAPIClient

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

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

func (*PolicyAPIClient) UploadPolicyData

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

UploadPolicyData sends a filtered set of a project's resource information to Diginfra 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
	Query  GraphQLQuery
	// contains filtered or unexported fields
}

type PricingAPIClient

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

func GetPricingAPIClient

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

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

func (*PricingAPIClient) BatchRequests

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

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

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

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

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

type TagPropagation

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

type UsageAPIClient

type UsageAPIClient struct {
	APIClient
	Currency string
}

func NewUsageAPIClient

func NewUsageAPIClient(ctx *config.RunContext) *UsageAPIClient

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

func (*UsageAPIClient) ListActualCosts

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

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

func (*UsageAPIClient) ListUsageQuantities

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

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

func (*UsageAPIClient) UploadCloudResourceIDs

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

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

type UsageQuantitiesQueryVariables

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