addy_lambda 0.1.4 → 0.1.5

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: edd02ecf392d417845a391ba9d92361f4a26aedce5826026f752c77bc59e7048
4
- data.tar.gz: c37b4ee80bbfb56bf62a00374bb98b6a947ea255748b21172ee11cfc05daa1d5
3
+ metadata.gz: ef00289a5bbb4b7cbb3b1e0ade183cb278e2d861d580c4586843914fcffafcb2
4
+ data.tar.gz: 52570679a38387934ece6b92eb052df4590d9e73b9bc09a7066d394ab29f3dd1
5
5
  SHA512:
6
- metadata.gz: edcd2c741c2561b935b77002700434bfb2d46fa1d4948da21798b19023916d7e67940471062640ef3438bf25ebaceef6f640a63a7ac5f4abada69597140e0db3
7
- data.tar.gz: a3d9fdf8ee0655e7d3925b5635b23a02849c95d7e37a3d9fdcb2fc7f5c1b7f937d72285de99af271889e268e085e30ae1135f3042238c1d24fb1b2db3cce852e
6
+ metadata.gz: 1e79f003be7d217fc5269fb81e9b8f42fb46be0ad2f31e9055f0e5783c3cb52116807c9814f7099d423c6e3d4b78e18ad825b7749e443bfa45ea5673226b6057
7
+ data.tar.gz: ab3823f1353aa845d608c870d169cc77241916d2fb37f595e2efede41d78be04411085168a7041246880af9d43e0214259a5b8ccd873e89c1e3febc7a487518a
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'logger'
2
3
 
3
4
  module AddyLambda
4
5
  # Generic methods such as logging, error handling HTTP requests etc.
@@ -6,11 +7,54 @@ module AddyLambda
6
7
  VARIABLE_DIRECT = 'direct'.freeze
7
8
  VARIABLE_QUERYSTRING = 'querystring'.freeze
8
9
 
9
- def self.generic_log(logger, event, context)
10
+ def self.generic_log(logger, event, context, safe_to_log_override = {})
11
+ # Dictionary to allow certain keys to be logged
12
+ # safe_to_log["key"] = True
13
+
14
+ safe_to_log = {}
15
+
16
+ # Override the dictionar (add or change allowed items)
17
+ safe_to_log.update(safe_to_log_override)
18
+
19
+ # logger.info('## ENVIRONMENT VARIABLES\r' +
20
+ # jsonpickle.encode(dict(**os.environ)))
21
+ #
22
+ # logger = self.logger
23
+ logged_event = recoursive_clean(event, nil, safe_to_log)
10
24
  logger.debug('## EVENT')
11
- logger.debug(event.inspect)
25
+ logger.debug(logged_event.to_json)
12
26
  logger.debug('## CONTEXT')
13
- logger.debug(context.inspect)
27
+ logger.debug(context.inspect.to_json)
28
+ # logger.info("## EVENT\r#{logged_event.to_json}")
29
+ # logger.info("## CONTEXT\r#{context.to_json}")
30
+ end
31
+
32
+ def self.recoursive_clean(obj, key, safe_to_log)
33
+ if obj.is_a?(Hash)
34
+ # Recoursively run for dictionary objects
35
+ # return {k: recoursive_clean(v, k, safe_to_log) for k, v in obj.items()}
36
+ obj.map { |k, v| { k => recoursive_clean(v, k, safe_to_log) } }
37
+ elsif obj.is_a?(Array)
38
+ # Recoursively run for arrays
39
+ # return [recoursive_clean(v, None, safe_to_log) for v in obj]
40
+ obj.map { |v| [recoursive_clean(v, key, safe_to_log)] }
41
+ elsif !!safe_to_log[key] || (key.to_s.strip.downcase.end_with?('id') && !safe_to_log.key?(key))
42
+ # If the key is safe to log, and is specified as True, or if it's not specified but ends with "id"
43
+ obj
44
+ elsif !obj.nil? && (!!obj == obj || obj.is_a?(String) && %w[yes no].include?(obj.strip.downcase))
45
+ # If it's "yes" / "no" or a boolean, it's safe to log.
46
+ obj
47
+ elsif obj.nil?
48
+ # Null can be logged
49
+ nil
50
+ elsif obj.is_a?(String) && obj.strip.empty?
51
+ # An empty string can be logged
52
+ ''
53
+ else
54
+ # Anything else becomes a "?"
55
+ # Note: This means that a number will become a "?" string.
56
+ '?'
57
+ end
14
58
  end
15
59
 
16
60
  def self.get_body_as_object(event)
@@ -1,3 +1,3 @@
1
1
  module AddyLambda
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addy_lambda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alon Sabi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-18 00:00:00.000000000 Z
11
+ date: 2022-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-lambda