-
Notifications
You must be signed in to change notification settings - Fork 82
Added SSL certificates uploading. #164
base: master
Are you sure you want to change the base?
Changes from 1 commit
edc2990
43e9580
988da51
b662d03
cd36011
b522bf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,27 @@ def nginx_custom_configuration(app_info) | |
|
||
empty_conf.merge(app_info["nginx_custom"] || {}) | ||
end | ||
|
||
# Returns a server path to certificate file | ||
# | ||
# applications_root = '/u/apps/' | ||
# name = 'my_app' | ||
# app_info['ssl_certificate'] = 'my_cert.crt' | ||
# ssl_certificate(applications_root, name, app_info) # => /u/apps/my_app/shared/config/my_cert.crt' | ||
# | ||
# applications_root = '/u/apps/' | ||
# name = 'my_app' | ||
# app_info['ssl_certificate'] = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace detected. |
||
# ssl_certificate(applications_root, name, app_info) # => /u/apps/my_app/shared/config/my_app.crt' | ||
# | ||
def ssl_certificate(applications_root, name, app_info) | ||
Pathname.new(applications_root).join(name, 'shared', 'config', app_info["ssl_certificate"] || "#{name}.crt") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
end | ||
|
||
# See #ssl_certificate | ||
# | ||
def ssl_certificate_key(applications_root, name, app_info) | ||
Pathname.new(applications_root).join(name, 'shared', 'config', app_info["ssl_certificate_key"] || "#{name}.key") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
|
||
# Include library helpers | ||
::Chef::Resource.send(:include, Rails::Helpers) | ||
::Chef::Recipe.send(:include, Rails::Helpers) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my curiosity: what does this do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without this line, the following wouldn't work, method missing:
since it's a level of recipe, not resource such as:
|
||
|
||
node[:active_applications].each do |app, app_info| | ||
rails_env = app_info['rails_env'] || "production" | ||
|
@@ -93,21 +94,17 @@ | |
|
||
end | ||
|
||
if app_info['ssl_info'] | ||
template "#{applications_root}/#{app}/shared/config/certificate.crt" do | ||
owner "deploy" | ||
group "deploy" | ||
mode 0644 | ||
source "app_cert.crt.erb" | ||
variables :app_crt=> app_info['ssl_info']['crt'] | ||
end | ||
|
||
template "#{applications_root}/#{app}/shared/config/certificate.key" do | ||
owner "deploy" | ||
group "deploy" | ||
mode 0644 | ||
source "app_cert.key.erb" | ||
variables :app_key=> app_info['ssl_info']['key'] | ||
ssl_certificate_path = ssl_certificate(applications_root, app, app_info) | ||
ssl_certificate_key_path = ssl_certificate_key(applications_root, app, app_info) | ||
|
||
if app_info["ssl_enabled"] | ||
[ssl_certificate_path, ssl_certificate_key_path].each do |pathname| | ||
cookbook_file pathname.to_s do | ||
source "certificates/#{pathname.basename.to_s}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant use of |
||
owner "deploy" | ||
group "deploy" | ||
mode 0644 | ||
end | ||
end | ||
end | ||
|
||
|
@@ -117,7 +114,9 @@ | |
name: app, | ||
domain_names: app_info["domain_names"], | ||
redirect_domain_names: app_info["redirect_domain_names"], | ||
enable_ssl: File.exists?("#{applications_root}/#{app}/shared/config/certificate.crt"), | ||
ssl_enabled: app_info["ssl_enabled"], | ||
ssl_certificate: ssl_certificate_path, | ||
ssl_certificate_key: ssl_certificate_key_path, | ||
custom_configuration: nginx_custom_configuration(app_info)) | ||
notifies :reload, resources(service: "nginx") | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ | |
|
||
# Include library helpers | ||
::Chef::Resource.send(:include, Rails::Helpers) | ||
::Chef::Recipe.send(:include, Rails::Helpers) | ||
|
||
node[:active_applications].each do |app, app_info| | ||
rails_env = app_info['rails_env'] || "production" | ||
|
@@ -98,32 +99,26 @@ | |
end | ||
|
||
if app_info['database_info'] | ||
|
||
template "#{applications_root}/#{app}/shared/config/database.yml" do | ||
owner deploy_user | ||
group deploy_user | ||
mode 0600 | ||
source "app_database.yml.erb" | ||
variables :database_info => app_info['database_info'], :rails_env => rails_env | ||
end | ||
|
||
end | ||
|
||
if app_info['ssl_info'] | ||
template "#{applications_root}/#{app}/shared/config/certificate.crt" do | ||
owner "deploy" | ||
group "deploy" | ||
mode 0644 | ||
source "app_cert.crt.erb" | ||
variables :app_crt=> app_info['ssl_info']['crt'] | ||
end | ||
|
||
template "#{applications_root}/#{app}/shared/config/certificate.key" do | ||
owner "deploy" | ||
group "deploy" | ||
mode 0644 | ||
source "app_cert.key.erb" | ||
variables :app_key=> app_info['ssl_info']['key'] | ||
ssl_certificate_path = ssl_certificate(applications_root, app, app_info) | ||
ssl_certificate_key_path = ssl_certificate_key(applications_root, app, app_info) | ||
|
||
if app_info["ssl_enabled"] | ||
[ssl_certificate_path, ssl_certificate_key_path].each do |pathname| | ||
cookbook_file pathname.to_s do | ||
source "certificates/#{pathname.basename.to_s}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant use of |
||
owner "deploy" | ||
group "deploy" | ||
mode 0644 | ||
end | ||
end | ||
end | ||
|
||
|
@@ -133,7 +128,9 @@ | |
name: app, | ||
rails_env: rails_env, | ||
domain_names: app_info["domain_names"], | ||
enable_ssl: File.exists?("#{applications_root}/#{app}/shared/config/certificate.crt"), | ||
ssl_enabled: app_info["ssl_enabled"], | ||
ssl_certificate: ssl_certificate_path, | ||
ssl_certificate_key: ssl_certificate_key_path, | ||
custom_configuration: nginx_custom_configuration(app_info)) | ||
notifies :reload, resources(:service => "nginx") | ||
end | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding this information back into a key value hash like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done