vagrant-trellis-cert 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d90d1bac3313e8d29841f7aff663d3cf740f01f
4
- data.tar.gz: 8ffc7bc412d84e1097c8e850db92fe24377475c0
3
+ metadata.gz: 3308c07a523d858144f4a8e86ef4d1a00f523495
4
+ data.tar.gz: 3f341bca0087eeaf4ada19da414f68c6d684329a
5
5
  SHA512:
6
- metadata.gz: 0b07752816d8b7e5392708a486002d6a4ad78c3a8f0b3a966200b2910d785d9a20e7772264624f84549363c62a97c2caf22cf89e2a2cd8c09bef35fbe534576e
7
- data.tar.gz: d48928d6ed153726b14c6910ea50a4228d3164726483198ffe9757630cf42f319c928c6c89c22a23faa578f1d40fa270619edc828ad8cd644d5ea640221461d3
6
+ metadata.gz: afb38d993e30a912e5c72f3c887c328142293847249cac0300dbd606d2a3fea656ae807c8b2fa7f9894861ca213029f2dff93fb4d2693a716ec214d35087def4
7
+ data.tar.gz: 2d2ea0c737ee4305c2c003082494fe83fdae6a0343420989959c57c04fb375045f1a4c2abc2304c53ee48be036cf82e6de3e9f030abfd0978ee5dac9ca7a4ef5
@@ -1,2 +1,2 @@
1
1
  unreleased=true
2
- future-release=v0.2.0
2
+ future-release=v0.3.0
data/.gitignore CHANGED
@@ -10,5 +10,6 @@
10
10
 
11
11
  .rbenv-gemsets
12
12
  .ruby-version
13
+ /.gems/
13
14
 
14
15
  .rubocop-http*
data/.rubocop.yml CHANGED
@@ -1,11 +1,15 @@
1
- inherit_from:
2
- - .rubocop.rails.yml
3
-
4
1
  AllCops:
5
2
  TargetRubyVersion: 2.3
6
3
 
7
- Layout/IndentationConsistency:
8
- EnforcedStyle: normal
4
+ Naming/FileName:
5
+ Exclude:
6
+ - 'lib/vagrant-trellis-cert.rb'
9
7
 
10
8
  Metrics/LineLength:
11
- Max: 156
9
+ Max: 143
10
+
11
+ Metrics/MethodLength:
12
+ Max: 13
13
+
14
+ Style/Documentation:
15
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,6 +1,28 @@
1
1
  # Change Log
2
2
 
3
- ## [v0.2.0](https://github.com/TypistTech/vagrant-trellis-cert/tree/v0.2.0) (2017-09-14)
3
+ ## [v0.3.0](https://github.com/TypistTech/vagrant-trellis-cert/tree/v0.3.0) (2017-09-18)
4
+ [Full Changelog](https://github.com/TypistTech/vagrant-trellis-cert/compare/v0.2.0...v0.3.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Filter out unnecessary hosts [\#22](https://github.com/TypistTech/vagrant-trellis-cert/issues/22)
9
+ - Fail if loaded without vagrant [\#19](https://github.com/TypistTech/vagrant-trellis-cert/issues/19)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Determine current VM via `vm-id` as a vagrant plugin should [\#35](https://github.com/TypistTech/vagrant-trellis-cert/pull/35) ([TangRufus](https://github.com/TangRufus))
14
+ - Extract class `Result` [\#34](https://github.com/TypistTech/vagrant-trellis-cert/pull/34) ([TangRufus](https://github.com/TangRufus))
15
+ - Rename module Commands --\> Command [\#33](https://github.com/TypistTech/vagrant-trellis-cert/pull/33) ([TangRufus](https://github.com/TangRufus))
16
+ - Re-raise error with original backtrace [\#32](https://github.com/TypistTech/vagrant-trellis-cert/pull/32) ([TangRufus](https://github.com/TangRufus))
17
+ - Extract System::Darwin and download certs into temporary directory [\#31](https://github.com/TypistTech/vagrant-trellis-cert/pull/31) ([TangRufus](https://github.com/TangRufus))
18
+ - Update Rubocop to ~\> ~\> 0.50.0 [\#30](https://github.com/TypistTech/vagrant-trellis-cert/pull/30) ([TangRufus](https://github.com/TangRufus))
19
+ - Filter out non-ssl hosts and fork Trellis::Config [\#29](https://github.com/TypistTech/vagrant-trellis-cert/pull/29) ([TangRufus](https://github.com/TangRufus))
20
+ - Re-raise `StandardError` as `Vagrant::Errors::CLIInvalidUsage` [\#28](https://github.com/TypistTech/vagrant-trellis-cert/pull/28) ([TangRufus](https://github.com/TangRufus))
21
+ - Check vagrant requirement and assume loading this plugin normally [\#27](https://github.com/TypistTech/vagrant-trellis-cert/pull/27) ([TangRufus](https://github.com/TangRufus))
22
+ - Use Rubocop's default style and Git: Ignore /.gems/ [\#26](https://github.com/TypistTech/vagrant-trellis-cert/pull/26) ([TangRufus](https://github.com/TangRufus))
23
+ - Require ruby version `~\> 2.3` [\#24](https://github.com/TypistTech/vagrant-trellis-cert/pull/24) ([TangRufus](https://github.com/TangRufus))
24
+
25
+ ## [v0.2.0](https://github.com/TypistTech/vagrant-trellis-cert/tree/v0.2.0) (2017-09-13)
4
26
  [Full Changelog](https://github.com/TypistTech/vagrant-trellis-cert/compare/v0.1.1...v0.2.0)
5
27
 
6
28
  **Closed issues:**
@@ -10,6 +32,7 @@
10
32
 
11
33
  **Merged pull requests:**
12
34
 
35
+ - Version bump 0.2.0 [\#18](https://github.com/TypistTech/vagrant-trellis-cert/pull/18) ([TangRufus](https://github.com/TangRufus))
13
36
  - Make rubocop happy [\#17](https://github.com/TypistTech/vagrant-trellis-cert/pull/17) ([TangRufus](https://github.com/TangRufus))
14
37
  - Early quit if not on macOS [\#16](https://github.com/TypistTech/vagrant-trellis-cert/pull/16) ([TangRufus](https://github.com/TangRufus))
15
38
  - Extract `trust` subcommand and lots of refactor [\#15](https://github.com/TypistTech/vagrant-trellis-cert/pull/15) ([TangRufus](https://github.com/TangRufus))
data/Gemfile CHANGED
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
5
 
6
6
  # To make `$ bundle exec vagrant` works
7
7
  embedded_directories = %w[/Applications/Vagrant/embedded /opt/vagrant/embedded]
8
8
  embedded_directories.each do |path|
9
- ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] = path if File.directory?(path)
9
+ ENV['VAGRANT_INSTALLER_EMBEDDED_DIR'] = path if File.directory?(path)
10
10
  end
11
11
 
12
- unless ENV.key?("VAGRANT_INSTALLER_EMBEDDED_DIR")
12
+ unless ENV.key?('VAGRANT_INSTALLER_EMBEDDED_DIR')
13
13
  $stderr.puts "Couldn't find a packaged install of vagrant, and we need this"
14
- $stderr.puts "in order to make use of the RubyEncoder libraries."
15
- $stderr.puts "I looked in:"
14
+ $stderr.puts 'in order to make use of the RubyEncoder libraries.'
15
+ $stderr.puts 'I looked in:'
16
16
  embedded_locations.each do |path|
17
17
  $stderr.puts " #{path}"
18
18
  end
@@ -22,7 +22,7 @@ group :development do
22
22
  # We depend on Vagrant for development, but we don't add it as a
23
23
  # gem dependency because we expect to be installed within the
24
24
  # Vagrant environment itself using `vagrant plugin`.
25
- gem "vagrant", github: "mitchellh/vagrant"
25
+ gem 'vagrant', github: 'hashicorp/vagrant'
26
26
  end
27
27
 
28
28
  group :plugins do
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Donate via PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.typist.tech/donate/vagrant-trellis-cert/)
8
8
  [![Hire Typist Tech](https://img.shields.io/badge/Hire-Typist%20Tech-ff69b4.svg)](https://www.typist.tech/contact/)
9
9
 
10
- Trust Trellis self-signed certificates with single command
10
+ Trust Trellis self-signed certificates with a single command
11
11
 
12
12
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
13
13
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -38,18 +38,20 @@ $ vagrant plugin install vagrant-trellis-cert
38
38
  ## Usage
39
39
 
40
40
  ```bash
41
- # Trust Trellis certificates on a Trellis vagrant VM
42
- #
43
- # Usage: vagrant trellis-cert trust [options]
44
- #
45
- # -p, --path PATH Path to the Trellis root
46
- # -h, --help Print this help
47
-
48
- # Example: Running at Trellis root (same level with ansible.cfg)
41
+ Usage: vagrant trellis-cert trust [options] [vm-id]
42
+
43
+ -h, --help Print this help
44
+
45
+ # Example: Running within Trellis directory
49
46
  $ vagrant trellis-cert trust
50
47
 
51
- # Example: Specify Trellis root
52
- $ vagrant trellis-cert trust --path /path/to/trellis
48
+ # Example: Specify VM id
49
+ $ vagrant global-status
50
+ id name provider state directory
51
+ -----------------------------------------------------------------------------------
52
+ fb90ab5 default virtualbox running /Users/me/Code/trellis
53
+
54
+ $ vagrant trellis-cert trust fb90ab5
53
55
  ```
54
56
 
55
57
  ## Going super lazy
data/Rakefile CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
3
+ require 'bundler/gem_tasks'
@@ -1,4 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "vagrant_plugins/trellis_cert/identity"
4
- require "vagrant_plugins/trellis_cert/plugin"
3
+ begin
4
+ require 'vagrant'
5
+ rescue LoadError
6
+ raise 'The Vagrant Trellis Cert plugin must be run within Vagrant.'
7
+ end
8
+
9
+ # This is a sanity check to make sure no one is attempting to install
10
+ # this into an early Vagrant version.
11
+ # Requiring 1.9.6 or later because of Ruby 2.3
12
+ if Vagrant::VERSION < '1.9.6'
13
+ raise 'The Vagrant Trellis Cert plugin is only compatible with Vagrant 1.9.6 or later'
14
+ end
15
+
16
+ require 'vagrant_plugins/trellis_cert/identity'
17
+ require 'vagrant_plugins/trellis_cert/plugin'
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ module VagrantPlugins
6
+ module TrellisCert
7
+ module Command
8
+ class Root < Vagrant.plugin('2', :command)
9
+ def self.synopsis
10
+ 'trust Trellis self-signed certificates'
11
+ end
12
+
13
+ def initialize(argv, env)
14
+ super
15
+
16
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
17
+
18
+ @subcommands = Vagrant::Registry.new
19
+
20
+ @subcommands.register(:trust) do
21
+ require_relative 'trust'
22
+ Trust
23
+ end
24
+ end
25
+
26
+ def execute
27
+ return help if help? || !sub_command?
28
+
29
+ # Initialize and execute the command class
30
+ @subcommands.get(@sub_command&.to_sym)
31
+ .new(@sub_args, @env)
32
+ .execute
33
+ rescue Vagrant::Errors::VagrantError => e
34
+ raise e
35
+ rescue StandardError => e
36
+ raise Vagrant::Errors::CLIInvalidUsage, help: "#{e.message}\r\n\r\nBacktrace:\r\n#{e.backtrace&.join("\r\n")}"
37
+ end
38
+
39
+ private
40
+
41
+ def help?
42
+ (@main_args & %w[-h --help]).any?
43
+ end
44
+
45
+ def sub_command?
46
+ @subcommands.key?(@sub_command&.to_sym)
47
+ end
48
+
49
+ def help
50
+ option_parser = OptionParser.new do |opts|
51
+ opts.banner = 'Usage: vagrant trellis-cert <command> [<args>]'
52
+ opts.separator ''
53
+ opts.separator 'Available subcommands:'
54
+
55
+ @subcommands.keys.sort.each do |key|
56
+ opts.separator " #{key}"
57
+ end
58
+
59
+ opts.separator ''
60
+ opts.separator "For help on any individual command run 'vagrant trellis-cert COMMAND -h'"
61
+ end
62
+
63
+ @env.ui.info(option_parser.help, prefix: false)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vagrant_plugins/trellis_cert/ssl_config'
4
+ require 'vagrant_plugins/trellis_cert/system'
5
+
6
+ module VagrantPlugins
7
+ module TrellisCert
8
+ module Command
9
+ class Trust < Vagrant.plugin('2', :command)
10
+ def execute
11
+ _options, argv = parse_options!
12
+
13
+ # To get result variable after mktmpdir block
14
+ result = nil
15
+
16
+ with_target_vms(argv) do |machine|
17
+ raise Vagrant::Errors::SSHNotReady unless machine.communicate.ready?
18
+
19
+ machine.env.ui.info('Importing certificates...')
20
+
21
+ Dir.mktmpdir do |tmp_dir|
22
+ result = System.build(
23
+ hosts: SSLConfig.new(root_path: machine.env.root_path).canonicals,
24
+ tmp_dir: tmp_dir
25
+ ).trust
26
+ end
27
+
28
+ result.print(ui: machine.env.ui)
29
+ end
30
+
31
+ result.exit_code
32
+ end
33
+
34
+ private
35
+
36
+ def parse_options!
37
+ options = {}
38
+ opts = OptionParser.new do |o|
39
+ o.banner = 'Usage: vagrant trellis-cert trust [options] [vm-id]'
40
+ o.separator ''
41
+
42
+ o.on('-h', '--help', 'Print this help') do
43
+ @env.ui.info(opts)
44
+ exit
45
+ end
46
+ end
47
+ [options, parse_options(opts)]
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ # This class is fork form TangRufus/trellis@b4a2d87
6
+ # See: https://github.com/TangRufus/trellis/commit/b4a2d87d911d85ef863ce6fe25c
7
+ #
8
+ # TODO: Remove after roots/trellis#890 is merged.
9
+ #
10
+ module VagrantPlugins
11
+ module TrellisCert
12
+ class Config
13
+ def initialize(root_path:)
14
+ @root_path = root_path
15
+ end
16
+
17
+ def multisite_subdomains?
18
+ @using_multisite_subdomains ||= begin
19
+ wordpress_sites.any? do |(_name, site)|
20
+ site.dig('multisite', 'enabled') && site.dig('multisite', 'subdomains')
21
+ end
22
+ end
23
+ end
24
+
25
+ def canonicals
26
+ @canonicals ||= site_hosts.map { |host| host['canonical'] }
27
+ end
28
+
29
+ def redirects
30
+ @redirects ||= site_hosts.flat_map { |host| host['redirects'] }.compact
31
+ end
32
+
33
+ def site_hosts
34
+ @site_hosts ||= begin
35
+ wordpress_sites.flat_map { |(_name, site)| site['site_hosts'] }.tap do |hosts|
36
+ fail_with message: template_content if malformed?(site_hosts: hosts)
37
+ end
38
+ end
39
+ end
40
+
41
+ def wordpress_sites
42
+ @wordpress_sites ||= begin
43
+ content['wordpress_sites'].tap do |sites|
44
+ fail_with message: "No sites found in #{path}." if sites.to_h.empty?
45
+ end
46
+ end
47
+ end
48
+
49
+ def content
50
+ @content ||= begin
51
+ fail_with message: "#{path} was not found. Please check `root_path`." unless exist?
52
+ YAML.load_file(path)
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def malformed?(site_hosts:)
59
+ site_hosts.any? do |host|
60
+ !host.is_a?(Hash) || !host.key?('canonical')
61
+ end
62
+ end
63
+
64
+ def exist?
65
+ File.exist?(path)
66
+ end
67
+
68
+ def path
69
+ File.join(@root_path, 'group_vars', 'development', 'wordpress_sites.yml')
70
+ end
71
+
72
+ def template_content
73
+ File.read(File.join(@root_path, 'roles', 'common', 'templates', 'site_hosts.j2')).sub!('{{ env }}', 'development').gsub!(/com$/, 'dev')
74
+ end
75
+
76
+ def fail_with(message:)
77
+ raise Vagrant::Errors::VagrantError.new, message
78
+ end
79
+ end
80
+ end
81
+ end
@@ -4,15 +4,15 @@ module VagrantPlugins
4
4
  module TrellisCert
5
5
  module Identity
6
6
  def self.name
7
- "vagrant-trellis-cert"
7
+ 'vagrant-trellis-cert'
8
8
  end
9
9
 
10
10
  def self.version
11
- "0.2.0"
11
+ '0.3.0'
12
12
  end
13
13
 
14
14
  def self.description
15
- "Trust all Trellis self-signed certificates with single command"
15
+ 'Trust all Trellis self-signed certificates with single command'
16
16
  end
17
17
 
18
18
  def self.summary
@@ -1,17 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "vagrant"
4
-
5
3
  module VagrantPlugins
6
4
  module TrellisCert
7
- class Plugin < Vagrant.plugin("2")
5
+ class Plugin < Vagrant.plugin('2')
8
6
  name Identity.name
9
7
 
10
8
  description Identity.description
11
9
 
12
- command "trellis-cert" do
13
- require_relative "commands/root"
14
- Commands::Root
10
+ command 'trellis-cert' do
11
+ require_relative 'command/root'
12
+ Command::Root
15
13
  end
16
14
  end
17
15
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module TrellisCert
5
+ class Result
6
+ def initialize
7
+ @store = {
8
+ true => [],
9
+ false => []
10
+ }
11
+ end
12
+
13
+ def add(host:, is_success:)
14
+ @store[is_success] << host
15
+ end
16
+
17
+ def print(ui:)
18
+ successes.each do |host|
19
+ ui.success("SUCCESS: #{host}")
20
+ end
21
+
22
+ failures.each do |host|
23
+ ui.error("FAIL: #{host}")
24
+ end
25
+ end
26
+
27
+ def exit_code
28
+ !successes.empty? && failures.empty? ? 1 : 0
29
+ end
30
+
31
+ private
32
+
33
+ def successes
34
+ @store[true]
35
+ end
36
+
37
+ def failures
38
+ @store[false]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # TODO: Require actual Trellis::Config dynamically after roots/trellis#890 is merged.
4
+ require 'vagrant_plugins/trellis_cert/config'
5
+
6
+ module VagrantPlugins
7
+ module TrellisCert
8
+ class SSLConfig < Config
9
+ def wordpress_sites
10
+ @wordpress_sites ||= begin
11
+ super.select do |_name, site|
12
+ site&.dig('ssl', 'enabled')
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vagrant_plugins/trellis_cert/system/darwin'
4
+
5
+ module VagrantPlugins
6
+ module TrellisCert
7
+ module System
8
+ def self.build(args)
9
+ unless Vagrant::Util::Platform.darwin?
10
+ raise 'vagrant-trellis-cert only works on macOS. Pull requests are welcome.'
11
+ end
12
+
13
+ Darwin.new(**args)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vagrant_plugins/trellis_cert/result'
4
+
5
+ module VagrantPlugins
6
+ module TrellisCert
7
+ module System
8
+ class Darwin
9
+ KEYCHAIN = '~/Library/Keychains/login.keychain'
10
+
11
+ def initialize(hosts:, tmp_dir:)
12
+ @hosts = hosts
13
+ @tmp_dir = tmp_dir
14
+ end
15
+
16
+ def trust
17
+ Result.new.tap do |result|
18
+ @hosts.map do |host|
19
+ cert_path = "#{@tmp_dir}/#{host}.pem"
20
+
21
+ # Download certs
22
+ system("openssl s_client -showcerts -connect #{host}:443 </dev/null 2>/dev/null | \
23
+ openssl x509 -outform PEM > #{cert_path} 2>/dev/null")
24
+
25
+ is_success = system("security add-trusted-cert -k #{KEYCHAIN} #{cert_path} >/dev/null 2>/dev/null")
26
+
27
+ result.add(host: host, is_success: is_success)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,29 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "vagrant_plugins/trellis_cert/identity.rb"
5
+ require 'vagrant_plugins/trellis_cert/identity.rb'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = VagrantPlugins::TrellisCert::Identity.name
9
9
  spec.version = VagrantPlugins::TrellisCert::Identity.version
10
- spec.authors = ["Tang Rufus", "Typist Tech"]
11
- spec.email = ["tangrufus@gmail.com", "vagrant-trellis-cert@typist.tech"]
10
+ spec.authors = ['Tang Rufus', 'Typist Tech']
11
+ spec.email = ['tangrufus@gmail.com', 'vagrant-trellis-cert@typist.tech']
12
12
 
13
13
  spec.summary = VagrantPlugins::TrellisCert::Identity.summary
14
- spec.homepage = "https://www.typist.tech/projects/vagrant-trellis-cert"
15
- spec.license = "MIT"
14
+ spec.homepage = 'https://www.typist.tech/projects/vagrant-trellis-cert'
15
+ spec.license = 'MIT'
16
16
 
17
- spec.required_ruby_version = ">= 2.3.0"
17
+ spec.required_ruby_version = '~> 2.3'
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
20
  f.match(%r{^(test|spec|features)/})
21
21
  end
22
- spec.bindir = "exe"
22
+ spec.bindir = 'exe'
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
- spec.require_paths = ["lib"]
24
+ spec.require_paths = ['lib']
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.15"
27
- spec.add_development_dependency "rake", "~> 12.0"
28
- spec.add_development_dependency "rubocop", "~> 0.49"
26
+ spec.add_development_dependency 'bundler', '~> 1.15'
27
+ spec.add_development_dependency 'rake', '~> 12.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.50.0'
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-trellis-cert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tang Rufus
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-09-13 00:00:00.000000000 Z
12
+ date: 2017-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0.49'
48
+ version: 0.50.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0.49'
55
+ version: 0.50.0
56
56
  description:
57
57
  email:
58
58
  - tangrufus@gmail.com
@@ -64,7 +64,6 @@ files:
64
64
  - ".github_changelog_generator"
65
65
  - ".gitignore"
66
66
  - ".hound.yml"
67
- - ".rubocop.rails.yml"
68
67
  - ".rubocop.yml"
69
68
  - CHANGELOG.md
70
69
  - CODE_OF_CONDUCT.md
@@ -73,11 +72,15 @@ files:
73
72
  - README.md
74
73
  - Rakefile
75
74
  - lib/vagrant-trellis-cert.rb
76
- - lib/vagrant_plugins/trellis_cert/commands/root.rb
77
- - lib/vagrant_plugins/trellis_cert/commands/trust.rb
75
+ - lib/vagrant_plugins/trellis_cert/command/root.rb
76
+ - lib/vagrant_plugins/trellis_cert/command/trust.rb
77
+ - lib/vagrant_plugins/trellis_cert/config.rb
78
78
  - lib/vagrant_plugins/trellis_cert/identity.rb
79
79
  - lib/vagrant_plugins/trellis_cert/plugin.rb
80
- - lib/vagrant_plugins/trellis_cert/trellis.rb
80
+ - lib/vagrant_plugins/trellis_cert/result.rb
81
+ - lib/vagrant_plugins/trellis_cert/ssl_config.rb
82
+ - lib/vagrant_plugins/trellis_cert/system.rb
83
+ - lib/vagrant_plugins/trellis_cert/system/darwin.rb
81
84
  - vagrant-trellis-cert.gemspec
82
85
  homepage: https://www.typist.tech/projects/vagrant-trellis-cert
83
86
  licenses:
@@ -89,9 +92,9 @@ require_paths:
89
92
  - lib
90
93
  required_ruby_version: !ruby/object:Gem::Requirement
91
94
  requirements:
92
- - - ">="
95
+ - - "~>"
93
96
  - !ruby/object:Gem::Version
94
- version: 2.3.0
97
+ version: '2.3'
95
98
  required_rubygems_version: !ruby/object:Gem::Requirement
96
99
  requirements:
97
100
  - - ">="
@@ -99,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
102
  version: '0'
100
103
  requirements: []
101
104
  rubyforge_project:
102
- rubygems_version: 2.5.2
105
+ rubygems_version: 2.6.13
103
106
  signing_key:
104
107
  specification_version: 4
105
108
  summary: Trust all Trellis self-signed certificates with single command
data/.rubocop.rails.yml DELETED
@@ -1,137 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.2
3
- # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
4
- # to ignore them, so only the ones explicitly set in this file are enabled.
5
- DisabledByDefault: true
6
- Exclude:
7
- - '**/templates/**/*'
8
- - '**/vendor/**/*'
9
- - 'actionpack/lib/action_dispatch/journey/parser.rb'
10
-
11
- # Prefer &&/|| over and/or.
12
- Style/AndOr:
13
- Enabled: true
14
-
15
- # Do not use braces for hash literals when they are the last argument of a
16
- # method call.
17
- Style/BracesAroundHashParameters:
18
- Enabled: true
19
- EnforcedStyle: context_dependent
20
-
21
- # Align `when` with `case`.
22
- Layout/CaseIndentation:
23
- Enabled: true
24
-
25
- # Align comments with method definitions.
26
- Layout/CommentIndentation:
27
- Enabled: true
28
-
29
- Layout/EmptyLineAfterMagicComment:
30
- Enabled: true
31
-
32
- # In a regular class definition, no empty lines around the body.
33
- Layout/EmptyLinesAroundClassBody:
34
- Enabled: true
35
-
36
- # In a regular method definition, no empty lines around the body.
37
- Layout/EmptyLinesAroundMethodBody:
38
- Enabled: true
39
-
40
- # In a regular module definition, no empty lines around the body.
41
- Layout/EmptyLinesAroundModuleBody:
42
- Enabled: true
43
-
44
- Layout/FirstParameterIndentation:
45
- Enabled: true
46
-
47
- # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
48
- Style/HashSyntax:
49
- Enabled: true
50
-
51
- # Method definitions after `private` or `protected` isolated calls need one
52
- # extra level of indentation.
53
- Layout/IndentationConsistency:
54
- Enabled: true
55
- EnforcedStyle: rails
56
-
57
- # Two spaces, no tabs (for indentation).
58
- Layout/IndentationWidth:
59
- Enabled: true
60
-
61
- Layout/SpaceAfterColon:
62
- Enabled: true
63
-
64
- Layout/SpaceAfterComma:
65
- Enabled: true
66
-
67
- Layout/SpaceAroundEqualsInParameterDefault:
68
- Enabled: true
69
-
70
- Layout/SpaceAroundKeyword:
71
- Enabled: true
72
-
73
- Layout/SpaceAroundOperators:
74
- Enabled: true
75
-
76
- Layout/SpaceBeforeFirstArg:
77
- Enabled: true
78
-
79
- # Defining a method with parameters needs parentheses.
80
- Style/MethodDefParentheses:
81
- Enabled: true
82
-
83
- Style/FrozenStringLiteralComment:
84
- Enabled: true
85
- EnforcedStyle: always
86
- Exclude:
87
- - 'actionview/test/**/*.builder'
88
- - 'actionview/test/**/*.ruby'
89
- - 'actionpack/test/**/*.builder'
90
- - 'actionpack/test/**/*.ruby'
91
- - 'activestorage/db/migrate/**/*.rb'
92
-
93
- # Use `foo {}` not `foo{}`.
94
- Layout/SpaceBeforeBlockBraces:
95
- Enabled: true
96
-
97
- # Use `foo { bar }` not `foo {bar}`.
98
- Layout/SpaceInsideBlockBraces:
99
- Enabled: true
100
-
101
- # Use `{ a: 1 }` not `{a:1}`.
102
- Layout/SpaceInsideHashLiteralBraces:
103
- Enabled: true
104
-
105
- Layout/SpaceInsideParens:
106
- Enabled: true
107
-
108
- # Check quotes usage according to lint rule below.
109
- Style/StringLiterals:
110
- Enabled: true
111
- EnforcedStyle: double_quotes
112
-
113
- # Detect hard tabs, no hard tabs.
114
- Layout/Tab:
115
- Enabled: true
116
-
117
- # Blank lines should not have any spaces.
118
- Layout/TrailingBlankLines:
119
- Enabled: true
120
-
121
- # No trailing whitespace.
122
- Layout/TrailingWhitespace:
123
- Enabled: true
124
-
125
- # Use quotes for string literals when they are enough.
126
- Style/UnneededPercentQ:
127
- Enabled: true
128
-
129
- # Align `end` with the matching keyword or starting expression except for
130
- # assignments, where it should be aligned with the LHS.
131
- Lint/EndAlignment:
132
- Enabled: true
133
- EnforcedStyleAlignWith: variable
134
-
135
- # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
136
- Lint/RequireParentheses:
137
- Enabled: true
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "optparse"
4
- require "vagrant"
5
-
6
- module VagrantPlugins
7
- module TrellisCert
8
- module Commands
9
- class Root < Vagrant.plugin("2", :command)
10
- def self.synopsis
11
- "trust Trellis self-signed certificates"
12
- end
13
-
14
- def initialize(argv, env)
15
- super
16
-
17
- @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
18
-
19
- @subcommands = Vagrant::Registry.new
20
-
21
- @subcommands.register(:trust) do
22
- require_relative "trust"
23
- Trust
24
- end
25
- end
26
-
27
- def execute
28
- return help if (@main_args & %w[-h --help]).any?
29
-
30
- command_class = @subcommands.get(@sub_command&.to_sym)
31
- return help unless command_class
32
-
33
- # Initialize and execute the command class
34
- command_class.new(@sub_args, @env).execute
35
- end
36
-
37
- private
38
-
39
- def help
40
- option_parser = OptionParser.new do |opts|
41
- opts.banner = "Usage: vagrant trellis-cert <command> [<args>]"
42
- opts.separator ""
43
- opts.separator "Available subcommands:"
44
-
45
- @subcommands.keys.sort.each do |key|
46
- opts.separator " #{key}"
47
- end
48
-
49
- opts.separator ""
50
- opts.separator "For help on any individual command run 'vagrant trellis-cert COMMAND -h'"
51
- end
52
-
53
- @env.ui.info(option_parser.help, prefix: false)
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "fileutils"
4
- require "optparse"
5
- require "vagrant"
6
- require "vagrant_plugins/trellis_cert/trellis"
7
-
8
- module VagrantPlugins
9
- module TrellisCert
10
- module Commands
11
- class Trust < Vagrant.plugin("2", :command)
12
- def execute
13
- check_platform!
14
-
15
- options = {}
16
- parse_options(option_parser(options: options))
17
- path = options[:path] || "."
18
-
19
- tmp_dir = File.join(@env.tmp_path, Identity.name)
20
- FileUtils.mkdir_p(tmp_dir)
21
- begin
22
- results = hosts(path: path).group_by { |host| trust(host: host, tmp_dir: tmp_dir) }
23
-
24
- print_success_messages_for(successes: results.dig(true))
25
- print_error_messages_for(failures: results.dig(false))
26
- ensure
27
- FileUtils.rm_rf(tmp_dir)
28
- end
29
-
30
- exit_code_for(results: results)
31
- end
32
-
33
- private
34
-
35
- def check_platform!
36
- return if Vagrant::Util::Platform.darwin?
37
- fail Vagrant::Errors::CLIInvalidUsage.new(help: "vagrant-trellis-cert only works on macOS. Pull requests are welcome.")
38
- end
39
-
40
- def option_parser(options:)
41
- OptionParser.new do |opts|
42
- opts.banner = "Usage: vagrant trellis-cert trust [options]"
43
- opts.separator ""
44
-
45
- opts.on("-p", "--path PATH", String, "Path to the Trellis root") do |path|
46
- options[:path] = path
47
- end
48
-
49
- opts.on("-h", "--help", "Print this help") do
50
- @env.ui.info(opts)
51
- exit
52
- end
53
- end
54
- end
55
-
56
- def hosts(path:)
57
- @hosts ||= Trellis.new(path: path).canonicals
58
- end
59
-
60
- def trust(host:, tmp_dir:)
61
- system("openssl s_client -showcerts -connect #{host}:443 </dev/null 2>/dev/null | openssl x509 -outform PEM > #{tmp_dir}/#{host}.pem 2>/dev/null")
62
- system("security add-trusted-cert -k ~/Library/Keychains/login.keychain #{tmp_dir}/#{host}.pem >/dev/null 2>/dev/null")
63
- end
64
-
65
- def print_success_messages_for(successes:)
66
- successes&.each do |host|
67
- @env.ui.success("#{host} certificate imported successfully")
68
- end
69
- end
70
-
71
- def print_error_messages_for(failures:)
72
- failures&.each do |host|
73
- @env.ui.error("#{host} certificate import failed")
74
- end
75
- end
76
-
77
- def exit_code_for(results:)
78
- results.dig(false).nil? ? 0 : 1
79
- end
80
- end
81
- end
82
- end
83
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "vagrant"
4
- require "yaml"
5
-
6
- module VagrantPlugins
7
- module TrellisCert
8
- class Trellis
9
- def initialize(path:)
10
- @path = path
11
- end
12
-
13
- def canonicals
14
- malformed = site_hosts.any? do |host|
15
- !host.is_a?(Hash) || !host.key?("canonical")
16
- end
17
- fail_with(message: site_hosts_example) if malformed
18
-
19
- site_hosts.map { |host| host["canonical"] }
20
- end
21
-
22
- private
23
-
24
- def site_hosts
25
- wordpress_sites.flat_map { |(_name, site)| site["site_hosts"] }
26
- end
27
-
28
- def wordpress_sites
29
- unless File.exist?(config_file)
30
- message = "#{config_file} was not found. Perhaps `--path` is missing or incorrect."
31
- fail_with(message: message)
32
- end
33
-
34
- YAML.load_file(config_file)["wordpress_sites"].tap do |sites|
35
- fail_with(message: "No sites found in #{config_file}.") if sites.to_h.empty?
36
- end
37
- end
38
-
39
- def config_file
40
- File.join(@path, "group_vars", "development", "wordpress_sites.yml")
41
- end
42
-
43
- def site_hosts_example
44
- template = File.join(@path, "roles/common/templates/site_hosts.j2")
45
- File.read(template).sub!("{{ env }}", "development").gsub!(/com$/, "dev")
46
- end
47
-
48
- def fail_with(message:)
49
- fail Vagrant::Errors::VagrantError.new, message
50
- end
51
- end
52
- end
53
- end