vault-tools 1.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +15 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +60 -66
- data/README.md +5 -14
- data/lib/vault-tools/app.rb +3 -3
- data/lib/vault-tools/config.rb +6 -24
- data/lib/vault-tools/log.rb +4 -4
- data/lib/vault-tools/pipeline.rb +2 -2
- data/lib/vault-tools/s3.rb +9 -9
- data/lib/vault-tools/statement_store.rb +15 -9
- data/lib/vault-tools/time.rb +1 -1
- data/lib/vault-tools/user.rb +3 -3
- data/lib/vault-tools/version.rb +1 -1
- data/lib/vault-tools/web.rb +10 -2
- data/lib/vault-tools.rb +1 -5
- data/test/config_test.rb +5 -34
- data/test/defaults_test.rb +4 -4
- data/test/helper.rb +12 -46
- data/test/log_test.rb +6 -5
- data/test/s3_test.rb +16 -16
- data/test/statement_store_test.rb +9 -12
- data/test/web_test.rb +1 -0
- data/vault-tools.gemspec +8 -7
- metadata +17 -47
- data/.travis.yml +0 -6
- data/lib/vault-tools/tracing/sidekiq_client.rb +0 -37
- data/lib/vault-tools/tracing/sidekiq_server.rb +0 -54
- data/lib/vault-tools/tracing.rb +0 -92
- data/test/tracing_test.rb +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30215f797eb0408bdb04fcef03f996e62742d53900ab541fa88778d3bd9c3bb7
|
4
|
+
data.tar.gz: 30dd62061f20a3f7c4d98485d33d2dfaed376ecd09d872a795879c3fa29e062a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47006d1b43d504f4faeb5052485b4fcc899be520353c84d1bbf80091983a2406977166a4089807f4222d54baafce4d0ccf1c74264cde82fa35c798448deb4c27
|
7
|
+
data.tar.gz: 23e8a5878796fef48fb97f809e87d813d9c12943d34e3acec788735920391bab399f32dbf7a33b94d51f3867ca5cbc048f149ae3c183b31d0237cb171ee84390
|
@@ -0,0 +1,15 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.7.1
|
7
|
+
|
8
|
+
steps:
|
9
|
+
- checkout
|
10
|
+
- run: export BUNDLE_GEMFILE=$PWD/Gemfile
|
11
|
+
- run: ruby --version
|
12
|
+
- run: gem update --system
|
13
|
+
- run: gem install bundler -v '< 2'
|
14
|
+
- run: bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
15
|
+
- run: bundle exec rake
|
data/Gemfile
CHANGED
@@ -4,12 +4,12 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :development do
|
7
|
-
gem 'rake', '~>
|
7
|
+
gem 'rake', '~> 13.0'
|
8
8
|
gem 'shotgun', '~> 0.9.2'
|
9
9
|
gem 'yard-sinatra'
|
10
10
|
end
|
11
11
|
|
12
12
|
group :test do
|
13
|
-
gem '
|
14
|
-
gem 'vault-test-tools', '~>
|
13
|
+
gem 'minitest-around'
|
14
|
+
gem 'vault-test-tools', '~> 1.1.0'
|
15
15
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,113 +1,107 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vault-tools (1.0
|
5
|
-
aws-sdk (~> 1.0)
|
4
|
+
vault-tools (2.1.0)
|
5
|
+
aws-sdk-s3 (~> 1.0)
|
6
6
|
coderay
|
7
7
|
excon
|
8
|
-
fernet (= 2.0
|
9
|
-
heroku-api
|
8
|
+
fernet (= 2.0)
|
10
9
|
rack (~> 2.0)
|
11
10
|
rack-ssl-enforcer
|
12
|
-
rollbar (~> 2.
|
11
|
+
rollbar (~> 2.18.2)
|
13
12
|
scrolls (~> 0.9)
|
14
13
|
sinatra (~> 2.0.4)
|
15
14
|
uuidtools
|
16
|
-
zipkin-tracer (~> 0.27)
|
17
15
|
|
18
16
|
GEM
|
19
17
|
remote: https://rubygems.org/
|
20
18
|
specs:
|
21
|
-
aws-
|
22
|
-
|
23
|
-
aws-sdk-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
19
|
+
aws-eventstream (1.1.1)
|
20
|
+
aws-partitions (1.491.0)
|
21
|
+
aws-sdk-core (3.119.1)
|
22
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
23
|
+
aws-partitions (~> 1, >= 1.239.0)
|
24
|
+
aws-sigv4 (~> 1.1)
|
25
|
+
jmespath (~> 1.0)
|
26
|
+
aws-sdk-kms (1.46.0)
|
27
|
+
aws-sdk-core (~> 3, >= 3.119.0)
|
28
|
+
aws-sigv4 (~> 1.1)
|
29
|
+
aws-sdk-s3 (1.99.0)
|
30
|
+
aws-sdk-core (~> 3, >= 3.119.0)
|
31
|
+
aws-sdk-kms (~> 1)
|
32
|
+
aws-sigv4 (~> 1.1)
|
33
|
+
aws-sigv4 (1.2.4)
|
34
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
35
|
+
coderay (1.1.3)
|
36
|
+
dotenv (2.7.6)
|
37
|
+
excon (0.85.0)
|
38
|
+
fernet (2.0)
|
33
39
|
valcro (= 0.1)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
pry (0.12.2)
|
54
|
-
coderay (~> 1.1.0)
|
55
|
-
method_source (~> 0.9.0)
|
56
|
-
rack (2.0.6)
|
57
|
-
rack-protection (2.0.4)
|
40
|
+
jmespath (1.4.0)
|
41
|
+
logfmt (0.0.9)
|
42
|
+
method_source (1.0.0)
|
43
|
+
mini_portile2 (2.6.1)
|
44
|
+
minitest (5.14.4)
|
45
|
+
minitest-around (0.5.0)
|
46
|
+
minitest (~> 5.0)
|
47
|
+
multi_json (1.15.0)
|
48
|
+
mustermann (1.1.1)
|
49
|
+
ruby2_keywords (~> 0.0.1)
|
50
|
+
nokogiri (1.12.3)
|
51
|
+
mini_portile2 (~> 2.6.1)
|
52
|
+
racc (~> 1.4)
|
53
|
+
pry (0.14.1)
|
54
|
+
coderay (~> 1.1)
|
55
|
+
method_source (~> 1.0)
|
56
|
+
racc (1.5.2)
|
57
|
+
rack (2.2.3)
|
58
|
+
rack-protection (2.0.8.1)
|
58
59
|
rack
|
59
60
|
rack-ssl-enforcer (0.2.9)
|
60
61
|
rack-test (1.1.0)
|
61
62
|
rack (>= 1.0, < 3)
|
62
|
-
rake (
|
63
|
-
rdoc (6.
|
64
|
-
rollbar (2.
|
63
|
+
rake (13.0.6)
|
64
|
+
rdoc (6.3.2)
|
65
|
+
rollbar (2.18.2)
|
65
66
|
multi_json
|
66
67
|
rr (1.2.1)
|
67
|
-
|
68
|
+
ruby2_keywords (0.0.5)
|
69
|
+
scrolls (0.9.1)
|
68
70
|
shotgun (0.9.2)
|
69
71
|
rack (>= 1.0)
|
70
|
-
sinatra (2.0.
|
72
|
+
sinatra (2.0.8.1)
|
71
73
|
mustermann (~> 1.0)
|
72
74
|
rack (~> 2.0)
|
73
|
-
rack-protection (= 2.0.
|
75
|
+
rack-protection (= 2.0.8.1)
|
74
76
|
tilt (~> 2.0)
|
75
|
-
|
76
|
-
|
77
|
-
thrift (0.9.3.0)
|
78
|
-
tilt (2.0.8)
|
79
|
-
uuidtools (2.1.5)
|
77
|
+
tilt (2.0.10)
|
78
|
+
uuidtools (2.2.0)
|
80
79
|
valcro (0.1)
|
81
|
-
vault-test-tools (
|
80
|
+
vault-test-tools (1.1.0)
|
82
81
|
logfmt
|
83
82
|
minitest (~> 5.11)
|
84
83
|
nokogiri
|
85
84
|
rack-test (~> 1.1)
|
86
|
-
rr
|
87
|
-
scrolls
|
88
|
-
yard (0.9.
|
85
|
+
rr (~> 1.2)
|
86
|
+
scrolls
|
87
|
+
yard (0.9.26)
|
89
88
|
yard-sinatra (1.0.0)
|
90
89
|
yard (~> 0.7)
|
91
|
-
zipkin-tracer (0.29.1)
|
92
|
-
faraday (~> 0.8)
|
93
|
-
finagle-thrift (~> 1.4.2)
|
94
|
-
rack (>= 1.0)
|
95
|
-
sucker_punch (~> 2.0)
|
96
90
|
|
97
91
|
PLATFORMS
|
98
92
|
ruby
|
99
93
|
|
100
94
|
DEPENDENCIES
|
101
95
|
dotenv
|
102
|
-
|
96
|
+
minitest-around
|
103
97
|
pry
|
104
|
-
rake (~>
|
98
|
+
rake (~> 13.0)
|
105
99
|
rdoc
|
106
100
|
shotgun (~> 0.9.2)
|
107
|
-
vault-test-tools (~>
|
101
|
+
vault-test-tools (~> 1.1.0)
|
108
102
|
vault-tools!
|
109
103
|
yard
|
110
104
|
yard-sinatra
|
111
105
|
|
112
106
|
BUNDLED WITH
|
113
|
-
|
107
|
+
2.2.26
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Tools is the English word for ツール. Tooling for the Heroku Vault
|
4
4
|
team to enable faster bootstrapping for Ruby projects.
|
5
5
|
|
6
|
-
[![
|
6
|
+
[![CircleCI](https://circleci.com/gh/heroku/vault-tools/tree/master.svg?style=shield&circle-token=39ec638ab252a4440ca919f9b09dc258b4459c58)](_https://circleci.com/gh/heroku/vault-tools/tree/master_)
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -26,9 +26,6 @@ calling `Vault.setup` will:
|
|
26
26
|
- if the `CONFIG_APP` environment variable is defined and this is
|
27
27
|
the production environment, it will attempt to use the Heroku API
|
28
28
|
to load the config vars from another app into `Vault::Config`
|
29
|
-
- enable distributed tracing via Zipkin, if the [required config
|
30
|
-
vars](#configs-for-tracing) are set
|
31
|
-
|
32
29
|
|
33
30
|
### `Vault::Config`
|
34
31
|
|
@@ -93,16 +90,10 @@ Generate the API documentation:
|
|
93
90
|
|
94
91
|
vendor/bin/d
|
95
92
|
|
96
|
-
## Configs for tracing
|
97
|
-
|
98
|
-
The following are config vars to be set in the consumer app for tracing with
|
99
|
-
Zipkin:
|
100
|
-
* `APP_NAME` (required) what the trace will show up as in the Zipkin interface.
|
101
|
-
* `ZIPKIN_ENABLED` (required) must be set to `true` to start tracing.
|
102
|
-
* `ZIPKIN_API_HOST` (required) where to post traces to. URL must contain the
|
103
|
-
basic auth creds from the Tools team.
|
104
|
-
* `ZIPKIN_SAMPLE_RATE` defaults to `0.1`.
|
105
|
-
|
106
93
|
## Releasing
|
107
94
|
|
108
95
|
> bundle exec rake release
|
96
|
+
|
97
|
+
## Release Notes
|
98
|
+
Version 2.1.0 (2021-08-26):
|
99
|
+
guard-minitest was removed due to it causing problems with the ruby version upgrade. Was not actively used anymore. Hasn't been updated in a long time.
|
data/lib/vault-tools/app.rb
CHANGED
@@ -5,7 +5,7 @@ module Vault
|
|
5
5
|
ID_CAPTURE = /\Aapp(\d+)\@[\w\.]+com\z/
|
6
6
|
# Convert a core app ID into a Heroku app ID.
|
7
7
|
#
|
8
|
-
# @param app_id [
|
8
|
+
# @param app_id [Integer] A core app ID.
|
9
9
|
# @return [String] A Heroku ID that uniquely represents the app.
|
10
10
|
def self.id_to_hid(app_id)
|
11
11
|
"app#{app_id}@heroku.com"
|
@@ -13,7 +13,7 @@ module Vault
|
|
13
13
|
|
14
14
|
# Convert a core app ID into a v5 UUID.
|
15
15
|
#
|
16
|
-
# @param app_id [
|
16
|
+
# @param app_id [Integer] An app ID.
|
17
17
|
# @return [String] A v5 UUID that uniquely represents the app.
|
18
18
|
def self.id_to_uuid(app_id)
|
19
19
|
url = "https://vault.heroku.com/apps/#{app_id}"
|
@@ -24,7 +24,7 @@ module Vault
|
|
24
24
|
#
|
25
25
|
# @param heroku_id [String] A Heroku app ID, such as `app1234@heroku.com`.
|
26
26
|
# @raise [ArgumentError] Raised if a malformed Heroku ID is provided.
|
27
|
-
# @return [
|
27
|
+
# @return [Integer] The core app ID that uniquely represents the app.
|
28
28
|
def self.hid_to_id(heroku_id)
|
29
29
|
if app_id = heroku_id.slice(ID_CAPTURE, 1)
|
30
30
|
app_id.to_i
|
data/lib/vault-tools/config.rb
CHANGED
@@ -32,30 +32,12 @@ module Vault
|
|
32
32
|
ENV[var_name] || @@shared[var_name] || @@defaults[default_name]
|
33
33
|
end
|
34
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
35
|
# Reset defaults and shared values
|
42
36
|
def self.reset!
|
43
37
|
@@defaults = {}
|
44
38
|
@@shared = {}
|
45
39
|
end
|
46
40
|
|
47
|
-
# An environment variable from another app.
|
48
|
-
#
|
49
|
-
# @param app [String] The name of the app to get the value from.
|
50
|
-
# @param name [String] The name of the environment variable to fetch a
|
51
|
-
# value for.
|
52
|
-
# @return [String] The value of an environment variable from another
|
53
|
-
# Heroku app or nil if no match is available.
|
54
|
-
def self.remote_env(app, name)
|
55
|
-
heroku = Heroku::API.new
|
56
|
-
heroku.get_config_vars(app).body[name]
|
57
|
-
end
|
58
|
-
|
59
41
|
# An environment variable.
|
60
42
|
#
|
61
43
|
# @param name [String] The name of the environment variable to fetch a
|
@@ -126,7 +108,7 @@ module Vault
|
|
126
108
|
|
127
109
|
# The port to listen on for web requests.
|
128
110
|
#
|
129
|
-
# @return [
|
111
|
+
# @return [Integer] The port to listen on for web requests.
|
130
112
|
def self.port
|
131
113
|
env!("PORT").to_i
|
132
114
|
end
|
@@ -148,12 +130,12 @@ module Vault
|
|
148
130
|
!bool?('VAULT_TOOLS_DISABLE_SSL')
|
149
131
|
end
|
150
132
|
|
151
|
-
# An environment variable converted to a
|
133
|
+
# An environment variable converted to a Integer.
|
152
134
|
#
|
153
135
|
# @param name [String] The name of the environment variable to fetch a
|
154
|
-
#
|
155
|
-
# @return [
|
156
|
-
#
|
136
|
+
# Integer for.
|
137
|
+
# @return [Integer] The number or nil if the value couldn't be coerced to a
|
138
|
+
# Integer.
|
157
139
|
def self.int(name)
|
158
140
|
self[name] && self[name].to_i
|
159
141
|
end
|
@@ -194,7 +176,7 @@ module Vault
|
|
194
176
|
|
195
177
|
# The number of threads to use in Sidekiq workers.
|
196
178
|
#
|
197
|
-
# @return [
|
179
|
+
# @return [Integer] The number of threads from the `SIDEKIQ_CONCURRENCY`
|
198
180
|
# environment variable or 25 if no variable is defined.
|
199
181
|
def self.sidekiq_concurrency
|
200
182
|
int('SIDEKIQ_CONCURRENCY') || 25
|
data/lib/vault-tools/log.rb
CHANGED
@@ -19,9 +19,9 @@ module Vault
|
|
19
19
|
# This makes it possible to easily measure individual HTTP status codes as
|
20
20
|
# well as classes of HTTP status codes.
|
21
21
|
#
|
22
|
-
# @param status [
|
23
|
-
def self.count_status(status)
|
24
|
-
count("http.#{status}")
|
22
|
+
# @param status [Integer] The HTTP status code to record.
|
23
|
+
def self.count_status(status, data)
|
24
|
+
count("http.#{status}", 1, data)
|
25
25
|
if status_prefix = status.to_s.match(/\d/)[0]
|
26
26
|
count("http.#{status_prefix}xx")
|
27
27
|
end
|
@@ -39,7 +39,7 @@ module Vault
|
|
39
39
|
# Log a timing metric.
|
40
40
|
#
|
41
41
|
# @param name [String] A Sinatra-formatted route URL.
|
42
|
-
# @param duration [
|
42
|
+
# @param duration [Integer] The duration to record, in milliseconds.
|
43
43
|
def self.time(name, duration)
|
44
44
|
if name
|
45
45
|
name.gsub(/\/:\w+/, ''). # Remove param names from path.
|
data/lib/vault-tools/pipeline.rb
CHANGED
data/lib/vault-tools/s3.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'aws-sdk'
|
1
|
+
require 'aws-sdk-s3'
|
2
2
|
|
3
3
|
module S3
|
4
4
|
extend self
|
@@ -10,7 +10,7 @@ module S3
|
|
10
10
|
# @param value [String]
|
11
11
|
def write(bucket, key, value)
|
12
12
|
Vault::Log.log(:fn => __method__, :key => key) do
|
13
|
-
s3.
|
13
|
+
s3.put_object({bucket: bucket, key: key, body: value})
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -20,17 +20,17 @@ module S3
|
|
20
20
|
# @param key [String]
|
21
21
|
def read(bucket, key)
|
22
22
|
Vault::Log.log(:fn => __method__, :key => key) do
|
23
|
-
s3.
|
23
|
+
s3.get_object({bucket: bucket, key: key}).body.read
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
# Get the underlying AWS::S3 instance, creating it using environment
|
28
|
-
# if necessary.
|
27
|
+
# Get the underlying AWS::S3::Client instance, creating it using environment
|
28
|
+
# vars if necessary.
|
29
29
|
def s3
|
30
|
-
@s3 ||=
|
31
|
-
:
|
32
|
-
|
33
|
-
:
|
30
|
+
@s3 ||= Aws::S3::Client.new(
|
31
|
+
credentials: Aws::Credentials.new(Config.env('AWS_ACCESS_KEY_ID'),
|
32
|
+
Config.env('AWS_SECRET_ACCESS_KEY')),
|
33
|
+
region: Config.env('AWS_REGION')
|
34
34
|
)
|
35
35
|
end
|
36
36
|
|
@@ -2,8 +2,9 @@ module Vault
|
|
2
2
|
# The StatementStore knows how to save and retrieve invoices from S3
|
3
3
|
class StatementStore
|
4
4
|
def initialize(opts = {})
|
5
|
-
@
|
6
|
-
|
5
|
+
@credentials = Aws::Credentials.new(opts.fetch(:key_id, Config[:aws_access_key_id]),
|
6
|
+
opts.fetch(:key, Config[:aws_secret_access_key]))
|
7
|
+
@region = opts.fetch(:region, Config[:aws_region])
|
7
8
|
end
|
8
9
|
|
9
10
|
# Retrieve invoice JSON from S3
|
@@ -34,20 +35,24 @@ module Vault
|
|
34
35
|
|
35
36
|
# Retrieve the contents in a given format of a given file from S3
|
36
37
|
def retrieve(format, opts)
|
37
|
-
s3.
|
38
|
+
s3.get_object({
|
39
|
+
bucket: bucket_for(format, opts),
|
40
|
+
key: path_for(opts)
|
41
|
+
}).body.read
|
38
42
|
end
|
39
43
|
|
40
44
|
# Write the contents in the given format to S3
|
41
45
|
def write(format, opts)
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
s3.put_object({
|
47
|
+
bucket: bucket_for(format, opts),
|
48
|
+
key: path_for(opts),
|
49
|
+
body: opts[:contents]
|
50
|
+
})
|
45
51
|
end
|
46
52
|
|
47
53
|
# Get an instance of the S3 client to work with
|
48
54
|
def s3
|
49
|
-
@s3 ||=
|
50
|
-
use_ssl: true)
|
55
|
+
@s3 ||= Aws::S3::Client.new(credentials: @credentials, region: @region)
|
51
56
|
end
|
52
57
|
|
53
58
|
# Determine which bucket an invoice should live in
|
@@ -73,10 +78,11 @@ module Vault
|
|
73
78
|
private
|
74
79
|
|
75
80
|
def validate_path_opts(opts)
|
81
|
+
user = opts[:user_hid] || opts[:user_id]
|
82
|
+
|
76
83
|
fail(ArgumentError, 'start_time required!') unless opts[:start_time]
|
77
84
|
fail(ArgumentError, 'stop_time required!') unless opts[:stop_time]
|
78
85
|
fail(ArgumentError, 'version required!') unless opts[:version]
|
79
|
-
user = opts[:user_hid] || opts[:user_id]
|
80
86
|
fail(ArgumentError, 'user_hid or or user_id required!') unless user
|
81
87
|
end
|
82
88
|
end
|