dev-vault 0.5.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d012554f26c1dd685c900a550f05afdeb0aceba
4
+ data.tar.gz: 220279ed96aa66f8aeb46182c6395389d8661015
5
+ SHA512:
6
+ metadata.gz: bec5ef4030ed4fe559c9abf7d4b09ad805d3e8439c5fe6e2a0d9a88289f1a9ec40836f7b67f6bc29f2da65b3f68dd87b370a04a9d45c037bf746f5fbd768ebb0
7
+ data.tar.gz: ad7ee8e0b5e41be7f451287b8a2f863985650f13a80a283595ebcd209347fbacc04a0d0dbb917dd69548ad919f44103e3f44d695ee18e4fbaaa46bbb20965136
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ # inherit_from: .rubocop_todo.yml
2
+
3
+ Metrics/AbcSize:
4
+ Max: 48
5
+ Metrics/CyclomaticComplexity:
6
+ Max: 24
7
+ Metrics/MethodLength:
8
+ Max: 48
9
+ Metrics/PerceivedComplexity:
10
+ Max: 12
11
+
12
+ Encoding:
13
+ Enabled: false
14
+ LineLength:
15
+ Enabled: false
16
+ HashSyntax:
17
+ Enabled: false
18
+ FileName:
19
+ Enabled: false
20
+ RescueModifier:
21
+ Enabled: false
22
+ SpaceInsideStringInterpolation:
23
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dev-vault.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016 Rapid7 Inc.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in the
6
+ Software without restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8
+ Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ Dev::Vault
2
+ ===========
3
+
4
+ `Dev::Vault` is a simple wrapper around the Vault binary for development and testing. It bundles all of the published Vault binaries at `Dev::Vault::VERSION` and runs the correct build for the local system.
5
+
6
+ Note that `Dev::Vault`'s version follows that of Vault.
7
+
8
+ Vault is maintained by Hashicorp. Please see https://www.vaultproject.io/ for details.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'dev-vault'
16
+ ```
17
+
18
+ Or Gemspec:
19
+
20
+ ```ruby
21
+ spec.add_development_dependency 'dev-vault', '0.6.4'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle install
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install dev-vault
31
+
32
+ ## Usage
33
+
34
+ Run `bundle exec rake` to launch a local instance of Vault.
35
+
36
+ To integrate into tests:
37
+
38
+ ```ruby
39
+ require 'dev/vault'
40
+
41
+ RSpec.configure do |config|
42
+ config.before(:suite) do
43
+ Dev::Vault.run
44
+
45
+ ## Mute output once the vault server is running
46
+ Dev::Vault.output(false)
47
+ end
48
+
49
+ config.after(:suite) do
50
+ Dev::Vault.stop
51
+ end
52
+
53
+ ## ...
54
+ end
55
+ ```
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rapid7/dev-vault.
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require_relative './lib/dev/vault/build'
2
+
3
+ ## On interupt, wait fot the Vault process to shutdown
4
+ Signal.trap('INT') do
5
+ Dev::Vault.stop
6
+ end
7
+
8
+ task :fetch do
9
+ Dev::Vault::Build.fetch
10
+ end
11
+
12
+ task :run do
13
+ Dev::Vault.run
14
+ end
15
+
16
+ task :wait do
17
+ Dev::Vault.wait
18
+ end
19
+
20
+ task :default => [:run, :wait]
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/dev-vault.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dev/vault/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dev-vault'
8
+ spec.version = Dev::Vault::VERSION
9
+ spec.authors = ['John Manero']
10
+ spec.email = ['jmanero@rapid7.com']
11
+
12
+ spec.summary = 'Test/development wrapper for Vault by Hashicorp'
13
+ spec.description = "dev/vault bundles all of Hashicorp's platform-specific binaries "\
14
+ 'for Vault and provides helpers to detect the local platform '\
15
+ 'and run the right build.'
16
+ spec.homepage = 'https://github.com/rapid7/dev-vault'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = 'bin'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'zipruby', '~> 0.3'
25
+ spec.add_development_dependency 'bundler', '~> 1.11'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ end
@@ -0,0 +1,54 @@
1
+ require_relative '../vault'
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ begin
7
+ require 'zipruby'
8
+ rescue LoadError
9
+ puts 'To use Dev::Vault::Build, you must install the zipruby gem!'
10
+ end
11
+
12
+ module Dev
13
+ module Vault
14
+ ##
15
+ # Tools to fetch and extract Hashicorp's platform builds of Vault
16
+ ##
17
+ module Build
18
+ REPOSITORY = "https://releases.hashicorp.com/vault/#{VERSION}".freeze
19
+ PACKAGES = [
20
+ "vault_#{VERSION}_darwin_386.zip",
21
+ "vault_#{VERSION}_darwin_amd64.zip",
22
+ "vault_#{VERSION}_freebsd_386.zip",
23
+ "vault_#{VERSION}_freebsd_amd64.zip",
24
+ "vault_#{VERSION}_freebsd_arm.zip",
25
+ "vault_#{VERSION}_linux_386.zip",
26
+ "vault_#{VERSION}_linux_amd64.zip",
27
+ "vault_#{VERSION}_linux_arm.zip"
28
+ ].freeze
29
+
30
+ class << self
31
+ def fetch
32
+ uri = URI.parse(REPOSITORY)
33
+ client = Net::HTTP.new(uri.host, uri.port)
34
+ client.use_ssl = true if uri.scheme == 'https'
35
+
36
+ PACKAGES.each do |package|
37
+ puts "Fetch #{File.join(uri.path, package)}"
38
+ request = Net::HTTP::Get.new(File.join(uri.path, package))
39
+
40
+ client.request(request) do |response|
41
+ Zip::Archive.open_buffer(response.body) do |archive|
42
+ archive.each do |file|
43
+ next unless file.name == 'vault'
44
+
45
+ open(File.join(Vault.bindir, File.basename(package, '.zip')), 'wb', 00755) { |io| io.write(file.read) }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module Dev
2
+ module Vault
3
+ VERSION = '0.5.2'.freeze
4
+ end
5
+ end
data/lib/dev/vault.rb ADDED
@@ -0,0 +1,125 @@
1
+ require_relative './vault/version'
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'securerandom'
6
+
7
+ module Dev
8
+ ##
9
+ # Helpers to fetch and run a development-instance of vault
10
+ ##
11
+ module Vault
12
+ class << self
13
+ def bindir
14
+ File.expand_path('../../bin', __dir__)
15
+ end
16
+
17
+ def architecture
18
+ case RUBY_PLATFORM
19
+ when /x86_64/ then 'amd64'
20
+ when /amd64/ then 'amd64'
21
+ when /386/ then '386'
22
+ when /arm/ then 'arm'
23
+ else raise NameError, "Unable to detect system architecture for #{RUBY_PLATFORM}"
24
+ end
25
+ end
26
+
27
+ def platform
28
+ case RUBY_PLATFORM
29
+ when /darwin/ then 'darwin'
30
+ when /freebsd/ then 'freebsd'
31
+ when /linux/ then 'linux'
32
+ else raise NameError, "Unable to detect system platfrom for #{RUBY_PLATFORM}"
33
+ end
34
+ end
35
+
36
+ def bin
37
+ File.join(bindir, "vault_#{VERSION}_#{platform}_#{architecture}")
38
+ end
39
+
40
+ def token
41
+ @token ||= SecureRandom.uuid
42
+ end
43
+
44
+ def mount(name)
45
+ post = Net::HTTP::Post.new("/v1/sys/mounts/#{name}")
46
+ post.body = JSON.generate(:type => name)
47
+ post['X-Vault-Token'] = token
48
+
49
+ Net::HTTP.new('localhost', 8200).request(post)
50
+ end
51
+
52
+ def output(arg = nil)
53
+ @thread[:output] = arg unless @thread.nil? || arg.nil?
54
+ @thread[:output] unless @thread.nil?
55
+ end
56
+
57
+ def run
58
+ puts "Starting #{bin}"
59
+
60
+ ## Fork a child process for Vault from a thread
61
+ @thread = Thread.new do
62
+ IO.popen(%(#{bin} server -dev -dev-root-token-id="#{token}"), 'r+') do |io|
63
+ Thread.current[:process] = io.pid
64
+ puts "Started #{bin} (#{io.pid})"
65
+
66
+ ## Stream output
67
+ loop do
68
+ break if io.eof?
69
+ chunk = io.readpartial(1024)
70
+
71
+ if Thread.current[:output]
72
+ Thread.current[:output].write(chunk)
73
+ Thread.current[:output].flush
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ @thread[:output] = $stdout
80
+
81
+ ## Wait for the service to become ready
82
+ loop do
83
+ begin
84
+ break if @stopped
85
+
86
+ status = Net::HTTP.get('localhost', '/v1/sys/seal-status', 8200)
87
+ status = JSON.parse(status, :symbolize_names => true)
88
+
89
+ if status[:sealed]
90
+ puts 'Waiting for Vault HTTP API to be ready'
91
+ sleep 1
92
+
93
+ next
94
+ end
95
+
96
+ puts 'Vault HTTP API is ready!'
97
+ break
98
+
99
+ rescue Errno::ECONNREFUSED, JSON::ParseError
100
+ puts 'Waiting for Vault HTTP API to be ready'
101
+ sleep 1
102
+ end
103
+ end
104
+ end
105
+
106
+ def wait
107
+ @thread.join unless @thread.nil?
108
+ end
109
+
110
+ def stop
111
+ unless @thread.nil?
112
+ unless @thread[:process].nil?
113
+ puts "Stop #{bin} (#{@thread[:process]})"
114
+ Process.kill('INT', @thread[:process])
115
+ end
116
+
117
+ @thread.join
118
+ end
119
+
120
+ @thread = nil
121
+ @stopped = true
122
+ end
123
+ end
124
+ end
125
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dev-vault
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
+ platform: ruby
6
+ authors:
7
+ - John Manero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zipruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: dev/vault bundles all of Hashicorp's platform-specific binaries for Vault
56
+ and provides helpers to detect the local platform and run the right build.
57
+ email:
58
+ - jmanero@rapid7.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .rubocop.yml
65
+ - .travis.yml
66
+ - Gemfile
67
+ - LICENSE
68
+ - README.md
69
+ - Rakefile
70
+ - bin/vault_0.5.2_darwin_386
71
+ - bin/vault_0.5.2_darwin_amd64
72
+ - bin/vault_0.5.2_freebsd_386
73
+ - bin/vault_0.5.2_freebsd_amd64
74
+ - bin/vault_0.5.2_freebsd_arm
75
+ - bin/vault_0.5.2_linux_386
76
+ - bin/vault_0.5.2_linux_amd64
77
+ - bin/vault_0.5.2_linux_arm
78
+ - dev-vault.gemspec
79
+ - lib/dev/vault.rb
80
+ - lib/dev/vault/build.rb
81
+ - lib/dev/vault/version.rb
82
+ homepage: https://github.com/rapid7/dev-vault
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.0.14.1
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Test/development wrapper for Vault by Hashicorp
106
+ test_files: []