lib.ec.secret_store.KvFile: Refactor and construct from a URI #167
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/feature/20261107-lib-ec-secret-store-kvfile-refactor-and-construct-from-a-uri"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR refactors the
KvFilesecret store ahead of the move from package- to path-based filters: it strips the code comments, renames the private symbols, hasKvFileconstruct from a URI alone likeSops,TarGpg, andVault, and makesget()refuse directories so it agrees withstat().lib.ec.secret_store.KvFile: Remove comments
KvFileworks 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 touchKvFile.lib.ec.secret_store.KvFile: Rename private symbols
KvFilecontains symbol namesaddrorentrywhich look better defined than they are. I prefer sticking to well-defined names likepath.pathin 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'srelpath,__resolve()strips the store's suffixes,__entry_kv()and__is_entry()operate on a config path that has a.jw-secretfile,__subtreeholds the path component of the URI, and__rawholds the context under theFcCache. The local variablesconfig,entry,real, andblobdo not name the things they hold either.__addr()method becomes__host_path(), its parameter is namedrelpath.__resolve()method becomes__strip_suffix().__entry_kv()and__is_entry()methods become__compound_kv()and__is_compound(), their parameters are namedconfig_path.__subtreeand__rawmembers become__rootand__inner.config,entry,real, andblobbecomeconfig_path,compound,host_path, andsecret_path.Update the error messages and the comments that name the old symbols to use the new ones.
lib.ec.secret_store.KvFile: Construct from a URI
KvFile.__init__()accepts a hostFileContextplus an optionalDistro, 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, andVaultare constructed from a URI alone, andFileContext.create()needs a special case that builds thekvfilestore's inner context before handing it to the constructor.This commit has
KvFileconstructed from a URI alone like the other stores. The URI's authority names the host, no authority meanslocal, and the constructor builds the inner context throughFileContext.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 theJW_DEFAULT_PKG_FILTERenvironment variable as the default package filter, as before.Adapt all call sites:
FileContext.create(): thekvfilecase returnsKvFile(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(): thekvfilesource wrap goes; the compounds read directly through the source context withparse_kv().Distro.instantiate()for the stores that list somethinglib.ec.secret_store.KvFile: Fail get() on directories
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
FileNotFoundErrornaming 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
IsADirectoryErrorfrom_get()when the path is a directory on the host, after the compound and the blob lookups, soget()andstat()agree: a directory stats asFT_DIRand refuses a get.