vagrant-trellis-sequel 0.1.0 → 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/.rubocop.yml +13 -3
- data/CHANGELOG.md +19 -0
- data/Gemfile +6 -6
- data/README.md +86 -15
- data/Rakefile +1 -1
- data/lib/vagrant-trellis-sequel.rb +15 -2
- data/lib/vagrant_plugins/trellis_sequel/commands/open.rb +49 -57
- data/lib/vagrant_plugins/trellis_sequel/commands/root.rb +31 -21
- data/lib/vagrant_plugins/trellis_sequel/identity.rb +3 -3
- data/lib/vagrant_plugins/trellis_sequel/plugin.rb +3 -5
- data/lib/vagrant_plugins/trellis_sequel/spf.rb +46 -0
- data/lib/vagrant_plugins/trellis_sequel/{template.spf → template.spf.erb} +7 -7
- data/lib/vagrant_plugins/trellis_sequel/vault.rb +78 -0
- data/lib/vagrant_plugins/trellis_sequel/vault_pass.rb +26 -0
- data/vagrant-trellis-sequel.gemspec +14 -12
- metadata +22 -6
- data/.rubocop.rails.yml +0 -137
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5db09d310f510cfbd9bac485be68e65d9189d4b8
|
4
|
+
data.tar.gz: be3af33b7524317a2a0a1259ac4804b68e8f6c5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fea5685cb85b56925ec6d7b521bf4ee4e647f80352ddddb5dcd2c5132546f774ea43c3d0300de16b76666961ea755f7e92cd39e6b73b6829ebf9e00f8640e156
|
7
|
+
data.tar.gz: cbf19fa3dafb94f7d00b2d206d76b34dc93d85aab23e651e701e914d8bb58c1bb6e300eeca1a1e5b55875c9e65e3ade592ae2ba0567a6ad632c91f6c1f3fbf39
|
data/.github_changelog_generator
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
unreleased=true
|
2
|
-
future-release=v0.
|
2
|
+
future-release=v0.2.0
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
inherit_from:
|
2
|
-
- .rubocop.rails.yml
|
3
|
-
|
4
1
|
AllCops:
|
5
2
|
TargetRubyVersion: 2.3
|
3
|
+
|
4
|
+
Naming/FileName:
|
5
|
+
Exclude:
|
6
|
+
- 'lib/vagrant-trellis-sequel.rb'
|
7
|
+
|
8
|
+
Metrics/LineLength:
|
9
|
+
Max: 120
|
10
|
+
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Max: 12
|
13
|
+
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.2.0](https://github.com/TypistTech/vagrant-trellis-sequel/tree/v0.2.0) (2017-09-17)
|
4
|
+
[Full Changelog](https://github.com/TypistTech/vagrant-trellis-sequel/compare/v0.1.0...v0.2.0)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Re-raise `StandardError` as `Vagrant::Errors::CLIInvalidUsage` [\#9](https://github.com/TypistTech/vagrant-trellis-sequel/pull/9) ([TangRufus](https://github.com/TangRufus))
|
9
|
+
- Refactor [\#8](https://github.com/TypistTech/vagrant-trellis-sequel/pull/8) ([TangRufus](https://github.com/TangRufus))
|
10
|
+
- Try harder to determine vault password by looking through more possible paths [\#7](https://github.com/TypistTech/vagrant-trellis-sequel/pull/7) ([TangRufus](https://github.com/TangRufus))
|
11
|
+
- Extract class `Spf` [\#6](https://github.com/TypistTech/vagrant-trellis-sequel/pull/6) ([TangRufus](https://github.com/TangRufus))
|
12
|
+
- Fix unable to open unencrypted vault file and refactor [\#5](https://github.com/TypistTech/vagrant-trellis-sequel/pull/5) ([TangRufus](https://github.com/TangRufus))
|
13
|
+
- Use default Rubocop style [\#4](https://github.com/TypistTech/vagrant-trellis-sequel/pull/4) ([TangRufus](https://github.com/TangRufus))
|
14
|
+
- Require ruby version `~\> 2.3` [\#3](https://github.com/TypistTech/vagrant-trellis-sequel/pull/3) ([TangRufus](https://github.com/TangRufus))
|
15
|
+
- Support Ansible vault encrypted config file [\#2](https://github.com/TypistTech/vagrant-trellis-sequel/pull/2) ([TangRufus](https://github.com/TangRufus))
|
16
|
+
|
17
|
+
## [v0.1.0](https://github.com/TypistTech/vagrant-trellis-sequel/tree/v0.1.0) (2017-09-15)
|
18
|
+
**Merged pull requests:**
|
19
|
+
|
20
|
+
- first release [\#1](https://github.com/TypistTech/vagrant-trellis-sequel/pull/1) ([TangRufus](https://github.com/TangRufus))
|
21
|
+
|
3
22
|
|
4
23
|
|
5
24
|
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/Gemfile
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
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[
|
9
|
+
ENV['VAGRANT_INSTALLER_EMBEDDED_DIR'] = path if File.directory?(path)
|
10
10
|
end
|
11
11
|
|
12
|
-
unless ENV.key?(
|
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
|
15
|
-
$stderr.puts
|
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
|
25
|
+
gem 'vagrant', github: 'hashicorp/vagrant'
|
26
26
|
end
|
27
27
|
|
28
28
|
group :plugins do
|
data/README.md
CHANGED
@@ -15,9 +15,15 @@ Open Trellis databases in Sequel Pro with a single command
|
|
15
15
|
|
16
16
|
- [Installation](#installation)
|
17
17
|
- [Usage](#usage)
|
18
|
+
- [Noob](#noob)
|
19
|
+
- [Specify which site's database](#specify-which-sites-database)
|
20
|
+
- [Specify vault password file](#specify-vault-password-file)
|
21
|
+
- [Specify vault password](#specify-vault-password)
|
22
|
+
- [Common Errors](#common-errors)
|
23
|
+
- [DB password not found for `example_dev`](#db-password-not-found-for-example_dev)
|
24
|
+
- [HMAC encoded in the file does not match calculated one](#hmac-encoded-in-the-file-does-not-match-calculated-one)
|
18
25
|
- [Connection Errors](#connection-errors)
|
19
26
|
- [`key_load_public: No such file or directory`](#key_load_public-no-such-file-or-directory)
|
20
|
-
- [Help Wanted!](#help-wanted)
|
21
27
|
- [Support!](#support)
|
22
28
|
- [Donate via PayPal *](#donate-via-paypal-)
|
23
29
|
- [Why don't you hire me?](#why-dont-you-hire-me)
|
@@ -39,18 +45,89 @@ $ vagrant plugin install vagrant-trellis-sequel
|
|
39
45
|
## Usage
|
40
46
|
|
41
47
|
```bash
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
$ vagrant trellis-sequel open --help
|
49
|
+
Usage: vagrant trellis-sequel open [options] [vm-id]
|
50
|
+
|
51
|
+
--site [site] Site whose database going to be opened.
|
52
|
+
--vault-password-file [VAULT_PASSWORD_FILE]
|
53
|
+
Vault password file.
|
54
|
+
--vault-pass [VAULT_PASS] Vault password.
|
55
|
+
-h, --help Print this help
|
50
56
|
```
|
51
57
|
|
58
|
+
### Noob
|
59
|
+
|
60
|
+
```bash
|
61
|
+
$ vagrant trellis-sequel open
|
62
|
+
```
|
63
|
+
|
64
|
+
This works for most of the cases:
|
65
|
+
- `vault.yml` is unencrypted
|
66
|
+
- `vault.yml` is encrypted and `.vault_pass` contains the vault password
|
67
|
+
- running from within the Trellis directory
|
68
|
+
|
69
|
+
### Specify which site's database
|
70
|
+
|
71
|
+
```
|
72
|
+
$ vagrant trellis-sequel open --site example.com
|
73
|
+
```
|
74
|
+
|
75
|
+
Use the `--site` option to specify which site's database to open. By default, the first site's database will be opened.
|
76
|
+
Note: This is the site key of `vault_wordpress_sites` in `vault.yml`, usually ends with `.com`.
|
77
|
+
|
78
|
+
### Specify vault password file
|
79
|
+
|
80
|
+
```
|
81
|
+
$ vagrant trellis-sequel open --vault-password-file .my_vault_password_file
|
82
|
+
$ vagrant trellis-sequel open --vault-password-file /my/top/secret.txt
|
83
|
+
```
|
84
|
+
|
85
|
+
Use the `--vault-password-file` option to specify path to the vault password file, either relative path from Trellis root or absolute path.
|
86
|
+
Default value is `.vault_pass` if `vault.yml` is encrypted.
|
87
|
+
|
88
|
+
### Specify vault password
|
89
|
+
|
90
|
+
```
|
91
|
+
$ vagrant trellis-sequel open --vault-pass my-top-secret
|
92
|
+
```
|
93
|
+
|
94
|
+
Use the `--vault-pass` option to provide vault password if you encrypted `vault.yml` but don't have a vault password file.
|
95
|
+
|
96
|
+
## Common Errors
|
97
|
+
|
98
|
+
### DB password not found for `example_dev`
|
99
|
+
|
100
|
+
That means you passed wrong `--site` or `vault.yml` is malformed.
|
101
|
+
|
102
|
+
```yaml
|
103
|
+
# group_vars/development/vault.yml
|
104
|
+
|
105
|
+
vault_wordpress_sites:
|
106
|
+
example.com:
|
107
|
+
admin_password: admin
|
108
|
+
env:
|
109
|
+
db_password: bye
|
110
|
+
www.typist.tech:
|
111
|
+
admin_password: admin
|
112
|
+
env:
|
113
|
+
db_password: hello
|
114
|
+
```
|
115
|
+
|
116
|
+
For the above `vault.yml`, these 2 commands are valid:
|
117
|
+
```bash
|
118
|
+
$ vagrant trellis-sequel open --site example.com
|
119
|
+
$ vagrant trellis-sequel open --site www.typist.tech
|
120
|
+
```
|
121
|
+
|
122
|
+
|
123
|
+
### HMAC encoded in the file does not match calculated one
|
124
|
+
|
125
|
+
That means vault password is incorrect.
|
126
|
+
|
52
127
|
## Connection Errors
|
53
128
|
|
129
|
+
(This part is stolen from from [Sequel Pro for Chassis](https://github.com/Chassis/SequelPro/tree/b3236ca5205e34f6c2e135a9f1b8aa0f1686717b#connection-errors).)
|
130
|
+
|
54
131
|
If you get a connection error, the first thing to attempt to debug is to check the details that Sequel Pro gives you (under the Show Details button).
|
55
132
|
|
56
133
|
### `key_load_public: No such file or directory`
|
@@ -75,12 +152,6 @@ The simple solution is to add this to your `~/.ssh/config` file:
|
|
75
152
|
|
76
153
|
This disables using system-level keys (both from the agent, and your regular SSH keys), and disables host checks (which are not necessary for localhost). This does not affect `vagrant ssh`, which already uses these options.
|
77
154
|
|
78
|
-
## Help Wanted!
|
79
|
-
|
80
|
-
Pull requests are welcome.
|
81
|
-
|
82
|
-
- Parse database passwords from config file.
|
83
|
-
|
84
155
|
## Support!
|
85
156
|
|
86
157
|
### Donate via PayPal [](https://www.typist.tech/donate/vagrant-trellis-sequel/)
|
data/Rakefile
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require
|
3
|
+
begin
|
4
|
+
require 'vagrant'
|
5
|
+
rescue LoadError
|
6
|
+
raise 'The Vagrant Trellis Sequel 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 Sequel plugin is only compatible with Vagrant 1.9.6 or later'
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'vagrant_plugins/trellis_sequel/identity'
|
17
|
+
require 'vagrant_plugins/trellis_sequel/plugin'
|
@@ -1,80 +1,72 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require "vagrant"
|
3
|
+
require 'vagrant_plugins/trellis_sequel/spf'
|
4
|
+
require 'vagrant_plugins/trellis_sequel/vault'
|
5
|
+
require 'vagrant_plugins/trellis_sequel/vault_pass'
|
7
6
|
|
8
7
|
module VagrantPlugins
|
9
8
|
module TrellisSequel
|
10
9
|
module Commands
|
11
|
-
class Open < Vagrant.plugin(
|
10
|
+
class Open < Vagrant.plugin('2', :command)
|
12
11
|
def execute
|
12
|
+
options, argv = parse_options!
|
13
|
+
|
14
|
+
with_target_vms(argv) do |machine|
|
15
|
+
raise Vagrant::Errors::SSHNotReady unless machine.communicate.ready?
|
16
|
+
|
17
|
+
Spf.create_and_open(
|
18
|
+
data: {
|
19
|
+
database: database_for(machine_root_path: machine.env.root_path, **options),
|
20
|
+
ssh: ssh_for(machine)
|
21
|
+
},
|
22
|
+
path: machine.env.tmp_path
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Always exit with success
|
27
|
+
0
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# rubocop:disable Metrics/MethodLength
|
33
|
+
def parse_options!
|
13
34
|
options = {}
|
14
35
|
opts = OptionParser.new do |o|
|
15
|
-
o.banner =
|
16
|
-
o.separator
|
36
|
+
o.banner = 'Usage: vagrant trellis-sequel open [options] [vm-id]'
|
37
|
+
o.separator ''
|
38
|
+
|
39
|
+
o.on('--site [site]', String, 'Site whose database going to be opened.') do |site|
|
40
|
+
options[:site] = site
|
41
|
+
end
|
17
42
|
|
18
|
-
o.on(
|
19
|
-
options[:
|
43
|
+
o.on('--vault-password-file [VAULT_PASSWORD_FILE]', String, 'Vault password file.') do |vault_password_file|
|
44
|
+
options[:vault_password_file] = vault_password_file
|
20
45
|
end
|
21
46
|
|
22
|
-
o.on(
|
23
|
-
options[:
|
47
|
+
o.on('--vault-pass [VAULT_PASS]', String, 'Vault password.') do |vault_pass|
|
48
|
+
options[:vault_pass] = vault_pass
|
24
49
|
end
|
25
50
|
|
26
|
-
o.on(
|
51
|
+
o.on('-h', '--help', 'Print this help') do
|
27
52
|
@env.ui.info(opts)
|
28
53
|
exit
|
29
54
|
end
|
30
55
|
end
|
31
|
-
|
56
|
+
[options, parse_options(opts)]
|
57
|
+
end
|
58
|
+
# rubocop:enable Metrics/MethodLength
|
32
59
|
|
33
|
-
|
34
|
-
|
35
|
-
|
60
|
+
def database_for(args)
|
61
|
+
Vault.build(**args)
|
62
|
+
.database_for(**args)
|
63
|
+
end
|
36
64
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
with_target_vms(argv) do |machine|
|
44
|
-
# Collect data
|
45
|
-
ssh_info = machine.ssh_info
|
46
|
-
raise Vagrant::Errors::SSHNotReady if ssh_info.nil?
|
47
|
-
|
48
|
-
data = {
|
49
|
-
"database" => {
|
50
|
-
"name" => "#{options[:user]}_development",
|
51
|
-
"user" => options[:user],
|
52
|
-
"password" => options[:password],
|
53
|
-
},
|
54
|
-
"ssh" => {
|
55
|
-
"host" => ssh_info[:host],
|
56
|
-
"port" => ssh_info[:port],
|
57
|
-
"user" => ssh_info[:username],
|
58
|
-
"private_key_path" => ssh_info[:private_key_path],
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
# Output template
|
63
|
-
content = template.result OpenStruct.new(data).instance_eval { binding }
|
64
|
-
|
65
|
-
# Write it to the file
|
66
|
-
path = File.join(@env.tmp_path, "#{data["database"]["name"]}.spf")
|
67
|
-
file = File.open(path, "w")
|
68
|
-
file.write(content)
|
69
|
-
file.close()
|
70
|
-
|
71
|
-
# And, open it
|
72
|
-
system("open \"#{path}\"")
|
73
|
-
end
|
74
|
-
|
75
|
-
# Always exit with success
|
76
|
-
0
|
77
|
-
end
|
65
|
+
def ssh_for(machine)
|
66
|
+
machine.ssh_info.select do |key, _value|
|
67
|
+
%i[host port username private_key_path].include?(key)
|
68
|
+
end
|
69
|
+
end
|
78
70
|
end
|
79
71
|
end
|
80
72
|
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require "vagrant"
|
3
|
+
require 'optparse'
|
5
4
|
|
6
5
|
module VagrantPlugins
|
7
6
|
module TrellisSequel
|
8
7
|
module Commands
|
9
|
-
class Root < Vagrant.plugin(
|
8
|
+
class Root < Vagrant.plugin('2', :command)
|
10
9
|
def self.synopsis
|
11
|
-
|
10
|
+
'open Trellis databases in Sequel Pro'
|
12
11
|
end
|
13
12
|
|
14
13
|
def initialize(argv, env)
|
@@ -19,39 +18,50 @@ module VagrantPlugins
|
|
19
18
|
@subcommands = Vagrant::Registry.new
|
20
19
|
|
21
20
|
@subcommands.register(:open) do
|
22
|
-
require_relative
|
21
|
+
require_relative 'open'
|
23
22
|
Open
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
26
|
def execute
|
28
|
-
return help if
|
29
|
-
|
30
|
-
command_class = @subcommands.get(@sub_command&.to_sym)
|
31
|
-
return help unless command_class
|
27
|
+
return help if help? || !sub_command?
|
32
28
|
|
33
29
|
# Initialize and execute the command class
|
34
|
-
|
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
|
35
37
|
end
|
36
38
|
|
37
39
|
private
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
def help
|
50
|
+
option_parser = OptionParser.new do |opts|
|
51
|
+
opts.banner = 'Usage: vagrant trellis-sequel <command> [<args>]'
|
52
|
+
opts.separator ''
|
53
|
+
opts.separator 'Available subcommands:'
|
48
54
|
|
49
|
-
|
50
|
-
opts.separator "
|
55
|
+
@subcommands.keys.sort.each do |key|
|
56
|
+
opts.separator " #{key}"
|
51
57
|
end
|
52
58
|
|
53
|
-
|
59
|
+
opts.separator ''
|
60
|
+
opts.separator "For help on any individual command run 'vagrant trellis-sequel COMMAND -h'"
|
54
61
|
end
|
62
|
+
|
63
|
+
@env.ui.info(option_parser.help, prefix: false)
|
64
|
+
end
|
55
65
|
end
|
56
66
|
end
|
57
67
|
end
|
@@ -4,15 +4,15 @@ module VagrantPlugins
|
|
4
4
|
module TrellisSequel
|
5
5
|
module Identity
|
6
6
|
def self.name
|
7
|
-
|
7
|
+
'vagrant-trellis-sequel'
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.version
|
11
|
-
|
11
|
+
'0.2.0'
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.description
|
15
|
-
|
15
|
+
'Open Trellis databases in Sequel Pro with a single command'
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.summary
|
@@ -1,16 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "vagrant"
|
4
|
-
|
5
3
|
module VagrantPlugins
|
6
4
|
module TrellisSequel
|
7
|
-
class Plugin < Vagrant.plugin(
|
5
|
+
class Plugin < Vagrant.plugin('2')
|
8
6
|
name Identity.name
|
9
7
|
|
10
8
|
description Identity.description
|
11
9
|
|
12
|
-
command
|
13
|
-
require_relative
|
10
|
+
command 'trellis-sequel' do
|
11
|
+
require_relative 'commands/root'
|
14
12
|
Commands::Root
|
15
13
|
end
|
16
14
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module TrellisSequel
|
8
|
+
class Spf
|
9
|
+
def self.create_and_open(args)
|
10
|
+
new(args).tap(&:write).open
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(data:, path:)
|
14
|
+
db_name = data.dig(:database, :name).to_s.gsub(/\s+/, '')
|
15
|
+
raise 'You must provide data[:database][:name]' if db_name.empty?
|
16
|
+
|
17
|
+
@data = data
|
18
|
+
@path = File.join(path, "#{db_name}.spf")
|
19
|
+
end
|
20
|
+
|
21
|
+
def write
|
22
|
+
File.open(@path, 'w') do |file|
|
23
|
+
file.write(content)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def open
|
28
|
+
system("open \"#{@path}\"")
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def content
|
34
|
+
template.result(OpenStruct.new(@data).instance_eval { binding })
|
35
|
+
end
|
36
|
+
|
37
|
+
def template
|
38
|
+
ERB.new(File.read(template_path), nil, '%<>')
|
39
|
+
end
|
40
|
+
|
41
|
+
def template_path
|
42
|
+
File.join(File.dirname(__FILE__), 'template.spf.erb')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -11,25 +11,25 @@
|
|
11
11
|
<key>connection</key>
|
12
12
|
<dict>
|
13
13
|
<key>database</key>
|
14
|
-
<string><%= database[
|
14
|
+
<string><%= database[:name] %></string>
|
15
15
|
<key>host</key>
|
16
16
|
<string>127.0.0.1</string>
|
17
17
|
<key>password</key>
|
18
|
-
<string><%= database[
|
18
|
+
<string><%= database[:password] %></string>
|
19
19
|
<key>ssh_host</key>
|
20
|
-
<string><%= ssh[
|
20
|
+
<string><%= ssh[:host] %></string>
|
21
21
|
<key>ssh_keyLocation</key>
|
22
|
-
<string><%= ssh[
|
22
|
+
<string><%= ssh[:private_key_path][0] %></string>
|
23
23
|
<key>ssh_keyLocationEnabled</key>
|
24
24
|
<integer>1</integer>
|
25
25
|
<key>ssh_port</key>
|
26
|
-
<string><%= ssh[
|
26
|
+
<string><%= ssh[:port] %></string>
|
27
27
|
<key>ssh_user</key>
|
28
|
-
<string><%= ssh[
|
28
|
+
<string><%= ssh[:username] %></string>
|
29
29
|
<key>type</key>
|
30
30
|
<string>SPSSHTunnelConnection</string>
|
31
31
|
<key>user</key>
|
32
|
-
<string><%= database[
|
32
|
+
<string><%= database[:user] %></string>
|
33
33
|
</dict>
|
34
34
|
</dict>
|
35
35
|
<key>format</key>
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ansible/vault'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module TrellisSequel
|
7
|
+
class Vault
|
8
|
+
def self.build(machine_root_path:, vault_pass: nil, vault_password_file: nil, **_)
|
9
|
+
vault_path = File.join(machine_root_path, 'group_vars', 'development', 'vault.yml')
|
10
|
+
|
11
|
+
if ::Ansible::Vault.encrypted?(vault_path)
|
12
|
+
vault_pass ||= VaultPass.read_from_file(
|
13
|
+
file_path: vault_password_file,
|
14
|
+
machine_root_path: machine_root_path
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
Vault.new(path: vault_path, password: vault_pass)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(path:, password:)
|
22
|
+
@path = path
|
23
|
+
@password = password
|
24
|
+
end
|
25
|
+
|
26
|
+
def database_for(site: nil, **_)
|
27
|
+
site ||= first_wordpress_site
|
28
|
+
|
29
|
+
raise "DB password not found for #{site}" unless password_exist_for?(site)
|
30
|
+
|
31
|
+
{
|
32
|
+
name: db_name_for(site),
|
33
|
+
user: db_user_for(site),
|
34
|
+
password: db_password_for(site)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def first_wordpress_site
|
41
|
+
wordpress_sites&.keys&.first
|
42
|
+
end
|
43
|
+
|
44
|
+
def password_exist_for?(site)
|
45
|
+
!db_password_for(site).nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
def db_name_for(site)
|
49
|
+
underscore(site) + '_development'
|
50
|
+
end
|
51
|
+
|
52
|
+
def db_user_for(site)
|
53
|
+
underscore(site)
|
54
|
+
end
|
55
|
+
|
56
|
+
def db_password_for(site)
|
57
|
+
content.dig('vault_wordpress_sites', site, 'env', 'db_password')
|
58
|
+
end
|
59
|
+
|
60
|
+
def wordpress_sites
|
61
|
+
content.dig('vault_wordpress_sites')
|
62
|
+
end
|
63
|
+
|
64
|
+
def content
|
65
|
+
@content ||= YAML.safe_load(content_raw)
|
66
|
+
end
|
67
|
+
|
68
|
+
def content_raw
|
69
|
+
@content_raw ||= ::Ansible::Vault.read(path: @path, password: @password, allow_blank_password: true)
|
70
|
+
end
|
71
|
+
|
72
|
+
def underscore(domain)
|
73
|
+
domain.downcase
|
74
|
+
.tr('.', '_')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module TrellisSequel
|
5
|
+
class VaultPass
|
6
|
+
def self.read_from_file(args)
|
7
|
+
path = candidates(**args).find do |p|
|
8
|
+
File.file?(p)
|
9
|
+
end
|
10
|
+
|
11
|
+
if path.nil?
|
12
|
+
raise "Couldn't determine vault password. I looked in:\r\n * #{candidates(**args).join("\r\n * ")}\r\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
File.read(path).chomp
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.candidates(file_path:, machine_root_path:)
|
19
|
+
paths = []
|
20
|
+
paths << file_path unless file_path.nil?
|
21
|
+
paths << File.join(machine_root_path, file_path) unless file_path.nil? || machine_root_path.nil?
|
22
|
+
paths << File.join(machine_root_path, '.vault_pass') unless machine_root_path.nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,29 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require 'vagrant_plugins/trellis_sequel/identity.rb'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = VagrantPlugins::TrellisSequel::Identity.name
|
9
9
|
spec.version = VagrantPlugins::TrellisSequel::Identity.version
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
10
|
+
spec.authors = ['Tang Rufus', 'Typist Tech']
|
11
|
+
spec.email = ['tangrufus@gmail.com', 'vagrant-trellis-sequel@typist.tech']
|
12
12
|
|
13
13
|
spec.summary = VagrantPlugins::TrellisSequel::Identity.summary
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://www.typist.tech/projects/vagrant-trellis-sequel'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
|
-
spec.required_ruby_version =
|
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 =
|
22
|
+
spec.bindir = 'exe'
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = [
|
24
|
+
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
|
28
|
-
spec.add_development_dependency
|
26
|
+
spec.add_development_dependency 'ansible-vault', '~> 0.2.1'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
29
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 0.49'
|
29
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-trellis-sequel
|
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,8 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-09-
|
12
|
+
date: 2017-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ansible-vault
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.2.1
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.2.1
|
14
28
|
- !ruby/object:Gem::Dependency
|
15
29
|
name: bundler
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,7 +78,6 @@ files:
|
|
64
78
|
- ".github_changelog_generator"
|
65
79
|
- ".gitignore"
|
66
80
|
- ".hound.yml"
|
67
|
-
- ".rubocop.rails.yml"
|
68
81
|
- ".rubocop.yml"
|
69
82
|
- CHANGELOG.md
|
70
83
|
- CODE_OF_CONDUCT.md
|
@@ -77,7 +90,10 @@ files:
|
|
77
90
|
- lib/vagrant_plugins/trellis_sequel/commands/root.rb
|
78
91
|
- lib/vagrant_plugins/trellis_sequel/identity.rb
|
79
92
|
- lib/vagrant_plugins/trellis_sequel/plugin.rb
|
80
|
-
- lib/vagrant_plugins/trellis_sequel/
|
93
|
+
- lib/vagrant_plugins/trellis_sequel/spf.rb
|
94
|
+
- lib/vagrant_plugins/trellis_sequel/template.spf.erb
|
95
|
+
- lib/vagrant_plugins/trellis_sequel/vault.rb
|
96
|
+
- lib/vagrant_plugins/trellis_sequel/vault_pass.rb
|
81
97
|
- vagrant-trellis-sequel.gemspec
|
82
98
|
homepage: https://www.typist.tech/projects/vagrant-trellis-sequel
|
83
99
|
licenses:
|
@@ -89,9 +105,9 @@ require_paths:
|
|
89
105
|
- lib
|
90
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
107
|
requirements:
|
92
|
-
- - "
|
108
|
+
- - "~>"
|
93
109
|
- !ruby/object:Gem::Version
|
94
|
-
version: 2.3
|
110
|
+
version: '2.3'
|
95
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
112
|
requirements:
|
97
113
|
- - ">="
|
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
|