pg-aws_rds_iam 0.3.1 → 0.4.1
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/workflows/pull-request.yml +7 -5
- data/.rubocop.yml +6 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +23 -1
- data/Gemfile +2 -2
- data/Gemfile.lock +41 -46
- data/README.md +1 -1
- data/bin/version-matrix +5 -5
- data/lib/pg/aws_rds_iam/active_record_postgresql_database_tasks/psql_env.rb +15 -0
- data/lib/pg/aws_rds_iam/active_record_postgresql_database_tasks/set_psql_env.rb +15 -0
- data/lib/pg/aws_rds_iam/active_record_postgresql_database_tasks.rb +16 -0
- data/lib/pg/aws_rds_iam/auth_token_injector.rb +20 -19
- data/lib/pg/aws_rds_iam/connection.rb +20 -6
- data/lib/pg/aws_rds_iam/connection_info/active_record_configuration_hash.rb +29 -0
- data/lib/pg/aws_rds_iam/connection_info/uri.rb +1 -1
- data/lib/pg/aws_rds_iam/connection_info.rb +6 -1
- data/lib/pg/aws_rds_iam/version.rb +1 -1
- data/lib/pg/aws_rds_iam.rb +6 -0
- data/pg-aws_rds_iam.gemspec +3 -1
- metadata +10 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 920be3b0e703f19eb05fbd79801ee15ffc4a261d811682426f8ff90e870b7445
|
|
4
|
+
data.tar.gz: b8b799ef04905de4e760320b6b7928f6e989ca7f167b2e5c0b5fa94b87c786a7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8661064d598861e2c7f9a0d91598335627c12acc901ec92a4de1b833a1b768dec4d3108a86d2d6e7331b831645db9092b4ea5b8ef2c0f36330465d2764203117
|
|
7
|
+
data.tar.gz: 439ab6a13b36c36baeb56c0e3bbdf33406e92816209e30cc6ed080e068e96eea201fcde24499d8a664bbc3523628fc9fd90ab83845800301d1fed852716f00ac
|
|
@@ -17,7 +17,7 @@ jobs:
|
|
|
17
17
|
run: apk add git
|
|
18
18
|
|
|
19
19
|
- name: Check out source code
|
|
20
|
-
uses: actions/checkout@
|
|
20
|
+
uses: actions/checkout@v3
|
|
21
21
|
|
|
22
22
|
- name: Install Bundler
|
|
23
23
|
run: bin/install-bundler
|
|
@@ -40,7 +40,7 @@ jobs:
|
|
|
40
40
|
run: test -n "${{ secrets.AVAILABLE }}"
|
|
41
41
|
|
|
42
42
|
- name: Check out source code
|
|
43
|
-
uses: actions/checkout@
|
|
43
|
+
uses: actions/checkout@v3
|
|
44
44
|
|
|
45
45
|
- name: Generate version matrix
|
|
46
46
|
id: version-matrix
|
|
@@ -66,10 +66,10 @@ jobs:
|
|
|
66
66
|
|
|
67
67
|
steps:
|
|
68
68
|
- name: Install dependencies
|
|
69
|
-
run: apk add build-base git postgresql-dev tar
|
|
69
|
+
run: apk add build-base git postgresql-client postgresql-dev tar
|
|
70
70
|
|
|
71
71
|
- name: Check out source code
|
|
72
|
-
uses: actions/checkout@
|
|
72
|
+
uses: actions/checkout@v3
|
|
73
73
|
|
|
74
74
|
- name: Install Bundler
|
|
75
75
|
run: bin/install-bundler
|
|
@@ -89,10 +89,12 @@ jobs:
|
|
|
89
89
|
"${postgresql_version}"
|
|
90
90
|
|
|
91
91
|
- name: Cache gems
|
|
92
|
-
uses: actions/cache@
|
|
92
|
+
uses: actions/cache@v3
|
|
93
93
|
with:
|
|
94
94
|
key: ${{ steps.cache-key.outputs.cache-key }}-gems-${{ hashFiles('Gemfile.lock') }}
|
|
95
95
|
path: vendor/bundle
|
|
96
|
+
restore-keys: |
|
|
97
|
+
${{ steps.cache-key.outputs.cache-key }}-gems-
|
|
96
98
|
|
|
97
99
|
- name: Install gems
|
|
98
100
|
run: bin/bundle install
|
data/.rubocop.yml
CHANGED
|
@@ -3,7 +3,7 @@ require:
|
|
|
3
3
|
- rubocop-rake
|
|
4
4
|
|
|
5
5
|
AllCops:
|
|
6
|
-
TargetRubyVersion: 2.
|
|
6
|
+
TargetRubyVersion: 2.7
|
|
7
7
|
NewCops: enable
|
|
8
8
|
Exclude:
|
|
9
9
|
- bin/bundle
|
|
@@ -26,8 +26,13 @@ Minitest/MultipleAssertions:
|
|
|
26
26
|
Naming/ClassAndModuleCamelCase:
|
|
27
27
|
Enabled: false
|
|
28
28
|
|
|
29
|
+
Naming/VariableNumber:
|
|
30
|
+
EnforcedStyle: snake_case
|
|
31
|
+
|
|
29
32
|
Style/Documentation:
|
|
30
33
|
Exclude:
|
|
34
|
+
- lib/pg/aws_rds_iam/active_record_postgresql_database_tasks.rb
|
|
35
|
+
- lib/pg/aws_rds_iam/active_record_postgresql_database_tasks/**/*.rb
|
|
31
36
|
- lib/pg/aws_rds_iam/auth_token_injector.rb
|
|
32
37
|
- lib/pg/aws_rds_iam/connection_info.rb
|
|
33
38
|
- lib/pg/aws_rds_iam/connection_info/**/*.rb
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby-3.
|
|
1
|
+
ruby-3.1.2
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
8
8
|
|
|
9
9
|
No notable changes.
|
|
10
10
|
|
|
11
|
+
## [0.4.1] - 2022-07-20
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
* Generate auth token for Active Record structure load ([#374](https://github.com/haines/pg-aws_rds_iam/pull/374))
|
|
15
|
+
|
|
16
|
+
## [0.4.0] - 2022-06-22
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
* Test against Ruby 3.1 ([#305](https://github.com/haines/pg-aws_rds_iam/pull/305))
|
|
20
|
+
* Require Ruby ≥ 2.6 and Active Record ≥ 6.0 ([#360](https://github.com/haines/pg-aws_rds_iam/pull/360))
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
* Compatibility with `pg` ≥ 1.4 ([#356](https://github.com/haines/pg-aws_rds_iam/pull/356))
|
|
24
|
+
|
|
25
|
+
## [0.3.2] - 2021-11-15
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
* Require MFA to publish gem ([#278](https://github.com/haines/pg-aws_rds_iam/pull/278))
|
|
29
|
+
|
|
11
30
|
## [0.3.1] - 2021-11-10
|
|
12
31
|
|
|
13
32
|
### Fixed
|
|
@@ -38,7 +57,10 @@ No notable changes.
|
|
|
38
57
|
* A plugin for the [`pg` gem](https://rubygems.org/gems/pg) that adds support for [IAM authentication](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html) when connecting to PostgreSQL databases hosted in Amazon RDS. ([#1](https://github.com/haines/pg-aws_rds_iam/pull/1))
|
|
39
58
|
* ActiveRecord support. ([#3](https://github.com/haines/pg-aws_rds_iam/pull/3))
|
|
40
59
|
|
|
41
|
-
[Unreleased]: https://github.com/haines/pg-aws_rds_iam/compare/v0.
|
|
60
|
+
[Unreleased]: https://github.com/haines/pg-aws_rds_iam/compare/v0.4.1...HEAD
|
|
61
|
+
[0.4.1]: https://github.com/haines/pg-aws_rds_iam/compare/v0.4.0...v0.4.1
|
|
62
|
+
[0.4.0]: https://github.com/haines/pg-aws_rds_iam/compare/v0.3.2...v0.4.0
|
|
63
|
+
[0.3.2]: https://github.com/haines/pg-aws_rds_iam/compare/v0.3.1...v0.3.2
|
|
42
64
|
[0.3.1]: https://github.com/haines/pg-aws_rds_iam/compare/v0.3.0...v0.3.1
|
|
43
65
|
[0.3.0]: https://github.com/haines/pg-aws_rds_iam/compare/v0.2.0...v0.3.0
|
|
44
66
|
[0.2.0]: https://github.com/haines/pg-aws_rds_iam/compare/v0.1.1...v0.2.0
|
data/Gemfile
CHANGED
|
@@ -14,8 +14,8 @@ gem "rubocop"
|
|
|
14
14
|
gem "rubocop-minitest"
|
|
15
15
|
gem "rubocop-rake"
|
|
16
16
|
gem "timecop"
|
|
17
|
-
gem "yard"
|
|
17
|
+
gem "yard"
|
|
18
18
|
|
|
19
19
|
["activerecord", "pg"].each do |gem_name|
|
|
20
|
-
gem gem_name, *ENV["#{gem_name.upcase}_VERSION"]&.
|
|
20
|
+
gem gem_name, *ENV["#{gem_name.upcase}_VERSION"]&.then { |gem_version| "~> #{gem_version}.0" }
|
|
21
21
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,95 +1,90 @@
|
|
|
1
|
-
GIT
|
|
2
|
-
remote: https://github.com/lsegal/yard.git
|
|
3
|
-
revision: 9865620413d3519b561d87479e44f1b4fe782904
|
|
4
|
-
specs:
|
|
5
|
-
yard (0.9.26)
|
|
6
|
-
webrick (~> 1.7.0)
|
|
7
|
-
|
|
8
1
|
PATH
|
|
9
2
|
remote: .
|
|
10
3
|
specs:
|
|
11
|
-
pg-aws_rds_iam (0.
|
|
4
|
+
pg-aws_rds_iam (0.4.1)
|
|
12
5
|
aws-sdk-rds (~> 1.0)
|
|
13
6
|
pg (>= 0.18, < 2.0)
|
|
14
7
|
|
|
15
8
|
GEM
|
|
16
9
|
remote: https://rubygems.org/
|
|
17
10
|
specs:
|
|
18
|
-
activemodel (
|
|
19
|
-
activesupport (=
|
|
20
|
-
activerecord (
|
|
21
|
-
activemodel (=
|
|
22
|
-
activesupport (=
|
|
23
|
-
activesupport (
|
|
11
|
+
activemodel (7.0.3.1)
|
|
12
|
+
activesupport (= 7.0.3.1)
|
|
13
|
+
activerecord (7.0.3.1)
|
|
14
|
+
activemodel (= 7.0.3.1)
|
|
15
|
+
activesupport (= 7.0.3.1)
|
|
16
|
+
activesupport (7.0.3.1)
|
|
24
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
25
18
|
i18n (>= 1.6, < 2)
|
|
26
19
|
minitest (>= 5.1)
|
|
27
20
|
tzinfo (~> 2.0)
|
|
28
|
-
zeitwerk (~> 2.3)
|
|
29
21
|
ansi (1.5.0)
|
|
30
22
|
ast (2.4.2)
|
|
31
23
|
aws-eventstream (1.2.0)
|
|
32
|
-
aws-partitions (1.
|
|
33
|
-
aws-sdk-core (3.
|
|
24
|
+
aws-partitions (1.607.0)
|
|
25
|
+
aws-sdk-core (3.131.2)
|
|
34
26
|
aws-eventstream (~> 1, >= 1.0.2)
|
|
35
27
|
aws-partitions (~> 1, >= 1.525.0)
|
|
36
28
|
aws-sigv4 (~> 1.1)
|
|
37
|
-
jmespath (~> 1.
|
|
38
|
-
aws-sdk-ec2 (1.
|
|
39
|
-
aws-sdk-core (~> 3, >= 3.
|
|
29
|
+
jmespath (~> 1, >= 1.6.1)
|
|
30
|
+
aws-sdk-ec2 (1.322.0)
|
|
31
|
+
aws-sdk-core (~> 3, >= 3.127.0)
|
|
40
32
|
aws-sigv4 (~> 1.1)
|
|
41
|
-
aws-sdk-rds (1.
|
|
42
|
-
aws-sdk-core (~> 3, >= 3.
|
|
33
|
+
aws-sdk-rds (1.148.0)
|
|
34
|
+
aws-sdk-core (~> 3, >= 3.127.0)
|
|
43
35
|
aws-sigv4 (~> 1.1)
|
|
44
|
-
aws-sigv4 (1.
|
|
36
|
+
aws-sigv4 (1.5.0)
|
|
45
37
|
aws-eventstream (~> 1, >= 1.0.2)
|
|
46
38
|
builder (3.2.4)
|
|
47
39
|
coderay (1.1.3)
|
|
48
|
-
commonmarker (0.23.
|
|
49
|
-
concurrent-ruby (1.1.
|
|
50
|
-
i18n (1.
|
|
40
|
+
commonmarker (0.23.5)
|
|
41
|
+
concurrent-ruby (1.1.10)
|
|
42
|
+
i18n (1.11.0)
|
|
51
43
|
concurrent-ruby (~> 1.0)
|
|
52
|
-
jmespath (1.
|
|
44
|
+
jmespath (1.6.1)
|
|
45
|
+
json (2.6.2)
|
|
53
46
|
method_source (1.0.0)
|
|
54
|
-
minitest (5.
|
|
55
|
-
minitest-reporters (1.
|
|
47
|
+
minitest (5.16.2)
|
|
48
|
+
minitest-reporters (1.5.0)
|
|
56
49
|
ansi
|
|
57
50
|
builder
|
|
58
51
|
minitest (>= 5.0)
|
|
59
52
|
ruby-progressbar
|
|
60
|
-
parallel (1.
|
|
61
|
-
parser (3.
|
|
53
|
+
parallel (1.22.1)
|
|
54
|
+
parser (3.1.2.0)
|
|
62
55
|
ast (~> 2.4.1)
|
|
63
|
-
pg (1.
|
|
56
|
+
pg (1.4.1)
|
|
64
57
|
pry (0.14.1)
|
|
65
58
|
coderay (~> 1.1)
|
|
66
59
|
method_source (~> 1.0)
|
|
67
|
-
rainbow (3.
|
|
60
|
+
rainbow (3.1.1)
|
|
68
61
|
rake (13.0.6)
|
|
69
|
-
regexp_parser (2.
|
|
62
|
+
regexp_parser (2.5.0)
|
|
70
63
|
rexml (3.2.5)
|
|
71
|
-
rubocop (1.
|
|
64
|
+
rubocop (1.31.2)
|
|
65
|
+
json (~> 2.3)
|
|
72
66
|
parallel (~> 1.10)
|
|
73
|
-
parser (>= 3.
|
|
67
|
+
parser (>= 3.1.0.0)
|
|
74
68
|
rainbow (>= 2.2.2, < 4.0)
|
|
75
69
|
regexp_parser (>= 1.8, < 3.0)
|
|
76
|
-
rexml
|
|
77
|
-
rubocop-ast (>= 1.
|
|
70
|
+
rexml (>= 3.2.5, < 4.0)
|
|
71
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
|
78
72
|
ruby-progressbar (~> 1.7)
|
|
79
73
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
80
|
-
rubocop-ast (1.
|
|
81
|
-
parser (>= 3.
|
|
82
|
-
rubocop-minitest (0.
|
|
74
|
+
rubocop-ast (1.19.1)
|
|
75
|
+
parser (>= 3.1.1.0)
|
|
76
|
+
rubocop-minitest (0.20.1)
|
|
83
77
|
rubocop (>= 0.90, < 2.0)
|
|
84
78
|
rubocop-rake (0.6.0)
|
|
85
79
|
rubocop (~> 1.0)
|
|
86
80
|
ruby-progressbar (1.11.0)
|
|
87
|
-
timecop (0.9.
|
|
81
|
+
timecop (0.9.5)
|
|
88
82
|
tzinfo (2.0.4)
|
|
89
83
|
concurrent-ruby (~> 1.0)
|
|
90
|
-
unicode-display_width (2.
|
|
84
|
+
unicode-display_width (2.2.0)
|
|
91
85
|
webrick (1.7.0)
|
|
92
|
-
|
|
86
|
+
yard (0.9.28)
|
|
87
|
+
webrick (~> 1.7.0)
|
|
93
88
|
|
|
94
89
|
PLATFORMS
|
|
95
90
|
ruby
|
|
@@ -109,7 +104,7 @@ DEPENDENCIES
|
|
|
109
104
|
rubocop-minitest
|
|
110
105
|
rubocop-rake
|
|
111
106
|
timecop
|
|
112
|
-
yard
|
|
107
|
+
yard
|
|
113
108
|
|
|
114
109
|
BUNDLED WITH
|
|
115
|
-
2.
|
|
110
|
+
2.3.18
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://rubygems.org/gems/pg-aws_rds_iam)
|
|
4
4
|
 
|
|
5
|
-
[](https://
|
|
5
|
+
[](https://www.rubydoc.info/gems/pg-aws_rds_iam)
|
|
6
6
|
|
|
7
7
|
`PG::AWS_RDS_IAM` is a plugin for the [`pg` gem](https://rubygems.org/gems/pg) that adds support for [IAM authentication](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html) when connecting to PostgreSQL databases hosted in Amazon RDS.
|
|
8
8
|
|
data/bin/version-matrix
CHANGED
|
@@ -9,15 +9,15 @@ def minor_versions(name, requirement)
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
ruby_activerecord_requirements = {
|
|
12
|
-
"2.
|
|
13
|
-
"
|
|
14
|
-
"3.
|
|
12
|
+
"2.7" => ">= 6.0",
|
|
13
|
+
"3.0" => ">= 6.0",
|
|
14
|
+
"3.1" => ">= 6.0"
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
activerecord_pg_requirements = {
|
|
18
|
-
"5.2" => [">= 0.18", "< 2.0"],
|
|
19
18
|
"6.0" => [">= 0.18", "< 2.0"],
|
|
20
|
-
"6.1" => "~> 1.1"
|
|
19
|
+
"6.1" => "~> 1.1",
|
|
20
|
+
"7.0" => "~> 1.1"
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
versions = ruby_activerecord_requirements.flat_map do |ruby_version, activerecord_requirement|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PG
|
|
4
|
+
module AWS_RDS_IAM
|
|
5
|
+
module ActiveRecordPostgreSQLDatabaseTasks
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def psql_env
|
|
9
|
+
super.tap do |psql_env|
|
|
10
|
+
AuthTokenInjector.new.inject_into_psql_env! configuration_hash, psql_env
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PG
|
|
4
|
+
module AWS_RDS_IAM
|
|
5
|
+
module ActiveRecordPostgreSQLDatabaseTasks
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def set_psql_env
|
|
9
|
+
super
|
|
10
|
+
hash = respond_to?(:configuration_hash, true) ? configuration_hash : configuration.symbolize_keys
|
|
11
|
+
AuthTokenInjector.new.inject_into_psql_env! hash, ENV
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PG
|
|
4
|
+
module AWS_RDS_IAM
|
|
5
|
+
module ActiveRecordPostgreSQLDatabaseTasks
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
private_constant :ActiveRecordPostgreSQLDatabaseTasks
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
if ActiveRecord::Tasks::PostgreSQLDatabaseTasks.private_instance_methods.include?(:psql_env)
|
|
13
|
+
require_relative "active_record_postgresql_database_tasks/psql_env"
|
|
14
|
+
else
|
|
15
|
+
require_relative "active_record_postgresql_database_tasks/set_psql_env"
|
|
16
|
+
end
|
|
@@ -3,38 +3,39 @@
|
|
|
3
3
|
module PG
|
|
4
4
|
module AWS_RDS_IAM
|
|
5
5
|
class AuthTokenInjector
|
|
6
|
-
def
|
|
7
|
-
new(connection_string, auth_token_generators: auth_token_generators).call
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def initialize(connection_string, auth_token_generators:)
|
|
11
|
-
@connection_string = connection_string
|
|
12
|
-
@connection_info = ConnectionInfo.new(connection_string)
|
|
13
|
-
@connection_defaults = PG::Connection.conndefaults_hash
|
|
6
|
+
def initialize(auth_token_generators: AWS_RDS_IAM.auth_token_generators)
|
|
14
7
|
@auth_token_generators = auth_token_generators
|
|
8
|
+
@connection_defaults = PG::Connection.conndefaults_hash
|
|
15
9
|
end
|
|
16
10
|
|
|
17
|
-
def
|
|
18
|
-
|
|
11
|
+
def inject_into_connection_string(connection_string)
|
|
12
|
+
connection_info = ConnectionInfo.from_connection_string(connection_string)
|
|
13
|
+
return connection_string unless generate_auth_token?(connection_info)
|
|
14
|
+
|
|
15
|
+
connection_info.password = generate_auth_token(connection_info)
|
|
16
|
+
connection_info.to_s
|
|
17
|
+
end
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
def inject_into_psql_env!(configuration_hash, psql_env)
|
|
20
|
+
connection_info = ConnectionInfo.from_active_record_configuration_hash(configuration_hash)
|
|
21
|
+
return unless generate_auth_token?(connection_info)
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
psql_env["PGPASSWORD"] = generate_auth_token(connection_info)
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
private
|
|
26
27
|
|
|
27
|
-
def generate_auth_token?
|
|
28
|
-
|
|
28
|
+
def generate_auth_token?(connection_info)
|
|
29
|
+
connection_info.auth_token_generator_name
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
def generate_auth_token
|
|
32
|
+
def generate_auth_token(connection_info)
|
|
32
33
|
@auth_token_generators
|
|
33
|
-
.fetch(
|
|
34
|
+
.fetch(connection_info.auth_token_generator_name)
|
|
34
35
|
.call(
|
|
35
|
-
user:
|
|
36
|
-
host:
|
|
37
|
-
port:
|
|
36
|
+
user: connection_info.user || default(:user),
|
|
37
|
+
host: connection_info.host || default(:host),
|
|
38
|
+
port: connection_info.port || default(:port)
|
|
38
39
|
)
|
|
39
40
|
end
|
|
40
41
|
|
|
@@ -4,7 +4,25 @@ module PG
|
|
|
4
4
|
module AWS_RDS_IAM
|
|
5
5
|
module Connection
|
|
6
6
|
def conndefaults
|
|
7
|
-
super + [
|
|
7
|
+
super + [conndefault_aws_rds_iam_auth_token_generator]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def conninfo_parse(connection_string)
|
|
11
|
+
connection_info = ConnectionInfo.from_connection_string(connection_string)
|
|
12
|
+
|
|
13
|
+
super(connection_info.to_s).tap do |result|
|
|
14
|
+
result << conndefault_aws_rds_iam_auth_token_generator.merge(val: connection_info.auth_token_generator_name) if connection_info.auth_token_generator_name
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def parse_connect_args(*args)
|
|
19
|
+
AuthTokenInjector.new.inject_into_connection_string(super)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def conndefault_aws_rds_iam_auth_token_generator
|
|
25
|
+
{
|
|
8
26
|
keyword: "aws_rds_iam_auth_token_generator",
|
|
9
27
|
envvar: nil,
|
|
10
28
|
compiled: nil,
|
|
@@ -12,11 +30,7 @@ module PG
|
|
|
12
30
|
label: "AWS-RDS-IAM-auth-token-generator",
|
|
13
31
|
dispchar: "",
|
|
14
32
|
dispsize: 64
|
|
15
|
-
}
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def parse_connect_args(*)
|
|
19
|
-
AuthTokenInjector.call(super)
|
|
33
|
+
}
|
|
20
34
|
end
|
|
21
35
|
end
|
|
22
36
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PG
|
|
4
|
+
module AWS_RDS_IAM
|
|
5
|
+
module ConnectionInfo
|
|
6
|
+
class ActiveRecordConfigurationHash
|
|
7
|
+
def initialize(configuration_hash)
|
|
8
|
+
@configuration_hash = configuration_hash
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def auth_token_generator_name
|
|
12
|
+
@configuration_hash[:aws_rds_iam_auth_token_generator]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def user
|
|
16
|
+
@configuration_hash[:username]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def host
|
|
20
|
+
@configuration_hash[:host]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def port
|
|
24
|
+
@configuration_hash[:port]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -12,7 +12,7 @@ module PG
|
|
|
12
12
|
|
|
13
13
|
def initialize(connection_string)
|
|
14
14
|
@uri = ::URI.parse(connection_string)
|
|
15
|
-
@query = ::URI.decode_www_form(@uri.query).to_h
|
|
15
|
+
@query = @uri.query ? ::URI.decode_www_form(@uri.query).to_h : {}
|
|
16
16
|
@auth_token_generator_name = @query.delete("aws_rds_iam_auth_token_generator")
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "connection_info/active_record_configuration_hash"
|
|
3
4
|
require_relative "connection_info/keyword_value_string"
|
|
4
5
|
require_relative "connection_info/parse_error"
|
|
5
6
|
require_relative "connection_info/uri"
|
|
@@ -7,13 +8,17 @@ require_relative "connection_info/uri"
|
|
|
7
8
|
module PG
|
|
8
9
|
module AWS_RDS_IAM
|
|
9
10
|
module ConnectionInfo
|
|
10
|
-
def self.
|
|
11
|
+
def self.from_connection_string(connection_string)
|
|
11
12
|
if URI.match?(connection_string)
|
|
12
13
|
URI.new(connection_string)
|
|
13
14
|
else
|
|
14
15
|
KeywordValueString.new(connection_string)
|
|
15
16
|
end
|
|
16
17
|
end
|
|
18
|
+
|
|
19
|
+
def self.from_active_record_configuration_hash(configuration_hash)
|
|
20
|
+
ActiveRecordConfigurationHash.new(configuration_hash)
|
|
21
|
+
end
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
private_constant :ConnectionInfo
|
data/lib/pg/aws_rds_iam.rb
CHANGED
|
@@ -26,5 +26,11 @@ module PG
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
PG::Connection.singleton_class.prepend Connection
|
|
29
|
+
|
|
30
|
+
if defined?(ActiveRecord)
|
|
31
|
+
require_relative "aws_rds_iam/active_record_postgresql_database_tasks"
|
|
32
|
+
|
|
33
|
+
ActiveRecord::Tasks::PostgreSQLDatabaseTasks.prepend ActiveRecordPostgreSQLDatabaseTasks
|
|
34
|
+
end
|
|
29
35
|
end
|
|
30
36
|
end
|
data/pg-aws_rds_iam.gemspec
CHANGED
|
@@ -21,11 +21,13 @@ Gem::Specification.new do |spec|
|
|
|
21
21
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
22
22
|
spec.metadata["source_code_uri"] = spec.homepage
|
|
23
23
|
|
|
24
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
25
|
+
|
|
24
26
|
spec.files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0").reject { |path| path.start_with?("test/") } }
|
|
25
27
|
|
|
26
28
|
spec.require_paths = ["lib"]
|
|
27
29
|
|
|
28
|
-
spec.required_ruby_version = ">= 2.
|
|
30
|
+
spec.required_ruby_version = ">= 2.7"
|
|
29
31
|
|
|
30
32
|
spec.add_dependency "aws-sdk-rds", "~> 1.0"
|
|
31
33
|
spec.add_dependency "pg", ">= 0.18", "< 2.0"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pg-aws_rds_iam
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Haines
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-07-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: aws-sdk-rds
|
|
@@ -74,11 +74,15 @@ files:
|
|
|
74
74
|
- bin/version-matrix
|
|
75
75
|
- bin/yard
|
|
76
76
|
- lib/pg/aws_rds_iam.rb
|
|
77
|
+
- lib/pg/aws_rds_iam/active_record_postgresql_database_tasks.rb
|
|
78
|
+
- lib/pg/aws_rds_iam/active_record_postgresql_database_tasks/psql_env.rb
|
|
79
|
+
- lib/pg/aws_rds_iam/active_record_postgresql_database_tasks/set_psql_env.rb
|
|
77
80
|
- lib/pg/aws_rds_iam/auth_token_generator.rb
|
|
78
81
|
- lib/pg/aws_rds_iam/auth_token_generator_registry.rb
|
|
79
82
|
- lib/pg/aws_rds_iam/auth_token_injector.rb
|
|
80
83
|
- lib/pg/aws_rds_iam/connection.rb
|
|
81
84
|
- lib/pg/aws_rds_iam/connection_info.rb
|
|
85
|
+
- lib/pg/aws_rds_iam/connection_info/active_record_configuration_hash.rb
|
|
82
86
|
- lib/pg/aws_rds_iam/connection_info/keyword_value_string.rb
|
|
83
87
|
- lib/pg/aws_rds_iam/connection_info/parse_error.rb
|
|
84
88
|
- lib/pg/aws_rds_iam/connection_info/uri.rb
|
|
@@ -90,9 +94,10 @@ licenses:
|
|
|
90
94
|
metadata:
|
|
91
95
|
bug_tracker_uri: https://github.com/haines/pg-aws_rds_iam/issues
|
|
92
96
|
changelog_uri: https://github.com/haines/pg-aws_rds_iam/blob/main/CHANGELOG.md
|
|
93
|
-
documentation_uri: https://rubydoc.info/gems/pg-aws_rds_iam/0.
|
|
97
|
+
documentation_uri: https://rubydoc.info/gems/pg-aws_rds_iam/0.4.1
|
|
94
98
|
homepage_uri: https://github.com/haines/pg-aws_rds_iam
|
|
95
99
|
source_code_uri: https://github.com/haines/pg-aws_rds_iam
|
|
100
|
+
rubygems_mfa_required: 'true'
|
|
96
101
|
post_install_message:
|
|
97
102
|
rdoc_options: []
|
|
98
103
|
require_paths:
|
|
@@ -101,14 +106,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
101
106
|
requirements:
|
|
102
107
|
- - ">="
|
|
103
108
|
- !ruby/object:Gem::Version
|
|
104
|
-
version: '2.
|
|
109
|
+
version: '2.7'
|
|
105
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
111
|
requirements:
|
|
107
112
|
- - ">="
|
|
108
113
|
- !ruby/object:Gem::Version
|
|
109
114
|
version: '0'
|
|
110
115
|
requirements: []
|
|
111
|
-
rubygems_version: 3.
|
|
116
|
+
rubygems_version: 3.3.18
|
|
112
117
|
signing_key:
|
|
113
118
|
specification_version: 4
|
|
114
119
|
summary: IAM authentication for PostgreSQL on Amazon RDS
|