atlhttp

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 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.

Documentation

Overview

Package atlhttp is the shared HTTP transport for Atlassian Cloud clients (Jira, Confluence): path safety, Authorization host pinning, and the Do/DoRaw loop. Retryable statuses, backoff plus Retry-After, the error snippet, the 64 MiB body cap, and Usage/Meter live in httppolicy so a non-Atlassian connector can share that policy without importing this package.

The token lives only in the Authorization header. It is never put in an error, a log line or a URL (constitution article 8), which is why DoRaw reports the method and path but never the request itself.

Index

Constants

View Source
const (
	KindSearchPages    = "search-pages"
	KindIssueComment   = "issue-comment"
	KindIssueChangelog = "issue-changelog"
	KindPageList       = "page-list"
	KindPageBody       = "page-body"
	KindPageComments   = "page-comments"
	KindPageVersions   = "page-versions"
	KindAgile          = "agile"
	KindOther          = "other"
)

Request kinds for the per-pass request breakdown. One classifier maps every origin dialect — Jira Cloud v3, Jira Server v2, Confluence Cloud v1, and the built-in tracker, which speaks the same shapes in-process — onto these, so the sync pass line is comparable across origins. kindOrder is the canonical print order; every tally, snapshot, and line iterates it, never a map.

Variables

View Source
var ErrAuth = errors.New("credential rejected")

ErrAuth is the shared identity for a rejected Atlassian credential (HTTP 401 or 403). Client packages keep named wrappers (jira.ErrAuth, confluence.ErrAuth) so existing errors.Is call sites keep compiling; those wrappers unwrap to this sentinel.

DoRaw never returns this: a completed HTTP response is status+body. JSON call helpers use Do, which classifies 401/403 here so a new client inherits the identity by using the transport.

Functions

func Auth added in v0.14.1

func Auth(prefix string) error

Auth returns a rejected-credential error named by prefix (Config.ErrPrefix: "jira", "confluence", …).

func Call added in v0.21.0

func Call(ctx context.Context, cfg Config, method, path string, body, out any, mutating bool, mapErr func(status int, data []byte) error) error

Call is the JSON request envelope on top of Do: marshal body, send, hand a non-2xx status to mapErr, unmarshal a 2xx body into out. The Atlassian clients (internal/jira, internal/confluence) differ only in how an HTTP failure becomes an error — the mapping is the mapErr parameter, so the envelope has one owner here (GDK-1577). out may be nil to ignore a body; an empty body with a non-nil out is not an error.

func Do added in v0.14.1

func Do(ctx context.Context, cfg Config, method, path string, payload []byte, hasBody, mutating bool) (int, []byte, error)

Do is DoRaw plus 401/403 classification. JSON call helpers use this so a new client inherits rejected-credential identity. Raw keeps DoRaw: a completed response is never an error there.

func DoRaw

func DoRaw(ctx context.Context, cfg Config, method, path string, payload []byte, hasBody, mutating bool) (int, []byte, error)

DoRaw is the single HTTP path for JSON call helpers and Raw: retries, backoff, and optional usage. Path must be site-relative (leading "/"); absolute URLs and scheme-relative paths are rejected so the Authorization header never leaves the configured site. mutating selects the write retry policy (429/503 only).

A completed HTTP response always returns err == nil with the status and body (including non-2xx). err is reserved for transport failures and bad paths. JSON call helpers use Do, which classifies 401/403 as ErrAuth; Raw stays here.

func DoRawWithHeaders added in v0.22.0

func DoRawWithHeaders(ctx context.Context, cfg Config, method, path string, payload []byte, hasBody, mutating bool) (int, http.Header, []byte, error)

DoRawWithHeaders is DoRaw that also returns the final response's headers — the surface `gadak api --headers` needs to show what the origin stated alongside the body (rate-limit headers on ordinary responses). Same retry and error contract as DoRaw; the header is nil on every error path.

func Snippet

func Snippet(b []byte) string

Snippet trims and truncates a response body for error messages.

func Stream added in v0.22.0

func Stream(ctx context.Context, cfg Config, method, path string, hdr http.Header) (*http.Response, error)

Stream is DoRaw for a response nobody wants in memory: it returns the live *http.Response with its Body unread, so the caller can copy it straight to a client or a file. The caller closes the Body.

It exists because DoRaw reads through io.LimitReader(res.Body, httppolicy.MaxBody) — right for a JSON document, wrong for attachment bytes, where the cap that used to be 64 MiB is now the origin's configurable upload limit and a real workspace's largest measured file is 884 MiB (GDK-1617).

Only transport failures retry. A response that has already begun cannot be replayed without reading it, which is the thing this function exists not to do; hdr carries request headers the caller needs passed through (Range, If-None-Match), and every status, including non-2xx, comes back as a response with err == nil.

Types

type AuthError added in v0.14.1

type AuthError struct {
	Prefix string
}

AuthError names which connector's credential died. Error() is "<prefix>: credential rejected" so last_error distinguishes sources. Unwrap returns ErrAuth so errors.Is(err, ErrAuth) is true for every client.

func (AuthError) Error added in v0.14.1

func (e AuthError) Error() string

func (AuthError) RejectedCredential added in v0.14.1

func (e AuthError) RejectedCredential()

func (AuthError) Unwrap added in v0.14.1

func (e AuthError) Unwrap() error

type Breakdown added in v0.22.0

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

Breakdown tallies per-kind request count and wall time for one client — the "sync: requests …" pass line. It also carries the Confluence client's PauseBetween sleep, which no request meter sees and which was 45.7 s of one first-sync benchmark. Same concurrency shape as Meter: atomics, never blocks a request, nil-safe.

func (*Breakdown) Note added in v0.22.0

func (b *Breakdown) Note(method, path string, d time.Duration)

Note records one completed attempt of method+path with the wall time the caller spent on it. The count is noted even when d is zero — the request still left the process.

func (*Breakdown) NoteSleep added in v0.22.0

func (b *Breakdown) NoteSleep(d time.Duration)

NoteSleep records time spent in the Confluence client's PauseBetween politeness sleep. Non-positive durations are ignored, like Meter.NoteWait.

func (*Breakdown) Take added in v0.22.0

func (b *Breakdown) Take() BreakdownSnapshot

Take returns the snapshot and zeroes the accumulators — the same accumulate-once contract as Meter.Take, so a per-pass printer cannot double-count the next pass.

type BreakdownSnapshot added in v0.22.0

type BreakdownSnapshot struct {
	Kinds   []KindTally `json:"kinds"`
	Total   int64       `json:"total"`
	WallMS  int64       `json:"wall_ms"`
	SleepMS int64       `json:"sleep_ms,omitempty"`
}

BreakdownSnapshot is the take-once view of a Breakdown: per-kind rows in canonical order (zero-count kinds omitted), their total, and the politeness-sleep total.

type Config

type Config struct {
	// Base is the site (or wiki) origin with no trailing slash.
	Base string
	// Auth is the full Authorization header value (e.g. "Basic …").
	Auth string
	// HTTP is the client used for each attempt; nil is a programming error.
	HTTP *http.Client
	// Retries is the total number of attempts per request; Backoff is the first
	// wait, doubling per attempt and capped at 30 s.
	Retries int
	Backoff time.Duration
	// ErrPrefix labels resolve errors ("jira" → "jira: bad site URL").
	ErrPrefix string
	// Usage, when non-nil, records every attempt that left the process.
	Usage *Meter
	// Breakdown, when non-nil, tallies per-kind request count and wall time
	// for the sync pass line. Nil keeps the request path
	// unchanged.
	Breakdown *Breakdown
	// Budget, when non-nil, spaces requests proactively from the origin's
	// stated rate limit (Jira Data Center's X-RateLimit-* headers, GDK-1646):
	// one Wait before every attempt, one Observe after every response. Nil
	// (Cloud, Linear, the built-in tracker) is disabled — those paths are
	// unchanged byte for byte.
	Budget *httppolicy.RateBudget
}

Config is the per-request transport configuration. Callers pass live client fields so tests can mutate HTTP/Retries/Backoff after construction.

type KindTally added in v0.22.0

type KindTally struct {
	Kind   string `json:"kind"`
	Count  int64  `json:"count"`
	WallMS int64  `json:"wall_ms"`
}

KindTally is one row of a breakdown snapshot.

type Meter

type Meter = httppolicy.Meter

Meter holds atomic counters shared by concurrent DoRaw goroutines.

type RejectedCredential added in v0.14.1

type RejectedCredential interface {
	RejectedCredential()
}

RejectedCredential is the marker Watch keys on. A source that is not built on this package can still implement the method; Do-produced errors implement it too.

type StatusError added in v0.24.2

type StatusError struct {
	Status int
	Err    error
}

StatusError preserves a response's HTTP status without changing the underlying error's identity or message. A caller may apply a narrower policy to one operation while other callers still see ErrAuth.

func (*StatusError) Error added in v0.24.2

func (e *StatusError) Error() string

func (*StatusError) Unwrap added in v0.24.2

func (e *StatusError) Unwrap() error

type Usage

type Usage = httppolicy.Usage

Usage is the host-neutral HTTP usage snapshot. The struct lives in httppolicy so Linear reports the same type without importing this package (path joining / Authorization host pinning stay here).

Callers (jira.Usage, confluence.Usage, sync.usageTaker, store.api_usage) keep using this name.

type UsageBox added in v0.22.0

type UsageBox struct {
	// Meter is the call-volume counter: requests, retries, throttles,
	// waits. See Usage / TakeUsage.
	Meter Meter
	// Breakdown tallies per-kind request count and wall time for the sync
	// pass's "sync: requests …" line. The Confluence client also records
	// its PauseBetween politeness sleep here.
	Breakdown Breakdown
}

UsageBox is the instrument pair every Atlassian-family client carries: the call meter behind Usage / TakeUsage and the per-kind request breakdown behind TakeRequestBreakdown. jira.Client and confluence.Client embed it by value (GDK-1780), so the three read methods promote from one owner instead of a byte-identical pair per package; transport wiring hands out &box.Meter / &box.Breakdown the same way the clients once handed their own fields. Counters are process-local, atomic, and never block a request.

func (*UsageBox) TakeRequestBreakdown added in v0.22.0

func (b *UsageBox) TakeRequestBreakdown() BreakdownSnapshot

TakeRequestBreakdown returns the per-kind request tally since the last take, zeroing it — the accumulate-once shape of TakeUsage, feeding the sync pass's "sync: requests …" line.

func (*UsageBox) TakeUsage added in v0.22.0

func (b *UsageBox) TakeUsage() Usage

TakeUsage returns the current counters and zeroes the numeric fields so a flusher can accumulate into daily totals without double-counting.

LastThrottledAt is a timestamp, not a counter: it is included in the snapshot but is NOT cleared.

func (*UsageBox) Usage added in v0.22.0

func (b *UsageBox) Usage() Usage

Usage returns the current counters without resetting them.

Jump to

Keyboard shortcuts

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