uc3-dmp-api-core 0.0.21 → 0.0.22

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: 814a119b8bc2cae5b1019b447d206158f32af4322d7027c5d67692790662b620
4
- data.tar.gz: 706c0127627df31924c712de0129f09e721d6659b8f04c0ce7ebdc4a819f1f14
3
+ metadata.gz: 3cb6321b051bb8cf697fff399dd0f5006e5bbff69dbcf52154c345f75ed70b82
4
+ data.tar.gz: 6e03e7e1c371df7ee993adedac572ed7e6a5cc6011985b1aef978cae99cee5bd
5
5
  SHA512:
6
- metadata.gz: 5aa2fb5aeea37687db35306f41c775ca5497f5184d5e04750830b8d2c9cd87a79d34e3c54c399f2531aa244d5bdf4f0e2c02684131f57d0892a06a0012fc9351
7
- data.tar.gz: e0b90e46aac95b8d63f355e5e4198f0c99d3888a05abda1ac48e45ca5fcaef77ad38f479263e215e080ece7cf74d909604c221648dac86845a8957674bc59e44
6
+ metadata.gz: cace3332f7ba2242e4393c736b9790ebe1f75db5e19a180deab9605f4d47294cc43d6d4f593eca9ca773fb436ea759fb17e7fa72e17cb020e863dbce77ea5a18
7
+ data.tar.gz: aa99982f94eb3c02cb8a5df72f52001d58bc82af9e43555e6892dcbdd81bba0ca767862639c3f8c8f21bac9d5987aff3a90067bbd02ee966d6d71d160c39232b
@@ -12,7 +12,7 @@ module Uc3DmpApiCore
12
12
  Aws::SNS::Client.new.publish(
13
13
  topic_arn: ENV.fetch('SNS_FATAL_ERROR_TOPIC', nil),
14
14
  subject: "DMPTool - fatal error in - #{source}",
15
- message: _build_admin_message(source: source, details: details, event: event)
15
+ message: _build_admin_message(source:, details:, event:)
16
16
  )
17
17
  true
18
18
  rescue Aws::Errors::ServiceError => e
@@ -12,7 +12,7 @@ module Uc3DmpApiCore
12
12
  def paginate(results:, params: {})
13
13
  return results unless results.is_a?(Array) && results.any? && params.is_a?(Hash)
14
14
 
15
- current = _current_page(item_count: results.length, params: params)
15
+ current = _current_page(item_count: results.length, params:)
16
16
  # Just return as is if there is only one page
17
17
  return results if current[:total_pages] == 1 || current[:per_page] >= results.length
18
18
 
@@ -25,7 +25,7 @@ module Uc3DmpApiCore
25
25
  # Construct the pagination meta information that will be included in the response
26
26
  # rubocop:disable Metrics/AbcSize
27
27
  def pagination_meta(url:, item_count: 0, params: {})
28
- prms = _current_page(item_count: item_count, params: params)
28
+ prms = _current_page(item_count:, params:)
29
29
 
30
30
  hash = { page: prms[:page], per_page: prms[:per_page], total_items: item_count }
31
31
  return hash if prms[:total_pages] == 1 || item_count <= prms[:per_page]
@@ -34,10 +34,10 @@ module Uc3DmpApiCore
34
34
  nxt = prms[:page] + 1
35
35
  last = prms[:total_pages]
36
36
 
37
- hash[:first] = _build_link(url: url, target_page: 1, per_page: prms[:per_page]) if prms[:page] > 1
38
- hash[:prev] = _build_link(url: url, target_page: prv, per_page: prms[:per_page]) if prms[:page] > 1
39
- hash[:next] = _build_link(url: url, target_page: nxt, per_page: prms[:per_page]) if prms[:page] < last
40
- hash[:last] = _build_link(url: url, target_page: last, per_page: prms[:per_page]) if prms[:page] < last
37
+ hash[:first] = _build_link(url:, target_page: 1, per_page: prms[:per_page]) if prms[:page] > 1
38
+ hash[:prev] = _build_link(url:, target_page: prv, per_page: prms[:per_page]) if prms[:page] > 1
39
+ hash[:next] = _build_link(url:, target_page: nxt, per_page: prms[:per_page]) if prms[:page] < last
40
+ hash[:last] = _build_link(url:, target_page: last, per_page: prms[:per_page]) if prms[:page] < last
41
41
  hash.compact
42
42
  end
43
43
  # rubocop:enable Metrics/AbcSize
@@ -45,24 +45,26 @@ module Uc3DmpApiCore
45
45
  private
46
46
 
47
47
  # Fetch the current :page and :per_page from the params or use the defaults
48
+ # rubocop:disable Metrics/AbcSize
48
49
  def _current_page(item_count: 0, params: {})
49
50
  page = params.fetch('page', DEFAULT_PAGE).to_i
50
51
  page = DEFAULT_PAGE if page.nil? || page.to_i <= 1
51
52
  per_page = params.fetch('per_page', DEFAULT_PER_PAGE).to_i
52
53
  per_page = DEFAULT_PER_PAGE if per_page.nil? || per_page.to_i >= MAXIMUM_PER_PAGE || per_page.to_i < 1
53
54
 
54
- total_pages = _page_count(total: item_count, per_page: per_page)
55
+ total_pages = _page_count(total: item_count, per_page:)
55
56
  page = total_pages if page > total_pages
56
57
 
57
58
  { page: page.to_i, per_page: per_page.to_i, total_pages: total_pages.to_i }
58
59
  end
60
+ # rubocop:enable Metrics/AbcSize
59
61
 
60
62
  # Generate a pagination link
61
63
  # --------------------------------------------------------------------------------
62
64
  def _build_link(url:, target_page:, per_page: DEFAULT_PER_PAGE)
63
65
  return nil if url.nil? || target_page.nil?
64
66
 
65
- link = _url_without_pagination(url: url)
67
+ link = _url_without_pagination(url:)
66
68
  return nil if link.nil?
67
69
 
68
70
  link += '?' unless link.include?('?')
@@ -24,10 +24,11 @@ module Uc3DmpApiCore
24
24
  #
25
25
  # Returns a hash that is a valid Lambda API response
26
26
  # --------------------------------------------------------------------------------
27
- # rubocop:disable Metrics/AbcSize
27
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
28
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
28
29
  def respond(status: DEFAULT_STATUS_CODE, logger: nil, items: [], errors: [], **args)
29
30
  url = _url_from_event(event: args[:event]) || SsmReader.get_ssm_value(key: 'api_base_url')
30
- return _standard_error(url: url) if url.nil?
31
+ return _standard_error(url:) if url.nil?
31
32
 
32
33
  args = JSON.parse(args.to_json)
33
34
  errors = [errors] unless errors.nil? || errors.is_a?(Array)
@@ -39,9 +40,9 @@ module Uc3DmpApiCore
39
40
  requested_at: Time.now.strftime(TIMESTAMP_FORMAT),
40
41
  total_items: item_count,
41
42
  items: items.is_a?(Array) ? Paginator.paginate(params: args, results: items) : [],
42
- errors: errors
43
+ errors:
43
44
  }
44
- body = body.merge(Paginator.pagination_meta(url: url, item_count: item_count, params: args))
45
+ body = body.merge(Paginator.pagination_meta(url:, item_count:, params: args))
45
46
 
46
47
  # If this is a server error, then notify the administrator!
47
48
  if status.to_s[0] == '5' && !logger.nil?
@@ -49,12 +50,13 @@ module Uc3DmpApiCore
49
50
  Notifier.notify_administrator(source: logger.source, details: body, event: logger.event)
50
51
  end
51
52
 
52
- { statusCode: status.to_i, body: body.compact.to_json, headers: headers }
53
+ { statusCode: status.to_i, body: body.compact.to_json, headers: }
53
54
  rescue StandardError => e
54
- logger.error(message: e.message, details: e.backtrace) unless logger.nil?
55
- _standard_error(url: url)
55
+ logger&.error(message: e.message, details: e.backtrace)
56
+ _standard_error(url:)
56
57
  end
57
- # rubocop:enable Metrics/AbcSize
58
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
59
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
58
60
 
59
61
  private
60
62
 
@@ -67,7 +69,7 @@ module Uc3DmpApiCore
67
69
  total_items: 0,
68
70
  errors: [message]
69
71
  }
70
- { statusCode: DEFAULT_STATUS_CODE, body: body.compact.to_json, headers: headers }
72
+ { statusCode: DEFAULT_STATUS_CODE, body: body.compact.to_json, headers: }
71
73
  end
72
74
 
73
75
  # Figure out the requested URL from the Lambda event hash
@@ -84,7 +86,7 @@ module Uc3DmpApiCore
84
86
  def headers
85
87
  return {} if ENV['CORS_ORIGIN'].nil?
86
88
 
87
- { 'access-control-allow-origin': ENV['CORS_ORIGIN'] }
89
+ { 'access-control-allow-origin': ENV.fetch('CORS_ORIGIN', nil) }
88
90
  end
89
91
  end
90
92
  end
@@ -22,16 +22,16 @@ module Uc3DmpApiCore
22
22
  # rubocop:disable Metrics/AbcSize
23
23
  def get_ssm_value(key:, provenance_name: nil, logger: nil)
24
24
  full_key = _ssm_keys[:"#{key.downcase}"] unless key.nil?
25
- logger.debug(message: "Looking for SSM Key: #{full_key}") unless logger.nil?
25
+ logger&.debug(message: "Looking for SSM Key: #{full_key}")
26
26
  return nil if full_key.nil?
27
27
 
28
28
  key_vals = { env: ENV.fetch('LAMBDA_ENV', 'dev').to_s.downcase }
29
29
  # Swap in the provenance name if applicable
30
30
  key_vals[:provenance] = provenance_name unless provenance_name.nil? ||
31
31
  !full_key.include?('%{provenance}')
32
- fetch_value(key: format(full_key, key_vals), logger: logger)
32
+ fetch_value(key: format(full_key, key_vals), logger:)
33
33
  rescue Aws::Errors::ServiceError => e
34
- logger.error(message: "Looking for SSM Key: #{key} - #{e.message}", details: e.backtrace) unless logger.nil?
34
+ logger&.error(message: "Looking for SSM Key: #{key} - #{e.message}", details: e.backtrace)
35
35
  nil
36
36
  end
37
37
  # rubocop:enable Metrics/AbcSize
@@ -39,7 +39,7 @@ module Uc3DmpApiCore
39
39
  # Call SSM to get the value for the specified key
40
40
  def fetch_value(key:, logger: nil)
41
41
  resp = Aws::SSM::Client.new.get_parameter(name: key, with_decryption: true)
42
- logger.debug(message: "Searching for SSM Key: #{key}, Found: '#{resp&.parameter&.value}'") unless logger.nil?
42
+ logger&.debug(message: "Searching for SSM Key: #{key}, Found: '#{resp&.parameter&.value}'")
43
43
  resp.nil? || resp.parameter.nil? ? nil : resp.parameter.value
44
44
  end
45
45
 
@@ -47,7 +47,6 @@ module Uc3DmpApiCore
47
47
 
48
48
  # DMPTool/DMPHub SSM keys. See the installation guide for information about how these values are used
49
49
  # https://github.com/CDLUC3/dmp-hub-cfn/wiki/installation-and-setup#required-ssm-parameters
50
- # rubocop:disable Metrics/MethodLength
51
50
  def _ssm_keys
52
51
  {
53
52
  administrator_email: '/uc3/dmp/hub/%{env}/AdminEmail',
@@ -75,7 +74,6 @@ module Uc3DmpApiCore
75
74
  dynamo_table_name: '/uc3/dmp/hub/%{env}/DynamoTableName'
76
75
  }
77
76
  end
78
- # rubocop:enable Metrics/MethodLength
79
77
  end
80
78
  end
81
79
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpApiCore
4
- VERSION = '0.0.21'
4
+ VERSION = '0.0.22'
5
5
  end
@@ -9,6 +9,7 @@ require 'uc3-dmp-api-core/paginator'
9
9
  require 'uc3-dmp-api-core/responder'
10
10
  require 'uc3-dmp-api-core/ssm_reader'
11
11
 
12
+ # Entrypoitn for the uc3-dmp-api-core gem
12
13
  module Uc3DmpApiCore
13
14
  # General HTTP Response Messages
14
15
  # ----------------------------------------
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc3-dmp-api-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-12 00:00:00.000000000 Z
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -141,7 +141,7 @@ licenses:
141
141
  - MIT
142
142
  metadata:
143
143
  rubygems_mfa_required: 'false'
144
- post_install_message:
144
+ post_install_message:
145
145
  rdoc_options: []
146
146
  require_paths:
147
147
  - lib
@@ -149,15 +149,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: '2.7'
152
+ version: '3.2'
153
153
  required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
155
  - - ">="
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
- rubygems_version: 3.1.6
160
- signing_key:
159
+ rubygems_version: 3.4.10
160
+ signing_key:
161
161
  specification_version: 4
162
162
  summary: DMPTool gem that provides general support for Lambda functions
163
163
  test_files: []