Skip to content

Commit e5868f5

Browse files
committed
main: better config handling
1 parent 76ead92 commit e5868f5

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

flyover/__main__.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,11 @@
2929

3030
def run_csv_job(config_file, output_dir):
3131
carte_loader = CarteLoader()
32-
extractors, connections = parse_config(config_file)
33-
34-
extractor_config = {}
35-
36-
for extractor, connection in zip(extractors, connections):
37-
scope = extractor.get_scope()
38-
config = connection.get("config", {})
39-
for conf_key, conf_value in config.items():
40-
extractor_config[f"{scope}.{conf_key}"] = conf_value
32+
extractors, config = parse_config(config_file)
4133

4234
job_config = ConfigFactory.from_dict(
4335
{"loader.carte.tables_output_path": output_dir,
44-
# f'extractor.postgres_metadata.where_clause_suffix: '
45-
**extractor_config}
36+
**config}
4637
)
4738

4839
for extractor in extractors:

flyover/utils/config_parser.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,31 @@
55

66
yaml = YAML()
77

8+
CONFIG_KEY = "config"
9+
810

911
def create_glue_connection(conn_dict):
10-
return GlueExtractor(conn_dict.get("name", "glue"))
12+
return GlueExtractor(conn_dict.get("name", "glue")), {}
1113

1214

1315
def create_postgres_connection(conn_dict):
14-
return PostgresMetadataExtractor()
16+
extractor = PostgresMetadataExtractor()
17+
extractor_scope = extractor.get_scope()
18+
config = conn_dict.get(CONFIG_KEY, {})
19+
included_schemas = config.get("included_schemas", ["public"])
20+
schemas_sql_list = "('{schemas}')".format(schemas="', '".join(included_schemas))
21+
schema_where_clause = f"where table_schema in {schemas_sql_list}"
22+
23+
connection_string = config.get("connection_string")
24+
if connection_string is None:
25+
raise KeyError(
26+
"connection_string is a required config item for PostgreSQL connections"
27+
)
28+
29+
return PostgresMetadataExtractor(), {
30+
f"{extractor_scope}.{PostgresMetadataExtractor.WHERE_CLAUSE_SUFFIX_KEY}": schema_where_clause,
31+
f"{extractor_scope}.extractor.sqlalchemy.conn_string": connection_string,
32+
}
1533

1634

1735
CONNECTION_FACTORIES = {
@@ -27,12 +45,23 @@ def parse_config(filename):
2745

2846
connections = parsed_data.get("connections", [])
2947

30-
extractors = [
31-
CONNECTION_FACTORIES[conn_dict.get("type")](conn_dict)
32-
for conn_dict in connections
33-
]
48+
extractors = []
49+
config = {}
50+
51+
for conn_dict in connections:
52+
extractor, extractor_config = CONNECTION_FACTORIES[conn_dict.get("type")](
53+
conn_dict
54+
)
55+
custom_config = {}
56+
scope = extractor.get_scope()
57+
config = conn_dict.get(CONFIG_KEY, {})
58+
for conf_key, conf_value in config.items():
59+
custom_config[f"{scope}.{conf_key}"] = conf_value
60+
61+
config = {**config, **extractor_config, **custom_config}
62+
extractors.append(extractor)
3463

35-
return extractors, connections
64+
return extractors, config
3665

3766

3867
def _read_file(filename: str):

flyover/utils/frontmatter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def parse(filename):
1212
metadata = {}
1313
content = ""
1414

15-
if len(data) >= 1 and data[0] != "":
16-
metadata = yaml.load(data[0])
15+
if len(data) >= 2 and data[1] != "":
16+
metadata = yaml.load(data[1])
1717

1818
if len(data) >= 2:
19-
content = data[1]
19+
content = data[2]
2020

2121
return metadata, content
2222

0 commit comments

Comments
 (0)