Documentation
¶
Overview ¶
Package credentialhttp authenticates requests to one explicit HTTPS origin using a live SDK credential source. The host, not the transport, owns refresh. A plugin module outside this SDK must also select the SDK's gRPC fork with a replace directive, which Go does not inherit; see docs/resource-v2-api.md, "Source-session transport".
Index ¶
- type Error
- type Option
- type Transport
- func (t *Transport) CloseIdleConnections()
- func (Transport) Format(s fmt.State, _ rune)
- func (Transport) GoString() string
- func (Transport) GobEncode() ([]byte, error)
- func (Transport) LogValue() slog.Value
- func (Transport) MarshalJSON() ([]byte, error)
- func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)
- func (Transport) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error uint8
Error classifies local HTTP policy and exchange failures without retaining inputs, peer text or native errors. Source failures keep their SDK types. http.Client can wrap these in a *url.Error containing the caller's URL. Do not log that outer string; inspect its Err or use errors.Is/As.
const ( // ErrOrigin refuses an invalid origin or a request outside its authority. ErrOrigin Error = iota + 1 // ErrInvalidRequest refuses unsupported or ambiguous request framing. ErrInvalidRequest // ErrHeaderConflict refuses an existing authentication or Host header. ErrHeaderConflict // ErrConfiguration refuses an invalid option or a source without SDK lifetime. ErrConfiguration // ErrExchange reports a network, TLS or body failure without its native text. ErrExchange )
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option selects a closed transport policy. Supply each option at most once.
func WithForbiddenRejection ¶
func WithForbiddenRejection() Option
WithForbiddenRejection treats 403 as credential rejection in addition to 401. Use only if the admitted service uses 403 for invalid credentials, not merely for insufficient permission to perform an operation.
func WithRootCAs ¶
WithRootCAs replaces system roots with a snapshot of roots. It must be non-nil. As with crypto/x509, keep certificates in the pool immutable.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport authenticates only at its exact origin. It owns its verified direct HTTP/1.1 transport, uses no proxy or caller httptrace hooks, and does not follow redirects. http.Client re-enters origin admission for each hop. Each attempt uses a fresh TLS connection. There is no automatic network replay, protocol upgrade, proxy, HTTP/2 frame logging or decompression. No connection is kept alive today, so CloseIdleConnections currently has nothing to release; call it from DestroyClient anyway. The configured origin is raw text. A request URL may have already lost its original escaping; the adapter validates its actual parsed authority. Only a source returned by credential.SourceFor works here, because only it carries the generation's lifetime. Any other Source, including a wrapper or a fake, is refused with ErrConfiguration; script a real source with the credentialtest harness instead. Keep the transport, not a lease, in the native client. Concurrent requests are safe. The zero value cannot send. Do not copy a Transport after first use.
func NewBasicTransport ¶
NewBasicTransport uses only an exact core.basic/v1 lease and RFC 7617 Basic authentication. It has the same source, origin, trust, and replay policy as bearer.
func NewBearerTransport ¶
func NewBearerTransport(source credential.Source, origin string, opts ...Option) (*Transport, error)
NewBearerTransport uses only an exact core.bearer/v1 lease. The origin is https://host[:port] with an optional final /. The host is an ASCII DNS name (IDNs already supplied as A-labels, whose last label is not all digits or hexadecimal), a dotted-decimal IPv4 address, or a bracketed IPv6 literal spelled as requests will spell it: no zone or IPv4-mapped form, and only ASCII case may differ. No trailing dot. The source must be the one credential.SourceFor returned; see Transport.
func (*Transport) CloseIdleConnections ¶
func (t *Transport) CloseIdleConnections()
CloseIdleConnections releases idle network resources without canceling requests. No connection is kept alive today, so there is currently nothing to release; later pooling would not change this call. Retirement of the source independently cancels active exchanges.
func (Transport) MarshalJSON ¶
func (*Transport) RoundTrip ¶
RoundTrip authenticates and sends one request. A source Get precedes every send: one for the first attempt and, after an authenticated rejection of a retryable request, one more to learn whether a newer revision exists. Each authenticated 401 (also 403 if opted in) reports the sent receipt, even on the last attempt. Only GET, HEAD, OPTIONS, PUT and DELETE can retry, with a strictly newer revision and either no body or a fresh GetBody copy. A fresh lease of the same or an older revision is never sent; its Get still happened, and the original rejection is returned. Idempotency-Key is not permission. A rejection not retried remains readable; source errors are returned as errors. The returned Request never references the private Authorization. As with net/http, Close on an upload must unblock its Read. GetBody has no cancellation argument and must return promptly; an abandoned copy is closed. A panic in GetBody or an upload body on the calling goroutine propagates, but only after the lease is wiped, an unreturned response is closed and the request scope is released. That cleanup is guaranteed for panics on the calling goroutine only: a panic in an upload body's Read on net/http's own writer goroutine ends the process, exactly as it does with net/http alone. Treat the peer's response headers, status and body as untrusted.