upstreamcall

package
v1.134.0 Latest Latest
Warning

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

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

Documentation

Overview

Package upstreamcall is one connection's authorized outbound transport, handed to a platform layer that must call that upstream without holding its credential (#1720).

It exists because a notification channel delivers through a connection the operator already created: the bot token is that connection's credential, encrypted at rest and rotated in one place, and a channel that held its own copy would be a second place to rotate and a second place to leak. The layer that posts a message therefore receives the ability to make an authorized call and never the material that authorizes it.

It is its own package rather than a file in the api gateway because it depends on none of the gateway: given a client, an authenticator and a base URL it makes a call, which is what lets a second connection kind hand one out without the gateway growing another export.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name is the connection's name, for an error that has to say which
	// connection refused.
	Name string
	// BaseURL is the connection's upstream root.
	BaseURL string
	// Client is the connection's materialized HTTP client, with its TLS
	// material and timeouts already applied.
	Client *http.Client
	// Auth applies the connection's credential to each request.
	Auth upstreamauth.Authenticator
	// StaticHeaders are the operator-configured headers on every request.
	StaticHeaders map[string]string
	// CallTimeout bounds a request that carries no deadline of its own.
	CallTimeout time.Duration
}

Config is what a connection kind hands over to make its upstream callable.

type Upstream

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

Upstream is one connection's authorized outbound transport.

Do applies the connection's authentication on each call rather than once at construction, so a connection whose credential is an OAuth token being refreshed behind it stays callable through an Upstream held for the life of a worker.

func New

func New(cfg Config) *Upstream

New builds the transport for a connection.

func (*Upstream) BaseURL

func (u *Upstream) BaseURL() string

BaseURL returns the connection's upstream root. A caller appends the path its protocol names (Slack's /chat.postMessage, Mattermost's /api/v4/posts) rather than being handed a whole URL, so the operator's base_url stays the one statement of which host is reached.

func (*Upstream) Connection

func (u *Upstream) Connection() string

Connection returns the name of the connection this transport belongs to, for an error message that has to say which connection refused.

func (*Upstream) Do

func (u *Upstream) Do(req *http.Request) (*http.Response, error)

Do applies the connection's static headers and authentication and sends the request through its client.

A request carrying no deadline of its own is bounded by the connection's call timeout, so a queued send cannot hang a worker on an upstream that accepts a connection and never answers.

Jump to

Keyboard shortcuts

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