Class: VagrantTrellisCert::Command
- Inherits:
-
Object
- Object
- VagrantTrellisCert::Command
- Defined in:
- lib/vagrant_trellis_cert/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #canonical_hosts ⇒ Object
- #config_file ⇒ Object
- #execute ⇒ Object
- #fail_with_message(msg) ⇒ Object
- #site_hosts ⇒ Object
- #sites ⇒ Object
- #tmp_path ⇒ Object
Class Method Details
.synopsis ⇒ Object
8 9 10 |
# File 'lib/vagrant_trellis_cert/command.rb', line 8 def self.synopsis "trust all Trellis self-signed certificates" end |
Instance Method Details
#canonical_hosts ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/vagrant_trellis_cert/command.rb', line 48 def canonical_hosts site_hosts.map do |host| if !host.is_a?(Hash) || !host.has_key?("canonical") File.read(File.join(@path, "roles/common/templates/site_hosts.j2")).sub!("{{ env }}", "development").gsub!(/com$/, "dev") end host.fetch("canonical") end end |
#config_file ⇒ Object
72 73 74 |
# File 'lib/vagrant_trellis_cert/command.rb', line 72 def config_file File.join(@path, "group_vars", "development", "wordpress_sites.yml") end |
#execute ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vagrant_trellis_cert/command.rb', line 12 def execute = {} opts = OptionParser.new do |o| o. = "Usage: vagrant trellis-cert [--path <path>]" o.separator "" o.version = VagrantTrellisCert::Identity.version o.program_name = "vagrant trellis-cert" o.on("--path <path>", String, "Path to the Trellis root") do |path| [:path] = path end end argv = (opts) @path = [:path] || "." FileUtils.rm_rf(tmp_path) FileUtils.mkdir_p(tmp_path) canonical_hosts.each do |host| system("openssl s_client -showcerts -connect #{host}:443 </dev/null 2>/dev/null | openssl x509 -outform PEM > #{tmp_path}/#{host}.pem 2>/dev/null") end canonical_hosts.each do |host| success = system("security add-trusted-cert -k ~/Library/Keychains/login.keychain #{tmp_path}/#{host}.pem >/dev/null 2>/dev/null") if success @env.ui.success("#{host} certificate imported successfully") else @env.ui.error("#{host} certificate import failed") end end FileUtils.rm_rf(tmp_path) end |
#fail_with_message(msg) ⇒ Object
76 77 78 |
# File 'lib/vagrant_trellis_cert/command.rb', line 76 def (msg) fail Vagrant::Errors::VagrantError.new, msg end |
#site_hosts ⇒ Object
58 59 60 |
# File 'lib/vagrant_trellis_cert/command.rb', line 58 def site_hosts sites.flat_map { |(_name, site)| site["site_hosts"] } end |
#sites ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/vagrant_trellis_cert/command.rb', line 62 def sites unless File.exists?(config_file) "#{config_file} was not found. Please run `$ vagrant trellis-cert` with `--path` option" end YAML.load_file(config_file)["wordpress_sites"].tap do |sites| "No sites found in #{config_file}." if sites.to_h.empty? end end |
#tmp_path ⇒ Object
80 81 82 |
# File 'lib/vagrant_trellis_cert/command.rb', line 80 def tmp_path "#{@env.tmp_path}/#{VagrantTrellisCert::Identity.name}" end |