-
Notifications
You must be signed in to change notification settings - Fork 49
/
config.json.erb
88 lines (75 loc) · 3.01 KB
/
config.json.erb
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<%=
require 'json'
postgres_host = ""
postgres_port = ""
postgres_role_name = ""
postgres_role_password = ""
postgres_database = ""
postgres_tls_enabled = false
postgres_tls_skip_host_verify = false
postgres_tls_ca = ""
postgres_tls_public_cert = ""
postgres_tls_private_key = ""
if_p("postgresql.address") do |addr|
postgres_host, postgres_port = addr.split(":")
end
postgres_host = p("postgresql.host", "")
postgres_port = p("postgresql.port")
postgres_database = p("postgresql.database")
postgres_role_name = p("postgresql.role.name")
postgres_role_password = p("postgresql.role.password", "")
postgres_tls_enabled = p("postgresql.tls.enabled", false)
if postgres_tls_enabled
postgres_tls_skip_host_verify = p("postgresql.tls.skip_host_verify", false)
postgres_tls_ca = p("postgresql.tls.cert.ca")
postgres_tls_public_cert = p("postgresql.tls.cert.certificate")
postgres_tls_private_key = p("postgresql.tls.cert.private_key")
end
if_link("db") do |db|
postgres_host = db.instances.first.address
postgres_port = db.p("bind_port")
postgres_database = p("postgresql_database")
postgres_db = db.p("databases").find { |db| db["name"] == postgres_database }
if postgres_db.nil?
raise "database '#{db_name}' not provided by 'postgresql' link"
end
postgres_role_name = postgres_db["role"]
postgres_role_password = postgres_db["password"]
end if postgres_host.empty?
if_link("postgres") do |l|
postgres_host = l.instances.first.address
end if postgres_host.empty?
if_link("concourse_db") do |cdb|
postgres_host = cdb.p("postgressql.host", "")
postgres_port = cdb.p("postgressql.port")
postgres_role_name = cdb.p("postgressql.role.name")
postgres_role_password = cdb.p("postgressql.role.password")
postgres_database = cdb.p("postgressql.database")
end if postgres_host.empty?
if_link("concourse_db") do |cdb|
postgres_tls_enabled = cdb.p("postgresql.sslmode", false)
if postgres_tls_enabled
postgres_tls_ca = cdb.p("postgresql.ca_cert")
postgres_tls_public_cert = cdb.p("postgresql.client_cert.certificate")
postgres_tls_private_key = cdb.p("postgresql.client_cert.private_key")
end
end
if postgres_host.empty?
raise "postgres.host not set and no 'db', 'postgres' or 'concourse_db' link available"
end
config_data = {
'username' => postgres_role_name,
'password' => postgres_role_password,
'host' => postgres_host,
'port' => postgres_port,
'database' => postgres_database,
'adapter' => 'postgres'
}
if postgres_tls_enabled
config_data['tls.skip_host_verify'] = postgres_tls_skip_host_verify
config_data['tls.cert.ca'] = postgres_tls_ca
config_data['tls.cert.certificate'] = postgres_tls_public_cert
config_data['tls.cert.private_key'] = postgres_tls_private_key
end
JSON.pretty_generate(config_data)
%>