vagrant-trellis-cert 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github_changelog_generator +1 -1
- data/.hound.yml +4 -0
- data/.rubocop.rails.yml +137 -0
- data/.rubocop.yml +10 -1
- data/CHANGELOG.md +18 -0
- data/Gemfile +20 -5
- data/README.md +12 -18
- data/lib/vagrant-trellis-cert.rb +2 -2
- data/lib/vagrant_plugins/trellis_cert/commands/root.rb +58 -0
- data/lib/vagrant_plugins/trellis_cert/commands/trust.rb +83 -0
- data/lib/vagrant_plugins/trellis_cert/identity.rb +23 -0
- data/lib/vagrant_plugins/trellis_cert/plugin.rb +18 -0
- data/lib/vagrant_plugins/trellis_cert/trellis.rb +53 -0
- data/vagrant-trellis-cert.gemspec +7 -10
- metadata +14 -13
- data/lib/vagrant_trellis_cert/command.rb +0 -84
- data/lib/vagrant_trellis_cert/identity.rb +0 -14
- data/lib/vagrant_trellis_cert/plugin.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d90d1bac3313e8d29841f7aff663d3cf740f01f
|
4
|
+
data.tar.gz: 8ffc7bc412d84e1097c8e850db92fe24377475c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b07752816d8b7e5392708a486002d6a4ad78c3a8f0b3a966200b2910d785d9a20e7772264624f84549363c62a97c2caf22cf89e2a2cd8c09bef35fbe534576e
|
7
|
+
data.tar.gz: d48928d6ed153726b14c6910ea50a4228d3164726483198ffe9757630cf42f319c928c6c89c22a23faa578f1d40fa270619edc828ad8cd644d5ea640221461d3
|
data/.github_changelog_generator
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
unreleased=true
|
2
|
-
future-release=v0.
|
2
|
+
future-release=v0.2.0
|
data/.hound.yml
ADDED
data/.rubocop.rails.yml
ADDED
@@ -0,0 +1,137 @@
|
|
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
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,10 +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)
|
4
|
+
[Full Changelog](https://github.com/TypistTech/vagrant-trellis-cert/compare/v0.1.1...v0.2.0)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- Early return with `--help` [\#8](https://github.com/TypistTech/vagrant-trellis-cert/issues/8)
|
9
|
+
- Fail fast on windows [\#7](https://github.com/TypistTech/vagrant-trellis-cert/issues/7)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Make rubocop happy [\#17](https://github.com/TypistTech/vagrant-trellis-cert/pull/17) ([TangRufus](https://github.com/TangRufus))
|
14
|
+
- Early quit if not on macOS [\#16](https://github.com/TypistTech/vagrant-trellis-cert/pull/16) ([TangRufus](https://github.com/TangRufus))
|
15
|
+
- Extract `trust` subcommand and lots of refactor [\#15](https://github.com/TypistTech/vagrant-trellis-cert/pull/15) ([TangRufus](https://github.com/TangRufus))
|
16
|
+
- Use rubygem naming convention [\#12](https://github.com/TypistTech/vagrant-trellis-cert/pull/12) ([TangRufus](https://github.com/TangRufus))
|
17
|
+
- Add Hound config [\#11](https://github.com/TypistTech/vagrant-trellis-cert/pull/11) ([TangRufus](https://github.com/TangRufus))
|
18
|
+
- Load vagrant source during development [\#9](https://github.com/TypistTech/vagrant-trellis-cert/pull/9) ([TangRufus](https://github.com/TangRufus))
|
19
|
+
|
3
20
|
## [v0.1.1](https://github.com/TypistTech/vagrant-trellis-cert/tree/v0.1.1) (2017-09-12)
|
4
21
|
[Full Changelog](https://github.com/TypistTech/vagrant-trellis-cert/compare/v0.1.0...v0.1.1)
|
5
22
|
|
6
23
|
**Merged pull requests:**
|
7
24
|
|
25
|
+
- Version bump 0.1.1 [\#6](https://github.com/TypistTech/vagrant-trellis-cert/pull/6) ([TangRufus](https://github.com/TangRufus))
|
8
26
|
- Fix: Uninitialized constant [\#5](https://github.com/TypistTech/vagrant-trellis-cert/pull/5) ([TangRufus](https://github.com/TangRufus))
|
9
27
|
|
10
28
|
## [v0.1.0](https://github.com/TypistTech/vagrant-trellis-cert/tree/v0.1.0) (2017-09-12)
|
data/Gemfile
CHANGED
@@ -1,15 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
|
-
|
5
4
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
5
|
|
6
|
+
# To make `$ bundle exec vagrant` works
|
7
|
+
embedded_directories = %w[/Applications/Vagrant/embedded /opt/vagrant/embedded]
|
8
|
+
embedded_directories.each do |path|
|
9
|
+
ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] = path if File.directory?(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
unless ENV.key?("VAGRANT_INSTALLER_EMBEDDED_DIR")
|
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:"
|
16
|
+
embedded_locations.each do |path|
|
17
|
+
$stderr.puts " #{path}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
7
21
|
group :development do
|
8
|
-
|
9
|
-
gem
|
10
|
-
|
22
|
+
# We depend on Vagrant for development, but we don't add it as a
|
23
|
+
# gem dependency because we expect to be installed within the
|
24
|
+
# Vagrant environment itself using `vagrant plugin`.
|
25
|
+
gem "vagrant", github: "mitchellh/vagrant"
|
11
26
|
end
|
12
27
|
|
13
28
|
group :plugins do
|
14
|
-
|
29
|
+
gemspec
|
15
30
|
end
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[](https://www.typist.tech/donate/vagrant-trellis-cert/)
|
8
8
|
[](https://www.typist.tech/contact/)
|
9
9
|
|
10
|
-
Trust
|
10
|
+
Trust Trellis self-signed certificates with 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,19 +38,23 @@ $ vagrant plugin install vagrant-trellis-cert
|
|
38
38
|
## Usage
|
39
39
|
|
40
40
|
```bash
|
41
|
-
# Trust
|
42
|
-
|
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
|
43
47
|
|
44
|
-
# Example: Running at Trellis root
|
45
|
-
$ vagrant trellis-cert
|
48
|
+
# Example: Running at Trellis root (same level with ansible.cfg)
|
49
|
+
$ vagrant trellis-cert trust
|
46
50
|
|
47
51
|
# Example: Specify Trellis root
|
48
|
-
$ vagrant trellis-cert --path /path/to/trellis
|
52
|
+
$ vagrant trellis-cert trust --path /path/to/trellis
|
49
53
|
```
|
50
54
|
|
51
55
|
## Going super lazy
|
52
56
|
|
53
|
-
If the [vagrant-triggers](https://github.com/emyl/vagrant-triggers) plugin is installed, we can run the command on Vagrant state changes like `vagrant
|
57
|
+
If the [vagrant-triggers](https://github.com/emyl/vagrant-triggers) plugin is installed, we can run the command on Vagrant state changes like `vagrant provision`. Add these lines into Trellis' `Vagrantfile`:
|
54
58
|
|
55
59
|
```ruby
|
56
60
|
# Vagrantfile
|
@@ -58,21 +62,11 @@ If the [vagrant-triggers](https://github.com/emyl/vagrant-triggers) plugin is in
|
|
58
62
|
# Some lines of code...
|
59
63
|
|
60
64
|
Vagrant.configure('2') do |config|
|
61
|
-
|
62
65
|
# Some more lines of code later...
|
63
66
|
|
64
|
-
config.trigger.after :up, :stdout => true do
|
65
|
-
run "vagrant trellis-cert"
|
66
|
-
end
|
67
|
-
|
68
67
|
config.trigger.after :provision, :stdout => true do
|
69
|
-
run "vagrant trellis-cert"
|
68
|
+
run "vagrant trellis-cert trust"
|
70
69
|
end
|
71
|
-
|
72
|
-
config.trigger.after :reload, :stdout => true do
|
73
|
-
run "vagrant trellis-cert"
|
74
|
-
end
|
75
|
-
|
76
70
|
end
|
77
71
|
```
|
78
72
|
|
data/lib/vagrant-trellis-cert.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
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
|
@@ -0,0 +1,83 @@
|
|
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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module TrellisCert
|
5
|
+
module Identity
|
6
|
+
def self.name
|
7
|
+
"vagrant-trellis-cert"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.version
|
11
|
+
"0.2.0"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.description
|
15
|
+
"Trust all Trellis self-signed certificates with single command"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.summary
|
19
|
+
description
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "vagrant"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module TrellisCert
|
7
|
+
class Plugin < Vagrant.plugin("2")
|
8
|
+
name Identity.name
|
9
|
+
|
10
|
+
description Identity.description
|
11
|
+
|
12
|
+
command "trellis-cert" do
|
13
|
+
require_relative "commands/root"
|
14
|
+
Commands::Root
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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
|
@@ -1,32 +1,29 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
lib = File.expand_path("../lib", __FILE__)
|
5
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
-
require "
|
5
|
+
require "vagrant_plugins/trellis_cert/identity.rb"
|
7
6
|
|
8
7
|
Gem::Specification.new do |spec|
|
9
|
-
spec.name =
|
10
|
-
spec.version =
|
8
|
+
spec.name = VagrantPlugins::TrellisCert::Identity.name
|
9
|
+
spec.version = VagrantPlugins::TrellisCert::Identity.version
|
11
10
|
spec.authors = ["Tang Rufus", "Typist Tech"]
|
12
11
|
spec.email = ["tangrufus@gmail.com", "vagrant-trellis-cert@typist.tech"]
|
13
12
|
|
14
|
-
spec.summary =
|
13
|
+
spec.summary = VagrantPlugins::TrellisCert::Identity.summary
|
15
14
|
spec.homepage = "https://www.typist.tech/projects/vagrant-trellis-cert"
|
16
15
|
spec.license = "MIT"
|
17
16
|
|
17
|
+
spec.required_ruby_version = ">= 2.3.0"
|
18
18
|
|
19
|
-
spec.files
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
20
|
f.match(%r{^(test|spec|features)/})
|
21
21
|
end
|
22
22
|
spec.bindir = "exe"
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.required_ruby_version = "~> 2.2", "< 2.4"
|
27
|
-
spec.required_rubygems_version = ">= 1.3.6"
|
28
|
-
|
29
26
|
spec.add_development_dependency "bundler", "~> 1.15"
|
30
|
-
spec.add_development_dependency "rake", "~>
|
27
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
31
28
|
spec.add_development_dependency "rubocop", "~> 0.49"
|
32
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.
|
4
|
+
version: 0.2.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-
|
12
|
+
date: 2017-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '12.0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '12.0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rubocop
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,6 +63,8 @@ extra_rdoc_files: []
|
|
63
63
|
files:
|
64
64
|
- ".github_changelog_generator"
|
65
65
|
- ".gitignore"
|
66
|
+
- ".hound.yml"
|
67
|
+
- ".rubocop.rails.yml"
|
66
68
|
- ".rubocop.yml"
|
67
69
|
- CHANGELOG.md
|
68
70
|
- CODE_OF_CONDUCT.md
|
@@ -71,9 +73,11 @@ files:
|
|
71
73
|
- README.md
|
72
74
|
- Rakefile
|
73
75
|
- lib/vagrant-trellis-cert.rb
|
74
|
-
- lib/
|
75
|
-
- lib/
|
76
|
-
- lib/
|
76
|
+
- lib/vagrant_plugins/trellis_cert/commands/root.rb
|
77
|
+
- lib/vagrant_plugins/trellis_cert/commands/trust.rb
|
78
|
+
- lib/vagrant_plugins/trellis_cert/identity.rb
|
79
|
+
- lib/vagrant_plugins/trellis_cert/plugin.rb
|
80
|
+
- lib/vagrant_plugins/trellis_cert/trellis.rb
|
77
81
|
- vagrant-trellis-cert.gemspec
|
78
82
|
homepage: https://www.typist.tech/projects/vagrant-trellis-cert
|
79
83
|
licenses:
|
@@ -85,17 +89,14 @@ require_paths:
|
|
85
89
|
- lib
|
86
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
91
|
requirements:
|
88
|
-
- - "
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '2.2'
|
91
|
-
- - "<"
|
92
|
+
- - ">="
|
92
93
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
94
|
+
version: 2.3.0
|
94
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
96
|
requirements:
|
96
97
|
- - ">="
|
97
98
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
99
|
+
version: '0'
|
99
100
|
requirements: []
|
100
101
|
rubyforge_project:
|
101
102
|
rubygems_version: 2.5.2
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "fileutils"
|
4
|
-
require "yaml"
|
5
|
-
|
6
|
-
module VagrantTrellisCert
|
7
|
-
class Command < Vagrant.plugin("2", :command)
|
8
|
-
def self.synopsis
|
9
|
-
"trust all Trellis self-signed certificates"
|
10
|
-
end
|
11
|
-
|
12
|
-
def execute
|
13
|
-
options = {}
|
14
|
-
opts = OptionParser.new do |o|
|
15
|
-
o.banner = "Usage: vagrant trellis-cert [--path <path>]"
|
16
|
-
o.separator ""
|
17
|
-
o.version = VagrantTrellisCert::Identity.version
|
18
|
-
o.program_name = "vagrant trellis-cert"
|
19
|
-
|
20
|
-
o.on("--path <path>", String, "Path to the Trellis root") do |path|
|
21
|
-
options[:path] = path
|
22
|
-
end
|
23
|
-
end
|
24
|
-
argv = parse_options(opts)
|
25
|
-
|
26
|
-
@path = options[:path] || "."
|
27
|
-
|
28
|
-
FileUtils.rm_rf(tmp_path)
|
29
|
-
FileUtils.mkdir_p(tmp_path)
|
30
|
-
|
31
|
-
canonical_hosts.each do |host|
|
32
|
-
system("openssl s_client -showcerts -connect #{host}:443 </dev/null 2>/dev/null | openssl x509 -outform PEM > #{tmp_path}/#{host}.pem 2>/dev/null")
|
33
|
-
end
|
34
|
-
|
35
|
-
canonical_hosts.each do |host|
|
36
|
-
success = system("security add-trusted-cert -k ~/Library/Keychains/login.keychain #{tmp_path}/#{host}.pem >/dev/null 2>/dev/null")
|
37
|
-
|
38
|
-
if success
|
39
|
-
@env.ui.success("#{host} certificate imported successfully")
|
40
|
-
else
|
41
|
-
@env.ui.error("#{host} certificate import failed")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
FileUtils.rm_rf(tmp_path)
|
46
|
-
end
|
47
|
-
|
48
|
-
def canonical_hosts
|
49
|
-
site_hosts.map do |host|
|
50
|
-
if !host.is_a?(Hash) || !host.has_key?("canonical")
|
51
|
-
fail_with_message File.read(File.join(@path, "roles/common/templates/site_hosts.j2")).sub!("{{ env }}", "development").gsub!(/com$/, "dev")
|
52
|
-
end
|
53
|
-
|
54
|
-
host.fetch("canonical")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def site_hosts
|
59
|
-
sites.flat_map { |(_name, site)| site["site_hosts"] }
|
60
|
-
end
|
61
|
-
|
62
|
-
def sites
|
63
|
-
unless File.exists?(config_file)
|
64
|
-
fail_with_message "#{config_file} was not found. Please run `$ vagrant trellis-cert` with `--path` option"
|
65
|
-
end
|
66
|
-
|
67
|
-
YAML.load_file(config_file)["wordpress_sites"].tap do |sites|
|
68
|
-
fail_with_message "No sites found in #{config_file}." if sites.to_h.empty?
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def config_file
|
73
|
-
File.join(@path, "group_vars", "development", "wordpress_sites.yml")
|
74
|
-
end
|
75
|
-
|
76
|
-
def fail_with_message(msg)
|
77
|
-
fail Vagrant::Errors::VagrantError.new, msg
|
78
|
-
end
|
79
|
-
|
80
|
-
def tmp_path
|
81
|
-
"#{@env.tmp_path}/#{VagrantTrellisCert::Identity.name}"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|