Skip to content

Commit

Permalink
feat: add from_file resolver + fix cache
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoVoges committed Sep 13, 2023
1 parent a24f05a commit 08ff2f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions kapitan/inventory/omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def load_class(self, target: InventoryTarget, class_name: str):
target.classes_redundancy_check.add(class_path)

# search in inventory classes cache, otherwise load class
if class_path in self.classes_cache.keys():
if class_name in self.classes_cache.keys():
return self.classes_cache[class_name]

# check if file exists
Expand Down Expand Up @@ -369,7 +369,7 @@ def load_class(self, target: InventoryTarget, class_name: str):
inv_class.dependents.append(c)

# add class to cache
self.classes_cache[class_path] = inv_class
self.classes_cache[class_name] = inv_class

return inv_class

Expand Down
10 changes: 10 additions & 0 deletions kapitan/inventory/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ def relpath(path: str, _node_):
return relative_interpolation


def from_file(path: str):
if os.path.isfile(path):
with open(path, "r") as f:
return f.read()
else:
logger.error(f"from_file: file {path} does not exist")
raise


def write_to_key(destination: str, origin: str, _root_):
"""
resolver function to write any content to different place in the inventory
Expand Down Expand Up @@ -215,6 +224,7 @@ def register_resolvers(inventory_path: str) -> None:
OmegaConf.register_new_resolver("add", lambda x, y: x + y, replace=replace)
OmegaConf.register_new_resolver("default", default, replace=replace)
OmegaConf.register_new_resolver("write", write_to_key, replace=replace)
OmegaConf.register_new_resolver("from_file", from_file, replace=replace)

# boolean algebra
OmegaConf.register_new_resolver("if", condition_if, replace=replace)
Expand Down
3 changes: 2 additions & 1 deletion kapitan/refs/secrets/vaultkv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from hvac.exceptions import Forbidden, InvalidPath

from kapitan import cached
from kapitan.refs.base import RefError, _ALREADY_EXISTING_SECRET_
from kapitan.refs.base import _ALREADY_EXISTING_SECRET_, RefError
from kapitan.refs.base64 import Base64Ref, Base64RefBackend
from kapitan.refs.vault_resources import VaultClient, VaultError

Expand Down Expand Up @@ -199,6 +199,7 @@ def _decrypt(self):
data.decode()
)
)
# TODO: don't have 'secret' as default (throw error instead)
mount = self.vault_params.get("mount", "secret")
secret_path = data_attrs[0]
secret_key = data_attrs[1]
Expand Down

0 comments on commit 08ff2f5

Please sign in to comment.