fmtres

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package fmtres resolves OpenJD "{{...}}" format strings on the worker, where the session working directory — and therefore Session.WorkingDirectory — is only known at run time.

The server resolves loc:// URIs and the job-parameter space before dispatching an assignment (see internal/scheduler/assign.go); this package performs the remaining, worker-local substitution of format-string references in command lines, argument lists, and environment-variable values.

Scopes

Two resolution contexts exist, matching the OpenJD specification:

  • Task-action context (a step's onRun command and args) exposes Param.<n> / RawParam.<n> (job parameters), Task.Param.<n> / Task.RawParam.<n> (task parameters), and Session.WorkingDirectory.
  • Environment-action context (an environment's onEnter/onExit actions and its variable values) exposes Param.<n> / RawParam.<n> and Session.WorkingDirectory, but NOT Task.Param.* — environments are session-scoped and entered once, not per task.

TaskScope and EnvScope return a fmtstring.MapScope (a plain map) so callers can extend the scope with future keys — such as Task.File.*, Env.File.*, or Session.PathMappingRulesFile — before resolving.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFileVars

func AddFileVars(scope fmtstring.MapScope, prefix string, files []protocol.EmbeddedFile, workDir string) error

AddFileVars sets "<prefix>.<name>" in scope to the absolute on-disk path of each embedded file's materialized location (filepath.Join(workDir, filename), where filename is derived via EmbeddedFileName). prefix is "Task.File" or "Env.File"; the key uses each file's Name. workDir is the absolute session working directory, so the resulting values are absolute paths.

If two files share the same Name, the later entry overwrites the earlier in the scope (last-wins); callers should ensure unique names upstream.

AddFileVars returns an error naming the offending file when a filename is invalid. The scope is mutated in place.

func EmbeddedFileName

func EmbeddedFileName(f protocol.EmbeddedFile) (string, error)

EmbeddedFileName computes the on-disk filename for an embedded file: it uses f.Filename when set, falling back to f.Name. Filenames containing path separators or null bytes are rejected to prevent directory traversal (a defense-in-depth check, since the assignment is server-signed).

This is the single source of truth for the materialized filename, shared by the embedded-file writer and by AddFileVars, so the path placed into Task.File.* / Env.File.* matches exactly where the file is written.

func EnvScope

func EnvScope(jobParams map[string]string, workDir, pathMapFile string, hasPathMap bool) fmtstring.MapScope

EnvScope builds the format-string scope for an environment action (an environment's onEnter/onExit command and args) and for environment variable values.

Unlike TaskScope, the environment scope does NOT expose Task.Param.* / Task.RawParam.*: environments are session-scoped and entered once, not per task. jobParams are exposed as Param.<n> and RawParam.<n>; workDir is exposed as Session.WorkingDirectory. pathMapFile and hasPathMap populate Session.PathMappingRulesFile / Session.HasPathMappingRules exactly as in TaskScope. The returned map may be mutated by the caller to add additional keys before resolving.

func ResolveAction

func ResolveAction(action *protocol.Action, scope fmtstring.Scope) (*protocol.Action, error)

ResolveAction returns a copy of action with its Command and every Args entry resolved against scope. All other fields (TimeoutSeconds, Cancelation) are copied unchanged. A nil action returns (nil, nil).

ResolveAction returns a descriptive error — naming the offending reference — if any reference is malformed or names a variable the scope does not provide. The input action is never mutated.

func ResolveEmbeddedFiles

func ResolveEmbeddedFiles(files []protocol.EmbeddedFile, scope fmtstring.Scope) ([]protocol.EmbeddedFile, error)

ResolveEmbeddedFiles returns copies of files with each file's Data resolved against scope. All other fields (Name, Filename, Runnable, EndOfLine) are copied unchanged. A nil slice returns (nil, nil).

ResolveEmbeddedFiles returns a descriptive error — naming the offending file and reference — when a file's data is malformed or names a variable the scope does not provide. The input slice and its elements are never mutated.

func ResolveVars

func ResolveVars(vars map[string]string, scope fmtstring.Scope) (map[string]string, error)

ResolveVars returns a copy of vars with every value resolved against scope. Keys are copied unchanged. A nil map returns (nil, nil).

ResolveVars returns a descriptive error — naming both the offending variable key and the reference — if any value is malformed or names a variable the scope does not provide. The input map is never mutated.

func TaskScope

func TaskScope(jobParams, taskParams map[string]string, workDir, pathMapFile string, hasPathMap bool) fmtstring.MapScope

TaskScope builds the format-string scope for a task action (a step's onRun command and args).

jobParams are the job-level parameter values (exposed as Param.<n> and RawParam.<n>); taskParams are the per-task parameter values (exposed as Task.Param.<n> and Task.RawParam.<n>); workDir is the session working directory (exposed as Session.WorkingDirectory).

pathMapFile is the absolute path to the written OpenJD path-mapping file and hasPathMap reports whether the assignment carries any path-mapping rules; they populate Session.HasPathMappingRules ("true"/"false") and, when hasPathMap is true, Session.PathMappingRulesFile (otherwise that key is absent).

Param.<n> and RawParam.<n> currently map to the same value; path-mapped (cooked) Param values are a later task. The returned map may be mutated by the caller to add additional keys before resolving.

Types

This section is empty.

Jump to

Keyboard shortcuts

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