"""Common config for all the workflows.""" import base64 from itertools import chain import os def merge_configs(c1, c2): """Merge two flat configs. Values from c1 get overridden by values from c2 if the keys collide. Args: c1 (dict): First config. c2 (dict): Second config. Returns: dict: Result dict containing merged result. """ c1 = c1 or {} c2 = c2 or {} return {k: v for k, v in chain(c1.items(), c2.items()) if v} # Default Snowflake connection parameters excluding credentials SF_PARAMS = { 'role': os.environ.get('SNOWFLAKE_ROLE'), 'warehouse': os.environ.get('SNOWFLAKE_WAREHOUSE'), 'db': os.environ.get('SNOWFLAKE_DATABASE'), 'schema': os.environ.get('SNOWFLAKE_SCHEMA') } # Snowflake connection credentials SF_CREDENTIALS = { 'user': os.environ.get('SNOWFLAKE_USER'), 'password': os.environ.get('SNOWFLAKE_PASSWORD', 'dummy_password'), 'account': os.environ.get('SNOWFLAKE_ACCOUNT') } SF_CONFIG = merge_configs(SF_PARAMS, SF_CREDENTIALS) # add optional private_key private_key = os.environ.get('SNOWFLAKE_KEY') if private_key: decoded_key = base64.b64decode(bytes(private_key, encoding='utf-8')) SF_CONFIG['private_key'] = decoded_key