costgraph

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

CostGraph Go management SDK

Use this Go module to manage tenants, FOCUS push connections, AWS role connections, Google Cloud impersonation connections, and AI gateway connections through the CostGraph API. It also reads API-key identity, integration metadata, and the FOCUS billing-provider catalog.

This SDK covers selected management APIs, not the whole CostGraph API. Tenant administration, cloud settings, and full AI gateway readback require the accompanying backend Terraform management changes. Existing hosted or self-hosted deployments may not contain those changes yet.

Configure the client

Pass the CostGraph API deployment URL and API key explicitly. The SDK does not load environment variables or saved CLI credentials and has no hosted default or fallback.

The URL is the deployment root, such as https://api.costgraph.ai, or a reverse-proxy prefix, such as https://costgraph.example.com/backend. Do not append /api/v1. Every SDK operation appends its API path under the supplied prefix. The URL must not contain user credentials, a query, or a fragment.

client, err := costgraph.New(os.Getenv("COSTGRAPH_API_URL"), os.Getenv("COSTGRAPH_API_KEY"))
if err != nil {
    return err
}

identity, err := client.CurrentIdentity(ctx)

Import the package with github.com/baselinehq/costgraph-go. The client uses X-API-Key, a 30-second request timeout, and standard certificate verification. HTTP is supported for local test deployments. Supply a configured HTTP client with costgraph.WithHTTPClient when needed. The SDK copies that client and disables redirects so credentials do not follow a redirect to another endpoint.

The same client constructor supports self-hosted API roots and reverse proxies.

selfHosted, err := costgraph.New("https://costgraph.internal.example.com", apiKey)
proxied, err := costgraph.New("https://platform.example.com/costgraph", apiKey)

Those clients call /api/v1/... and /costgraph/api/v1/... respectively. Use the API host rather than the dashboard host.

API keys are anchored to a tenant, and connection listing uses that tenant. Creating a push connection can omit TenantID to use the key's tenant. An organization owner can explicitly grant organization:manage for supported management operations in other tenants of the same organization. This does not turn normal tenant data queries into organization-wide queries. Identity organization fields are optional pointers because the API can omit them.

Manage a push connection

The following calls create a billing account connection and read it back by its internal UUID.

connection, err := client.CreatePushConnection(ctx, costgraph.CreatePushConnectionRequest{
    Provider:          "aws",
    ProviderAccountID: "billing-account-123",
    DisplayName:       "Production billing",
})
if err != nil {
    return err
}

connection, err = client.GetConnection(ctx, connection.ID)

connection.ID is the internal UUID used for lookup, rename, and deletion. connection.ConnectionID is the public fpc_ identifier used when sending billing records. The SDK does not ingest those records in this initial slice.

Use RenameConnection(ctx, id, name) to update the display name. Provider, billing-account ID, and tenant changes are not update operations in this SDK. DeleteConnection(ctx, id) disconnects the integration and stops collection through that connection. It is a destructive action.

ListIntegrationProviders reads the FOCUS billing-provider catalog. It does not list every kind of CostGraph integration or establish that each provider has a supported managed Terraform resource.

Manage organization tenants

ListTenants, GetTenant, CreateTenant, UpdateTenant, and DeleteTenant take the organization UUID explicitly. The API key must include organization:manage, and the account that owns the key must remain an active organization owner. Existing keys do not gain this capability automatically. Read CurrentIdentity to identify the organization and granted permission scopes.

Tenant creation and updates accept a name. Names are trimmed by the API. The response includes the tenant and organization identity and its active state. Listing returns the complete active-tenant list without pagination. Deleting the default tenant or the tenant that owns the active API key is refused. These methods do not manage members, roles, or API keys.

Manage cloud connections

ConnectAWSIntegration accepts an AWS role ARN and the FOCUS export's billing account, region, bucket, and prefix. ConnectGoogleCloudIntegration accepts a billing account and Google Cloud impersonation target and query project. Their corresponding Get and Update settings methods operate on the connection UUID. Connection creation returns both UUID and public ingestion ID.

This SDK does not accept AWS access keys or Google Cloud service-account key JSON. Cloud operations require an organization owner with the explicit organization:manage scope. CostGraph verifies billing-export access before creating or updating a connection. Existing AWS automation settings are preserved by the supported updates.

Update request fields are pointers. A nil field preserves its value; a non-nil pointer sends the supplied value, including false. A pointer to an empty AWS prefix clears the prefix. Required role, project, and target settings cannot be cleared. The same distinction applies to fields inside the optional role and impersonation update objects.

Manage AI gateways

CreateAIGatewayConnection creates a gateway account using its tenant, gateway kind, and account identifier. The request can set model mappings, a cluster or host instance, and scrape overrides. GetAIGatewaySettings returns the saved collection and pricing settings. UpdateAIGatewayConnection changes these settings; use RenameConnection for its display name and DeleteConnection to disconnect it.

Gateway update maps are pointers so omission preserves the saved map. Point to an empty map to clear it. Empty cluster or instance strings detach that scope, and a zero scrape port clears the override. Nullable scrape values returned by the API mean the gateway registry defaults apply. Advanced attribution rules and custom metric bindings are outside this SDK slice and are preserved by its updates.

SearchCatalogModels(ctx, query) returns up to twenty models whose keys, display names, or aliases match the query. Use the returned Key as a model-map target. A matching alias is a search term rather than the canonical key persisted by CostGraph.

Handle API errors

HTTP failures return *costgraph.APIError, with StatusCode and Operation. Its string contains only a safe operation name and HTTP status. It does not include arbitrary server messages, response bodies, credentials, or request URLs. Inspect the status with errors.As. A 404 establishes absence; authentication, permission, network, and server failures do not.

Cancellation remains detectable with errors.Is(err, context.Canceled). Mutation methods accept successful JSON envelopes and 204 No Content. The SDK does not retry writes automatically.

Build and generate

Go 1.26 or later is required. The public API contract is reviewed and committed at api/management.openapi.json. It describes the subset exposed here, including API-key authentication and typed response envelopes. Generated HTTP and model code lives under internal/api; the public facade owns configuration and safe error handling.

make build
make lint
make check-generated

Run make generate after an intentional contract change. It uses oapi-codegen v2.9.0. Ordinary builds do not download a live API schema or regenerate files.

Build, vet, and generated-diff checks establish local compilation and reproducibility. Real resource lifecycle verification belongs to the Terraform provider acceptance scenario against an isolated CostGraph backend. Cloud account acceptance requires separately configured AWS and Google Cloud test accounts; it must not be reported as passed from compilation or mocked discovery alone.

License

This project uses the MIT License.

Documentation

Index

Constants

View Source
const ScopeOrganizationManage = "organization:manage"
View Source
const ScopeVirtualTagsRead = "virtual-tags:read"
View Source
const ScopeVirtualTagsWrite = "virtual-tags:write"

Variables

This section is empty.

Functions

This section is empty.

Types

type AIGatewayConnectRequest

type AIGatewayConnectRequest = api.AIGatewayConnectRequest

type AIGatewaySettings

type AIGatewaySettings = api.AIGatewaySettings

type AIGatewayUpdateRequest

type AIGatewayUpdateRequest = api.AIGatewayUpdateRequest

type APIError

type APIError struct {
	StatusCode int
	Operation  string
	Code       string
}

func (*APIError) Error

func (e *APIError) Error() string

type AWSAssumeRole

type AWSAssumeRole = api.AWSAssumeRole

type AWSAssumeRoleSettings

type AWSAssumeRoleSettings = api.AWSAssumeRoleSettings

type AWSAssumeRoleUpdate

type AWSAssumeRoleUpdate = api.AWSAssumeRoleUpdate

type AWSConnectRequest

type AWSConnectRequest = api.AWSConnectRequest

type AWSConnectionSettings

type AWSConnectionSettings = api.AWSConnectionSettings

type AWSConnectionUpdateRequest

type AWSConnectionUpdateRequest = api.AWSConnectionUpdateRequest

type AzureConnectRequest added in v0.2.0

type AzureConnectRequest = api.AzureConnectRequest

type AzureConnectionSettings added in v0.2.0

type AzureConnectionSettings = api.AzureConnectionSettings

type AzureConnectionUpdateRequest added in v0.2.0

type AzureConnectionUpdateRequest = api.AzureConnectionUpdateRequest

type CatalogModel

type CatalogModel = api.CatalogModel

type Client

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

func New

func New(apiURL, apiKey string, opts ...Option) (*Client, error)

func (*Client) ConnectAWSIntegration

func (c *Client) ConnectAWSIntegration(ctx context.Context, request AWSConnectRequest) (*ConnectedIntegration, error)

func (*Client) ConnectAzureIntegration added in v0.2.0

func (c *Client) ConnectAzureIntegration(ctx context.Context, request AzureConnectRequest) (*ConnectedIntegration, error)

func (*Client) ConnectGoogleCloudIntegration

func (c *Client) ConnectGoogleCloudIntegration(ctx context.Context, request GCPConnectRequest) (*ConnectedIntegration, error)

func (*Client) CreateAIGatewayConnection

func (c *Client) CreateAIGatewayConnection(ctx context.Context, request AIGatewayConnectRequest) (*Connection, error)

func (*Client) CreateKubernetesCluster added in v0.2.0

func (c *Client) CreateKubernetesCluster(ctx context.Context, organizationID string, request CreateKubernetesClusterRequest) (*KubernetesCluster, error)

func (*Client) CreatePushConnection

func (c *Client) CreatePushConnection(ctx context.Context, request CreatePushConnectionRequest) (*Connection, error)

func (*Client) CreateTenant

func (c *Client) CreateTenant(ctx context.Context, organizationID string, request CreateTenantRequest) (*ManagedTenant, error)

func (*Client) CreateVirtualTag added in v0.2.0

func (c *Client) CreateVirtualTag(ctx context.Context, tenantID string, request VirtualTagRequest) (*VirtualTag, error)

func (*Client) CurrentIdentity

func (c *Client) CurrentIdentity(ctx context.Context) (*Identity, error)

func (*Client) DeleteConnection

func (c *Client) DeleteConnection(ctx context.Context, id string) error

func (*Client) DeleteKubernetesCluster added in v0.2.0

func (c *Client) DeleteKubernetesCluster(ctx context.Context, organizationID, id string) error

func (*Client) DeleteTenant

func (c *Client) DeleteTenant(ctx context.Context, organizationID, tenantID string) error

func (*Client) DeleteVirtualTag added in v0.2.0

func (c *Client) DeleteVirtualTag(ctx context.Context, tenantID, id, revision string) error

func (*Client) GetAIGatewaySettings

func (c *Client) GetAIGatewaySettings(ctx context.Context, id string) (*AIGatewaySettings, error)

func (*Client) GetAWSIntegrationSettings

func (c *Client) GetAWSIntegrationSettings(ctx context.Context, id string) (*AWSConnectionSettings, error)

func (*Client) GetAzureIntegrationSettings added in v0.2.0

func (c *Client) GetAzureIntegrationSettings(ctx context.Context, id string) (*AzureConnectionSettings, error)

func (*Client) GetConnection

func (c *Client) GetConnection(ctx context.Context, id string) (*Connection, error)

func (*Client) GetGoogleCloudIntegrationSettings

func (c *Client) GetGoogleCloudIntegrationSettings(ctx context.Context, id string) (*GCPConnectionSettings, error)

func (*Client) GetKubernetesCluster added in v0.2.0

func (c *Client) GetKubernetesCluster(ctx context.Context, organizationID, id string) (*KubernetesCluster, error)

func (*Client) GetTenant

func (c *Client) GetTenant(ctx context.Context, organizationID, tenantID string) (*ManagedTenant, error)

func (*Client) GetVirtualTag added in v0.2.0

func (c *Client) GetVirtualTag(ctx context.Context, tenantID, id string) (*VirtualTag, error)

func (*Client) ListConnections

func (c *Client) ListConnections(ctx context.Context) ([]Connection, error)

func (*Client) ListIntegrationProviders

func (c *Client) ListIntegrationProviders(ctx context.Context) ([]IntegrationProvider, error)

func (*Client) ListTenants

func (c *Client) ListTenants(ctx context.Context, organizationID string) ([]ManagedTenant, error)

func (*Client) ListVirtualTags added in v0.2.0

func (c *Client) ListVirtualTags(ctx context.Context, tenantID string) ([]VirtualTagMetadata, error)

func (*Client) LookupVirtualTag added in v0.2.0

func (c *Client) LookupVirtualTag(ctx context.Context, tenantID, key string) (*VirtualTag, error)

func (*Client) RenameConnection

func (c *Client) RenameConnection(ctx context.Context, id, name string) error

func (*Client) SearchCatalogModels

func (c *Client) SearchCatalogModels(ctx context.Context, query string) ([]CatalogModel, error)

func (*Client) UpdateAIGatewayConnection

func (c *Client) UpdateAIGatewayConnection(ctx context.Context, id string, request AIGatewayUpdateRequest) (*Connection, error)

func (*Client) UpdateAWSIntegrationSettings

func (c *Client) UpdateAWSIntegrationSettings(ctx context.Context, id string, request AWSConnectionUpdateRequest) (*AWSConnectionSettings, error)

func (*Client) UpdateAzureIntegrationSettings added in v0.2.0

func (c *Client) UpdateAzureIntegrationSettings(ctx context.Context, id string, request AzureConnectionUpdateRequest) (*AzureConnectionSettings, error)

func (*Client) UpdateGoogleCloudIntegrationSettings

func (c *Client) UpdateGoogleCloudIntegrationSettings(ctx context.Context, id string, request GCPConnectionUpdateRequest) (*GCPConnectionSettings, error)

func (*Client) UpdateTenant

func (c *Client) UpdateTenant(ctx context.Context, organizationID, tenantID string, request UpdateTenantRequest) (*ManagedTenant, error)

func (*Client) UpdateVirtualTag added in v0.2.0

func (c *Client) UpdateVirtualTag(ctx context.Context, tenantID, id string, request VirtualTagRequest) (*VirtualTag, error)

type ConnectedIntegration

type ConnectedIntegration = api.ConnectedIntegration

type Connection

type Connection = api.Connection

type CreateKubernetesClusterRequest added in v0.2.0

type CreateKubernetesClusterRequest = api.CreateKubernetesClusterRequest

type CreatePushConnectionRequest

type CreatePushConnectionRequest = api.CreatePushConnectionRequest

type CreateTenantRequest

type CreateTenantRequest = api.CreateTenantRequest

type GCPConnectRequest

type GCPConnectRequest = api.GCPConnectRequest

type GCPConnectionSettings

type GCPConnectionSettings = api.GCPConnectionSettings

type GCPConnectionUpdateRequest

type GCPConnectionUpdateRequest = api.GCPConnectionUpdateRequest

type GCPImpersonation

type GCPImpersonation = api.GCPImpersonation

type GCPImpersonationUpdate

type GCPImpersonationUpdate = api.GCPImpersonationUpdate

type Identity

type Identity = api.Identity

type IntegrationProvider

type IntegrationProvider = api.IntegrationProvider

type KubernetesCluster added in v0.2.0

type KubernetesCluster = api.KubernetesCluster

type ManagedTenant

type ManagedTenant = api.ManagedTenant

type Option

type Option func(*options)

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

type ProviderEnvironmentVariable

type ProviderEnvironmentVariable = api.ProviderEnvironmentVariable

type Tenant

type Tenant = api.Tenant

type UpdateTenantRequest

type UpdateTenantRequest = api.UpdateTenantRequest

type VirtualTag added in v0.2.0

type VirtualTag = api.VirtualTag

type VirtualTagMetadata added in v0.2.0

type VirtualTagMetadata = api.VirtualTagMetadata

type VirtualTagRequest added in v0.2.0

type VirtualTagRequest = api.VirtualTagRequest

type VirtualTagRule added in v0.2.0

type VirtualTagRule = api.VirtualTagRule

type VirtualTagRuleInput added in v0.2.0

type VirtualTagRuleInput = api.VirtualTagRuleInput

Directories

Path Synopsis
internal
api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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