-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit_pma.rb
51 lines (44 loc) · 1.27 KB
/
init_pma.rb
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
require 'rubygems'
require "http"
require 'oj'
require 'timeout'
require 'erb'
begin
puts "Loading Metadata..."
metadata = Timeout::timeout(5) do
Oj.load HTTP.auth("Bearer #{ENV['METADATA_AUTH']}").get("#{ENV['METADATA_URL']}").body
end
unless metadata
puts "Timeout reached during metadata lookup, exiting."
exit 1
end
pma_conf = <<-EOF
<?php
$cfg['blowfish_secret'] = '<%= SecureRandom.urlsafe_base64(24) %>';
$cfg['ShowChgPassword'] = false;
$i = 0;
<% metadata['services'].each do |service| -%>
<% next if service.dig('image','role').nil? -%>
<% next unless service['image']['role'] == 'mysql' -%>
<% service['containers'].each do |server| -%>
$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = '<%= server['ip'] %>';
$cfg['Servers'][$i]['port'] = "3306";
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
<% end -%>
<% end -%>
?>
EOF
pma_conf_file = ERB.new pma_conf, nil, '-'
puts "Writing phpMyAdmin config file..."
File.open('/var/www/html/default/config.inc.php', 'w') do |f|
f.write pma_conf_file.result(binding)
end
`chmod 644 /var/www/html/default/config.inc.php`
rescue => e
puts "Fatal error: #{e.message}"
exit 1
end