externalsource

package
v0.6.24 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const MaxArtifactBytes int64 = 256 << 20

Variables

This section is empty.

Functions

func ResolvePublicAddresses

func ResolvePublicAddresses(ctx context.Context, resolver AddressResolver, locator PackageURL) ([]netip.Addr, error)

ResolvePublicAddresses resolves and validates every returned A/AAAA address. A mixed public/private answer rejects the entire hop.

Types

type AddressResolver

type AddressResolver interface {
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

AddressResolver permits host products and tests to supply DNS while keeping address classification and pinning inside ReDevPlugin.

type ArtifactFetchRequest added in v0.6.21

type ArtifactFetchRequest struct {
	URL            string
	QuotaKey       string
	MaxBytes       int64
	AllowedHosts   []string
	ExpectedSize   int64
	ExpectedSHA256 string
}

ArtifactFetchRequest binds a remote read to exact public hosts, byte length, and content digest. It is intended for signed release documents and package artifacts whose identity was resolved before the download starts.

type ArtifactFetchResult added in v0.6.21

type ArtifactFetchResult struct {
	Bytes     []byte
	Source    string
	Final     string
	Redirects []RedirectHop
}

type CredentialProvider

type CredentialProvider interface {
	CredentialFor(ctx context.Context, request CredentialRequest) (http.Header, error)
}

CredentialProvider is called independently for every validated hop. A returned header is never forwarded to a different origin.

type CredentialRequest

type CredentialRequest struct {
	SourceID string
	Origin   Origin
}

CredentialRequest scopes credentials to one exact origin and source.

type Error

type Error struct {
	Code       ErrorCode
	Operation  string
	DisplayURL string
	// contains filtered or unexported fields
}

Error intentionally omits the wrapped cause from Error() so URL query credentials and transport headers cannot be copied into user-facing errors.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorCode

type ErrorCode string

ErrorCode is a stable classification for external-source admission failures.

const (
	ErrorInvalidURL           ErrorCode = "external_source_invalid_url"
	ErrorInvalidSource        ErrorCode = "external_source_invalid_source"
	ErrorTargetBlocked        ErrorCode = "external_source_target_blocked"
	ErrorDNS                  ErrorCode = "external_source_dns_failed"
	ErrorRedirectDenied       ErrorCode = "external_source_redirect_denied"
	ErrorTooManyRedirects     ErrorCode = "external_source_too_many_redirects"
	ErrorCredentialDenied     ErrorCode = "external_source_credential_denied"
	ErrorTransport            ErrorCode = "external_source_transport_failed"
	ErrorHTTPStatus           ErrorCode = "external_source_http_status"
	ErrorUnsupportedEncoding  ErrorCode = "external_source_unsupported_encoding"
	ErrorArtifactTooLarge     ErrorCode = "external_source_artifact_too_large"
	ErrorArtifactEmpty        ErrorCode = "external_source_artifact_empty"
	ErrorGitHubRelease        ErrorCode = "external_source_github_release_failed"
	ErrorGitHubAssetMissing   ErrorCode = "external_source_github_asset_missing"
	ErrorGitHubAssetAmbiguous ErrorCode = "external_source_github_asset_ambiguous"
	ErrorStageInvalid         ErrorCode = "external_source_stage_invalid"
	ErrorStageIntegrity       ErrorCode = "external_source_stage_integrity_failed"
	ErrorQuotaExceeded        ErrorCode = "external_source_quota_exceeded"
)

func CodeOf

func CodeOf(err error) ErrorCode

CodeOf returns the stable external-source code carried by err.

type FetchRequest

type FetchRequest struct {
	URL      string
	QuotaKey string
}

type FetchResult

type FetchResult struct {
	Artifact  StagedArtifact
	Source    string
	Final     string
	Redirects []RedirectHop
}

type Fetcher

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

func NewFetcher

func NewFetcher(options FetcherOptions) (*Fetcher, error)

func (*Fetcher) FetchArtifact added in v0.6.21

func (fetcher *Fetcher) FetchArtifact(ctx context.Context, request ArtifactFetchRequest) (result ArtifactFetchResult, returnErr error)

FetchArtifact downloads one content-addressed artifact through the same hardened network and staging boundary as FetchPackage. Every redirect host must be explicitly allowed and returned bytes are rehashed before use.

func (*Fetcher) FetchPackage

func (fetcher *Fetcher) FetchPackage(ctx context.Context, request FetchRequest) (FetchResult, error)

type FetcherOptions

type FetcherOptions struct {
	Stage        *StageStore
	Resolver     AddressResolver
	Credentials  CredentialProvider
	SourceID     string
	TotalTimeout time.Duration
}

type GitHubRESTReleaseClient

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

GitHubRESTReleaseClient resolves GitHub release and commit identities through the fixed public GitHub REST origin. It never follows redirects or uses an ambient HTTP proxy.

func NewGitHubRESTReleaseClient

func NewGitHubRESTReleaseClient(options GitHubRESTReleaseClientOptions) (*GitHubRESTReleaseClient, error)

NewGitHubRESTReleaseClient creates a host-neutral concrete implementation of GitHubReleaseClient. Empty Token enables public unauthenticated requests.

func (*GitHubRESTReleaseClient) LatestRelease

func (client *GitHubRESTReleaseClient) LatestRelease(ctx context.Context, owner, repository string) (GitHubRelease, error)

func (*GitHubRESTReleaseClient) ReleaseByTag

func (client *GitHubRESTReleaseClient) ReleaseByTag(ctx context.Context, owner, repository, tag string) (GitHubRelease, error)

type GitHubRESTReleaseClientOptions

type GitHubRESTReleaseClientOptions struct {
	Token     string
	UserAgent string
	Transport http.RoundTripper
}

GitHubRESTReleaseClientOptions configures the public GitHub REST client. Transport is injectable for deterministic testing, but every request URL remains fixed to https://api.github.com. Injected *http.Transport values are cloned with proxy use disabled.

type GitHubRelease

type GitHubRelease struct {
	RepositoryID int64
	ReleaseID    int64
	Tag          string
	// ResolvedCommitSHA is the immutable 40-character commit selected for the
	// release. Clients must resolve branch-like target_commitish values before
	// returning a release.
	ResolvedCommitSHA string
	Assets            []GitHubReleaseAsset
}

type GitHubReleaseAsset

type GitHubReleaseAsset struct {
	AssetID     int64
	Name        string
	DownloadURL string
	Size        int64
}

type GitHubReleaseClient

type GitHubReleaseClient interface {
	LatestRelease(ctx context.Context, owner, repository string) (GitHubRelease, error)
	ReleaseByTag(ctx context.Context, owner, repository, tag string) (GitHubRelease, error)
}

GitHubReleaseClient owns GitHub API authentication and returns stable GitHub identities. The resolver never clones, checks out, builds, or executes source.

type GitHubReleaseResolver

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

func NewGitHubRESTReleaseResolver

func NewGitHubRESTReleaseResolver(options GitHubRESTReleaseClientOptions, fetcher *Fetcher) (*GitHubReleaseResolver, error)

NewGitHubRESTReleaseResolver wires the concrete REST client into the existing release asset resolver. Hosts supply only credentials, egress transport, and the shared hardened package fetcher.

func NewGitHubReleaseResolver

func NewGitHubReleaseResolver(client GitHubReleaseClient, fetcher *Fetcher) (*GitHubReleaseResolver, error)

func (*GitHubReleaseResolver) ResolvePackage

func (resolver *GitHubReleaseResolver) ResolvePackage(ctx context.Context, source GitHubRepositorySource) (ResolvedGitHubAsset, error)

ResolvePackage selects the unique .redevplugin asset and downloads it through the same public-HTTPS, redirect, DNS, and staging policy as a direct URL. Signed download query parameters are accepted but never exposed.

type GitHubRepositorySource

type GitHubRepositorySource struct {
	RepositoryURL string
	Tag           string
	QuotaKey      string
}

GitHubRepositorySource selects either the latest release or one exact tag. RepositoryURL must be exactly https://github.com/{owner}/{repository}.

type Origin

type Origin struct {
	Scheme string
	Host   string
	Port   uint16
}

Origin identifies the exact credential and transport origin for one hop.

func (Origin) String

func (origin Origin) String() string

type PackageURL

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

PackageURL is a validated public-HTTPS package locator. DisplayURL never contains userinfo, query, or fragment data.

func ParseDirectPackageURL

func ParseDirectPackageURL(raw string) (PackageURL, error)

ParseDirectPackageURL validates the v1 direct-package source. Query strings are rejected because credentials and version selectors belong in host-owned adapters rather than persisted source locators.

func (PackageURL) DisplayURL

func (locator PackageURL) DisplayURL() string

func (PackageURL) Origin

func (locator PackageURL) Origin() Origin

type RedirectHop

type RedirectHop struct {
	StatusCode int
	From       string
	To         string
}

type ResolvedGitHubAsset

type ResolvedGitHubAsset struct {
	RepositoryURL     string
	RepositoryID      int64
	ReleaseID         int64
	Tag               string
	ResolvedCommitSHA string
	AssetID           int64
	AssetName         string
	DeclaredSize      int64
	Fetch             FetchResult
}

ResolvedGitHubAsset binds downloaded bytes to immutable GitHub release and asset identities. URLs in this result are safe for logs and persistence.

type StageStore

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

StageStore owns external artifacts in a host-selected private directory.

func NewStageStore

func NewStageStore(directory string) (*StageStore, error)

func NewStageStoreWithOptions

func NewStageStoreWithOptions(directory string, options StageStoreOptions) (*StageStore, error)

func (*StageStore) Close

func (store *StageStore) Close() error

func (*StageStore) ReadArtifact added in v0.6.21

func (store *StageStore) ReadArtifact(ctx context.Context, artifact StagedArtifact, maxBytes int64) ([]byte, error)

ReadArtifact returns verified staged bytes without exposing a filesystem path. The fixed byte slice is hashed again after reading so callers never consume content that differs from the staged handle.

func (*StageStore) Remove

func (store *StageStore) Remove(artifact StagedArtifact) error

func (*StageStore) Stage

func (store *StageStore) Stage(ctx context.Context, source io.Reader) (StagedArtifact, error)

Stage streams at most MaxArtifactBytes into an exclusive 0600 regular file.

func (*StageStore) StageUpload

func (store *StageStore) StageUpload(ctx context.Context, ownerKey string, source io.Reader, declaredSize int64) (StagedArtifact, error)

StageUpload streams an owner-scoped upload into the shared external artifact stage. A negative declaredSize means the size is unknown. Zero is an explicitly empty upload and is rejected before source is read.

func (*StageStore) VerifyPackage

func (store *StageStore) VerifyPackage(ctx context.Context, artifact StagedArtifact, limits pluginpkg.ReadLimits) (pluginpkg.Package, error)

VerifyPackage safely reopens, rehashes, reparses, and rehashes the same file descriptor before returning a package. The second hash detects mutation that overlaps package parsing.

type StageStoreOptions

type StageStoreOptions struct {
	MaxConcurrentFetches      int
	MaxOwnerConcurrentFetches int
	MaxStagedBytes            int64
	MaxOwnerStagedBytes       int64
}

StageStoreOptions bounds concurrent external transfers and retained stage bytes. Quota keys are opaque host-derived owner identifiers and are never persisted.

type StagedArtifact

type StagedArtifact struct {
	ID     string
	Size   int64
	SHA256 string
}

StagedArtifact is a path-free handle to exact bytes owned by StageStore.

Jump to

Keyboard shortcuts

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