uc3-dmp-api-core 0.0.6 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fdf225c15fdb31fde0c5b580c65fe11cc1f954ca5095c3ba65b97ec5a75706c
4
- data.tar.gz: 312895d96acf566e198b8159ced5cdf99055330fcddf62b105cfc750fa2d124b
3
+ metadata.gz: cbc951e48875269d72952ec846fb48d262edc1de0646f922b989fcca081c3365
4
+ data.tar.gz: 29d964e6a26deef238cc42d67d24fb1d5fd33334160405d5a03e8da0a7c8a7cd
5
5
  SHA512:
6
- metadata.gz: c70e9f61cd6d20b1936561a15257d89d13655eb6d163c28c9cd75f2e1c46927118128155312e6b2e6797d704de6fa5360ea4c2ae3019fd159b8a39d95dc4bc4b
7
- data.tar.gz: 7dd073b4a5c47ac0fef2c750bb780282b8b0cdf23fc8243dcbcf64a27b02787ec3dc692d25dbc2c962803f2b5a99f480c2363b62950bfec7d99bb45287a858b5
6
+ metadata.gz: 0eecb4937d2f190f2e620ab5ba7598030a2bfd085c860e2a8714fbc25e3f1cd434f63f08cfe875ed46322f1d1fcde520d1a3bdcefe3967b5f375a566564f58cc
7
+ data.tar.gz: 82db9a348a62d816998170aa6c954859a3ce68843d3e2f393193b5066cdd31aa19741c8c6163933ad7daa51b81e6b2b5175f33e15585da8dad791ced188b869a
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Basic helper classes used by the DMPTool Lambda functions.
4
4
 
5
- - Logger: Helper for logging messages and errors to CloudWatch
5
+ - LogWriter: Helper for logging messages and errors to CloudWatch
6
6
  - Notifier: Helper for sending emails via SNS and sending events to EventBridge
7
+ - Paginator: Helper for paginating search results and building the pagination links for the response
7
8
  - Responder: Helper that formats API responses in a standardized way
8
9
  - SsmReader: Helper that fetches values from the SSM parameter store
@@ -34,6 +34,7 @@ module Uc3DmpApiCore
34
34
  # Is there a better way here than just 'print'? This ends up in the CloudWatch logs
35
35
  puts "INFO: #{source} - #{message}"
36
36
  puts " - DETAILS: #{details.to_json}" if details.is_a?(Hash) && details.keys.any?
37
+ puts " - EVENT: #{event.to_json}" if event.is_a?(Hash) && event.keys.any?
37
38
  true
38
39
  end
39
40
  end
@@ -8,7 +8,6 @@ module Uc3DmpApiCore
8
8
  class << self
9
9
  # Sends the Administrator an email notification
10
10
  # --------------------------------------------------------------------------------
11
- # rubocop:disable Metrics/AbcSize
12
11
  def notify_administrator(source:, details:, event: {})
13
12
  Aws::SNS::Client.new.publish(
14
13
  topic_arn: ENV.fetch('SNS_FATAL_ERROR_TOPIC', nil),
@@ -22,13 +21,13 @@ module Uc3DmpApiCore
22
21
  puts " - DETAILS: #{details.to_json}" if details.is_a?(Hash) && details.keys.any?
23
22
  false
24
23
  end
25
- # rubocop:enable Metrics/AbcSize
26
24
 
27
25
  private
28
26
 
29
27
  # Format the Admin email message
30
28
  def _build_admin_message(source:, details:, event: {})
31
- payload = "DMPTool #{ENV.fetch('LAMBDA_ENV', 'dev')} has encountered a fatal error within a Lambda function.\n\n /
29
+ payload = "DMPTool #{ENV.fetch('LAMBDA_ENV',
30
+ 'dev')} has encountered a fatal error within a Lambda function.\n\n /
32
31
  SOURCE: #{source}\n /
33
32
  TIME STAMP: #{Time.now.strftime('%Y-%m-%dT%H:%M:%S%L%Z')}\n /
34
33
  NOTES: Check the CloudWatch logs for additional details.\n\n"
@@ -36,6 +35,7 @@ module Uc3DmpApiCore
36
35
  payload += "DETAILS: #{details.to_json}\n\n" if details.is_a?(Hash) && details.keys.any?
37
36
  payload += "This is an automated email generated by the Uc3DmpCore.Notifier gem.\n /
38
37
  Please do not reply to this message."
38
+ payload
39
39
  end
40
40
  end
41
41
  end
@@ -8,7 +8,8 @@ module Uc3DmpApiCore
8
8
  MAXIMUM_PER_PAGE = 250
9
9
 
10
10
  class << self
11
- def paginate(params: {}, results:)
11
+ # rubocop:disable Metrics/AbcSize
12
+ def paginate(results:, params: {})
12
13
  return results unless results.is_a?(Array) && results.any? && params.is_a?(Hash)
13
14
 
14
15
  current = _current_page(item_count: results.length, params: params)
@@ -17,18 +18,16 @@ module Uc3DmpApiCore
17
18
 
18
19
  # Calculate the offset and extract those results
19
20
  offset = current[:page] == 1 ? 0 : (current[:page] - 1) * current[:per_page]
20
- results[offset,current[:per_page]]
21
+ results[offset, current[:per_page]]
21
22
  end
23
+ # rubocop:enable Metrics/AbcSize
22
24
 
23
25
  # Construct the pagination meta information that will be included in the response
26
+ # rubocop:disable Metrics/AbcSize
24
27
  def pagination_meta(url:, item_count: 0, params: {})
25
28
  prms = _current_page(item_count: item_count, params: params)
26
29
 
27
- hash = {
28
- page: prms[:page],
29
- per_page: prms[:per_page],
30
- total_items: item_count
31
- }
30
+ hash = { page: prms[:page], per_page: prms[:per_page], total_items: item_count }
32
31
  return hash if prms[:total_pages] == 1 || item_count <= prms[:per_page]
33
32
 
34
33
  prv = prms[:page] - 1
@@ -41,6 +40,7 @@ module Uc3DmpApiCore
41
40
  hash[:last] = _build_link(url: url, target_page: last, per_page: prms[:per_page]) if prms[:page] < last
42
41
  hash.compact
43
42
  end
43
+ # rubocop:enable Metrics/AbcSize
44
44
 
45
45
  private
46
46
 
@@ -24,8 +24,7 @@ module Uc3DmpApiCore
24
24
  #
25
25
  # Returns a hash that is a valid Lambda API response
26
26
  # --------------------------------------------------------------------------------
27
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
28
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
27
+ # rubocop:disable Metrics/AbcSize
29
28
  def respond(status: DEFAULT_STATUS_CODE, items: [], errors: [], **args)
30
29
  url = _url_from_event(event: args[:event]) || SsmReader.get_ssm_value(key: 'api_base_url')
31
30
  return _standard_error(url: url) if url.nil?
@@ -45,7 +44,7 @@ module Uc3DmpApiCore
45
44
  body = body.merge(Paginator.pagination_meta(url: url, item_count: item_count, params: args))
46
45
 
47
46
  # If this is a server error, then notify the administrator!
48
- log_error(source: url, message: errors, details: body, event: args[:event]) if status.to_s[0] == '5'
47
+ Logger.log_error(source: url, message: errors, details: body, event: args[:event]) if status.to_s[0] == '5'
49
48
 
50
49
  { statusCode: status.to_i, body: body.compact.to_json, headers: headers }
51
50
  rescue StandardError => e
@@ -53,8 +52,7 @@ module Uc3DmpApiCore
53
52
  puts " - STACK: #{e.backtrace}"
54
53
  _standard_error(url: url)
55
54
  end
56
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
57
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
55
+ # rubocop:enable Metrics/AbcSize
58
56
 
59
57
  private
60
58
 
@@ -85,9 +83,9 @@ module Uc3DmpApiCore
85
83
  return {} if ENV['CORS_ORIGIN'].nil?
86
84
 
87
85
  {
88
- 'Access-Control-Allow-Headers': ENV['CORS_HEADERS'],
89
- 'Access-Control-Allow-Origin': ENV['CORS_ORIGIN'],
90
- 'Access-Control-Allow-Methods': ENV['CORS_METHODS']
86
+ 'Access-Control-Allow-Headers': ENV.fetch('CORS_HEADERS', nil),
87
+ 'Access-Control-Allow-Origin': ENV.fetch('CORS_ORIGIN', nil),
88
+ 'Access-Control-Allow-Methods': ENV.fetch('CORS_METHODS', nil)
91
89
  }
92
90
  end
93
91
  end
@@ -21,10 +21,9 @@ module Uc3DmpApiCore
21
21
  # ----------------------------------------------------
22
22
  # rubocop:disable Metrics/AbcSize
23
23
  def get_ssm_value(key:, provenance_name: nil)
24
- full_key = _ssm_keys[:"#{key.downcase.to_s}"] unless key.nil?
24
+ full_key = _ssm_keys[:"#{key.downcase}"] unless key.nil?
25
25
  return nil if full_key.nil?
26
26
 
27
-
28
27
  key_vals = { env: ENV.fetch('LAMBDA_ENV', 'dev').to_s.downcase }
29
28
  # Swap in the provenance name if applicable
30
29
  key_vals[:provenance] = provenance_name unless provenance_name.nil? ||
@@ -54,6 +53,7 @@ module Uc3DmpApiCore
54
53
 
55
54
  # DMPTool/DMPHub SSM keys. See the installation guide for information about how these values are used
56
55
  # https://github.com/CDLUC3/dmp-hub-cfn/wiki/installation-and-setup#required-ssm-parameters
56
+ # rubocop:disable Metrics/MethodLength
57
57
  def _ssm_keys
58
58
  {
59
59
  administrator_email: '/uc3/dmp/hub/%{env}/AdminEmail',
@@ -82,6 +82,7 @@ module Uc3DmpApiCore
82
82
  dynamo_table_name: '/uc3/dmp/hub/%{env}/DynamoTableName'
83
83
  }
84
84
  end
85
+ # rubocop:enable Metrics/MethodLength
85
86
  end
86
87
  end
87
88
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpApiCore
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
  end
@@ -1,3 +1,4 @@
1
+ # rubocop:disable Naming/FileName
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require 'aws-sdk-sns'
@@ -16,3 +17,4 @@ module Uc3DmpApiCore
16
17
  MSG_INVALID_ARGS = 'Invalid arguments.' # For HTTP 400 (Bad request)
17
18
  MSG_SERVER_ERROR = 'Unable to process your request at this time.' # For HTTP 500 (Server error)
18
19
  end
20
+ # rubocop:enable Naming/FileName
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.6
4
+ version: 0.0.7
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-01 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -100,14 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.88.0
103
+ version: 1.50.2
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.88.0
110
+ version: 1.50.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.20.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 2.20.0
111
125
  description: Helpers for SSM, EventBridge, standardizing responses/errors
112
126
  email:
113
127
  - brian.riley@ucop.edu
@@ -126,7 +140,8 @@ files:
126
140
  homepage: https://github.com/CDLUC3/dmp-hub-cfn/blob/main/src/sam/gems/uc3-dmp-api-core
127
141
  licenses:
128
142
  - MIT
129
- metadata: {}
143
+ metadata:
144
+ rubygems_mfa_required: 'false'
130
145
  post_install_message:
131
146
  rdoc_options: []
132
147
  require_paths: