-
Notifications
You must be signed in to change notification settings - Fork 5
/
InitializeSchema.swift
74 lines (57 loc) · 2.09 KB
/
InitializeSchema.swift
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
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// InitializeSchema.swift
// Perfect-OAuth2-Server
//
// Created by Jonathan Guthrie on 2017-02-06.
//
//
import PerfectLib
import StORM
import MySQLStORM
import JSONConfig
import PerfectSessionMySQL
public func initializeSchema(_ fname: String = "./config/ApplicationConfiguration.json") -> [String:Any] {
var opts = [String:Any]()
if let config = JSONConfig(name: fname) {
let dict = config.getValues()!
opts["httpPort"] = dict["httpport"] as! Int
// StORM Connector Config
MySQLConnector.host = dict["mysqlhost"] as? String ?? ""
MySQLConnector.username = dict["mysqluser"] as? String ?? ""
MySQLConnector.password = dict["mysqlpwd"] as? String ?? ""
MySQLConnector.database = dict["mysqldbname"] as? String ?? ""
MySQLConnector.port = dict["mysqlport"] 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
MySQLSessionConnector.host = MySQLConnector.host
MySQLSessionConnector.port = MySQLConnector.port
MySQLSessionConnector.username = MySQLConnector.username
MySQLSessionConnector.password = MySQLConnector.password
MySQLSessionConnector.database = MySQLConnector.database
MySQLSessionConnector.table = "sessions"
} else {
print("Unable to get Configuration")
MySQLConnector.host = "localhost"
MySQLConnector.username = "perfect"
MySQLConnector.password = "perfect"
MySQLConnector.database = "perfect_testing"
MySQLConnector.port = 3306
}
// StORMdebug = true
MySQLConnector.quiet = true
// Account
Account.setup()
// Application
Application.setup()
// Access Token
AccessToken.setup()
MySQLConnector.quiet = false
return opts
}