uc3-dmp-rds 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uc3-dmp-rds/adapter.rb +21 -21
- data/lib/uc3-dmp-rds/version.rb +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4181722f3ac149e1843e0372c04cc326341021eef62df0d52efafbf524fb4876
|
4
|
+
data.tar.gz: 9e561848f90dc6961e89f8b051b6dac8f896d119bf6f4e25e409fcf5ac1f4562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 439be8d21f8eb86b72d0599e0bcfa89e93c032a372bcf4321462cd83435995a9115433bf533a3b88930c2f641b058eb54df7cdca9e80f85979b8dbd632d5919a
|
7
|
+
data.tar.gz: 6118678a2c94fbd6d871d15403ab17fc4e52434b422fe7bf1b093aa481ab97d41615cd5037a9a032ce230626a72452c01f0ad7fa23728e9c4f6ee934f03a0898
|
data/lib/uc3-dmp-rds/adapter.rb
CHANGED
@@ -6,58 +6,58 @@ require 'aws-sdk-sns'
|
|
6
6
|
require 'aws-sdk-ssm'
|
7
7
|
require 'mysql2'
|
8
8
|
|
9
|
-
require 'uc3-dmp-api-core'
|
10
|
-
|
11
9
|
module Uc3DmpRds
|
10
|
+
# Error from the Rds Adapter
|
11
|
+
class AdapterError < StandardError; end
|
12
|
+
|
12
13
|
# A module to interact with the RDS DB. Expects the following ENV variables to be set:
|
13
14
|
# DATABASE_HOST: The host URL
|
14
15
|
# DATABASE_PORT: The port to use
|
15
16
|
# DATABASE_NAME: The name of the database
|
16
17
|
#
|
17
|
-
# and the following
|
18
|
+
# and the following should be passed into the :connect method:
|
18
19
|
# RDS_USERNAME: The RDS username
|
19
20
|
# RDS_PASSWORD: The RDS password
|
20
21
|
#
|
21
22
|
class Adapter
|
22
|
-
|
23
|
-
|
23
|
+
MSG_KEYWORDS_INVALID = 'The parameters specified do not match those in the SQL query'
|
24
|
+
MSG_MISSING_CREDENTIALS = 'No username and/or password specified'
|
25
|
+
MSG_UNABLE_TO_CONNECT = 'Unable to establish a connection'
|
26
|
+
MSG_UNABLE_TO_QUERY = 'Unable to process the query'
|
24
27
|
|
25
28
|
class << self
|
26
29
|
# Connect to the RDS instance
|
27
|
-
def connect(
|
28
|
-
|
29
|
-
|
30
|
+
def connect(username:, password:)
|
31
|
+
raise AdapterError, MSG_MISSING_CREDENTIALS if username.nil? || username.to_s.strip.empty? ||
|
32
|
+
password.nil? || password.to_s.strip.empty?
|
33
|
+
|
34
|
+
connection = ActiveRecord::Base.establish_connection(
|
30
35
|
adapter: 'mysql2',
|
31
36
|
host: ENV.fetch('DATABASE_HOST', nil),
|
32
37
|
port: ENV.fetch('DATABASE_PORT', nil),
|
33
38
|
database: ENV.fetch('DATABASE_NAME', nil),
|
34
|
-
username:
|
35
|
-
password:
|
39
|
+
username: username,
|
40
|
+
password: password,
|
36
41
|
encoding: 'utf8mb4'
|
37
42
|
)
|
38
|
-
|
43
|
+
!connection.nil?
|
44
|
+
rescue StandardError => e
|
45
|
+
raise AdapterError, "#{MSG_UNABLE_TO_CONNECT} - #{e.message}"
|
39
46
|
end
|
40
47
|
|
41
48
|
# Execute the specified query using ActiveRecord's helpers to sanitize the input
|
42
49
|
def execute_query(sql:, **params)
|
43
|
-
raise StandardError, MSG_NO_CONNECTION unless ActiveRecord::Base.connected?
|
44
50
|
return [] unless sql.is_a?(String) && !sql.strip.empty? && (params.nil? || params.is_a?(Hash))
|
45
51
|
# Verify that all of the kewords are accounted for and that values were supplied
|
46
|
-
raise
|
52
|
+
raise AdapterError, MSG_KEYWORDS_INVALID unless _verify_params(sql: sql, params: params)
|
47
53
|
|
48
54
|
ActiveRecord::Base.simple_execute(sql, params)
|
55
|
+
rescue StandardError => e
|
56
|
+
raise AdapterError, "#{MSG_UNABLE_TO_QUERY} - #{e.message}"
|
49
57
|
end
|
50
58
|
|
51
59
|
private
|
52
60
|
|
53
|
-
# Fetch the DB credentials from SSM parameter store
|
54
|
-
def _credentials
|
55
|
-
{
|
56
|
-
username: Uc3DmpApiCore::SsmReader.get_ssm_value(key: :rds_username),
|
57
|
-
password: Uc3DmpApiCore::SsmReader.get_ssm_value(key: :rds_password)
|
58
|
-
}
|
59
|
-
end
|
60
|
-
|
61
61
|
# Verify that all params defined in the SQL exist in the params hash and vice versa
|
62
62
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
63
63
|
def _verify_params(sql:, params:)
|
data/lib/uc3-dmp-rds/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uc3-dmp-rds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Riley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_record_simple_execute
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.5.5
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: uc3-dmp-api-core
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.0.6
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.0.6
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: byebug
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +122,20 @@ dependencies:
|
|
136
122
|
- - '='
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: 1.50.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-performance
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.17.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.17.1
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rubocop-rspec
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|