acorns-rds-auth 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +57 -0
- data/README.md +3 -0
- data/acorns-rds-auth.gemspec +31 -0
- data/bin/acorns-rds-auth +7 -0
- data/lib/acorns-rds-auth.rb +12 -0
- data/lib/acorns-rds-auth/cli.rb +192 -0
- data/lib/acorns-rds-auth/version.rb +3 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: edff6c512aa7001a8a263f0c7ed9dad2a041ee1a
|
4
|
+
data.tar.gz: 7b4e3564e17d0a655a6fd86ba139e4a8030cef3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05b1abdab386799b5143d314d1c8c07f9238d291c0e128da4453ad0c8a290bb4bfbf5d65cd7661f6ab97ecc9abda6df7a107ec590826b73af65987c16aee3a99
|
7
|
+
data.tar.gz: d98515021a4d7fd01de11329185bf3ef7a3c65fd8912f7730c3188b28d752e39c57b6e5d51ecbe0820283d1b0f74d453fa851433b8c4a8b742efa65d6ed0577e
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
acorns-rds-auth (1.0.0)
|
5
|
+
aws-sdk-core (~> 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
aws-eventstream (1.0.3)
|
11
|
+
aws-partitions (1.294.0)
|
12
|
+
aws-sdk-core (3.92.0)
|
13
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
14
|
+
aws-partitions (~> 1, >= 1.239.0)
|
15
|
+
aws-sigv4 (~> 1.1)
|
16
|
+
jmespath (~> 1.0)
|
17
|
+
aws-sigv4 (1.1.1)
|
18
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
docile (1.1.5)
|
21
|
+
jmespath (1.4.0)
|
22
|
+
json (2.3.0)
|
23
|
+
rake (10.5.0)
|
24
|
+
rspec (3.9.0)
|
25
|
+
rspec-core (~> 3.9.0)
|
26
|
+
rspec-expectations (~> 3.9.0)
|
27
|
+
rspec-mocks (~> 3.9.0)
|
28
|
+
rspec-core (3.9.1)
|
29
|
+
rspec-support (~> 3.9.1)
|
30
|
+
rspec-expectations (3.9.1)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-mocks (3.9.1)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-support (3.9.2)
|
37
|
+
rspec_junit_formatter (0.4.1)
|
38
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
39
|
+
simplecov (0.13.0)
|
40
|
+
docile (~> 1.1.0)
|
41
|
+
json (>= 1.8, < 3)
|
42
|
+
simplecov-html (~> 0.10.0)
|
43
|
+
simplecov-html (0.10.2)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
acorns-rds-auth!
|
50
|
+
bundler (~> 1.13)
|
51
|
+
rake (~> 10.0)
|
52
|
+
rspec (~> 3.0)
|
53
|
+
rspec_junit_formatter (~> 0.3, >= 0.3.0)
|
54
|
+
simplecov (~> 0.13.0, >= 0.13.0)
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
1.14.3
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'acorns-rds-auth/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'acorns-rds-auth'
|
8
|
+
spec.version = AcornsRdsAuth::VERSION
|
9
|
+
spec.authors = ['Mitch Dempsey']
|
10
|
+
spec.email = ['mitch@acorns.com']
|
11
|
+
|
12
|
+
spec.summary = 'Get RDS Auth'
|
13
|
+
spec.description = "Get credentials for acorns"
|
14
|
+
spec.homepage = 'https://github.com/Acornsgrow/acorns-rds-auth-gem'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'bin'
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'aws-sdk-core', '~> 3.0'
|
25
|
+
# spec.add_dependency 'tty-prompt'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3', '>= 0.3.0'
|
30
|
+
spec.add_development_dependency 'simplecov', '~> 0.13.0', '>= 0.13.0'
|
31
|
+
end
|
data/bin/acorns-rds-auth
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
module AcornsRdsAuth
|
2
|
+
class CLI
|
3
|
+
|
4
|
+
ENDPOINT_URL = "https://1mv4djbzee.execute-api.us-east-1.amazonaws.com/production/command".freeze
|
5
|
+
|
6
|
+
def self.start
|
7
|
+
|
8
|
+
puts ARGV.inspect
|
9
|
+
puts ENV.inspect
|
10
|
+
CLI.new.start
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@command = :auth
|
17
|
+
@options = {
|
18
|
+
profile: nil,
|
19
|
+
database: nil,
|
20
|
+
role: nil,
|
21
|
+
timeout: 5,
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def start
|
26
|
+
parse_options!
|
27
|
+
|
28
|
+
case @command
|
29
|
+
when :auth, :authenticate
|
30
|
+
do_auth_request!
|
31
|
+
|
32
|
+
else
|
33
|
+
raise StandardError.new("Invalid command '#{@command}'")
|
34
|
+
end
|
35
|
+
|
36
|
+
rescue => err
|
37
|
+
|
38
|
+
STDERR.puts "ERROR:"
|
39
|
+
STDERR.puts err.message
|
40
|
+
exit(1)
|
41
|
+
end
|
42
|
+
|
43
|
+
private unless $TESTING
|
44
|
+
|
45
|
+
def do_auth_request!
|
46
|
+
|
47
|
+
envname = @options[:env] || ARGV.shift
|
48
|
+
database = @options[:database] || ARGV.shift
|
49
|
+
role = @options[:role] || ARGV.shift
|
50
|
+
|
51
|
+
raise OptionParser::MissingArgument.new("env") if envname.nil?
|
52
|
+
raise OptionParser::MissingArgument.new("database") if database.nil?
|
53
|
+
|
54
|
+
payload = {
|
55
|
+
command: :auth,
|
56
|
+
env: envname,
|
57
|
+
database: database,
|
58
|
+
role: role,
|
59
|
+
}
|
60
|
+
|
61
|
+
STDERR.printf("Requesting credentials for '%s' in '%s'", payload[:database], payload[:env])
|
62
|
+
|
63
|
+
if payload[:role]
|
64
|
+
STDERR.printf(" (Using role '%s')", payload[:role])
|
65
|
+
end
|
66
|
+
|
67
|
+
STDERR.puts ""
|
68
|
+
|
69
|
+
response = do_request(payload)
|
70
|
+
|
71
|
+
# STDERR.puts JSON.pretty_generate(response)
|
72
|
+
STDERR.puts "DATABASE USERNAME: #{response[:role]}"
|
73
|
+
STDERR.puts ""
|
74
|
+
STDERR.puts "PASSWORD TO USE FOR THIS CONNECTION:"
|
75
|
+
|
76
|
+
print response[:token]
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def options_parser
|
81
|
+
@options_parser ||= OptionParser.new do |opts|
|
82
|
+
opts.banner = "Usage: acorns-rds-auth [COMMAND] [options] [...]"
|
83
|
+
|
84
|
+
opts.on("-p", "--profile PROFILE", "Specify the AWS profile to use") do |v|
|
85
|
+
@options[:profile] = v
|
86
|
+
# Aws.config[:profile_name] = v
|
87
|
+
end
|
88
|
+
|
89
|
+
opts.on("-e", "--env ENV", "Specify the environment to connect") do |v|
|
90
|
+
@options[:env] = v
|
91
|
+
end
|
92
|
+
|
93
|
+
opts.on("-d", "--database NAME", "Specify the database to connect") do |v|
|
94
|
+
@options[:database] = v
|
95
|
+
end
|
96
|
+
|
97
|
+
opts.on("-r", "--role NAME", "Specify the role to connect with. Optional") do |v|
|
98
|
+
@options[:role] = v
|
99
|
+
end
|
100
|
+
|
101
|
+
opts.on("-h", "--help", "Prints this help") do
|
102
|
+
puts opts
|
103
|
+
exit
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def parse_options!
|
109
|
+
options_parser.parse!
|
110
|
+
@command = (ARGV.shift || "auth").downcase.to_sym
|
111
|
+
end
|
112
|
+
|
113
|
+
def credentials_provider
|
114
|
+
@credentials_provider ||= Aws::CredentialProviderChain.new.resolve.credentials
|
115
|
+
end
|
116
|
+
|
117
|
+
def credentials
|
118
|
+
if @options[:profile]
|
119
|
+
Aws::SharedCredentials.new(profile_name: @options[:profile]).credentials
|
120
|
+
else
|
121
|
+
credentials_provider.credentials
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def endpoint_url
|
126
|
+
ENV.fetch("RDS_AUTH_URL", ENDPOINT_URL)
|
127
|
+
end
|
128
|
+
|
129
|
+
def endpoint
|
130
|
+
@endpoint ||= URI.parse(endpoint_url)
|
131
|
+
end
|
132
|
+
|
133
|
+
def do_request(payload)
|
134
|
+
|
135
|
+
raw_payload = JSON.generate(payload)
|
136
|
+
|
137
|
+
signer = Aws::Sigv4::Signer.new(
|
138
|
+
service: 'execute-api',
|
139
|
+
region: "us-east-1",
|
140
|
+
credentials: credentials,
|
141
|
+
)
|
142
|
+
|
143
|
+
headers = {
|
144
|
+
'content-type' => "application/json",
|
145
|
+
}
|
146
|
+
|
147
|
+
signature = signer.sign_request({
|
148
|
+
http_method: "POST",
|
149
|
+
url: endpoint.to_s,
|
150
|
+
headers: headers,
|
151
|
+
body: raw_payload,
|
152
|
+
})
|
153
|
+
|
154
|
+
http = Net::HTTP.new(endpoint.host, endpoint.port)
|
155
|
+
http.open_timeout = @options[:timeout]
|
156
|
+
http.read_timeout = @options[:timeout]
|
157
|
+
http.use_ssl = true
|
158
|
+
|
159
|
+
request = Net::HTTP::Post.new(endpoint.path)
|
160
|
+
request.add_field('user-agent', "AcornsRdsAuth-ruby/#{::AcornsRdsAuth::VERSION}")
|
161
|
+
headers.each do |k,v|
|
162
|
+
request.add_field(k,v)
|
163
|
+
end
|
164
|
+
|
165
|
+
signature.headers.each do |k,v|
|
166
|
+
request.add_field(k,v)
|
167
|
+
end
|
168
|
+
|
169
|
+
request.body = raw_payload
|
170
|
+
|
171
|
+
res = http.request(request)
|
172
|
+
|
173
|
+
result = JSON.parse(res.body, symbolize_names: true)
|
174
|
+
|
175
|
+
if res.code.to_i == 200
|
176
|
+
return result
|
177
|
+
else
|
178
|
+
|
179
|
+
# STDERR.puts "ERROR:"
|
180
|
+
|
181
|
+
if result[:Message]
|
182
|
+
raise StandardError.new(result[:Message])
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
raise StandardError.new("#{res.message}: #{res.body}")
|
187
|
+
# exit(1)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acorns-rds-auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mitch Dempsey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
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.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec_junit_formatter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.3'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.3.0
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.3'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.3.0
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: simplecov
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.13.0
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 0.13.0
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 0.13.0
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.13.0
|
109
|
+
description: Get credentials for acorns
|
110
|
+
email:
|
111
|
+
- mitch@acorns.com
|
112
|
+
executables:
|
113
|
+
- acorns-rds-auth
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- Gemfile
|
118
|
+
- Gemfile.lock
|
119
|
+
- README.md
|
120
|
+
- acorns-rds-auth.gemspec
|
121
|
+
- bin/acorns-rds-auth
|
122
|
+
- lib/acorns-rds-auth.rb
|
123
|
+
- lib/acorns-rds-auth/cli.rb
|
124
|
+
- lib/acorns-rds-auth/version.rb
|
125
|
+
homepage: https://github.com/Acornsgrow/acorns-rds-auth-gem
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.6.10
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Get RDS Auth
|
149
|
+
test_files: []
|