uc3-dmp-api-core 0.0.16 → 0.0.18

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: ed9b757e777dcc7b4f9f7376301bb9862a72225e656b64330f8f7339f6b9da25
4
- data.tar.gz: 2f015eb315d4e025dc7083b650613bee20060ce97b5c4d0d9466d624333f6f6f
3
+ metadata.gz: ecd9ce7aa91e92f0bc0497c413d90dabceeb90e0038f3625d95da02551cdb6b3
4
+ data.tar.gz: 81a93bfd340caf3cc9b03765d822465eb7b82565f9e31e5c4b56414fa09c9060
5
5
  SHA512:
6
- metadata.gz: 9f8dd989a5057d25ebc7f9cc662aa813927986814147440350eb6409278055c113cb8cb7ca9995917ed23ddc699cbbcaef25d541567c2f96fadc7e66ddc8a750
7
- data.tar.gz: 64abd3e9580f36a92d2d917398caf2f6914c43a2618c10d0198b89ecb96e404bc2842d39df26cd68ecd61f4f349a157e7cfe7b0fc252488e2c27d5a2c3ea889e
6
+ metadata.gz: 1be8abaad5987e0bce3925cf55f1e3faf3770322d5539a5f48129b2cc0a93f22818224e0cb07828b17ff13e7129fe567c3b7b6f6e19f91967f0920778e1d792a
7
+ data.tar.gz: 0f89e11e6058b8315829d86adac3fd3d3d8956bb567fbea3ae75f930d5e72d1c50bfb842e18cca43ce13ca881c7a07271f0c80ad7f2e5e101b4e6d9675a48752
@@ -25,7 +25,7 @@ module Uc3DmpApiCore
25
25
  # Returns a hash that is a valid Lambda API response
26
26
  # --------------------------------------------------------------------------------
27
27
  # rubocop:disable Metrics/AbcSize
28
- def respond(status: DEFAULT_STATUS_CODE, items: [], errors: [], **args)
28
+ def respond(status: DEFAULT_STATUS_CODE, logger: nil, items: [], errors: [], **args)
29
29
  url = _url_from_event(event: args[:event]) || SsmReader.get_ssm_value(key: 'api_base_url')
30
30
  return _standard_error(url: url) if url.nil?
31
31
 
@@ -44,7 +44,10 @@ module Uc3DmpApiCore
44
44
  body = body.merge(Paginator.pagination_meta(url: url, item_count: item_count, params: args))
45
45
 
46
46
  # If this is a server error, then notify the administrator!
47
- LogWriter.log_error(source: url, message: errors, details: body, event: args[:event]) if status.to_s[0] == '5'
47
+ if status.to_s[0] == '5' && !logger.nil?
48
+ logger.error(message: errors, details: body)
49
+ Notifier.notify_administrator(source: logger.source, details: body, event: logger.event)
50
+ end
48
51
 
49
52
  { statusCode: status.to_i, body: body.compact.to_json, headers: headers }
50
53
  rescue StandardError => e
@@ -9,7 +9,7 @@ module Uc3DmpApiCore
9
9
  # Shared helper methods for accessing SSM parameters
10
10
  # ----------------------------------------------------
11
11
  class SsmReader
12
- SOURCE = 'SsmReader gem'
12
+ SOURCE = 'Uc3DmpApiCore::SsmReader'
13
13
 
14
14
  class << self
15
15
  # Return all of the available keys
@@ -20,8 +20,9 @@ module Uc3DmpApiCore
20
20
  # Fetch the value for the specified :key
21
21
  # ----------------------------------------------------
22
22
  # rubocop:disable Metrics/AbcSize
23
- def get_ssm_value(key:, provenance_name: nil)
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}")
25
26
  return nil if full_key.nil?
26
27
 
27
28
  key_vals = { env: ENV.fetch('LAMBDA_ENV', 'dev').to_s.downcase }
@@ -30,29 +31,19 @@ module Uc3DmpApiCore
30
31
  !full_key.include?('%{provenance}')
31
32
  fetch_value(key: format(full_key, key_vals))
32
33
  rescue Aws::Errors::ServiceError => e
33
- LogWriter.log_error(
34
- source: "#{SOURCE} - looking for #{key}", message: e.message, details: e.backtrace
35
- )
34
+ puts "Fatal error in #{SOURCE} - #{e.message}" if logger.nil?
35
+ logger.error(message: "Looking for SSM Key: #{key} - #{e.message}", details: e.backtrace) unless logger.nil?
36
36
  nil
37
37
  end
38
38
  # rubocop:enable Metrics/AbcSize
39
39
 
40
40
  # Call SSM to get the value for the specified key
41
- def fetch_value(key:)
41
+ def fetch_value(key:, logger:)
42
42
  resp = Aws::SSM::Client.new.get_parameter(name: key, with_decryption: true)
43
+ logger.debug(message: "Searching for SSM Key: #{key}, Found: '#{resp&.parameter&.value}'")
43
44
  resp.nil? || resp.parameter.nil? ? nil : resp.parameter.value
44
45
  end
45
46
 
46
- # Checks to see if debug mode has been enabled in SSM
47
- # ----------------------------------------------------
48
- def debug_mode?
49
-
50
- puts "Checking to see if we are in debug mode."
51
- puts "Key: #{_ssm_keys[:debug_mode]}, Val: #{get_ssm_value(key: _ssm_keys[:debug_mode])}, Downcased: #{get_ssm_value(key: _ssm_keys[:debug_mode])&.to_s&.downcase&.strip} "
52
-
53
- get_ssm_value(key: _ssm_keys[:debug_mode])&.to_s&.downcase&.strip == 'true'
54
- end
55
-
56
47
  private
57
48
 
58
49
  # DMPTool/DMPHub SSM keys. See the installation guide for information about how these values are used
@@ -63,7 +54,6 @@ puts "Key: #{_ssm_keys[:debug_mode]}, Val: #{get_ssm_value(key: _ssm_keys[:debug
63
54
  administrator_email: '/uc3/dmp/hub/%{env}/AdminEmail',
64
55
  api_base_url: '/uc3/dmp/hub/%{env}/ApiBaseUrl',
65
56
  base_url: '/uc3/dmp/hub/%{env}/BaseUrl',
66
- debug_mode: '/uc3/dmp/hub/%{env}/Debug',
67
57
 
68
58
  dmp_id_api_url: '/uc3/dmp/hub/%{env}/EzidApiUrl',
69
59
  dmp_id_base_url: '/uc3/dmp/hub/%{env}/EzidBaseUrl',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpApiCore
4
- VERSION = '0.0.16'
4
+ VERSION = '0.0.18'
5
5
  end
@@ -4,7 +4,6 @@
4
4
  require 'aws-sdk-sns'
5
5
  require 'aws-sdk-ssm'
6
6
 
7
- require 'uc3-dmp-api-core/log_writer'
8
7
  require 'uc3-dmp-api-core/notifier'
9
8
  require 'uc3-dmp-api-core/paginator'
10
9
  require 'uc3-dmp-api-core/responder'
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.16
4
+ version: 0.0.18
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-07-03 00:00:00.000000000 Z
11
+ date: 2023-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -131,7 +131,6 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - README.md
133
133
  - lib/uc3-dmp-api-core.rb
134
- - lib/uc3-dmp-api-core/log_writer.rb
135
134
  - lib/uc3-dmp-api-core/notifier.rb
136
135
  - lib/uc3-dmp-api-core/paginator.rb
137
136
  - lib/uc3-dmp-api-core/responder.rb
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Uc3DmpApiCore
4
- # Standardized ways for logging messages and errors to CloudWatch
5
- #
6
- # Methods expect the following inputs:
7
- # - source: the name of the Lambda function or Layer file
8
- # - message: the error message as a String or Array of Strings
9
- # - details: any additional context as a Hash
10
- # - event: the Lambda event if available
11
- #
12
- # --------------------------------------------------------------------------------
13
- class LogWriter
14
- class << self
15
- # rubocop:disable Metrics/AbcSize
16
- def log_error(source:, message:, details: {}, event: {})
17
- return false if source.nil? || message.nil?
18
-
19
- message = message.join(', ') if message.is_a?(Array)
20
- # Is there a better way here than just 'print'? This ends up in the CloudWatch logs
21
- puts "ERROR: #{source} - #{message}"
22
- puts " - DETAILS: #{details.to_json}" if details.is_a?(Hash) && details.keys.any?
23
- puts " - EVENT: #{event.to_json}" if event.is_a?(Hash) && event.keys.any?
24
-
25
- Notifier.notify_administrator(source: source, details: details, event: event)
26
- end
27
- # rubocop:enable Metrics/AbcSize
28
-
29
- def log_message(source:, message:, details: {}, event: {})
30
- return false if source.nil? || message.nil?
31
-
32
- message = message.join(', ') if message.is_a?(Array)
33
-
34
- # Is there a better way here than just 'print'? This ends up in the CloudWatch logs
35
- puts "INFO: #{source} - #{message}"
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?
38
- true
39
- end
40
- end
41
- end
42
- end