@@ -52,70 +52,36 @@ def shuffled_alphabet():
52
52
###############
53
53
# User inputs #
54
54
###############
55
- print ("\n Please enter the requested data at each prompt and press enter.\n " )
55
+ print ("Please enter the requested data at each prompt and press enter.\n " )
56
56
57
57
root_domain = input (f"Root domain (e.g., { COLOR_BLUE } example.com{ COLOR_END } ): " )
58
58
59
- auth0_domain = input (f"Auth0 Domain (e.g., { COLOR_BLUE } example.auth0.com{ COLOR_END } ): " )
60
- auth0_audience = input (f"Auth0 Audience (e.g., { COLOR_BLUE } https://api.example.com{ COLOR_END } ): " )
59
+ #############
60
+ # Generated #
61
+ #############
62
+ # Database
63
+ api_database_password = secrets .token_urlsafe (14 )
64
+ keycloak_database_password = secrets .token_urlsafe (14 )
61
65
62
- syncfusion_license_key = input (f"Syncfusion License Key { COLOR_YELLOW } (Get from: https://www.syncfusion.com/account/downloads){ COLOR_END } : " )
63
-
64
- certificate_password = getpass (f"Certificate Password { COLOR_GREEN } (input will not show){ COLOR_END } : " )
65
-
66
- database_password = secrets .token_urlsafe (14 )
66
+ # Meilisearch
67
+ meilisearch_master_key = secrets .token_urlsafe (42 )
67
68
68
69
##########
69
70
# Server #
70
71
##########
71
- # Auth0
72
- compose ["services" ]["server" ]["environment" ]["Auth0__DOMAIN" ] = auth0_domain
73
- compose ["services" ]["server" ]["environment" ]["Auth0__Audience" ] = auth0_audience
72
+ # Authentication
73
+ compose ["services" ]["server" ]["environment" ]["Authentication__Authority" ] = f"https://idp.{ root_domain } "
74
74
75
75
# Connection string
76
- compose ["services" ]["server" ]["environment" ]["ConnectionStrings__Database" ] = f"Host=database ;Database=lighthousenotes;Username=lighthousenotes;Password={ database_password } "
76
+ compose ["services" ]["server" ]["environment" ]["ConnectionStrings__Database" ] = f"Host=postgresql ;Database=lighthousenotes;Username=lighthousenotes;Password={ api_database_password } "
77
77
78
78
# Sqids
79
79
compose ["services" ]["server" ]["environment" ]["Sqids__Alphabet" ] = shuffled_alphabet ()
80
80
81
- # Syncfusion
82
- compose ["services" ]["server" ]["environment" ]["Syncfusion__LicenseKey" ] = syncfusion_license_key
83
-
84
- # Web app
85
- compose ["services" ]["server" ]["environment" ]["WebApp" ] = f"https://app.{ root_domain } "
86
-
87
- #######
88
- # Web #
89
- #######
90
- # Certificate
91
- compose ["services" ]["web" ]["environment" ]["ASPNETCORE_Kestrel__Certificates__Default__Password" ] = certificate_password
92
-
93
- # Auth0
94
- compose ["services" ]["web" ]["environment" ]["Auth0__DOMAIN" ] = auth0_domain
95
-
96
- # Auth0 Authentication
97
- compose ["services" ]["web" ]["environment" ]["Auth0__Auth__Audience" ] = auth0_audience
98
- compose ["services" ]["web" ]["environment" ]["Auth0__Auth__ClientId" ] = input (f"Authentication client ID { COLOR_YELLOW } (Dashboard > Applications > Applications > Lighthouse Notes){ COLOR_END } : " )
99
- compose ["services" ]["web" ]["environment" ]["Auth0__Auth__ClientSecret" ] = input (f"Authentication client secret { COLOR_YELLOW } (Dashboard > Applications > Applications > Lighthouse Notes){ COLOR_END } : " )
100
-
101
- # Auth0 Management
102
- compose ["services" ]["web" ]["environment" ]["Auth0__Management__Audience" ] = auth0_audience
103
- compose ["services" ]["web" ]["environment" ]["Auth0__Management__ClientId" ] = input (f"Management client ID { COLOR_YELLOW } (Dashboard > Applications > Applications > Lighthouse Notes M2M){ COLOR_END } : " )
104
- compose ["services" ]["web" ]["environment" ]["Auth0__Management__ClientSecret" ] = input (f"Management client secret { COLOR_YELLOW } (Dashboard > Applications > Applications > Lighthouse Notes M2M){ COLOR_END } : " )
105
-
106
- # Auth0 Role IDs
107
- compose ["services" ]["web" ]["environment" ]["Auth0__Roles__user" ] = input (f"User role ID { COLOR_YELLOW } (Dashboard > User Management > Roles > user){ COLOR_END } : " )
108
- compose ["services" ]["web" ]["environment" ]["Auth0__Roles__sio" ] = input (f"SIO role ID { COLOR_YELLOW } (Dashboard > User Management > Roles > sio){ COLOR_END } : " )
109
- compose ["services" ]["web" ]["environment" ]["Auth0__Roles__organization-administrator" ] = input (f"Organization-administrator role ID { COLOR_YELLOW } (Dashboard > User Management > Roles > organization-administrator){ COLOR_END } : " )
110
-
111
- # Auth0 Connection ID
112
- compose ["services" ]["web" ]["environment" ]["Auth0__ConnectionId" ] = input (f"Connection ID { COLOR_YELLOW } (Dashboard > Authentication > Database > Username-Password-Authentication){ COLOR_END } : " )
113
-
114
- # Syncfusion
115
- compose ["services" ]["web" ]["environment" ]["Syncfusion__LicenseKey" ] = syncfusion_license_key
81
+ # Minio
82
+ compose ["services" ]["server" ]["environment" ]["Minio__Endpoint" ] = f"https://s3.{ root_domain } "
83
+ compose ["services" ]["server" ]["environment" ]["Meilisearch__Key" ] = meilisearch_master_key
116
84
117
- # API Url
118
- compose ["services" ]["web" ]["environment" ]["LighthouseNotesApiUrl" ] = f"https://api.{ root_domain } "
119
85
120
86
########
121
87
# SWAG #
@@ -125,17 +91,23 @@ def shuffled_alphabet():
125
91
############
126
92
# Postgres #
127
93
############
128
- compose ["services" ]["database" ]["environment" ]["POSTGRES_PASSWORD" ] = database_password
129
94
compose ["services" ]["database" ]["environment" ]["POSTGRES_ROOT_PASSWORD" ] = secrets .token_urlsafe (14 )
130
95
96
+ ############
97
+ # Keycloak #
98
+ ############
99
+ compose ["services" ]["keycloak" ]["environment" ]["KC_DB_PASSWORD" ] = keycloak_database_password
100
+ compose ["services" ]["keyclaok" ]["environment" ]["KC_HOSTNAME" ] = f"https://idp.{ root_domain } "
101
+ compose ["services" ]["keyclaok" ]["environment" ]["KEYCLOAK_ADMIN" ] = getpass (f"Keycloak admin password { COLOR_GREEN } (input will not show){ COLOR_END } : " )
102
+
131
103
#########
132
104
# Minio #
133
105
#########
134
106
# Certificate volumes
135
- compose ["services" ]["minio" ]["volumes" ][1 ] = f"./swag/etc/letsencrypt/live/app .{ root_domain } /fullchain.pem:/root/.minio/certs/public.crt"
136
- compose ["services" ]["minio" ]["volumes" ][2 ] = f"./swag/etc/letsencrypt/live/app .{ root_domain } /privkey.pem:/root/.minio/certs/private.key"
137
- compose ["services" ]["minio" ]["volumes" ][3 ] = f"./swag/etc/letsencrypt/live/app .{ root_domain } /fullchain.pem:/root/.minio/certs/CAs/public.crt"
138
- compose ["services" ]["minio" ]["volumes" ][4 ] = f"./swag/etc/letsencrypt/live/app .{ root_domain } /privkey.pem:/root/.minio/certs/CAs/private.key"
107
+ compose ["services" ]["minio" ]["volumes" ][1 ] = f"./data/ swag/etc/letsencrypt/live/api .{ root_domain } /fullchain.pem:/root/.minio/certs/public.crt"
108
+ compose ["services" ]["minio" ]["volumes" ][2 ] = f"./data/ swag/etc/letsencrypt/live/api .{ root_domain } /privkey.pem:/root/.minio/certs/private.key"
109
+ compose ["services" ]["minio" ]["volumes" ][3 ] = f"./data/ swag/etc/letsencrypt/live/api .{ root_domain } /fullchain.pem:/root/.minio/certs/CAs/public.crt"
110
+ compose ["services" ]["minio" ]["volumes" ][4 ] = f"./data/ swag/etc/letsencrypt/live/api .{ root_domain } /privkey.pem:/root/.minio/certs/CAs/private.key"
139
111
140
112
141
113
compose ["services" ]["minio" ]["environment" ]["MINIO_SERVER_URL" ] = f"https://s3.{ root_domain } "
@@ -144,7 +116,6 @@ def shuffled_alphabet():
144
116
###############
145
117
# Meilisearch #
146
118
###############
147
- meilisearch_master_key = secrets .token_urlsafe (42 )
148
119
compose ["services" ]["meilisearch" ]["environment" ]["MEILI_MASTER_KEY" ] = meilisearch_master_key
149
120
150
121
###############################
@@ -181,58 +152,41 @@ def shuffled_alphabet():
181
152
api_site_config .write (data )
182
153
api_site_config .truncate ()
183
154
184
-
185
- shutil .move (f'site-confs/app.example.com.conf' , f'site-confs/app.{ root_domain } .conf' )
186
- with open (f'site-confs/app.{ root_domain } .conf' , 'r+' ) as app_site_config :
187
- data = app_site_config .read ()
188
- app_site_config .seek (0 )
155
+ shutil .move (f'site-confs/idp.example.com.conf' , f'site-confs/idp.{ root_domain } .conf' )
156
+ with open (f'site-confs/idp.{ root_domain } .conf' , 'r+' ) as api_site_config :
157
+ data = api_site_config .read ()
158
+ api_site_config .seek (0 )
189
159
data = data .replace ('example.com' , root_domain )
190
- app_site_config .write (data )
191
- app_site_config .truncate ()
192
-
160
+ api_site_config .write (data )
161
+ api_site_config .truncate ()
193
162
194
163
#######
195
164
# SQL #
196
165
#######
197
- print ("\n Please enter the requested data at each prompt and press enter." )
198
- print ("This information will be used to generate the SQL file which seeds the database.\n " )
199
- # Organization
200
- organization_id = input (f"Organization ID { COLOR_YELLOW } (Dashboard > Organizations){ COLOR_END } : " )
201
- organization_name = input (f"Organization Name { COLOR_YELLOW } (Dashboard > Organizations){ COLOR_END } : " )
202
- organization_display_name = input (f"Organization Display Name { COLOR_YELLOW } (Dashboard > Organizations){ COLOR_END } : " )
203
-
204
- organization_sql = f"INSERT INTO \" Organization\" (\" Id\" , \" Name\" , \" DisplayName\" , \" Created\" , \" Modified\" ) VALUES ('{ organization_id } ', '{ organization_name } ', '{ organization_display_name } ', NOW(), NOW());"
205
-
206
- # User
207
- user_id = input (f"User ID { COLOR_YELLOW } (Dashboard > User Management > Your Name){ COLOR_END } : " )
208
- job_title = input (f"Job Title { COLOR_GREEN } (Can be changed later){ COLOR_END } : " )
209
- given_name = input (f"Given Name { COLOR_GREEN } (Can be changed later){ COLOR_END } : " )
210
- last_name = input (f"Last Name { COLOR_GREEN } (Can be changed later){ COLOR_END } : " )
211
- email_address = input (f"Email Address { COLOR_GREEN } (Can be changed later){ COLOR_END } : " ) # Double check this
212
- profile_picture = input (f"Profile Picture URL: { COLOR_YELLOW } (Dashboard > User Management > Your Name > Identity Provider Attributes){ COLOR_END } : " )
213
-
214
- user_sql = f"INSERT INTO \" User\" (\" Auth0Id\" , \" JobTitle\" , \" DisplayName\" , \" GivenName\" , \" LastName\" , \" EmailAddress\" , \" ProfilePicture\" , \" OrganizationId\" , \" Created\" , \" Modified\" ) VALUES ('{ user_id } ', '{ job_title } ', '{ given_name } { last_name } ', '{ given_name } ', '{ last_name } ', '{ email_address } ', '{ profile_picture } ', '{ organization_id } ', NOW(), NOW());\n "
215
-
216
- # User roles
217
- user_roles_sql = """
218
- INSERT INTO "Role" ("Name", "UserId", "Created", "Modified") VALUES ('organization administrator', 1, NOW(), NOW());
219
- INSERT INTO "Role" ("Name", "UserId", "Created", "Modified") VALUES ('sio', 1, NOW(), NOW());
220
- INSERT INTO "Role" ("Name", "UserId", "Created", "Modified") VALUES ('user', 1, NOW(), NOW());
166
+ keycloak_create_sql = f"""
167
+ create database keycloak;
168
+ create user keycloak with encrypted password '{ keycloak_database_password } ';
169
+ grant all privileges on database keycloak to keycloak;
170
+ ALTER DATABASE keycloak OWNER TO keycloak;
221
171
"""
222
172
223
- # User settings
224
- user_settings_sql = "INSERT INTO \" UserSettings\" (\" UserId\" , \" TimeZone\" , \" DateFormat\" , \" TimeFormat\" , \" Locale\" , \" Created\" , \" Modified\" ) VALUES (1, 'GMT Standard Time', 'dddd dd MMMM yyyy', 'HH:mm:ss', 'en-GB', NOW(), NOW());\n "
225
173
226
- # Organization settings
227
- organization_settings_sql = f"INSERT INTO \" OrganizationSettings\" (\" OrganizationId\" , \" S3Endpoint\" , \" S3BucketName\" , \" S3NetworkEncryption\" , \" S3AccessKey\" , \" S3SecretKey\" , \" MeilisearchUrl\" , \" MeilisearchApiKey\" , \" Created\" , \" Modified\" ) VALUES ('{ organization_id } ', 's3.{ root_domain } :9000', 'lighthouse-notes', true, 'CHANGME', 'CHANGEME', 'http://meilisearch:7700', 'CHANGME', NOW(), NOW());\n "
174
+ lighthousenotes_create_sql = f"""
175
+ create database lighthousenotes;
176
+ create user lighthousenotes with encrypted password '{ api_database_password } ';
177
+ grant all privileges on database lighthousenotes to lighthousenotes;
178
+ ALTER DATABASE lighthousenotes OWNER TO lighthousenotes;
179
+ """
180
+
181
+ with open ('sample.init.sql' , 'r' ) as sql_file :
182
+ existing_content = sql_file .read ()
228
183
229
- with open (f'init.sql' , 'a' ) as sql_file :
230
- sql_file .write (organization_sql )
231
- sql_file .write (user_sql )
232
- sql_file .write (user_roles_sql )
233
- sql_file .write (user_settings_sql )
234
- sql_file .write (organization_settings_sql )
184
+ # Write new content followed by the existing content
185
+ with open ('init.sql' , 'w' ) as sql_file :
186
+ sql_file .write (keycloak_create_sql )
187
+ sql_file .write (lighthousenotes_create_sql )
188
+ sql_file .write (existing_content )
235
189
236
190
# Final
237
191
print (f"Meilisearch API key is: { meilisearch_master_key } " )
238
- print (f"\n { COLOR_GREEN } docker-compose.yml file, nginx configurations and initialization database script successfully created!{ COLOR_END } \n " )
192
+ print (f"\n { COLOR_GREEN } docker-compose.yml file and NGINX configurations created!\n " )
0 commit comments