def test_non_json_keys_omitted(): class WeirdObject: pass loader = load_from_dict( config_convention=dict( enabled="true", ), weird_thing=WeirdObject(), ) secrets = load_from_dict(dict()) partitioned_loader = load_config_and_secrets(config=loader, secrets=secrets) graph = create_object_graph(name="example", testing=True, loader=partitioned_loader) graph.use("config_convention") client = graph.flask.test_client() response = client.get( "/api/config", ) assert_that(response.status_code, is_(equal_to(200))) data = loads(response.get_data().decode("utf-8")) assert_that(data, has_entries(config_convention=dict(enabled="true"))) assert_that("weird_thing" not in data.keys())
def test_config_discovery(): """ Config-minus secrets is shareable. """ config = load_from_dict( config_convention=dict( enabled="true", ), ) secrets = load_from_dict( config_convention=dict( enabled="true", ), ) paritioned_loader = load_config_and_secrets(config, secrets) graph = create_object_graph(name="example", testing=True, loader=paritioned_loader) graph.use("config_convention") client = graph.flask.test_client() response = client.get( "/api/config", ) assert_that(response.status_code, is_(equal_to(200))) data = loads(response.get_data().decode("utf-8")) assert_that(data, has_entries(config_convention=dict(enabled="true")))
def create_app(debug=False, testing=False, model_only=False): """ Create the object graph for the application. """ config_loader = load_each( load_default_config, load_from_environ, load_from_json_file, ) partitioned_loader = load_config_and_secrets( config=config_loader, secrets=load_from_secretsmanager(), ) graph = create_object_graph( name=__name__.split(".")[0], debug=debug, testing=testing, loader=partitioned_loader, ) graph.use( "pizza_store", "order_store", "order_event_store", "topping_store", "logging", "postgres", "sessionmaker", "session_factory", ) if not model_only: graph.use( "sns_producer", # Factories "order_event_factory", # conventions "build_info_convention", "config_convention", "discovery_convention", "health_convention", "landing_convention", "port_forwarding", "postgres_health_check", "swagger_convention", # routes "pizza_routes", "order_routes", "topping_routes", "order_event_routes", ) return graph.lock()
def test_load_config_and_secrets(): metadata = Metadata("foo") loader = load_config_and_secrets( config=load_from_dict(credentials=dict(username="******", ), ), secrets=load_from_dict(credentials=dict(password="******", ), ), ) config = loader(metadata) # configuration is loaded as a usual merge assert_that( config, is_( equal_to( dict(credentials=dict( username="******", password="******", ), )))) assert_that(loader.config, is_(equal_to(dict(credentials=dict(username="******", ), )))) assert_that(loader.secrets, is_(equal_to(dict(credentials=dict(password="******", ), ))))