lib/piedesaint/cli.rb in piedesaint-0.1.3 vs lib/piedesaint/cli.rb in piedesaint-0.2.0
- old
+ new
@@ -1,9 +1,10 @@
require 'piedesaint'
require 'openssl'
require 'yaml'
+require 'json'
module Piedesaint
# The CLI class encapsulates the behavior of Piedesaint when it is invoked
# as a command-line utility. This allows other programs to embed Piedesaint
@@ -13,10 +14,11 @@
end
def execute
load_config
cert(@config[:host]) if @config[:refresh_cert]
+ refresh_asset_provider if @config[:refresh_asset_provider]
piedesanto = Piedesaint.new @config
piedesanto.start
end
def init ( parameters = [] )
@@ -31,10 +33,13 @@
host: "localhost",
key: File.join(".", ".piedesaint", "ssl", "server.key" ),
cert: File.join(".", ".piedesaint", "ssl", "server.crt" ),
username: "user",
password: "password",
+ asset_provider_config: "",
+ asset_provider_helper_vagrantfile: "",
+ refresh_asset_provider: true,
freshness: 3600,
metastore: 'file:/tmp/rack/meta',
entitystore: 'file:/tmp/rack/body',
tar: true,
folders: parameters }
@@ -48,10 +53,19 @@
@config[:host] = host[0]
save_config @config
cert host[0]
end
+ def asset_provider ( parameters = [] )
+ load_config
+ asset_provider_helper_vagrantfile = parameters[0] || "chef_vagrant"
+ asset_provider_config = parameters[1] || File.join("kitchen", "nodes", "vagrant.json")
+ @config[:asset_provider_helper_vagrantfile] = asset_provider_helper_vagrantfile
+ @config[:asset_provider_config] = asset_provider_config
+ save_config @config
+ end
+
private
def load_config
config_path = find_default_config_path
if config_path.nil?
abort "Configuration not provided.\nExecute '#{$PROGRAM_NAME} init' to generate one"
@@ -76,9 +90,22 @@
FileUtils.cd "ssl" do
open 'server.key', 'w' do |io| io.write key.to_pem end
open 'server.crt', 'w' do |io| io.write cert.to_pem end
end
end
+ end
+
+ def refresh_asset_provider
+ return if @config[:asset_provider_helper_vagrantfile].nil?
+ return if @config[:asset_provider_helper_vagrantfile].empty?
+ File.write(@config[:asset_provider_helper_vagrantfile], "trusted_certs_dir \"/vagrant/#{File.dirname(@config[:key])}\"")
+
+ return if @config[:asset_provider_config].nil?
+ return if @config[:asset_provider_config].empty?
+
+ asset_provider_config = JSON.parse(File.read(@config[:asset_provider_config]))
+ asset_provider_config["asset_provider"]["host"] = @config[:host]
+ File.write(@config[:asset_provider_config], JSON.pretty_generate(asset_provider_config))
end
def create_ssl_artifacts ( cn = 'localhost' )
key = OpenSSL::PKey::RSA.new 2048
\ No newline at end of file