uc3-dmp-rds 0.0.6 → 0.0.8
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 +22 -20
- 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: 1ceba0e24d5a6a925fde46a68d7d8f1586aa29bf1687e94000d989f6ab522e3e
|
4
|
+
data.tar.gz: 0d6ef838acd8ce79e5638e83b45c8bbdb72cd919863916ad0d48d5658ab079b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aa9e392a307c55483d432c487ef5a5c0ab6c501e7e3081646f5945ba7fe5322fd29b2eb1d3b81d110f94db0ec252f624fcdcf70a4f903df0cdc434e2851b99b
|
7
|
+
data.tar.gz: 2ced3df663f4dc6ee3d360625ff12c3a267c9a136c1d9535a54a41d51092691a7e8e316ec39fb8eca207b98807abc623f0a47bcaacbca3dd6c55275997211fba
|
data/lib/uc3-dmp-rds/adapter.rb
CHANGED
@@ -6,58 +6,60 @@ 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_NO_CONNECTION = 'No current database connection. Call Uc3DmpRds.connect first'
|
24
26
|
|
25
27
|
class << self
|
26
28
|
# Connect to the RDS instance
|
27
|
-
def connect(
|
28
|
-
|
29
|
-
|
29
|
+
def connect(username:, password:)
|
30
|
+
raise AdapterError, MSG_MISSING_CREDENTIALS if username.nil? || username.to_s.strip.empty? ||
|
31
|
+
password.nil? || password.to_s.strip.empty?
|
32
|
+
|
33
|
+
puts "CONNECT - host: #{ENV['DATABASE_HOST']}, port: #{ENV['DATABASE_PORT']}, name: #{ENV['DATABASE_NAME']}, username: #{username}, password.lenght: #{password.length}"
|
34
|
+
|
35
|
+
connection = ActiveRecord::Base.establish_connection(
|
30
36
|
adapter: 'mysql2',
|
31
37
|
host: ENV.fetch('DATABASE_HOST', nil),
|
32
38
|
port: ENV.fetch('DATABASE_PORT', nil),
|
33
39
|
database: ENV.fetch('DATABASE_NAME', nil),
|
34
|
-
username:
|
35
|
-
password:
|
40
|
+
username: username,
|
41
|
+
password: password,
|
36
42
|
encoding: 'utf8mb4'
|
37
43
|
)
|
44
|
+
|
45
|
+
puts connection.inspect
|
46
|
+
puts "CONNECTED? #{ActiveRecord::Base.connected?}"
|
47
|
+
|
38
48
|
ActiveRecord::Base.connected?
|
39
49
|
end
|
40
50
|
|
41
51
|
# Execute the specified query using ActiveRecord's helpers to sanitize the input
|
42
52
|
def execute_query(sql:, **params)
|
43
|
-
raise
|
53
|
+
raise AdapterError, MSG_NO_CONNECTION unless ActiveRecord::Base.connected?
|
44
54
|
return [] unless sql.is_a?(String) && !sql.strip.empty? && (params.nil? || params.is_a?(Hash))
|
45
55
|
# Verify that all of the kewords are accounted for and that values were supplied
|
46
|
-
raise
|
56
|
+
raise AdapterError, MSG_KEYWORDS_INVALID unless _verify_params(sql: sql, params: params)
|
47
57
|
|
48
58
|
ActiveRecord::Base.simple_execute(sql, params)
|
49
59
|
end
|
50
60
|
|
51
61
|
private
|
52
62
|
|
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
63
|
# Verify that all params defined in the SQL exist in the params hash and vice versa
|
62
64
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
63
65
|
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.8
|
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
|