1
+ from indexd .index .drivers .alchemy import SQLAlchemyIndexDriver
2
+ from indexd .alias .drivers .alchemy import SQLAlchemyAliasDriver
3
+ from indexd .auth .drivers .alchemy import SQLAlchemyAuthDriver
4
+ from indexd .index .drivers .single_table_alchemy import SingleTableSQLAlchemyIndexDriver
5
+ import config_helper
6
+ from os import environ
7
+ import json
8
+
9
+ APP_NAME = "indexd"
10
+
11
+
12
+ def load_json (file_name ):
13
+ return config_helper .load_json (file_name , APP_NAME )
14
+
15
+
16
+ conf_data = load_json ("creds.json" )
17
+
18
+ usr = conf_data .get ("db_username" , "{{db_username}}" )
19
+ db = conf_data .get ("db_database" , "{{db_database}}" )
20
+ psw = conf_data .get ("db_password" , "{{db_password}}" )
21
+ pghost = conf_data .get ("db_host" , "{{db_host}}" )
22
+ pgport = 5432
23
+ index_config = conf_data .get ("index_config" )
24
+ CONFIG = {}
25
+
26
+ CONFIG ["JSONIFY_PRETTYPRINT_REGULAR" ] = False
27
+
28
+ dist = environ .get ("DIST" , None )
29
+ if dist :
30
+ CONFIG ["DIST" ] = json .loads (dist )
31
+
32
+ arborist = environ .get ("ARBORIST" , "false" ).lower () == "true"
33
+
34
+ USE_SINGLE_TABLE = True
35
+
36
+ if USE_SINGLE_TABLE is True :
37
+
38
+
39
+ CONFIG ["INDEX" ] = {
40
+ "driver" : SingleTableSQLAlchemyIndexDriver (
41
+ "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}" .format (
42
+ usr = usr , psw = psw , pghost = pghost , pgport = pgport , db = db
43
+ ),
44
+ index_config = index_config ,
45
+ )
46
+ }
47
+ else :
48
+ CONFIG ["INDEX" ] = {
49
+ "driver" : SQLAlchemyIndexDriver (
50
+ "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}" .format (
51
+ usr = usr , psw = psw , pghost = pghost , pgport = pgport , db = db
52
+ ),
53
+ index_config = index_config ,
54
+ )
55
+ }
56
+
57
+ CONFIG ["ALIAS" ] = {
58
+ "driver" : SQLAlchemyAliasDriver (
59
+ "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}" .format (
60
+ usr = usr , psw = psw , pghost = pghost , pgport = pgport , db = db
61
+ )
62
+ )
63
+ }
64
+
65
+ if arborist :
66
+ AUTH = SQLAlchemyAuthDriver (
67
+ "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}" .format (
68
+ usr = usr , psw = psw , pghost = pghost , pgport = pgport , db = db
69
+ ),
70
+ arborist = "http://arborist-service/" ,
71
+ )
72
+ else :
73
+ AUTH = SQLAlchemyAuthDriver (
74
+ "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}" .format (
75
+ usr = usr , psw = psw , pghost = pghost , pgport = pgport , db = db
76
+ )
77
+ )
78
+
79
+ settings = {"config" : CONFIG , "auth" : AUTH }
0 commit comments