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 +4 -4
- data/lib/addy_lambda/common.rb +47 -3
- data/lib/addy_lambda/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef00289a5bbb4b7cbb3b1e0ade183cb278e2d861d580c4586843914fcffafcb2
|
4
|
+
data.tar.gz: 52570679a38387934ece6b92eb052df4590d9e73b9bc09a7066d394ab29f3dd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e79f003be7d217fc5269fb81e9b8f42fb46be0ad2f31e9055f0e5783c3cb52116807c9814f7099d423c6e3d4b78e18ad825b7749e443bfa45ea5673226b6057
|
7
|
+
data.tar.gz: ab3823f1353aa845d608c870d169cc77241916d2fb37f595e2efede41d78be04411085168a7041246880af9d43e0214259a5b8ccd873e89c1e3febc7a487518a
|
data/lib/addy_lambda/common.rb
CHANGED
@@ -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(
|
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)
|
data/lib/addy_lambda/version.rb
CHANGED
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
|
+
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-
|
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
|