Skip to content
This repository was archived by the owner on Jan 8, 2019. It is now read-only.

Commit 1b0da50

Browse files
committed
added endpoint /json
1 parent 28598f4 commit 1b0da50

File tree

3 files changed

+43
-32
lines changed

3 files changed

+43
-32
lines changed

cookbooks/bcpc/attributes/apache2.rb

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
# bach web info page
1+
default['bcpc']['bach_web'].tap do |bach_web|
2+
# bach web configs
3+
bach_web['document_root'] = '/var/www/bach'
4+
bach_web['port'] = 80
25

3-
default['bcpc']['bach_web']['document_root'] = '/var/www/bach'
4-
default['bcpc']['bach_web']['port'] = 80
6+
# html portal page
7+
bach_web['html_url'] = ''
8+
bach_web['html_file'] = 'index.html'
59

6-
# { '<name>' => { 'port' => '<port_number>', 'desc' => '<description>' }, ... }
7-
default['bcpc']['bach_web']['services'] = {}
10+
# json conf page file
11+
bach_web['json_url'] = 'json'
12+
bach_web['json_file'] = 'bach_web.json'
813

9-
# { '<name>' => { 'url' => '<port_number>', 'desc' => '<description>' }, ... }
10-
default['bcpc']['bach_web']['links'] = {}
11-
12-
# { '<name>' => { 'path' => '<relative_path>', 'desc' => '<description>' }, ... }
13-
default['bcpc']['bach_web']['files'] = {}
14+
# extra files to be exposed
15+
bach_web['files_url'] = 'files'
16+
end

cookbooks/bcpc/recipes/apache2.rb

+27-15
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,32 @@
107107
mode 0o0644
108108
end
109109

110-
# for providing information on services, links, and config files
110+
# bach web document root
111111
directory node['bcpc']['bach_web']['document_root'].to_s do
112112
owner 'root'
113113
group 'root'
114114
mode 0o0755
115115
action :create
116116
end
117117

118-
directory "#{node['bcpc']['bach_web']['document_root']}/files" do
118+
# bach web configs
119+
template '/etc/apache2/sites-available/bach-web.conf' do
120+
source 'bach-web.conf.erb'
119121
owner 'root'
120122
group 'root'
121-
mode 0o0755
122-
action :create
123+
mode 0o0644
124+
variables(
125+
'host_ip' => node['bcpc']['floating']['ip'],
126+
'host_port' => node['bcpc']['bach_web']['port'],
127+
'document_root' => node['bcpc']['bach_web']['document_root'],
128+
'json_url' => node['bcpc']['bach_web']['json_url'],
129+
'json_file' => node['bcpc']['bach_web']['json_file']
130+
)
131+
notifies :restart, 'service[apache2]', :delayed
123132
end
124133

125-
template "#{node['bcpc']['bach_web']['document_root']}/index.html" do
134+
# A portal html pages for useful links
135+
template "#{node['bcpc']['bach_web']['document_root']}/#{node['bcpc']['bach_web']['html_file']}" do
126136
source 'bach.html.erb'
127137
owner 'root'
128138
group 'root'
@@ -136,20 +146,22 @@
136146
notifies :restart, 'service[apache2]', :delayed
137147
end
138148

139-
template '/etc/apache2/sites-available/bach-web.conf' do
140-
source 'bach-web.conf.erb'
149+
# A json files that expose the configs for easier consumption programatically.
150+
# NOTE: node['bcpc']['bach_web'] should NOT contain anything sensitive or confidential
151+
# otherwise a dedicated hash should be used
152+
file "#{node['bcpc']['bach_web']['document_root']}/#{node['bcpc']['bach_web']['json_file']}" do
153+
content Chef::JSONCompat.to_json_pretty(node['bcpc']['bach_web'].to_hash)
154+
end
155+
156+
157+
directory "#{node['bcpc']['bach_web']['document_root']}/files" do
141158
owner 'root'
142159
group 'root'
143-
mode 0o0644
144-
variables(
145-
'host_ip' => node['bcpc']['floating']['ip'],
146-
'host_port' => node['bcpc']['bach_web']['port'],
147-
'document_root' => node['bcpc']['bach_web']['document_root'],
148-
'files' => node['bcpc']['bach_web']['files']
149-
)
150-
notifies :restart, 'service[apache2]', :delayed
160+
mode 0o0755
161+
action :create
151162
end
152163

164+
# enable bach-web
153165
bash 'enable_bach_web' do
154166
user 'root'
155167
code 'a2ensite bach-web'

cookbooks/bcpc/templates/default/bach-web.conf.erb

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
################################################
66
<VirtualHost <%= "#{@host_ip}:#{@host_port}" %>>
77

8-
DocumentRoot "<%= @document_root %>"
8+
DocumentRoot <%= @document_root %>
99

10-
Alias /files <%= @document_root %>/files
11-
<Directory <%= @document_root %>/files >
10+
<Directory <%= @document_root %> >
1211
Options -Indexes
1312
</Directory>
1413

15-
<% (@files || {}).each do |file, values| %>
16-
Alias /<%= values['path'] %> <%= @document_root %>/<%= values['path'] %>
17-
<% end %>
18-
14+
Alias /<%= @json_url %> <%= @document_root %>/<%= @json_file %>
1915
</VirtualHost>

0 commit comments

Comments
 (0)