vault-tools 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vault-tools.rb +15 -0
- data/lib/vault-tools/config.rb +42 -20
- data/lib/vault-tools/doc_tasks.rb +44 -0
- data/lib/vault-tools/tasks.rb +1 -1
- data/lib/vault-tools/version.rb +1 -1
- data/test/config_test.rb +22 -0
- metadata +5 -4
data/lib/vault-tools.rb
CHANGED
@@ -10,6 +10,12 @@ Honeybadger.configure do |config|
|
|
10
10
|
config.api_key = ENV['HONEYBADGER_API_KEY']
|
11
11
|
end
|
12
12
|
|
13
|
+
# Yes, there's a lot of stuff on STDERR. But its on
|
14
|
+
# stderr and not stdout so you can pipe to /dev/null if
|
15
|
+
# you hate it. These methods do some pretty heavy-handed
|
16
|
+
# environment munging and could lead to some hair-pulling
|
17
|
+
# errors if you're not aware of whats going on.
|
18
|
+
|
13
19
|
module Vault
|
14
20
|
#require bundler and the proper gems for the ENV
|
15
21
|
def self.require
|
@@ -45,6 +51,14 @@ module Vault
|
|
45
51
|
Object.const_set(:Config, Vault::Config)
|
46
52
|
end
|
47
53
|
|
54
|
+
def self.load_shared_config
|
55
|
+
return unless Config.production?
|
56
|
+
if Config[:config_app]
|
57
|
+
$stderr.puts "Loading shared config from app: #{Config[:config_app]}..."
|
58
|
+
Config.load_shared!(Config[:config_app])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
48
62
|
# all in one go
|
49
63
|
def self.setup
|
50
64
|
self.require
|
@@ -52,6 +66,7 @@ module Vault
|
|
52
66
|
self.set_timezones
|
53
67
|
self.hack_time_class
|
54
68
|
self.override_global_config
|
69
|
+
self.load_shared_config
|
55
70
|
end
|
56
71
|
end
|
57
72
|
|
data/lib/vault-tools/config.rb
CHANGED
@@ -1,6 +1,48 @@
|
|
1
1
|
module Vault
|
2
2
|
module Config
|
3
3
|
@@defaults = {}
|
4
|
+
@@shared = {}
|
5
|
+
|
6
|
+
# Get a Config value
|
7
|
+
#
|
8
|
+
# This is the preferred and uniform way to access config vars because
|
9
|
+
# defaults and shared config are included in the lookup
|
10
|
+
#
|
11
|
+
# Uses defaults and shared if available. Converts upper-case ENV var names
|
12
|
+
# to lower-case default names.
|
13
|
+
#
|
14
|
+
# Order of precedence is:
|
15
|
+
# 1) app's local ENV
|
16
|
+
# 2) shared config vars
|
17
|
+
# 3) default values
|
18
|
+
#
|
19
|
+
# Config[:foo] == nil
|
20
|
+
#
|
21
|
+
# Config.default(:foo, 'bar')
|
22
|
+
# Config[:foo] == 'bar'
|
23
|
+
#
|
24
|
+
# ENV['FOO'] = 'baz'
|
25
|
+
# Config[:foo] == 'baz'
|
26
|
+
#
|
27
|
+
# @param key [Symbol] The lower-case name of the ENV value
|
28
|
+
# @return [String] The value of the ENV value or default.
|
29
|
+
def self.[](name)
|
30
|
+
var_name = name.to_s.upcase
|
31
|
+
default_name = name.to_s.downcase.to_sym
|
32
|
+
ENV[var_name] || @@shared[var_name] || @@defaults[default_name]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Loads config from another app.
|
36
|
+
def self.load_shared!(app = nil)
|
37
|
+
heroku = Heroku::API.new
|
38
|
+
@@shared = heroku.get_config_vars(app).body
|
39
|
+
end
|
40
|
+
|
41
|
+
# Reset defaults and shared values
|
42
|
+
def self.reset!
|
43
|
+
@@defaults = {}
|
44
|
+
@@shared = {}
|
45
|
+
end
|
4
46
|
|
5
47
|
# An environment variable from another app.
|
6
48
|
#
|
@@ -39,26 +81,6 @@ module Vault
|
|
39
81
|
@@defaults
|
40
82
|
end
|
41
83
|
|
42
|
-
# Get a Config value
|
43
|
-
# Uses defaults if available. Converts upper-case ENV var names
|
44
|
-
# to lower-case default names.
|
45
|
-
#
|
46
|
-
# Config[:foo] == nil
|
47
|
-
#
|
48
|
-
# Config.default(:foo, 'bar')
|
49
|
-
# Config[:foo] == 'bar'
|
50
|
-
#
|
51
|
-
# ENV['FOO'] = 'baz'
|
52
|
-
# Config[:foo] == 'baz'
|
53
|
-
#
|
54
|
-
# @param key [Symbol] The lower-case name of the ENV value
|
55
|
-
# @return [String] The value of the ENV value or default.
|
56
|
-
def self.[](name)
|
57
|
-
var_name = name.to_s.upcase
|
58
|
-
default_name = name.to_s.downcase.to_sym
|
59
|
-
ENV[var_name] || @@defaults[default_name]
|
60
|
-
end
|
61
|
-
|
62
84
|
# An environment variable.
|
63
85
|
#
|
64
86
|
# @param name [String] The name of the environment variable to fetch a
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Documentation Tasks
|
2
|
+
#
|
3
|
+
#
|
4
|
+
require 'vault-tools/s3'
|
5
|
+
|
6
|
+
namespace :docs do
|
7
|
+
desc "Publish Docs to S3"
|
8
|
+
task :publish do
|
9
|
+
DOC_BUCKET = "heroku-vault-docs2"
|
10
|
+
DOC_DIR_NAME = Dir.pwd.split("/").last
|
11
|
+
|
12
|
+
# Check for s3cmd CLI
|
13
|
+
response = system('s3cmd --version')
|
14
|
+
raise "\n\n\033[1;31m Install s3cmd through 'brew install s3cmd' if you are on a Mac or from 'http://s3tools.org/s3cmd' to use this feature.\033[0m\n\n\n" unless response
|
15
|
+
|
16
|
+
# Configure your docs amazon creds if you haven't already
|
17
|
+
unless File.exist?("#{Dir.home}/.s3cfg_docs")
|
18
|
+
puts "Configuring S3 Doc Creds - make sure you answer 'y' when asked to save ..."
|
19
|
+
sh 's3cmd --configure --config ~/.s3cfg_docs'
|
20
|
+
end
|
21
|
+
|
22
|
+
# Build Docs
|
23
|
+
Rake::Task["yard"].invoke
|
24
|
+
|
25
|
+
# Copy
|
26
|
+
sh 'mkdir -p ~/tmp'
|
27
|
+
sh "cp -R doc ~/tmp/#{DOC_DIR_NAME}"
|
28
|
+
|
29
|
+
system "s3cmd mb s3://#{DOC_BUCKET} --config ~/.s3cfg_docs"
|
30
|
+
res = system("s3cmd -P put -r ~/tmp/#{DOC_DIR_NAME} s3://#{DOC_BUCKET}/ --config ~/.s3cfg_docs")
|
31
|
+
|
32
|
+
unless res
|
33
|
+
puts "\n\033[1;31m Make sure you put the doc credentials in .s3cfg_docs file. If you don't have them talk to the S3 doc administrator.\033[0m\n\n"
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
|
37
|
+
# Cleanup
|
38
|
+
sh "rm -r ~/tmp/#{DOC_DIR_NAME}"
|
39
|
+
|
40
|
+
# Restart Vault Docs
|
41
|
+
sh "hk restart -a vault-docs"
|
42
|
+
puts "\n\033[1;32m Make sure to restart the vault-docs app to see NEW docs ( If hk restart fails )! \033[0m\n"
|
43
|
+
end
|
44
|
+
end
|
data/lib/vault-tools/tasks.rb
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
# include in Rakefile via:
|
4
4
|
#
|
5
5
|
# require 'vault-tools/tasks'
|
6
|
-
|
7
6
|
require 'vault-tools/core_db_tasks'
|
8
7
|
require 'vault-tools/vault_db_tasks'
|
9
8
|
require 'vault-tools/usage_db_tasks'
|
10
9
|
require 'vault-tools/analytics_db_tasks'
|
10
|
+
require 'vault-tools/doc_tasks'
|
11
11
|
|
12
12
|
desc "Run all pull schema tasks (all tasks that match pull_.*_schema)"
|
13
13
|
task :pull_schemas do
|
data/lib/vault-tools/version.rb
CHANGED
data/test/config_test.rb
CHANGED
@@ -4,6 +4,11 @@ require 'minitest/mock'
|
|
4
4
|
class ConfigTest < Vault::TestCase
|
5
5
|
include Vault::Test::EnvironmentHelpers
|
6
6
|
|
7
|
+
def teardown
|
8
|
+
super
|
9
|
+
Config.reset!
|
10
|
+
end
|
11
|
+
|
7
12
|
# Config.remote_env uses the Heroku API to read config vars from
|
8
13
|
# other apps.
|
9
14
|
def test_remote_env
|
@@ -16,6 +21,23 @@ class ConfigTest < Vault::TestCase
|
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
24
|
+
# Config.remote_env uses the Heroku API to read config vars from
|
25
|
+
# other apps.
|
26
|
+
def test_shared_config_loads_shared_with_correct_precedence
|
27
|
+
set_env('CONFIG_APP', 'vault-config')
|
28
|
+
api_mock = MiniTest::Mock.new
|
29
|
+
api_response = OpenStruct.new(body: {'HELLO' => 'world'})
|
30
|
+
Heroku::API.stub(:new, api_mock) do
|
31
|
+
api_mock.expect(:get_config_vars, api_response, ['vault-config'])
|
32
|
+
assert_equal(nil, Config[:hello])
|
33
|
+
Config.default(:hello, 'foo')
|
34
|
+
assert_equal('foo', Config[:hello])
|
35
|
+
# this is how we'll call it in the code
|
36
|
+
Config.load_shared!(Config[:config_app])
|
37
|
+
assert_equal('world', Config[:hello])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
19
41
|
# Config.env returns the value matching the specified environment
|
20
42
|
# variable name.
|
21
43
|
def test_env
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vault-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: scrolls
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- lib/vault-tools/app.rb
|
198
198
|
- lib/vault-tools/config.rb
|
199
199
|
- lib/vault-tools/core_db_tasks.rb
|
200
|
+
- lib/vault-tools/doc_tasks.rb
|
200
201
|
- lib/vault-tools/hid.rb
|
201
202
|
- lib/vault-tools/log.rb
|
202
203
|
- lib/vault-tools/pipeline.rb
|
@@ -239,7 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
239
240
|
version: '0'
|
240
241
|
segments:
|
241
242
|
- 0
|
242
|
-
hash:
|
243
|
+
hash: 915007437591633538
|
243
244
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
244
245
|
none: false
|
245
246
|
requirements:
|
@@ -248,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
249
|
version: '0'
|
249
250
|
segments:
|
250
251
|
- 0
|
251
|
-
hash:
|
252
|
+
hash: 915007437591633538
|
252
253
|
requirements: []
|
253
254
|
rubyforge_project:
|
254
255
|
rubygems_version: 1.8.23
|