pg-aws_rds_iam 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7894b340911ed1dd4bf4ade1a3a93830f34a353107036f0bf974b098b332ad04
4
- data.tar.gz: 7387170d637e6f5a57cb4e39146c03496595d7fd2bc785eae4dacd1dc7978a90
3
+ metadata.gz: 920be3b0e703f19eb05fbd79801ee15ffc4a261d811682426f8ff90e870b7445
4
+ data.tar.gz: b8b799ef04905de4e760320b6b7928f6e989ca7f167b2e5c0b5fa94b87c786a7
5
5
  SHA512:
6
- metadata.gz: 7ed4c84823ac809c74ac63358df8a31aebaa8ba09572cd8a8343a47c41768f5bb226b6ce99fb8ec052e90c37575e296538680ba1a3ab03bb4d100120fc0e044d
7
- data.tar.gz: 1575d6f6e008a311edd01fb62cd9d3bf4615a14b41d0ed2f5163812999661180da5010252cf8013c82abcfc46c4d680d6dc995a21e8c02d3164949f929887b14
6
+ metadata.gz: 8661064d598861e2c7f9a0d91598335627c12acc901ec92a4de1b833a1b768dec4d3108a86d2d6e7331b831645db9092b4ea5b8ef2c0f36330465d2764203117
7
+ data.tar.gz: 439ab6a13b36c36baeb56c0e3bbdf33406e92816209e30cc6ed080e068e96eea201fcde24499d8a664bbc3523628fc9fd90ab83845800301d1fed852716f00ac
@@ -66,7 +66,7 @@ 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
72
  uses: actions/checkout@v3
@@ -93,6 +93,8 @@ jobs:
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
@@ -31,6 +31,8 @@ Naming/VariableNumber:
31
31
 
32
32
  Style/Documentation:
33
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
34
36
  - lib/pg/aws_rds_iam/auth_token_injector.rb
35
37
  - lib/pg/aws_rds_iam/connection_info.rb
36
38
  - lib/pg/aws_rds_iam/connection_info/**/*.rb
data/CHANGELOG.md CHANGED
@@ -8,6 +8,11 @@ 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
+
11
16
  ## [0.4.0] - 2022-06-22
12
17
 
13
18
  ### Changed
@@ -52,7 +57,8 @@ No notable changes.
52
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))
53
58
  * ActiveRecord support. ([#3](https://github.com/haines/pg-aws_rds_iam/pull/3))
54
59
 
55
- [Unreleased]: https://github.com/haines/pg-aws_rds_iam/compare/v0.4.0...HEAD
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
56
62
  [0.4.0]: https://github.com/haines/pg-aws_rds_iam/compare/v0.3.2...v0.4.0
57
63
  [0.3.2]: https://github.com/haines/pg-aws_rds_iam/compare/v0.3.1...v0.3.2
58
64
  [0.3.1]: https://github.com/haines/pg-aws_rds_iam/compare/v0.3.0...v0.3.1
data/Gemfile.lock CHANGED
@@ -1,19 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg-aws_rds_iam (0.4.0)
4
+ pg-aws_rds_iam (0.4.1)
5
5
  aws-sdk-rds (~> 1.0)
6
6
  pg (>= 0.18, < 2.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (7.0.3)
12
- activesupport (= 7.0.3)
13
- activerecord (7.0.3)
14
- activemodel (= 7.0.3)
15
- activesupport (= 7.0.3)
16
- activesupport (7.0.3)
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)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (>= 1.6, < 2)
19
19
  minitest (>= 5.1)
@@ -21,16 +21,16 @@ GEM
21
21
  ansi (1.5.0)
22
22
  ast (2.4.2)
23
23
  aws-eventstream (1.2.0)
24
- aws-partitions (1.600.0)
24
+ aws-partitions (1.607.0)
25
25
  aws-sdk-core (3.131.2)
26
26
  aws-eventstream (~> 1, >= 1.0.2)
27
27
  aws-partitions (~> 1, >= 1.525.0)
28
28
  aws-sigv4 (~> 1.1)
29
29
  jmespath (~> 1, >= 1.6.1)
30
- aws-sdk-ec2 (1.319.0)
30
+ aws-sdk-ec2 (1.322.0)
31
31
  aws-sdk-core (~> 3, >= 3.127.0)
32
32
  aws-sigv4 (~> 1.1)
33
- aws-sdk-rds (1.146.0)
33
+ aws-sdk-rds (1.148.0)
34
34
  aws-sdk-core (~> 3, >= 3.127.0)
35
35
  aws-sigv4 (~> 1.1)
36
36
  aws-sigv4 (1.5.0)
@@ -39,11 +39,12 @@ GEM
39
39
  coderay (1.1.3)
40
40
  commonmarker (0.23.5)
41
41
  concurrent-ruby (1.1.10)
42
- i18n (1.10.0)
42
+ i18n (1.11.0)
43
43
  concurrent-ruby (~> 1.0)
44
44
  jmespath (1.6.1)
45
+ json (2.6.2)
45
46
  method_source (1.0.0)
46
- minitest (5.16.1)
47
+ minitest (5.16.2)
47
48
  minitest-reporters (1.5.0)
48
49
  ansi
49
50
  builder
@@ -52,7 +53,7 @@ GEM
52
53
  parallel (1.22.1)
53
54
  parser (3.1.2.0)
54
55
  ast (~> 2.4.1)
55
- pg (1.4.0)
56
+ pg (1.4.1)
56
57
  pry (0.14.1)
57
58
  coderay (~> 1.1)
58
59
  method_source (~> 1.0)
@@ -60,7 +61,8 @@ GEM
60
61
  rake (13.0.6)
61
62
  regexp_parser (2.5.0)
62
63
  rexml (3.2.5)
63
- rubocop (1.30.1)
64
+ rubocop (1.31.2)
65
+ json (~> 2.3)
64
66
  parallel (~> 1.10)
65
67
  parser (>= 3.1.0.0)
66
68
  rainbow (>= 2.2.2, < 4.0)
@@ -69,7 +71,7 @@ GEM
69
71
  rubocop-ast (>= 1.18.0, < 2.0)
70
72
  ruby-progressbar (~> 1.7)
71
73
  unicode-display_width (>= 1.4.0, < 3.0)
72
- rubocop-ast (1.18.0)
74
+ rubocop-ast (1.19.1)
73
75
  parser (>= 3.1.1.0)
74
76
  rubocop-minitest (0.20.1)
75
77
  rubocop (>= 0.90, < 2.0)
@@ -79,7 +81,7 @@ GEM
79
81
  timecop (0.9.5)
80
82
  tzinfo (2.0.4)
81
83
  concurrent-ruby (~> 1.0)
82
- unicode-display_width (2.1.0)
84
+ unicode-display_width (2.2.0)
83
85
  webrick (1.7.0)
84
86
  yard (0.9.28)
85
87
  webrick (~> 1.7.0)
@@ -105,4 +107,4 @@ DEPENDENCIES
105
107
  yard
106
108
 
107
109
  BUNDLED WITH
108
- 2.3.16
110
+ 2.3.18
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem](https://img.shields.io/gem/v/pg-aws_rds_iam?style=flat-square)](https://rubygems.org/gems/pg-aws_rds_iam)
4
4
  &ensp;
5
- [![Docs](https://img.shields.io/badge/yard-docs-blue?style=flat-square)](https://haines.github.io/pg-aws_rds_iam/)
5
+ [![Docs](https://img.shields.io/badge/yard-docs-blue?style=flat-square)](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
 
@@ -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 self.call(connection_string, auth_token_generators: AWS_RDS_IAM.auth_token_generators)
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 call
18
- return @connection_string unless generate_auth_token?
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
- @connection_info.password = generate_auth_token
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
- @connection_info.to_s
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
- @connection_info.auth_token_generator_name
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(@connection_info.auth_token_generator_name)
34
+ .fetch(connection_info.auth_token_generator_name)
34
35
  .call(
35
- user: @connection_info.user || default(:user),
36
- host: @connection_info.host || default(:host),
37
- port: @connection_info.port || default(: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
 
@@ -8,7 +8,7 @@ module PG
8
8
  end
9
9
 
10
10
  def conninfo_parse(connection_string)
11
- connection_info = ConnectionInfo.new(connection_string)
11
+ connection_info = ConnectionInfo.from_connection_string(connection_string)
12
12
 
13
13
  super(connection_info.to_s).tap do |result|
14
14
  result << conndefault_aws_rds_iam_auth_token_generator.merge(val: connection_info.auth_token_generator_name) if connection_info.auth_token_generator_name
@@ -16,7 +16,7 @@ module PG
16
16
  end
17
17
 
18
18
  def parse_connect_args(*args)
19
- AuthTokenInjector.call(super)
19
+ AuthTokenInjector.new.inject_into_connection_string(super)
20
20
  end
21
21
 
22
22
  private
@@ -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
@@ -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.new(connection_string)
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
@@ -3,6 +3,6 @@
3
3
  module PG
4
4
  module AWS_RDS_IAM
5
5
  # The current version of the gem.
6
- VERSION = "0.4.0"
6
+ VERSION = "0.4.1"
7
7
  end
8
8
  end
@@ -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
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.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: 2022-06-22 00:00:00.000000000 Z
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,7 +94,7 @@ 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.4.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
96
100
  rubygems_mfa_required: 'true'
@@ -109,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
113
  - !ruby/object:Gem::Version
110
114
  version: '0'
111
115
  requirements: []
112
- rubygems_version: 3.3.16
116
+ rubygems_version: 3.3.18
113
117
  signing_key:
114
118
  specification_version: 4
115
119
  summary: IAM authentication for PostgreSQL on Amazon RDS