activerecord-dsql-adapter 0.1.5 → 0.1.7
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/README.md +6 -1
- data/lib/active_record/connection_adapters/dsql_adapter.rb +81 -6
- metadata +17 -23
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 81afc0eadfb8cdb952f08d241f353bb1f1c5d46a50a6b09d565077b1c246eb1a
|
|
4
|
+
data.tar.gz: 7d7f733127949fcb07b775341a5eee5d53a87b5c557e614e3c2bc72bd99b7c7b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ce09be3cd960b9fecb8030eba9f1a211e8ca45724756b38d532659a91657fc9301813c9f1bff0ab1fd2c1872c26bd8537f35ece7aa8d17291f012647219f47e2
|
|
7
|
+
data.tar.gz: 4ae7f099010634f3bf477789557b0815610eb270a5370918d99eb7386f9c35ead5bef2f22e03e5d54d48abae246f354af7d7e3c66ceb9f106ac6a3449eebc5f1
|
data/README.md
CHANGED
|
@@ -11,12 +11,17 @@ bundle add activerecord-dsql-adapter
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
|
-
|
|
14
|
+
Below is a suggested database configuration.
|
|
15
|
+
Optimistic Concurrency Conflicts can be automatically retried.
|
|
16
|
+
Generated tokens for DSQL expire after 1 hour so any connections should be invalidated before then.
|
|
15
17
|
```
|
|
16
18
|
# config/database.yml
|
|
17
19
|
development:
|
|
18
20
|
adapter: dsql
|
|
19
21
|
host: abc123.dsql.us-east-1.on.aws
|
|
22
|
+
occ_max_retries: 3
|
|
23
|
+
max_lifetime_minutes: 45
|
|
24
|
+
sslmode: require
|
|
20
25
|
```
|
|
21
26
|
|
|
22
27
|
Credentials available in ENV or inside your `~/.aws/config` file will be used to generate an appropriate AWS signature as a password:
|
|
@@ -5,6 +5,8 @@ require "aws-sdk-dsql"
|
|
|
5
5
|
require "active_record"
|
|
6
6
|
require "active_record/connection_adapters/postgresql_adapter"
|
|
7
7
|
|
|
8
|
+
require "aurora_dsql_pg"
|
|
9
|
+
|
|
8
10
|
module ActiveRecord
|
|
9
11
|
module ConnectionAdapters
|
|
10
12
|
class DSQLAdapter < PostgreSQLAdapter
|
|
@@ -12,14 +14,87 @@ module ActiveRecord
|
|
|
12
14
|
|
|
13
15
|
include ActiveRecord::ConnectionAdapters::DSQL::SchemaStatements
|
|
14
16
|
|
|
17
|
+
def max_lifetime_seconds
|
|
18
|
+
if @config[:max_lifetime_minutes]
|
|
19
|
+
@config[:max_lifetime_minutes].to_f * 60
|
|
20
|
+
else
|
|
21
|
+
AuroraDsql::Pg::CONFIG[:max_lifetime].to_i
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def token_expired?
|
|
26
|
+
!@token_refreshed_at || Time.now.utc - @token_refreshed_at >= max_lifetime_seconds
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def active?
|
|
30
|
+
return false if token_expired? && !in_transaction?
|
|
31
|
+
super
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def occ_max_retries
|
|
35
|
+
@config[:occ_max_retries].to_i
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def occ_retry_config
|
|
39
|
+
AuroraDsql::Pg::OCCRetry::DEFAULT_CONFIG.merge(max_retries: occ_max_retries)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def reconnect
|
|
45
|
+
@raw_connection = nil
|
|
46
|
+
connect
|
|
47
|
+
@token_refreshed_at = Time.now.utc
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
public
|
|
51
|
+
|
|
52
|
+
# we cannot reconnect if in the middle of a transaction
|
|
53
|
+
# as a safety, put padding in max_lifetime_minutes
|
|
54
|
+
def transaction(requires_new: nil, isolation: nil, joinable: true, &block)
|
|
55
|
+
AuroraDsql::Pg::OCCRetry.retry_on_occ(occ_retry_config, logger: ActiveRecord::Base.logger) do
|
|
56
|
+
reconnect! if token_expired?
|
|
57
|
+
super(requires_new:, isolation:, joinable:, &block)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def with_raw_connection(allow_retry: false, materialize_transactions: true)
|
|
62
|
+
reconnect! if token_expired? && !in_transaction?
|
|
63
|
+
super(allow_retry:, materialize_transactions:) do |conn|
|
|
64
|
+
yield conn
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
15
68
|
class << self
|
|
16
69
|
def new_client(conn_params)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
70
|
+
# AuroraDsql::Pg.connect forces sslmode: verify-full!
|
|
71
|
+
# Instead of using that we re-write it here with an optional sslmode override.
|
|
72
|
+
# In development mode using sslmode: require is easier to set up than verify-full.
|
|
73
|
+
# AuroraDsql::Pg.connect(**conn_params)
|
|
74
|
+
|
|
75
|
+
config = conn_params
|
|
76
|
+
options = {}
|
|
77
|
+
resolved = AuroraDsql::Pg::Config.from(config, **options).resolve
|
|
78
|
+
token = AuroraDsql::Pg::Token.generate(
|
|
79
|
+
host: resolved.host, region: resolved.region,
|
|
80
|
+
user: resolved.user, credentials: resolved.credentials_provider,
|
|
81
|
+
profile: resolved.profile, expires_in: resolved.token_duration
|
|
82
|
+
)
|
|
83
|
+
pg_params = resolved.to_pg_params(password: token)
|
|
84
|
+
pg_params[:sslmode] = conn_params[:sslmode] if conn_params[:sslmode]
|
|
85
|
+
::PG.connect(pg_params)
|
|
86
|
+
rescue ::PG::Error => error
|
|
87
|
+
if conn_params && conn_params[:dbname] == "postgres"
|
|
88
|
+
raise ActiveRecord::ConnectionNotEstablished, error.message
|
|
89
|
+
elsif conn_params && conn_params[:dbname] && error.message.include?(conn_params[:dbname])
|
|
90
|
+
raise ActiveRecord::NoDatabaseError.db_error(conn_params[:dbname])
|
|
91
|
+
elsif conn_params && conn_params[:user] && error.message.include?(conn_params[:user])
|
|
92
|
+
raise ActiveRecord::DatabaseConnectionError.username_error(conn_params[:user])
|
|
93
|
+
elsif conn_params && conn_params[:host] && error.message.include?(conn_params[:host])
|
|
94
|
+
raise ActiveRecord::DatabaseConnectionError.hostname_error(conn_params[:host])
|
|
95
|
+
else
|
|
96
|
+
raise ActiveRecord::ConnectionNotEstablished, error.message
|
|
97
|
+
end
|
|
23
98
|
end
|
|
24
99
|
|
|
25
100
|
def dbconsole(config, options = {})
|
metadata
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-dsql-adapter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Cochran
|
|
8
8
|
bindir: bin
|
|
9
|
-
cert_chain:
|
|
10
|
-
- |
|
|
11
|
-
-----BEGIN CERTIFICATE-----
|
|
12
|
-
MIIDKDCCAhCgAwIBAgIBBDANBgkqhkiG9w0BAQsFADA6MQ0wCwYDVQQDDARzajI2
|
|
13
|
-
MRQwEgYKCZImiZPyLGQBGRYEc2oyNjETMBEGCgmSJomT8ixkARkWA2NvbTAeFw0y
|
|
14
|
-
NTA5MDEwNTU2MDhaFw0yNjA5MDEwNTU2MDhaMDoxDTALBgNVBAMMBHNqMjYxFDAS
|
|
15
|
-
BgoJkiaJk/IsZAEZFgRzajI2MRMwEQYKCZImiZPyLGQBGRYDY29tMIIBIjANBgkq
|
|
16
|
-
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsr60Eo/ttCk8GMTMFiPr3GoYMIMFvLak
|
|
17
|
-
xSmTk9YGCB6UiEePB4THSSA5w6IPyeaCF/nWkDp3/BAam0eZMWG1IzYQB23TqIM0
|
|
18
|
-
1xzcNRvFsn0aQoQ00k+sj+G83j3T5OOV5OZIlu8xAChMkQmiPd1NXc6uFv+Iacz7
|
|
19
|
-
kj+CMsI9YUFdNoU09QY0b+u+Rb6wDYdpyvN60YC30h0h1MeYbvYZJx/iZK4XY5zu
|
|
20
|
-
4O/FL2ChjL2CPCpLZW55ShYyrzphWJwLOJe+FJ/ZBl6YXwrzQM9HKnt4titSNvyU
|
|
21
|
-
KzE3L63A3PZvExzLrN9u09kuWLLJfXB2sGOlw3n9t72rJiuBr3/OQQIDAQABozkw
|
|
22
|
-
NzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU99dfRjEKFyczTeIz
|
|
23
|
-
m3ZsDWrNC80wDQYJKoZIhvcNAQELBQADggEBABLxSFRmde7YPaefFvqzjWZ7snrT
|
|
24
|
-
/QdsnhlLypvIUeGCuLemQKq5sO7YFJ4UUnYbzrhPScnh5odx0XuXDWLN2Xr7Sz9A
|
|
25
|
-
cw4c0gEWhZAv5xm9taOyw0Wuy2u7RNeAgLikufrIdr+Fei4fj0zEzdUQs6OxDZBV
|
|
26
|
-
ZJpG1F3YsIupbaQEFZFOMoP111ziIeddeS/+xJYB9iXxWdgBcKgPchpPjp//D1kk
|
|
27
|
-
rbxUJAPpJ+AnctA9Kgqa7b71x6DG8aFCTN3TUGKpQUnt5Qe6eynYnNBQ+yyo8J8r
|
|
28
|
-
rVaBG/8I33rEoBAyw3BuV44TS7DG1kGbv4DOByI46JFAZU4aLEr6lpAmvPs=
|
|
29
|
-
-----END CERTIFICATE-----
|
|
9
|
+
cert_chain: []
|
|
30
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
31
11
|
dependencies:
|
|
32
12
|
- !ruby/object:Gem::Dependency
|
|
@@ -63,6 +43,20 @@ dependencies:
|
|
|
63
43
|
- - "~>"
|
|
64
44
|
- !ruby/object:Gem::Version
|
|
65
45
|
version: '1.1'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: aurora-dsql-ruby-pg
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - "~>"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '1.1'
|
|
53
|
+
type: :runtime
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - "~>"
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '1.1'
|
|
66
60
|
- !ruby/object:Gem::Dependency
|
|
67
61
|
name: aws-sdk-dsql
|
|
68
62
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -110,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
110
104
|
- !ruby/object:Gem::Version
|
|
111
105
|
version: '0'
|
|
112
106
|
requirements: []
|
|
113
|
-
rubygems_version:
|
|
107
|
+
rubygems_version: 4.0.21
|
|
114
108
|
specification_version: 4
|
|
115
109
|
summary: ActiveRecord adapter for AWS Aurora DSQL (PostgreSQL)
|
|
116
110
|
test_files: []
|
checksums.yaml.gz.sig
DELETED
|
Binary file
|
data.tar.gz.sig
DELETED
|
Binary file
|
metadata.gz.sig
DELETED
|
Binary file
|