Skip to content

Commit

Permalink
Separate validation from loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Dec 12, 2023
1 parent 8e3e72c commit cc396e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions prototypes/python/src/opentelemetry/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
process_schema,
render_schema,
create_object,
load_configuration
)

__all__ = [
Expand All @@ -32,4 +33,5 @@
"process_schema",
"render_schema",
"create_object",
"load_configuration"
]
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ def resolve_schema(json_file_path) -> dict:
return dictionary


def validate_configuration(configuration_file_path: str) -> dict:
def load_configuration(configuration_file_path: str) -> dict:

with open(configuration_file_path, "r") as configuration_file:

configuration = safe_load(configuration_file)
return safe_load(configuration_file)


def validate_configuration(configuration: dict):

root_path = Path(getcwd()).parent.parent

Expand All @@ -63,10 +66,8 @@ def retrieve_from_path(path: str):
registry=Registry(retrieve=retrieve_from_path)
).validate(configuration)

return configuration


def process_schema(schema: dict):
def process_schema(schema: dict) -> dict:

type_type = {
"integer": "int",
Expand Down
5 changes: 4 additions & 1 deletion prototypes/python/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
process_schema,
create_object,
validate_configuration,
load_configuration,
)
from pathlib import Path

Expand All @@ -27,10 +28,12 @@

def test_create_object():

configuration = validate_configuration(
configuration = load_configuration(
data_path.joinpath("kitchen-sink.yaml")
)

validate_configuration(configuration)

processed_schema = process_schema(
resolve_schema(
data_path.joinpath("opentelemetry_configuration.json")
Expand Down

0 comments on commit cc396e7

Please sign in to comment.