uc3-dmp-api-core 0.0.17 → 0.0.19

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: efebb403fd0b700fb57385c2b63e66cb0aec9530b3f6b08bf3dd85dd2417aef7
4
- data.tar.gz: 93ab1915f7db8882f065b53fc8e1616228c9b1b3d345ce68df82e26c3ad6dcf8
3
+ metadata.gz: 5ce7df10e928100fae5b672089be84d873cf758ecac695c9c571abb0ab02a407
4
+ data.tar.gz: 93dc08eb6b46eefbe86c236edcd273679eadffad2e7283f59016d2ffbbc25ee6
5
5
  SHA512:
6
- metadata.gz: bff15a217476c17d0dfd3985b8462b2a8ada6956ff697f8de7a574faf55a441f3cd3e9c58cdd802a902630e76cd6d24e3e80f3d6afa076049f8472ab6bce758a
7
- data.tar.gz: 928f0bb01da885343052564b4f1bb45b483c34d7a3bc49ec88b5d5f2f5947577634beab236937802aed17f49f91d0ed9c6fcfe46f47203b11c9c6389eb372294
6
+ metadata.gz: 3f312834841be19dd00700c2be8b9627f8c68321a8264733af87a87bec0e2863b857591c51e5489a26aabdbfbf236213d79511ac1d3294c87abf28d4876655de
7
+ data.tar.gz: 15c9bd557334bbaf9338ec1e2fd2904522f728d30ffeac6a2c6d498fce5620ce22fc92ebb11eac2e9e8b3e620d4632ff898f973c02be5a1d66c14aefd1be8159
@@ -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,48 +20,30 @@ 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
-
26
- puts "FULL KEY: #{full_key}"
27
-
25
+ logger.debug(message: "Looking for SSM Key: #{full_key}")
28
26
  return nil if full_key.nil?
29
27
 
30
28
  key_vals = { env: ENV.fetch('LAMBDA_ENV', 'dev').to_s.downcase }
31
29
  # Swap in the provenance name if applicable
32
30
  key_vals[:provenance] = provenance_name unless provenance_name.nil? ||
33
31
  !full_key.include?('%{provenance}')
34
-
35
- puts "KEY VALS: #{key_vals}"
36
-
37
- fetch_value(key: format(full_key, key_vals))
32
+ fetch_value(key: format(full_key, key_vals, logger: logger))
38
33
  rescue Aws::Errors::ServiceError => e
39
- LogWriter.log_error(
40
- source: "#{SOURCE} - looking for #{key}", message: e.message, details: e.backtrace
41
- )
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?
42
36
  nil
43
37
  end
44
38
  # rubocop:enable Metrics/AbcSize
45
39
 
46
40
  # Call SSM to get the value for the specified key
47
- def fetch_value(key:)
41
+ def fetch_value(key:, logger: nil)
48
42
  resp = Aws::SSM::Client.new.get_parameter(name: key, with_decryption: true)
49
-
50
- puts "FETCHING `#{key}` -- GOT: #{resp.inspect}"
51
-
43
+ logger.debug(message: "Searching for SSM Key: #{key}, Found: '#{resp&.parameter&.value}'") unless logger.nil?
52
44
  resp.nil? || resp.parameter.nil? ? nil : resp.parameter.value
53
45
  end
54
46
 
55
- # Checks to see if debug mode has been enabled in SSM
56
- # ----------------------------------------------------
57
- def debug_mode?
58
-
59
- puts "Checking to see if we are in debug mode."
60
- 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} "
61
-
62
- get_ssm_value(key: _ssm_keys[:debug_mode])&.to_s&.downcase&.strip == 'true'
63
- end
64
-
65
47
  private
66
48
 
67
49
  # DMPTool/DMPHub SSM keys. See the installation guide for information about how these values are used
@@ -72,7 +54,6 @@ puts "Key: #{_ssm_keys[:debug_mode]}, Val: #{get_ssm_value(key: _ssm_keys[:debug
72
54
  administrator_email: '/uc3/dmp/hub/%{env}/AdminEmail',
73
55
  api_base_url: '/uc3/dmp/hub/%{env}/ApiBaseUrl',
74
56
  base_url: '/uc3/dmp/hub/%{env}/BaseUrl',
75
- debug_mode: '/uc3/dmp/hub/%{env}/Debug',
76
57
 
77
58
  dmp_id_api_url: '/uc3/dmp/hub/%{env}/EzidApiUrl',
78
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.17'
4
+ VERSION = '0.0.19'
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.17
4
+ version: 0.0.19
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