Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "splight-lib"
version = "5.24.10"
version = "5.24.11"
description = "Splight Python Library"
authors = [
{name = "Splight Dev",email = "dev@splight.com"}
Expand Down
24 changes: 19 additions & 5 deletions splight_lib/models/_v3/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
from splight_lib.models._v3.asset import Asset
from splight_lib.models._v3.attribute import Attribute
from splight_lib.models._v3.data_address import DataAddresses as DLDataAddress
from splight_lib.models._v3.exceptions import InvalidObjectInstance
from splight_lib.models._v3.exceptions import (
InvalidObjectInstance,
SecretNotFound,
)
from splight_lib.models._v3.file import File
from splight_lib.models._v3.secret import Secret
from splight_lib.models._v3.variable_types import CUSTOM_TYPES, NATIVE_TYPES
Expand Down Expand Up @@ -187,17 +190,28 @@ class Component(SplightDatabaseBaseModel):
**DATALAKE_TYPES,
}

VALID_CONTEXTS = {"secret", "secrets"}


def parse_variable_string(raw_value: str | None) -> Any:
if raw_value is None:
return ""
pattern = re.compile(r"^\$\{\{(\w+)\.(\w+)\}\}$")
# NOTE: The patter could be changed to a generalized form
# to accept different vars
pattern = re.compile(r"^\$\{\{(?P<context>\w+)\.(?P<key>\w+)\}\}$")
match = pattern.search(raw_value)
if not match:
return raw_value
_, secret_name = match.groups()
# TODO: handle errors (not found or not allowed)
secret = Secret.decrypt(name=secret_name)
context = match.group("context")
key = match.group("key")
if context not in VALID_CONTEXTS:
raise ValueError(f"Invalid reference: {raw_value}")

try:
secret = Secret.decrypt(name=key)
except Exception:
raise SecretNotFound()

return secret.value


Expand Down
Loading