From 79f770c9d629fe90d98e380f51cb11b3c88d4adc Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Sun, 10 Jul 2022 20:43:08 -0400 Subject: [PATCH] Add examples --- examples/providers/configuration/config.json | 6 +++++ .../configuration/configuration_json.py | 27 +++++++++++++++++++ .../configuration/configuration_json_init.py | 25 +++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 examples/providers/configuration/config.json create mode 100644 examples/providers/configuration/configuration_json.py create mode 100644 examples/providers/configuration/configuration_json_init.py diff --git a/examples/providers/configuration/config.json b/examples/providers/configuration/config.json new file mode 100644 index 00000000..5d79c0b6 --- /dev/null +++ b/examples/providers/configuration/config.json @@ -0,0 +1,6 @@ +{ + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET" + } +} diff --git a/examples/providers/configuration/configuration_json.py b/examples/providers/configuration/configuration_json.py new file mode 100644 index 00000000..54dbd1a2 --- /dev/null +++ b/examples/providers/configuration/configuration_json.py @@ -0,0 +1,27 @@ +"""`Configuration` provider values loading example.""" + +from dependency_injector import containers, providers + + +class Container(containers.DeclarativeContainer): + + config = providers.Configuration() + + +if __name__ == "__main__": + container = Container() + + container.config.from_json("./config.json") + + assert container.config() == { + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET", + }, + } + assert container.config.aws() == { + "access_key_id": "KEY", + "secret_access_key": "SECRET", + } + assert container.config.aws.access_key_id() == "KEY" + assert container.config.aws.secret_access_key() == "SECRET" diff --git a/examples/providers/configuration/configuration_json_init.py b/examples/providers/configuration/configuration_json_init.py new file mode 100644 index 00000000..a69b92c2 --- /dev/null +++ b/examples/providers/configuration/configuration_json_init.py @@ -0,0 +1,25 @@ +"""`Configuration` provider values loading example.""" + +from dependency_injector import containers, providers + + +class Container(containers.DeclarativeContainer): + + config = providers.Configuration(json_files=["./config.json"]) + + +if __name__ == "__main__": + container = Container() + + assert container.config() == { + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET", + }, + } + assert container.config.aws() == { + "access_key_id": "KEY", + "secret_access_key": "SECRET", + } + assert container.config.aws.access_key_id() == "KEY" + assert container.config.aws.secret_access_key() == "SECRET"