Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[READY] Allows server to pick up DOCKER_CERT_PATH variable #9

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/spurious-server
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require 'eventmachine'
require 'spurious/server/options'

options = Spurious::Server::Options.new(ENV)
ENV['DOCKER_HOST'] = options.ssl_docker_host

Excon.defaults[:write_timeout] = options.write_timeout
Excon.defaults[:read_timeout] = options.read_timeout
Expand Down
27 changes: 26 additions & 1 deletion lib/spurious/server/options.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Spurious
module Server
class Options
attr_reader :docker_full_path, :docker_host, :docker_port, :docker_api, :server_port, :server_ip, :write_timeout, :read_timeout
attr_reader :docker_full_path, :docker_host, :docker_port, :docker_api, :server_port, :server_ip, :write_timeout, :read_timeout, :cert_path

def initialize(env)
@docker_host = env['DOCKER_HOST'].nil? ? 'localhost' : env['DOCKER_HOST'][/\/\/([0-9a-z\.]+):/,1]
Expand All @@ -11,8 +11,33 @@ def initialize(env)
@server_ip = env.fetch('SPURIOUS_SERVER_IP', '0.0.0.0')
@write_timeout = env.fetch('EXCON_WRITE_TIMEOUT', 30000)
@read_timeout = env.fetch('EXCON_READ_TIMEOUT', 30000)
@cert_path = env.fetch('DOCKER_CERT_PATH', nil)
setup_ssl if @cert_path
end

def ssl_docker_host
"https://#{docker_host}:#{docker_port}"
end

protected

def setup_ssl
Docker.options = {
:client_cert => valid_cert_path?('cert.pem'),
:client_key => valid_cert_path?('key.pem'),
:ssl_ca_file => valid_cert_path?('ca.pem')
}
end

def valid_cert_path?(cert)
File.join(absolute_cert_path, cert).tap do |path|
raise "Could not find: #{path}, please check it exists in your DOCKER_CERTS_PATH folder" unless File.exists? path
end
end

def absolute_cert_path
@absolute_cert_path ||= File.expand_path cert_path
end
end
end
end