The App's target exec context's path_filter gets passed to util.copy().
That might be a fine idea, but the semantics are too hard to understand at
this point, so, if copy should be limited by a path filter, it should to be
passed as a query string attached to the source- or target file context.
This commit enforces just that by dropping the default_exec_context
argument to copy().
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
ExecApp's --target parameter and the ec.Local.__init__()'s uri argument carry
"local" as their default value which was meant as a keyword but doesn't pass
as an URI. Fix that.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
The path filter of the exec context filtered the compile's own file
operations: put() and rename() silently no-op on a filtered path, stat()
raises, and the compile swallows that into a false '<missing>' verdict.
A compile-templates run with a path filter therefore reported '@content'
for every template while installing nothing, and left the empty temp files
behind.
The filter scopes the distro's package selection, not the command's own
output. Write the compiled file and its temp unfiltered: put, stat, the
read of the previous output, rename, and unlink. The reads of the template
and of the attribute files keep the filter.
Add a unit test with a context whose package space holds only the template:
the output must be written and no temp must leak.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
Since jw/#170, jw-pkg packages select expects the filter string in
"name:rest" form. The old spec "url =~ janware" is now illegal and breaks
CI, "make pkg-delete-ours" prints an error and deletes nothing.
Fix the filter's spec to "pkg:url=~janware", which matches installed
packages whose URL contains "janware", i.e. our packages.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
apt 3.x distinguishes versions with the same version number by their
control metadata, so a .deb installed with dpkg -i that differs from the
repository's same-version package is regarded as a separate version, and
apt-get install of the package name "upgrades" it to the repository
version, replacing the installed package. If the installed package was
built from the source code repo's master, this is effectively a downgrade
and can break a CI run in currently unintended ways.
This commit detects same-version packages in apt-get's install todo list by
running apt-get -s install (simulate installation), parsing the output, and
removing those packages from the command line of the subsequent, real
install command.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
The exec context's default filter selects paths, not just packages, so the
pkg spelling of the option and environment variable that set it no longer
fit. Rename both and some variables accordingly:
- ExecApp: --pkg-filter becomes --path-filter, and the fallback environment
variable JW_DEFAULT_PKG_FILTER becomes JW_DEFAULT_PATH_FILTER
- Distro: the default_pkg_filter constructor argument and property become
default_path_filter, matching FileContext, ExecContext, and CopyContext;
App and KvFile pass the renamed argument
- Adapt the help test's expected output and the unit tests
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Drop the re-read of JW_DEFAULT_PKG_FILTER, and derive the filter from the
ctor and URI like all other FileContext instances would. Use that to filter
the backend for the packages provinding secrets.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
PackageFilterString and Pkg are duplicates. The PackageFilter and
FileContextFilter base classes live in lib/PackageFilter.py, imported by
Pkg, Distro, and the tests.
Move the two base classes into lib/pf/Pkg.py (where Pkg already lives),
drop PackageFilterString, delete lib/PackageFilter.py, and repoint Distro
and the tests to the new location. Move the test suite with the module to
test/.../pf/Pkg/.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Create an app's exec context with the user-specified path filter, and drop
the ExecApp.path_filter property, now a duplicate of
exec_context.path_filter. Use the latter in the two call sites.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
The select command names PackageFilterString directly, but the filter is a
spec string and the class is resolved dynamically by the loader. Build the
filter through PathFilter.create() so the concrete class no longer appears
at the call site.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
The default package filter is typed PackageFilter, but it is handed over
from file contexts that carry a PathFilter. Widen the default_pkg_filter
parameter.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Add the Pkg path filter to the lib.pf module, the loader-visible home
of the package filter spec. A spec of the form pkg:criterion=~regex
instantiates Pkg through PathFilter.create(). The parsing duplicates the
one of PackageFilterString for now; a later commit consolidates the two.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
This commit moves package-based filtering from the package level to the
path level, using the new path filter framework. Derive PackageFilter from
a new FileContextFilter base, which binds a PathFilter to the FileContext
it guards, and implements _access().
The filter's space is the file list of the packages it selects, taken from
the backing distro's pkg_files(). An address is allowed only if it names
one of those files.
The backing distro is taken from the file context, if the context carries
one, and is otherwise autodetected from the host the context executes on,
so the filter also works on a bare exec context. A context that is not an
exec context and carries no distro rejects path queries with an error.
The filter string now follows the loader syntax, pkg:url=~ regex, and
a bare url=~regex like the old url=~jw.dev form is rejected; update
JW_DEFAULT_PKG_FILTER values accordingly.
PackageFilter's match() is renamed match_pkg(), to make clear that it
matches packages, and Distro._select() calls the new name.
ExecApp.path_filter builds the filter through PathFilter.create() and
binds it to the exec context. CmdSelect passes its argument to the new
constructor, CmdCopy hands the app's filter to the copy, and the App distro
picks it up as the default package filter.
Extend the unit test to cover the space membership and the distro lookup.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Hand the new default_path_filter parameter to the CopyContext copy() opens,
and to the recursive calls it makes for a list of URIs, so an app can limit
the addresses a copy touches the same way it limits its own contexts.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
CopyContext creates its src and dst contexts from URIs when they are
not given as instances. Pass an optional default_path_filter into that
creation, so a copy made under a filter limits the addresses it reads and
writes. A context given as an instance keeps the filter it already carries.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Allow to attach a default path filter to a FileContext, given in the
constructor as default_path_filter, or in the URI query as "path-filter".
Passing False as default_path_filter will make the FileContext ignore any
path-filter in the query.
The filter is created lazily on first use through PathFilter.create(), so a
string spec is loaded from the lib.pf module like any other filter.
Every path based action evaluates the filter before it is carried out.
An IGNORE verdict is logged and the action is skipped: reads and stats
raise FileNotFoundError, writes, unlinks, erases, renames, and mkdirs are
no-ops, and readdir() drops the filtered entries. An ABORT verdict raises
PermissionError.
Every path-driven method also takes a flag parameter, "filtered",
defaulting to True, so a caller that must work regardless of the context's
filter can opt out of the check.
Add a unit test that exercises the verdicts, the filtered bypass, and the
distribution probe on a Local context.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Add the abstract PathFilter class, designed to be attached to a FileContext
in later commits. This is the first commit of a series that generalizes the
JW_DEFAULT_PKG_FILTER / --pkg-filter framework into loadable path filters
that can be attached to any FileContext.
A filter answers an access check, _access(), with a bool. run() turns the
answer into a verdict: ALLOW when the check passes, otherwise ABORT or
IGNORE according to the filter's deny action, LOG or ABORT. The verdict is
handled by the filter's handle, a pair of per-verdict gates: with the ABORT
gate set, an ABORT verdict raises PermissionError; with the LOG gate set,
an IGNORE verdict is logged and returned. A verdict whose gate is not set
passes through unhandled.
Also add the lib.pf module that hosts the concrete filters. A filter spec
of the form foo:something is loaded by PathFilter.create() as the Foo class
from the jw.pkg.lib.pf.Foo module. A spec without the name prefix, or a
name that no module provides, is rejected with an error that names the
expected class and module.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
copy() handed a non-recursive copy of a directory to the single-object
get() path. For a plain context the backend then fails with a transport
error, and for a kvfile store the store root is a branch, not an entry,
so the get() fails with a FileNotFoundError naming a transformed address:
copying "kvfile:///etc" reported "FileNotFoundError: etc".
Require recursive for a directory source that is not fetchable as a whole,
as cp requires -r for directories: copy() now raises with a message naming
the source and the recursive option, instead of falling through to get().
Add a unit test that covers a directory source for a plain context and a
kvfile store.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
SERVICE_SECRET[n] keys of an entry are used as rotation metadata by
downstream software, and their values don't need to be kept secret: they
name the macro and the account that owns it. Encrypting them buys nothing,
and it forces every annotation tool to decrypt and re-encrypt the whole
entry for a one-line read or edit.
Run sops encrypt with --unencrypted-regex SERVICE_SECRET, so the annotation
keys stay plain text in the repository file and the store stays greppable
without the age key, and with --mac-only-encrypted, so the MAC covers the
encrypted values only and the annotation lines can be edited as plain text
without invalidating the file.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
A directory node of the store, the root included, stats as a directory, but
a get on it falls through to the key lookup below its parent and fails with
a FileNotFoundError naming a path the caller never asked for: get() on the
root fails with an empty name, get() on a branch with its parent's compound
path.
Raise IsADirectoryError from _get() when the path is a directory on the
host, after the compound and the blob lookups, so get() and stat() agree: a
directory stats as FT_DIR and refuses a get.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
KvFile.__init__() accepts a host FileContext plus an optional Distro, and
the two may live on different hosts. In effect, files are read from one
host based on another host's package set, which may have its use cases but
is generally undesirable. The context parameter also breaks the uniformity
of the store constructors: Sops, TarGpg, and Vault are constructed from a
URI alone, and FileContext.create() needs a special case that builds the
kvfile store's inner context before handing it to the constructor.
This commit has KvFile constructed from a URI alone like the other stores.
The URI's authority names the host, no authority means "local", and the
constructor builds the inner context through FileContext.create() with
chroot off, forwarding the store's constructor parameters to it. The inner
context is always an exec context, which the distro derivation needs: it is
lazy, Distro.instantiate() runs on the first file listing, with the
JW_DEFAULT_PKG_FILTER environment variable as the default package filter,
as before.
Adapt all call sites:
- FileContext.create(): the kvfile case returns KvFile(uri) directly.
- FilesContext: the distro parameter goes; the store URI is derived from
the exec context's scheme, authority, and path, so a local context with a
hostname in its URI stays local.
- DistroContext.install(): the kvfile source wrap goes; the compounds read
directly through the source context with parse_kv().
- The store tests monkey-patch Distro.instantiate() for the stores that
list something
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
KvFile contains symbol names "addr" or "entry" which look better defined
than they are. I prefer sticking to well-defined names like "path". "path"
in itself is ambiguous and makes it necessary to understand its context,
but so be it: At least it's used uniformly throughout the codebase and
makes it even more obvious that the function it's used in needs to bear a
meaningful name. Which is what this commit does, along with renaming some
member variables to more self-explanatory variants.
In detail, __addr() composes a host path from the URI path and the store's
relpath, __resolve() strips the store's suffixes, __entry_kv() and
__is_entry() operate on a config path that has a .jw-secret file, __subtree
holds the path component of the URI, and __raw holds the context under the
FcCache. The local variables config, entry, real, and blob do not name the
things they hold either.
- The __addr() method becomes __host_path(), its parameter is named
relpath.
- The __resolve() method becomes __strip_suffix().
- The __entry_kv() and __is_entry() methods become __compound_kv() and
__is_compound(), their parameters are named config_path.
- The __subtree and __raw members become __root and __inner.
- The locals config, entry, real, and blob become config_path, compound,
host_path, and secret_path.
Update the error messages and the comments that name the old symbols to use
the new ones.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
KvFile works but is up for a major refactoring: It features an unnecessary
amount of special cases, and its private method names are not
self-explanatory enough. First thing to remove are the code comments,
because they would account for much churn and would be obsolete afterwards
anyway. This commit does it now in the expectation that the move from
package- to path-based filters will also touch KvFile.
Signed-off-by: Jan Lindemann <jan@janware.com>
Uri exposes the query as a raw string only, so a consumer that wants the
query's key/value pairs has to parse the string itself with urllib.parse.
Add a cached property query_dict that returns None when the Uri has no
query and a dictionary of the query's key/value pairs when it does.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
The --pkg-filter flag and the JW_DEFAULT_PKG_FILTER env read live in the
jw.pkg.App, but the filter could have its merits in every application
deriving from lib.ExecApp, so heave the package filter machinery into
ExecApp: flag, filter resolution and the cached pkg_filter property. Then
have jw.pkg.App use self.pkg_filter.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0