-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathInitializeSchema.swift
More file actions
59 lines (49 loc) · 1.95 KB
/
InitializeSchema.swift
File metadata and controls
59 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// InitializeSchema.swift
// Perfect-OAuth2-Server
//
// Created by Jonathan Guthrie on 2017-02-06.
//
//
import PerfectLib
import StORM
import PostgresStORM
import JSONConfig
import PerfectSessionPostgreSQL
public func initializeSchema(_ fname: String = "./config/ApplicationConfiguration.json") -> [String:Any] {
var opts = [String:Any]()
guard let config = JSONConfig(name: fname) else {
fatalError("Unable to open configuration file: \(fname)")
}
guard let dict = config.getValues() else {
fatalError("Unable to parse configuration file: \(fname)")
}
opts["httpPort"] = dict["httpport"] as! Int
// StORM Connector Config
PostgresConnector.host = dict["postgreshost"] as? String ?? ""
PostgresConnector.username = dict["postgresuser"] as? String ?? ""
PostgresConnector.password = dict["postgrespwd"] as? String ?? ""
PostgresConnector.database = dict["postgresdbname"] as? String ?? ""
PostgresConnector.port = dict["postgresport"] as? Int ?? 0
// Outbound email config
SMTPConfig.mailserver = dict["mailserver"] as? String ?? ""
SMTPConfig.mailuser = dict["mailuser"] as? String ?? ""
SMTPConfig.mailpass = dict["mailpass"] as? String ?? ""
SMTPConfig.mailfromaddress = dict["mailfromaddress"] as? String ?? ""
SMTPConfig.mailfromname = dict["mailfromname"] as? String ?? ""
opts["baseURL"] = dict["baseURL"] as? String ?? ""
AuthenticationVariables.baseURL = dict["baseURL"] as? String ?? ""
// session driver config
PostgresSessionConnector.host = PostgresConnector.host
PostgresSessionConnector.port = PostgresConnector.port
PostgresSessionConnector.username = PostgresConnector.username
PostgresSessionConnector.password = PostgresConnector.password
PostgresSessionConnector.database = PostgresConnector.database
PostgresSessionConnector.table = "sessions"
// StORMdebug = true
// Account
PostgresConnector.quiet = true
Account.setup()
PostgresConnector.quiet = false
return opts
}