hyera.backends
Data backends: a self-registering Backend registry.
Every format or provider is a :class:Backend subclass. Registration is by
subclassing (NAMES, keyed by namespace) rather than an explicit call;
lookup goes through :meth:Backend.find/:meth:Backend.get/:meth:Backend.new.
SOPS_TIMEOUT = 30
module-attribute
Backend(conf=None, *, strict=None)
A data format and/or Hiera 5 provider, registered by name.
A subclass registers itself by declaring NAMES, a mapping of
namespace (one of :attr:KINDS) to the names (plain strings and/or
:class:NamePattern) it answers to in that namespace. Puppet function
names (data_hash/lookup_key/data_dig values in a v5
hierarchy), v3 backend names, plain format names and CLI/render names
are separate namespaces -- a name is only ever looked up within one.
Anything a backend does not implement raises :class:NotImplementedError
from the methods below (the base class's defaults); callers turn that
into a specific, user-facing error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conf
|
Optional[Mapping[str, Any]]
|
the hierarchy entry's/ |
None
|
strict
|
Optional[Union[Strict, str]]
|
overrides the call-time default (see :attr: |
None
|
Source code in src/hyera/backends/_base.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
EXTENSIONS = ()
class-attribute
KINDS = ('function', 'v3', 'format', 'render')
class-attribute
NAMES = {}
class-attribute
conf = conf or {}
instance-attribute
limits
property
The :class:~hyera.Limits of the read in progress, or None
when nothing is bounded. A backend that parses untrusted text honours
the fields it can.
name = type(self)._default_name()
instance-attribute
strict
property
This backend's effective strictness: an explicit constructor
value, else the call-time default (see :func:_default_strict).
Never cache a result that depends on this -- it can change call to
call once the ContextVar-backed default lands.
__init_subclass__(**kwargs)
Source code in src/hyera/backends/_base.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
check_available()
classmethod
Raise :class:BackendError if this backend cannot be used (e.g.
a missing optional dependency). A no-op by default.
Source code in src/hyera/backends/_base.py
403 404 405 406 | |
data_dig(key_segments, options, context)
The data_dig provider hook: resolve one already-split
key_segments path in one hierarchy location. Raises
:class:NotImplementedError unless overridden.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_segments
|
Sequence[str]
|
the already-split dotted key path. |
required |
options
|
Mapping[str, Any]
|
the hierarchy entry's |
required |
context
|
LookupContext
|
the per-location :class: |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the found value. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
the base class; a subclass must
override this to support |
Source code in src/hyera/backends/_base.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
data_hash(path, options, context)
The data_hash provider hook: parse the whole file at
path and adapt it into hiera data (see :meth:_as_data_hash).
The base implementation is a file function: it accepts only a
single path location and no hierarchy options
(:meth:_require_path_only), Puppet's own yaml_data/
json_data/hocon_data contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
'Path'
|
the location's file path. |
required |
options
|
Mapping[str, Any]
|
the hierarchy entry's |
required |
context
|
LookupContext
|
the per-location :class: |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
the parsed data, adapted into a hash. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
|
BackendError
|
the file could not be read or parsed. |
Source code in src/hyera/backends/_base.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
dump(obj, fp, **kw)
Render obj and write it to the open text file fp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
the value to render. |
required |
fp
|
'_ty.IO[str]'
|
the open text file to write to. |
required |
kw
|
Any
|
format-specific rendering options. |
{}
|
Source code in src/hyera/backends/_base.py
485 486 487 488 489 490 491 492 | |
dumps(obj, **kw)
Render obj back to text. Raises path-free problem text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
the value to render. |
required |
kw
|
Any
|
format-specific rendering options. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
the rendered text. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
the base class; a subclass must
override this to support |
Source code in src/hyera/backends/_base.py
422 423 424 425 426 427 428 429 430 431 432 433 | |
find(name, kind='function')
classmethod
The registered class for name in kind, or None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the registered name (or a matching pattern) to find. |
required |
kind
|
Union[BackendKind, str]
|
the namespace to search. |
'function'
|
Returns:
| Type | Description |
|---|---|
'_ty.Optional[_ty.Type[Backend]]'
|
the class, or |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
Source code in src/hyera/backends/_base.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
for_path(path)
classmethod
The format-namespace backend class whose :attr:EXTENSIONS
has the longest case-sensitive suffix match against path, or
None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, 'os.PathLike[str]']
|
the file path to match. |
required |
Returns:
| Type | Description |
|---|---|
'_ty.Optional[_ty.Type[Backend]]'
|
the class, or |
Source code in src/hyera/backends/_base.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
get(name, kind='function')
classmethod
The registered, available class for name in kind.
Raises :class:ValueError for an unknown name (listing the known
names) and, via :meth:check_available, :class:BackendError for a
registered backend whose optional dependency is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the registered name (or a matching pattern) to get. |
required |
kind
|
Union[BackendKind, str]
|
the namespace to search. |
'function'
|
Returns:
| Type | Description |
|---|---|
'_ty.Type[Backend]'
|
the class. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
BackendError
|
|
Source code in src/hyera/backends/_base.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
implements(op)
classmethod
Whether this class overrides what op needs.
load/dump follow loads/dumps; data_hash is true
when data_hash or loads is overridden (the base
data_hash delegates to load -> loads).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
str
|
one of |
required |
Returns:
| Type | Description |
|---|---|
bool
|
whether this class implements |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/hyera/backends/_base.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
load(source)
Parse source -- a path-like or a file object.
Reads the bytes and decodes them as strict UTF-8 (Puppet's data
files are read this way: pops/lookup/context.rb:53); a str
already produced by a text file object is used as-is. A decode
error, or the problem text of a :class:BackendError from
:meth:loads, is re-raised (outside the except block, so
neither holds the original as __cause__/__context__) as
BackendError("Unable to parse (<path>): <problem>", path=...).
Because .path is set here, a caller (_LocationStore.load_file) does
not need to prefix it again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Union[str, 'os.PathLike[str]', '_ty.IO[str]', '_ty.IO[bytes]']
|
a path-like, or an already-open file object. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the parsed value. |
Raises:
| Type | Description |
|---|---|
BackendError
|
|
Source code in src/hyera/backends/_base.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
loads(text)
Parse text (a str). Raises path-free problem text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the text to parse. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the parsed value. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
the base class; a subclass must
override this to support |
Source code in src/hyera/backends/_base.py
410 411 412 413 414 415 416 417 418 419 420 | |
lookup_key(key, options, context)
The lookup_key provider hook: resolve one dotted key in
one hierarchy location. Raises :class:NotImplementedError unless
overridden (see :class:EyamlBackend).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
the dotted key to resolve. |
required |
options
|
Mapping[str, Any]
|
the hierarchy entry's |
required |
context
|
LookupContext
|
the per-location :class: |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the found value. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
the base class; a subclass must
override this to support |
Source code in src/hyera/backends/_base.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
names(kind='function')
classmethod
Registered names in kind: exact names in registration order,
then patterns by their :attr:NamePattern.display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
Union[BackendKind, str]
|
the namespace to list. |
'function'
|
Returns:
| Type | Description |
|---|---|
List[str]
|
the registered names. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
Source code in src/hyera/backends/_base.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
new(name, conf=None, *, kind='function', strict=None)
classmethod
Instantiate the registered backend for name in kind.
Any named groups captured by a matching :class:NamePattern are
passed as constructor keywords. .name is set to name (the
name actually asked for, which may be a pattern instance such as
sops_json, not the class's default name).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the registered name (or a matching pattern) to instantiate. |
required |
conf
|
Optional[Mapping[str, Any]]
|
passed to the backend's constructor. |
None
|
kind
|
Union[BackendKind, str]
|
the namespace to search. |
'function'
|
strict
|
Optional[Union[Strict, str]]
|
passed to the backend's constructor. |
None
|
Returns:
| Type | Description |
|---|---|
'Backend'
|
the new instance. |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
|
BackendError
|
|
Source code in src/hyera/backends/_base.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
BackendError(*args, path=None)
Bases: HieraError, ValueError
A data file could not be read or parsed. .path names it.
Also a :class:ValueError.
Source code in src/hyera/exceptions.py
37 38 39 | |
BackendKind
Bases: _StrEnum
Which of :attr:Backend.KINDS a registered name belongs to: the
kind= argument of :meth:Backend.find/:meth:Backend.get/
:meth:Backend.new/:meth:Backend.names. A name is only ever
registered, and looked up, within one namespace.
FORMAT = 'format'
class-attribute
instance-attribute
A plain data-format name, also matched by :meth:Backend.for_path's
file-extension lookup (yaml, json, ...).
FUNCTION = 'function'
class-attribute
instance-attribute
A Hiera 5 hierarchy entry's data_hash/lookup_key/
data_dig function name (yaml_data, json_data, ...).
RENDER = 'render'
class-attribute
instance-attribute
A puppet lookup --render-as output format (s, json,
yaml).
V3 = 'v3'
class-attribute
instance-attribute
A Hiera 3/hiera3_backend backend name (yaml, json, ...).
DotenvBackend(conf=None, *, strict=None)
Bases: Backend
dotenv, in exactly the shape the sops CLI's writer emits it
(stores/dotenv/store.go) -- reachable only through
:class:SopsBackend.
Source code in src/hyera/backends/_base.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
EXTENSIONS = ('.env',)
class-attribute
NAMES = {'format': ('dotenv',)}
class-attribute
loads(text)
Parse dotenv the way sops's own writer emits it: KEY=value
lines, # comments, blank lines skipped, \n unescaped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the dotenv text to parse. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
the parsed key/value pairs. |
Raises:
| Type | Description |
|---|---|
BackendError
|
a non-blank, non-comment line has no |
Source code in src/hyera/backends/_sops.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
EyamlBackend(conf=None, *, strict=None)
Bases: Backend
Puppet's hiera-eyaml lookup_key function, PKCS7 only (behind the
optional eyaml extra). Ports functions/eyaml_lookup_key.
rb:25-79: the raw .eyaml file loads once per change (through
:meth:~hyera._lookup.function_provider.LookupContext.cached_file_data, its
raw parse only -- caching the non-Hash rule's strict-sensitive result
would freeze whichever strictness read it first, exactly the trap
_LocationStore.load_file guards against for data_hash), then each
requested key's value is decrypted (:func:hyera.backends._eyaml.decrypt_string);
the engine keeps that result until the file changes. The raw hash is
never returned to the engine, and its
values are never interpolated except through
:func:~hyera.backends._eyaml.decrypt_string's own trailing context.
interpolate call.
Source code in src/hyera/backends/_base.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
NAMES = {'function': ('eyaml_lookup_key',)}
class-attribute
check_available()
classmethod
Raise :class:BackendError naming the eyaml extra
when cryptography is not importable.
Source code in src/hyera/backends/_eyaml.py
330 331 332 333 334 | |
lookup_key(key, options, context)
Decrypt key's PKCS7 ENC[...] value from the .eyaml
file named by the hierarchy location, matching Puppet's
eyaml_lookup_key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
the key to decrypt. |
required |
options
|
Mapping[str, Any]
|
the hierarchy entry's |
required |
context
|
LookupContext
|
the per-location :class: |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the decrypted (and interpolated) value. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
no |
BackendError
|
the private key or ciphertext could not be read, parsed or decrypted. |
Source code in src/hyera/backends/_eyaml.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
HOCONBackend(conf=None, *, strict=None, hocon_includes=None, hocon_env=None)
Bases: Backend
HOCON (.conf) data via the optional pyhocon package.
Always registered: a missing/broken pyhocon fails at
:meth:check_available (backend/level construction) and again in
:meth:loads, both naming the hocon extra -- so the failure
is always reachable instead of silently disappearing from
:func:default_backends.
include directives resolve exactly as Puppet's own hocon_data
does by default (see :func:_allow_hocon_includes for the
rule): a plain quoted include contributes
nothing, include file(...) really reads the file (relative to the
process cwd, or absolute), and every other form (url(...),
classpath(...), required(...), package(...), a
case-mismatched keyword, a bare include with nothing valid after
it) raises, matching Puppet's own parse/method errors for those forms.
A value-position directive (including inside a [...] array) is
kept as literal text, as Puppet keeps it.
Passing hocon_includes=False (to the constructor directly, or via
a hocon_includes: false key on the hierarchy entry/defaults --
hyera's own extension, not Puppet vocabulary) restricts it instead
(see :func:_refuse_hocon_includes): every
directive form other than a plain quoted include raises, including
file(...).
In either mode, pyhocon's own include entry points are also wrapped
(see :func:_install_hocon_include_guard) as a fail-closed backstop
for the forms that mode does not intend to resolve for real, so a gap
in the text scanner still fails closed instead of silently reading a
file or reaching the network. Durations are parsed via a private
module copy (see :func:_hocon_parser) so they stay text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conf
|
Optional[Mapping[str, Any]]
|
the hierarchy entry's/ |
None
|
strict
|
Optional[str]
|
overrides the call-time default. |
None
|
hocon_includes
|
Optional[bool]
|
|
None
|
hocon_env
|
Optional[bool]
|
|
None
|
Source code in src/hyera/backends/_hocon.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
EXTENSIONS = ('.conf',)
class-attribute
NAMES = {'function': ('hocon_data',), 'format': ('hocon',)}
class-attribute
hocon_env = bool(hocon_env)
instance-attribute
hocon_includes = bool(hocon_includes)
instance-attribute
check_available()
classmethod
Raise :class:BackendError naming the hocon extra
when pyhocon is not importable.
Source code in src/hyera/backends/_hocon.py
397 398 399 400 401 402 | |
data_hash(path, options, context)
The data_hash hook. Besides path, the hierarchy options
accepted are hocon_includes (a Boolean), which selects the include
mode for this level, and hocon_env (a Boolean), which allows or
stops reading the process environment; any other option raises as
for every built-in file function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Any
|
the location's file path. |
required |
options
|
Mapping[str, Any]
|
the hierarchy entry's |
required |
context
|
LookupContext
|
the per-location :class: |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
the parsed data. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
|
BackendError
|
the file could not be read or parsed. |
Source code in src/hyera/backends/_hocon.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
loads(text)
Parse HOCON the way Puppet's hocon_data does: include
file(...) really reads the file, include url(...)/
classpath(...)/required(...) and durations raise/stay text
(see the class docstring for the full fidelity rule).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the HOCON text to parse. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the parsed value. |
Raises:
| Type | Description |
|---|---|
BackendError
|
|
Source code in src/hyera/backends/_hocon.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
JSONBackend(conf=None, *, strict=None)
Bases: Backend
JSON (.json) data, matching Ruby's json gem: /* *//
// ... comments allowed, NaN/Infinity/-Infinity and a
lone (unpaired) surrogate code point rejected.
Source code in src/hyera/backends/_base.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
EXTENSIONS = ('.json',)
class-attribute
NAMES = {'function': ('json_data',), 'format': ('json',)}
class-attribute
dumps(obj, **kw)
Render obj as JSON, with non-ASCII characters left as-is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
the value to render. |
required |
kw
|
Any
|
forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
the rendered JSON text. |
Source code in src/hyera/backends/_json.py
164 165 166 167 168 169 170 171 172 | |
loads(text)
Parse JSON the way Ruby's json gem does: /* *////
comments allowed, NaN/Infinity/-Infinity and a lone
surrogate rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the JSON text to parse. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the parsed value. |
Raises:
| Type | Description |
|---|---|
BackendError
|
|
Source code in src/hyera/backends/_json.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
LookupContext(function_context, invocation)
The context argument handed to a lookup_key/data_dig
backend hook (Puppet's public Context API, context.rb:126-206).
Built by the engine for each call; a backend never constructs one
itself. A test builds one with :meth:for_testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function_context
|
_FunctionContext
|
the per-location state to read/write through. |
required |
invocation
|
Invocation
|
the current lookup's per-lookup state. |
required |
Source code in src/hyera/_lookup/function_provider.py
347 348 349 350 351 352 353 354 | |
environment_name
property
The current lookup's environment name, or None.
module_name
property
The current hierarchy entry's module name, or None at the
global/environment layer.
cache(key, value)
Cache value under key for this location, for the life of
the owning Hiera/h.scoped(...) view. Returns value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
the cache key. |
required |
value
|
Any
|
the value to cache. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
|
Source code in src/hyera/_lookup/function_provider.py
419 420 421 422 423 424 425 426 427 428 | |
cache_all(mapping)
:meth:cache every key/value pair of mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
Mapping[Any, Any]
|
the key/value pairs to cache. |
required |
Source code in src/hyera/_lookup/function_provider.py
430 431 432 433 434 435 | |
cache_has_key(key)
Whether key was already :meth:cache\ d for this location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
the cache key. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
whether |
Source code in src/hyera/_lookup/function_provider.py
437 438 439 440 441 442 443 | |
cached_entries()
An iterator over every (key, value) pair :meth:cache\ d
for this location.
Returns:
| Type | Description |
|---|---|
'_ty.Iterator[_ty.Tuple[_ty.Any, _ty.Any]]'
|
an iterator of |
Source code in src/hyera/_lookup/function_provider.py
453 454 455 456 457 458 459 | |
cached_file_data(path, parse=None)
The cached result of parse(text) (or the raw text when
parse is None) for the file at path, shared with every
other location of this Hiera instance (see
:class:_EnvironmentContext).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, 'os.PathLike[str]']
|
the file to read. |
required |
parse
|
Optional[Callable[[str], Any]]
|
applied to the file's text; identity when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
the (cached) parsed result, or raw text. |
Raises:
| Type | Description |
|---|---|
BackendError
|
|
Source code in src/hyera/_lookup/function_provider.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
cached_value(key)
The value :meth:cache\ d under key, or None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
the cache key. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the cached value, or |
Source code in src/hyera/_lookup/function_provider.py
445 446 447 448 449 450 451 | |
explain(producer)
Add producer's text to this lookup's explain() report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
producer
|
Callable[[], str]
|
a zero-argument callable producing the text. |
required |
Source code in src/hyera/_lookup/function_provider.py
412 413 414 415 416 417 | |
for_testing(*, scope=None, module_name=None, data=None)
classmethod
A context to call a hook with outside a lookup.
:meth:cache, :meth:cached_file_data and :meth:explain behave as
in a lookup, except that :meth:explain never calls its producer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Optional[Scope]
|
what :meth: |
None
|
module_name
|
Optional[str]
|
the value of :attr: |
None
|
data
|
Optional[Mapping[str, Any]]
|
the keys |
None
|
Returns:
| Type | Description |
|---|---|
'LookupContext'
|
the new context. |
Source code in src/hyera/_lookup/function_provider.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
interpolate(value)
Interpolate value (methods allowed) against the current
lookup's scope -- a backend calls this itself; the engine never
interpolates a lookup_key/data_dig result on its own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
the value (or nested structure) to interpolate. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the interpolated result. |
Source code in src/hyera/_lookup/function_provider.py
394 395 396 397 398 399 400 401 402 | |
not_found()
Signal a miss for this location -- Puppet's throw :no_such_key.
Raises:
| Type | Description |
|---|---|
Exception
|
always; the raised object is an internal control-flow signal, not a documented public exception. |
Source code in src/hyera/_lookup/function_provider.py
404 405 406 407 408 409 410 | |
NamePattern
Bases: NamedTuple
A registered name that matches by regex instead of exact string.
regex is matched with :meth:re.Pattern.fullmatch; its named groups
are passed as keyword arguments to the backend's constructor.
display
instance-attribute
regex
instance-attribute
RubySymbol(name)
A Ruby :symbol value (!ruby/sym/!ruby/symbol, or a plain
:name scalar). Not a str subclass -- no string-typed code path
should ever accept one by accident.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the symbol's name, without the leading |
required |
Source code in src/hyera/backends/_psych.py
31 32 | |
__slots__ = ('_name',)
class-attribute
instance-attribute
name
property
The symbol's name, without the leading :.
__eq__(other)
Source code in src/hyera/backends/_psych.py
39 40 41 42 | |
__hash__()
Source code in src/hyera/backends/_psych.py
49 50 | |
__ne__(other)
Source code in src/hyera/backends/_psych.py
44 45 46 47 | |
__reduce__()
Source code in src/hyera/backends/_psych.py
52 53 | |
__repr__()
Source code in src/hyera/backends/_psych.py
55 56 | |
SopsBackend(conf=None, *, strict=None, format=None, timeout=None)
Bases: Backend
Decrypted on the fly via the sops CLI (sops_data; the
one kept non-Puppet deviation).
Hardened for unattended use: the subprocess has a finite timeout and
its whole process group is killed when it expires (a
:class:BackendTimeoutError), its stdin is the null device, its
stderr is captured and surfaced (the last 2,000 characters), a missing
sops binary raises a clear :class:BackendError,
and a decrypted file that fails to parse reports only the problem and
its line/column -- never the decrypted plaintext.
sops_data and sops infer the format from the file extension
with sops's own rule (:data:_SOPS_SUFFIXES); the sops_<format>
name (a :class:NamePattern, added in a later commit alongside the
sops alias) forces one regardless of extension via the format
constructor keyword.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conf
|
Optional[Mapping[str, Any]]
|
the hierarchy entry's/ |
None
|
strict
|
Optional[str]
|
overrides the call-time default. |
None
|
format
|
Optional[str]
|
forces the decrypted plaintext's format
( |
None
|
timeout
|
Optional[float]
|
seconds to wait for |
None
|
Raises:
| Type | Description |
|---|---|
ConfigError
|
|
Source code in src/hyera/backends/_sops.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
NAMES = {'function': ('sops_data', 'sops', NamePattern('sops_<yaml|json|ini|dotenv>', re.compile('sops_(?P<format>yaml|json|ini|dotenv)')))}
class-attribute
data_hash(path, options, context)
Decrypt path with the sops CLI and parse the plaintext
in the format sops itself reports for it (or the format
constructor keyword, when given).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
'Path'
|
the encrypted file's location. |
required |
options
|
Mapping[str, Any]
|
the hierarchy entry's |
required |
context
|
LookupContext
|
the per-location :class: |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
the decrypted, parsed data. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
|
BackendError
|
|
Source code in src/hyera/backends/_sops.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
YAMLBackend(conf=None, *, strict=None)
Bases: Backend
YAML (.yaml/.yml) data via Puppet's own Psych-compatible
rules (:mod:hyera.backends._psych): numbers/booleans/dates/symbols
parse Ruby's way, and a non-Hash top-level document warns (or raises
under strict="error") and reads as empty.
Source code in src/hyera/backends/_base.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
EXTENSIONS = ('.yaml', '.yml')
class-attribute
NAMES = {'function': ('yaml_data',), 'format': ('yaml',)}
class-attribute
dumps(obj, **kw)
Render obj as YAML (block style, sorted keys off, Unicode
left unescaped).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
the value to render. |
required |
kw
|
Any
|
forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
the rendered YAML text. |
Source code in src/hyera/backends/_yaml.py
46 47 48 49 50 51 52 53 54 55 56 57 | |
loads(text)
Parse YAML the way Puppet's yaml_data does (Ruby Psych
semantics via :mod:hyera.backends._psych), not PyYAML's own
Python-flavored resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the YAML text to parse. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the parsed value. |
Source code in src/hyera/backends/_yaml.py
32 33 34 35 36 37 38 39 40 41 42 43 44 | |
default_backends()
The distinct backend classes registered in the function
namespace, in definition order (YAML, JSON, HOCON, sops, eyaml).
Returns:
| Type | Description |
|---|---|
'_ty.List[_ty.Type[Backend]]'
|
the default |
Source code in src/hyera/backends/_base.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | |
has_hocon()
True iff the optional pyhocon dependency imports without error.
Any import-time exception (not just ImportError -- an installed but
broken pyhocon can raise something else entirely, e.g.
AttributeError against a too-new stdlib) is caught and logged at
debug, so a broken optional dependency never breaks every Hiera().
Returns:
| Type | Description |
|---|---|
bool
|
whether |
Source code in src/hyera/backends/_hocon.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |