Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2SDCDataExchange Endpoint Factory 

3""" 

4import importlib 

5import logging 

6 

7logging.basicConfig(format='%(levelname)s: %(asctime)s: %(funcName)s: %(message)s') 

8logger = logging.getLogger(__name__) 

9logger.setLevel(logging.INFO) 

10 

11endpoint_class = lambda x: importlib.import_module(name=available_endpoints[x]['lib_path']) 

12available_endpoints = { 

13 'mock': { 

14 'endpoint': 'SDCMockEndpoint', 

15 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.mock_endpoints.sdc_mock_endpoint' 

16 }, 

17 'sftp': { 

18 'endpoint': 'SDCSFTPEndpoint', 

19 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.file_endpoints.SDCSFTPEndpoint' 

20 }, 

21 's3': { 

22 'endpoint': 'SDCS3Endpoint', 

23 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.file_endpoints.SDCS3Endpoint' 

24 }, 

25 'api': { 

26 'endpoint': 'SDCAPIEndpoint', 

27 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.api_endpoints.SDCAPIEndpoint' 

28 }, 

29 'snowflake': { 

30 'endpoint': 'SDCSnowflakeEndpoint', 

31 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.database_endpoints.SDCSnowflakeEndpoint' 

32 }, 

33 'postgres': { 

34 'endpoint': 'SDCPostgresEndpoint', 

35 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.database_endpoints.SDCPostgresEndpoint' 

36 }, 

37 'odbc': { 

38 'endpoint': 'SDCODBCEndpoint', 

39 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.database_endpoints.SDCODBCEndpoint' 

40 }, 

41 'dynamodb': { 

42 'endpoint': 'SDCDynamoDBEndpoint', 

43 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.database_endpoints.SDCDynamoDBEndpoint' 

44 }, 

45 'local_disk': { 

46 'endpoint': 'SDCLocalDiskEndpoint', 

47 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.file_endpoints.SDCLocalDiskEndpoint' 

48 }, 

49 'xcom_airflow': { 

50 'endpoint': 'AirflowEndpoint', 

51 'lib_path': 'sdc_etl_libs.sdc_exchange_endpoints.api_endpoints.AirflowEndpoint' 

52 } 

53} 

54 

55 

56class SDCDataExchangeEndpointFactory: 

57 """ 

58 SDCDataExchangeEndpointFactory class 

59 """ 

60 

61 @staticmethod 

62 def get_endpoint(data_schema_: dict, endpoint_schema_: dict, **kwargs): 

63 """ 

64 Factory for returning the proper SDCDataExcbangeEndpoint class. 

65 :param data_schema_: JSON of data schema. 

66 :param endpoint_schema_: JSON of endpoint schema. 

67 :param kwargs: optional params 

68 :return: SDCDataExchange class. 

69 :rtype: SDC Endpoint 

70 """ 

71 kva_kwargs = {} 

72 if data_schema_ is not None: 

73 kva_kwargs['data_schema_'] = data_schema_ 

74 if endpoint_schema_ is not None: 

75 kva_kwargs['endpoint_schema_'] = endpoint_schema_ 

76 if kwargs is not None: 

77 kva_kwargs = {**kva_kwargs, **kwargs} 

78 

79 endpoint_type = endpoint_schema_["info"]["type"] 

80 

81 if endpoint_type in available_endpoints.keys(): 

82 endpoint = getattr(endpoint_class(endpoint_type), available_endpoints[endpoint_type]['endpoint'])() 

83 endpoint.create_exchange_endpoint(**kva_kwargs) 

84 return endpoint 

85 

86 logging.exception("%s is not a valid endpoint option.", endpoint_type)