gcp

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package gcp provides authenticated HTTP access to GCP APIs using Application Default Credentials. It is a shared foundation used by the Vertex AI inference provider and the GCF dispatch provisioner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractErrorMessage

func ExtractErrorMessage(body []byte) string

ExtractErrorMessage parses a GCP API error response and returns only the error message, avoiding leakage of sensitive metadata.

Types

type Client

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

Client provides authenticated HTTP access to GCP APIs using Application Default Credentials.

func NewClient

func NewClient() *Client

NewClient creates a new Client with default settings.

func NewClientWithHTTP

func NewClientWithHTTP(httpClient *http.Client) *Client

NewClientWithHTTP creates a Client that uses the given HTTP client and a static "test-token" for auth. Intended for unit tests that redirect GCP API calls to httptest servers.

func (*Client) AccessToken

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

AccessToken obtains a GCP access token using Application Default Credentials.

func (*Client) DoRequest

func (c *Client) DoRequest(ctx context.Context, method, url, body string) (*http.Response, error)

DoRequest creates and executes an authenticated HTTP request. It retries transient failures using exponential backoff with jitter, but only for idempotent HTTP methods (GET, HEAD, PUT, DELETE) to avoid duplicating side effects for non-idempotent requests.

Retryable conditions (idempotent methods only):

  • HTTP status codes 500, 502, 503, 504
  • Transport errors: connection resets, timeouts, unexpected EOF

Non-idempotent methods (POST, PATCH) are never retried because the server may have processed the request before returning the error or dropping the connection. For example, retrying AddSecretVersion (POST) after a 500 could create a duplicate secret version.

HTTP 429 is not retried here; callers that need 429 retry (e.g. doWIFRequestWithRetry) handle it at a higher level with their own backoff strategy.

Jump to

Keyboard shortcuts

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