Documentation
¶
Overview ¶
Package resolve turns pipe references (baseline §4) into loaded manifests: local project paths, `std:` and `builtin:` pipes, npm packages, git repositories and registry references, with a project-local cache (`.openflange/cache`), the `openflange.lock.yaml` lockfile, integrity hashing, locked verification, transitive resolution and cycle detection.
References and everything they point to are untrusted: paths cannot escape the project (or the fetched package they live in), fetches are bounded and HTTPS-only, npm installs never run lifecycle scripts, git clones never run hooks, no shell is involved, and nothing from a fetched package is executed by this package.
Index ¶
- Constants
- func BytesIntegrity(data []byte) string
- func FindLock(startDir string) string
- func FindRoot(target string) string
- func Integrity(m *manifest.Manifest) (string, error)
- func IsCommit(ref string) bool
- func NpmInstallArgs(prefix, pkg, spec string) []string
- func RemoteBase(rawURL string) (base, id, host, hostport string, err error)
- type Dependency
- type Kind
- type Lockfile
- type Ref
- type Remote
- type Resolver
- func (r *Resolver) FetchRemote(ctx context.Context, rawURL string) (*Remote, error)
- func (r *Resolver) GitCloneArgs(url, ref, dest string) []string
- func (r *Resolver) Key(ref, fromDir string) string
- func (r *Resolver) LocalKey(p string) string
- func (r *Resolver) LockAll(ctx context.Context, targets []string) (*Lockfile, error)
- func (r *Resolver) Resolve(ctx context.Context, ref, fromDir string) (*pipeline.Resolved, error)
- func (r *Resolver) Update(ctx context.Context, targets []string, refs ...string) (*Lockfile, error)
- func (r *Resolver) Verify(ctx context.Context, targets []string) error
Constants ¶
const ( LockFileName = "openflange.lock.yaml" LockSpec = "openflange.org/lock/v0.1" )
Lockfile constants.
const ( MaxDependencies = 10000 MaxDepth = 64 )
Limits against resource exhaustion (lock/v0.1 §7).
const DefaultTimeout = 2 * time.Minute
DefaultTimeout bounds one fetch (npm install, git clone, HTTP request).
const MaxDefinitionBytes = 1 << 20
MaxDefinitionBytes bounds a remote pipe definition.
Variables ¶
This section is empty.
Functions ¶
func BytesIntegrity ¶
BytesIntegrity returns "sha256-<hex>" of data (used for remote definitions).
func FindLock ¶
FindLock walks up from startDir and returns the nearest lockfile path, or "" if there is none.
func FindRoot ¶
FindRoot determines the project root for a target path: the nearest ancestor directory (starting at the target itself, or its directory when it is a file) that contains openflange.lock.yaml, openflange.yaml or .git; otherwise the current working directory if it contains the target; otherwise the target's directory.
func Integrity ¶
Integrity computes the lockfile integrity of a pipe (lock/v0.1 §4): "sha256-" followed by the lower-case hex SHA-256 of the byte string built as follows. Take the file set of m.Files() — the manifest plus every file its frontmatter references: implementation.path, a relative implementation.command[0] and every port schema.path (for a composite, the pipeline file; the pipes it uses are separate lock entries). Express each path relative to the manifest's directory with `/` separators and no leading `./`, sort the paths by their UTF-8 bytes, and for each file append
path + "\x00" + <decimal byte length of content> + "\x00" + content
with the content exactly as stored. A referenced file that is missing is an error (E_PATH), never an empty contribution. A builtin such as `std:filter` has a single file: the runner's canonical manifest, hashed under the path `OPENFLANGE.md`.
func NpmInstallArgs ¶
NpmInstallArgs returns the npm argument vector used to install pkg@spec into prefix. Lifecycle scripts are never run.
func RemoteBase ¶
RemoteBase splits a remote pipe URL (`{base}/pipes/{id}`) into the server base URL, the pipe id and the server's host and host:port.
Types ¶
type Dependency ¶
type Dependency struct {
// Resolved is the exact location: a path relative to the project root
// (`pipes/lowercase`), `std:name@0.1.0`, `npm:pkg@1.2.3[#subpath]`,
// `git:url#<commit>[:subpath]` or the https URL of a remote pipe.
Resolved string
// Version is the pipe contract version.
Version string
// Revision is the commit, npm dist integrity or remote-reported revision
// ("" = null).
Revision string
// Integrity is `sha256-<hex>` (see Integrity).
Integrity string
// Dependencies are the lock keys of the direct dependencies.
Dependencies []string
// Extra holds `x-` extension keys of the entry; preserved on Save.
Extra map[string]any
}
Dependency is one locked reference.
type Lockfile ¶
type Lockfile struct {
// Path is the lockfile's location.
Path string
Dependencies map[string]*Dependency
// Extra holds top-level `x-` extension keys; they are preserved on Save.
Extra map[string]any
}
Lockfile is a parsed `openflange.lock.yaml`.
Keys (lock/v0.1 §3): every reference is keyed exactly as written, except that a relative path reference is rewritten relative to the project root (the lockfile's directory), beginning with `./` or `../` and using `/` separators (for example `./pipes/lowercase`), so that one pipe referenced from several directories has one entry. A relative reference inside a fetched package is written relative to that package's root.
func LoadLock ¶
LoadLock reads a lockfile. A missing file yields an error for which errors.Is(err, os.ErrNotExist) is true; a malformed file yields E_LOCK.
type Ref ¶
type Ref struct {
// Raw is the reference exactly as written.
Raw string
Kind Kind
// Name is the std pipe name, the builtin `<runtime>/<name>`, the npm
// package, the registry `<publisher>/<name>`, or the pypi/cran/oci payload.
Name string
// Range is the version range (std, npm, registry); "" = any.
Range string
// Path is the local path (Local).
Path string
// URL is the repository URL (Git) or the remote pipe URL (HTTP).
URL string
// GitRef is the branch, tag or commit of a git reference ("" = default
// branch).
GitRef string
// Subpath is the manifest sub-path inside an npm package or git repo.
Subpath string
// PipeID is the remote pipe id of an HTTP reference.
PipeID string
}
Ref is a parsed pipe reference.
type Remote ¶
type Remote struct {
URL string
// Manifest is built from the served definition (no attribution check).
Manifest *manifest.Manifest
// Revision is the revision the server reports ("" if none).
Revision string
// Integrity is sha256 over the exact served response body.
Integrity string
// Body is the served definition.
Body []byte
}
Remote is the fetched definition of a remote HTTP pipe.
type Resolver ¶
type Resolver struct {
// Registry provides `std:` and `builtin:` pipes.
Registry *adapter.Registry
// Root is the project root: local references may not escape it (E_PATH).
// A local reference inside a fetched package may not escape that package.
// Empty means unrestricted.
Root string
// CacheDir holds fetched packages (default: Root/.openflange/cache).
CacheDir string
// AllowNetwork permits npm installs, git fetches and HTTP requests. When
// false only the cache is used.
AllowNetwork bool
// Index lazily loads the registry index for `<publisher>/<name>`
// references. Nil means registry references report E_UNSUPPORTED (unless
// they are pinned by the lockfile).
Index func(ctx context.Context) (*registry.Index, error)
// Lock is the project's lockfile, if any. Its entries pin what npm, git
// and registry references resolve to.
Lock *Lockfile
// Locked enforces the lockfile: every reference must have an entry and
// its content must hash to the locked integrity (E_LOCK otherwise).
Locked bool
// AllowInsecureGit permits file:// git URLs. For tests only.
AllowInsecureGit bool
// NpmPath and GitPath override the tools (default: looked up on PATH when
// first needed).
NpmPath, GitPath string
// Timeout bounds one fetch (default DefaultTimeout).
Timeout time.Duration
// Offline forbids every network request, including the fetch of a remote
// pipe's definition that a locked run otherwise performs (lock/v0.1 §6).
Offline bool
// Credentials returns the bearer token for the server of a remote pipe,
// identified by its lower-case "host:port". May be nil. Tokens are only
// ever sent over HTTPS (or to loopback) and never across a redirect.
Credentials func(hostport string) (token string, ok bool)
// Warn receives non-fatal messages (deprecations, references resolved
// outside the lockfile). May be nil; calls may be concurrent.
Warn func(msg string)
// contains filtered or unexported fields
}
Resolver resolves pipe references for a project. It implements pipeline.Resolver and is safe for concurrent use. Configure the exported fields before first use and do not change them afterwards.
func (*Resolver) FetchRemote ¶
FetchRemote fetches and validates the definition of a remote HTTP pipe (`GET {base}/pipes/{id}`) with bounded, SSRF-safe HTTP. The returned manifest is the contract as the server describes it; Resolve turns it into a pipe that the HTTP Pipe Protocol adapter executes on that server.
func (*Resolver) GitCloneArgs ¶
GitCloneArgs returns the git argument vector for a shallow clone of url at ref ("" = default branch) into dest.
func (*Resolver) LocalKey ¶
LocalKey returns the lock key of the local pipe at the absolute path p: its path relative to the project root, beginning with `./` or `../`, or — inside a fetched package — relative to that package's root.
func (*Resolver) LockAll ¶
LockAll resolves every target (pipe directories, manifest files, pipeline files, or references) and, transitively, every `pipe:` reference of every pipeline file involved, and returns a complete lockfile for them. Existing entries of r.Lock stay pinned (npm versions, git commits, registry resolutions are not moved); local pipes are re-hashed; entries that are no longer referenced are pruned; `x-` keys are preserved. Composite cycles are E_CYCLE. All problems are returned together as an errs.List. Nothing is written: call Save on the result.
func (*Resolver) Resolve ¶
Resolve implements pipeline.Resolver. With Locked set, the reference must be in the lockfile and its content must match the locked integrity. A remote HTTP pipe (`https://host/base/pipes/<id>`) resolves to its served definition, bound to an `http` implementation on that server; a locked run still fetches the definition, because its integrity is what the lockfile pins (lock/v0.1 §6).
func (*Resolver) Update ¶
Update is LockAll, except that the named references (lock keys, or references as written) and everything reachable through them are re-resolved to the newest versions their references allow. Without refs every entry is re-resolved.