uc3-dmp-rds 0.0.9 → 0.0.10

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: 4181722f3ac149e1843e0372c04cc326341021eef62df0d52efafbf524fb4876
4
- data.tar.gz: 9e561848f90dc6961e89f8b051b6dac8f896d119bf6f4e25e409fcf5ac1f4562
3
+ metadata.gz: 3091e4b4c758fd05dd75c866ef07a3f43f13daa15c909ee32349161f74b8a32f
4
+ data.tar.gz: a173d9fa491a0fdb756ec409f8ba0f106e0d155f80a752c23fb9d89964201997
5
5
  SHA512:
6
- metadata.gz: 439be8d21f8eb86b72d0599e0bcfa89e93c032a372bcf4321462cd83435995a9115433bf533a3b88930c2f641b058eb54df7cdca9e80f85979b8dbd632d5919a
7
- data.tar.gz: 6118678a2c94fbd6d871d15403ab17fc4e52434b422fe7bf1b093aa481ab97d41615cd5037a9a032ce230626a72452c01f0ad7fa23728e9c4f6ee934f03a0898
6
+ metadata.gz: c762ea939a7536dc10e0a551fe3d8ab6dda43944e59e5a84f32fdcdc9af06712ee4baef7b54e99ed253a99f38cdd12ec39630af990f46cc4957f7189a00c5d4b
7
+ data.tar.gz: e82053a5d6a44958f7f08d965493dfa4045f36ab7d5e6735f8cc0fabc013c7d1531af879dc4ad4fd83934602f50a6ef5c67f8a7c6ca8c25bfc88248391236e03
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'active_record'
4
4
  require 'active_record_simple_execute'
5
- require 'aws-sdk-sns'
6
- require 'aws-sdk-ssm'
7
5
  require 'mysql2'
8
6
 
9
7
  module Uc3DmpRds
@@ -24,9 +22,11 @@ module Uc3DmpRds
24
22
  MSG_MISSING_CREDENTIALS = 'No username and/or password specified'
25
23
  MSG_UNABLE_TO_CONNECT = 'Unable to establish a connection'
26
24
  MSG_UNABLE_TO_QUERY = 'Unable to process the query'
25
+ MSG_UNAUTHORIZED = 'You are not authorized to perform that action'
27
26
 
28
27
  class << self
29
28
  # Connect to the RDS instance
29
+ # rubocop:disable Metrics/AbcSize
30
30
  def connect(username:, password:)
31
31
  raise AdapterError, MSG_MISSING_CREDENTIALS if username.nil? || username.to_s.strip.empty? ||
32
32
  password.nil? || password.to_s.strip.empty?
@@ -44,9 +44,11 @@ module Uc3DmpRds
44
44
  rescue StandardError => e
45
45
  raise AdapterError, "#{MSG_UNABLE_TO_CONNECT} - #{e.message}"
46
46
  end
47
+ # rubocop:enable Metrics/AbcSize
47
48
 
48
49
  # Execute the specified query using ActiveRecord's helpers to sanitize the input
49
- def execute_query(sql:, **params)
50
+ def execute_query(user:, sql:, **params)
51
+ raise AdapterError, MSG_UNAUTHORIZED unless user.is_a?(User)
50
52
  return [] unless sql.is_a?(String) && !sql.strip.empty? && (params.nil? || params.is_a?(Hash))
51
53
  # Verify that all of the kewords are accounted for and that values were supplied
52
54
  raise AdapterError, MSG_KEYWORDS_INVALID unless _verify_params(sql: sql, params: params)
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record'
4
+ require 'active_record_simple_execute'
5
+ require 'mysql2'
6
+
7
+ module Uc3DmpRds
8
+ # Error from the Rds Adapter
9
+ class AuthenticatorError < StandardError; end
10
+
11
+ # Use Rails' ActiveResource to communicate with the DMPHub REST API
12
+ class Authenticator
13
+ MSG_INVALID_TOKEN = 'Invalid user token'
14
+ MSG_INACTIVE_USER = 'User is inactive'
15
+
16
+ class << self
17
+ def authenticate(token:)
18
+ raise AuthenticatorError, MSG_INVALID_TOKEN if token.nil? || token.to_s.strip.empty?
19
+
20
+ sql = <<~SQL.squish
21
+ SELECT users.firstname, users.surname, users.email, users.active, i.value orcid,
22
+ orgs.name org_name, ro.name ror_name, ro.ror_id
23
+ FROM users
24
+ INNER JOIN orgs ON users.org_id = orgs.id
25
+ LEFT OUTER JOIN registry_orgs ro
26
+ ON orgs.id = ro.org_id
27
+ LEFT OUTER JOIN identifiers i
28
+ ON i.identifiable_id = users.id
29
+ AND i.identifiable_type = 'User'
30
+ AND i.identifier_scheme_id IN (SELECT sch.id FROM identifier_schemes sch WHERE sch.name = 'orcid')
31
+ WHERE users.api_token = :token
32
+ LIMIT 1
33
+ SQL
34
+ users = ActiveRecord::Base.simple_execute(sql, token: token.to_s.strip)
35
+ raise AuthenticatorError, MSG_INVALID_TOKEN unless users.is_a?(Array) and users.any?
36
+
37
+ user = users.first
38
+ raise AuthenticatorError, MSG_INACTIVE_USER unless user['active']
39
+
40
+ hash = { name: [user['surname'], user['firstname']].join(', '), mbox: user['email'] }
41
+ hash[:user_id] = { type: 'orcid', identifier: user['orcid'] } unless user['orcid'].nil?
42
+ return hash.to_json if user['org_name'].nil?
43
+
44
+ hash[:affiliation] = { name: user.fetch('ror_name', user['org_name']) }
45
+ hash[:affiliation][:affiliation_id] = { type: 'ror', identifier: user['ror_id'] } unless user['ror_id'].nil?
46
+ hash.to_json
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpRds
4
- VERSION = '0.0.9'
4
+ VERSION = '0.0.10'
5
5
  end
data/lib/uc3-dmp-rds.rb CHANGED
@@ -1,11 +1,6 @@
1
1
  # rubocop:disable Naming/FileName
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'aws-sdk-sns'
5
- require 'aws-sdk-ssm'
6
-
7
- require 'uc3-dmp-api-core'
8
-
9
4
  require 'uc3-dmp-rds/adapter'
10
5
 
11
6
  # RDS Database adapter
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.9
4
+ version: 0.0.10
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-03 00:00:00.000000000 Z
11
+ date: 2023-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_record_simple_execute
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.1
27
- - !ruby/object:Gem::Dependency
28
- name: aws-sdk-sns
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.60'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.60'
41
- - !ruby/object:Gem::Dependency
42
- name: aws-sdk-ssm
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.150'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.150'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: json
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -160,6 +132,7 @@ files:
160
132
  - README.md
161
133
  - lib/uc3-dmp-rds.rb
162
134
  - lib/uc3-dmp-rds/adapter.rb
135
+ - lib/uc3-dmp-rds/authenticator.rb
163
136
  - lib/uc3-dmp-rds/version.rb
164
137
  homepage: https://github.com/CDLUC3/dmp-hub-cfn/blob/main/src/sam/gems/uc3-dmp-rds
165
138
  licenses: