Skip to content

Commit

Permalink
Merge pull request #87 from higanworks/support_ssl
Browse files Browse the repository at this point in the history
Support ssl (--[no-]ssl option)
  • Loading branch information
jkeiser committed Aug 22, 2014
2 parents 03ccf12 + 6824b0d commit 6319b1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bin/chef-zero
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ OptionParser.new do |opts|
options[:data_store] = ChefZero::DataStore::RawFileStore.new(value)
end

opts.on("--[no-]ssl", "Use SSL with self-signed certificate(Auto generate before every run). Default: false.") do |value|
options[:ssl] = value
end

opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
Expand Down
11 changes: 8 additions & 3 deletions lib/chef_zero/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

require 'rack'
require 'webrick'
require 'webrick/https'

require 'chef_zero'
require 'chef_zero/cookbook_data'
Expand Down Expand Up @@ -87,7 +88,8 @@ class Server
:port => 8889,
:log_level => :info,
:generate_real_keys => true,
:single_org => 'chef'
:single_org => 'chef',
:ssl => false
}.freeze

def initialize(options = {})
Expand Down Expand Up @@ -128,10 +130,11 @@ def port
# @return [String]
#
def url
sch = @options[:ssl] ? 'https' : 'http'
@url ||= if @options[:host].include?(':')
URI("http://[#{@options[:host]}]:#{port}").to_s
URI("#{sch}://[#{@options[:host]}]:#{port}").to_s
else
URI("http://#{@options[:host]}:#{port}").to_s
URI("#{sch}://#{@options[:host]}:#{port}").to_s
end
end

Expand Down Expand Up @@ -229,6 +232,8 @@ def start_background(wait = 5)
:DoNotListen => true,
:AccessLog => [],
:Logger => WEBrick::Log.new(StringIO.new, 7),
:SSLEnable => options[:ssl],
:SSLCertName => [ [ 'CN', WEBrick::Utils::getservername ] ],
:StartCallback => proc {
@running = true
}
Expand Down

0 comments on commit 6319b1e

Please sign in to comment.