cloudstorage

package
v0.0.0-dev Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package cloudstorage issues unauthenticated, idempotent HTTP requests to cloud object storage (S3, Azure Blob, GCS) using short-lived presigned URLs. The URLs are self-authenticating, so the client deliberately carries no Databricks credentials. It owns the inactivity-stall and exact-length guards and a capped retry-with-backoff policy; callers supply the bytes via a Body and interpret the returned Response.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRetriable

func IsRetriable(err error) bool

IsRetriable reports whether an error from Attempt is worth retrying: a stalled attempt is, a short read (deterministic) is not, a retryable HTTP status (as an APIError) is, and any other failure is retried only if it is a transient network error (which excludes context cancellation and deadline). It is exported for callers (such as a resumable upload) that run their own resume-aware retry loop over Attempt.

func IsRetryableStatus

func IsRetryableStatus(code int) bool

IsRetryableStatus reports whether an HTTP status code should be retried. It is exported for callers (such as a resumable upload) that run their own resume-aware retry loop over Attempt rather than using Send.

func IsURLExpired

func IsURLExpired(err error) bool

IsURLExpired reports whether err (as returned by Send) is one of the known cloud-provider "presigned URL expired" errors: a 403 with the AWS or Azure signature-expiry body.

Types

type Body

type Body interface {
	// Reader returns a reader over the body positioned at the start. It is called
	// once per attempt.
	Reader() (io.Reader, error)
	// Size reports the body length in bytes, for Content-Length and the
	// short-read guard.
	Size() int64
}

Body supplies a request's bytes and can re-supply them for each retry attempt, so a request is retried without the caller buffering it again.

func BytesBody

func BytesBody(data []byte) Body

BytesBody returns a Body backed by an in-memory buffer.

func SectionBody

func SectionBody(ra io.ReaderAt, offset, length int64) Body

SectionBody returns a Body that reads length bytes starting at offset from ra on each attempt. ra may be shared across concurrent bodies: positioned reads via io.ReaderAt are safe to run in parallel.

type Client

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

Client issues requests to cloud object storage over presigned URLs. It holds only an *http.Client: no Databricks credentials, no config.

func New

func New(httpClient *http.Client, opts ...Option) *Client

New returns a Client that sends over the given HTTP client. The caller owns the client's transport, timeouts, and connection-pool sizing; it must not attach Databricks credentials, and should not set a whole-request http.Client.Timeout (it would abort a legitimately long transfer; bound the operation with the request context instead).

func (*Client) Attempt

func (c *Client) Attempt(ctx context.Context, method, url string, headers map[string]string, body Body) (*Response, error)

Attempt performs a single request and returns the raw response. body may be nil for a bodyless request (a status query or an abort).

func (*Client) Send

func (c *Client) Send(ctx context.Context, method, url string, headers map[string]string, body Body) (*Response, error)

Send performs Attempt with capped retries: transient network errors, the retryable statuses in retryStatusCodes (honoring Retry-After), and stalled attempts are retried with exponential backoff. A fresh request and body reader are built per attempt, so no explicit rewind is needed. Exhausting retries on a retryable status returns that status as an error.

type Option

type Option func(*Client)

Option configures a Client.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger used for debug-level transfer diagnostics. When unset, transfer diagnostics are discarded.

type Response

type Response struct {
	StatusCode int
	Header     http.Header
	Body       []byte
}

Response is the captured result of a presigned request. Unlike a Databricks API call, cloud requests expose the raw status and headers (ETag, Range, 308) and are never mapped to a Databricks API error.

Jump to

Keyboard shortcuts

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