saltext.vault.utils.vault.helpers

Several utility functions for the Vault modules

saltext.vault.utils.vault.helpers.get_salt_run_type(opts: dict[str, Any]) Literal[0, 1, 2, 3, 4][source]

Determine the current operation’s calling context from specific markers in __opts__ and the vault config. Possible contexts:

  • regular minion, credentials issued by master (e.g. via salt-call or salt minion_id)

  • regular minion, locally configured (e.g. via salt-call or salt minion_id)

  • regular master (e.g. via salt-run)

  • master impersonating a minion (during pillar compilation or via salt-ssh)

  • master called via peer running (e.g. when a minion requests new credentials)

saltext.vault.utils.vault.helpers.iso_to_timestamp(iso_time: str) int[source]

Most endpoints respond with RFC3339-formatted strings This is a hacky way to use inbuilt tools only for converting to a timestamp

saltext.vault.utils.vault.helpers.expand_pattern_lists(pattern: str, **mappings) list[str][source]

Expands the pattern for any list-valued mappings, such that for any list of length N in the mappings present in the pattern, N copies of the pattern are returned, each with an element of the list substituted.

pattern

A pattern to expand, for example by-role/{pillar[roles]}

mappings

A dictionary of variables that can be expanded into the pattern.

Example: Given the pattern `` by-role/{pillar[roles]}`` and the below pillar

roles:
  - web
  - database

This function expands into two patterns, [by-role/web, by-role/database].

Note that this method does not expand any non-list patterns.

saltext.vault.utils.vault.helpers.timestring_map(val: int | float | str, cast: type[int]) int[source]
saltext.vault.utils.vault.helpers.timestring_map(val: int | float | str, cast: type[float] = float) float
saltext.vault.utils.vault.helpers.timestring_map(val: int | float | str) float
saltext.vault.utils.vault.helpers.timestring_map(val: int | float | str | None, cast: type[int]) int | None
saltext.vault.utils.vault.helpers.timestring_map(val: int | float | str | None) float | None
saltext.vault.utils.vault.helpers.timestring_map(val: int | float | str | None, cast: type[float] = float) float | None

Turn a time string (like 60m) into a float with seconds as a unit.

saltext.vault.utils.vault.helpers.dec2hex(decval: int | str) str[source]

Converts decimal values to nicely formatted hex strings

saltext.vault.utils.vault.helpers.filter_state_internal_kwargs(kwargs: dict[str, Any]) dict[str, Any][source]

Removes state-internal kwargs from a kwargs dict.

saltext.vault.utils.vault.helpers.deserialize_csl(data: None) None[source]
saltext.vault.utils.vault.helpers.deserialize_csl(data: str | list[str]) list[str]

Ensure a value is a proper Python list, not a string containing a comma-separated list.

saltext.vault.utils.vault.helpers.filter_unset(data: Mapping[K, V | None], unset: None = None) dict[K, V][source]
saltext.vault.utils.vault.helpers.filter_unset(data: Mapping[K, V | EllipsisType], unset: EllipsisType) dict[K, V]
saltext.vault.utils.vault.helpers.filter_unset(data: Mapping[K, V], unset: object) dict[K, V]

Remove all unset values in a dictionary and return the filtered result.

data

Dictionary to filter.

unset

Identity of what counts as unset; evaluated via is not. Defaults to None. Other working examples: ... (ellipsis), a specific object such as salt.defaults.NOT_SET or a string literal (not recommended though).

saltext.vault.utils.vault.helpers.try_base64(data: str | bytes) tuple[bytes, bool][source]

Given a string or bytes input, check if it is valid Base64 and decode it if so. Otherwise, return the raw bytes.

Returns a tuple of output, was_base64.

saltext.vault.utils.vault.helpers.x_of(*, _min=1, _max=1, _reason=None, _predicate=<function <lambda>>, **kwargs)[source]

Ensure a minimum and maximum number of parameters passed as keyword arguments to this function satisfy a predicate. By default, exactly one parameter must be not None.

_min

Minimum number of params that must satisfy _predicate. Defaults to 1.

_max

Maximum number of params that must satisfy _predicate. Defaults to 1.

_predicate

Predicate function that receives the value of each passed kwarg and returns a boolean. Defaults to bool.

kwargs

Pass all parameters to check by name (which is included in the error message).

saltext.vault.utils.vault.helpers.one_of(*, _reason=None, _predicate=<function <lambda>>, **kwargs)[source]

Ensure exactly one of the passed-in kwargs satsifies a predicate.

_predicate

Predicate function that receives the value of each passed kwarg and returns a boolean. Defaults to lambda x: x is not None.

kwargs

Pass all parameters to check by name (which is included in the error message).

saltext.vault.utils.vault.helpers.none_of(*, _reason, _predicate=<function <lambda>>, **kwargs)[source]

Ensure none one of the passed-in kwargs satsifies a predicate.

_predicate

Predicate function that receives the value of each passed kwarg and returns a boolean. Defaults to lambda x: x is not None.

kwargs

Pass all parameters to check by name (which is included in the error message).

saltext.vault.utils.vault.helpers.in_vals(vals: Sequence[T], *, _multi: Literal[True], **kwargs: object) list[T][source]
saltext.vault.utils.vault.helpers.in_vals(vals: Sequence[T], *, _multi: Literal[False] = False, **kwargs: object) T

Ensure an input is a subset of allowed values. Raises an exception if validation fails, otherwise returns the normalized value. By default, the input must be exactly one of the allowed values. A single variadic keyword argument defines the parameter name to include in the error message and the value to check.

vals

A sequence of allowed values.

_multi

Allow a sequence of more than one allowed value. Defaults to false. If true, the return is ensured to be a list. Otherwise, returns the validated value as passed in.