addy_lambda 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/addy_lambda/aws.rb +21 -3
- data/lib/addy_lambda/common.rb +7 -6
- 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: edd02ecf392d417845a391ba9d92361f4a26aedce5826026f752c77bc59e7048
|
4
|
+
data.tar.gz: c37b4ee80bbfb56bf62a00374bb98b6a947ea255748b21172ee11cfc05daa1d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edcd2c741c2561b935b77002700434bfb2d46fa1d4948da21798b19023916d7e67940471062640ef3438bf25ebaceef6f640a63a7ac5f4abada69597140e0db3
|
7
|
+
data.tar.gz: a3d9fdf8ee0655e7d3925b5635b23a02849c95d7e37a3d9fdcb2fc7f5c1b7f937d72285de99af271889e268e085e30ae1135f3042238c1d24fb1b2db3cce852e
|
data/Gemfile.lock
CHANGED
data/lib/addy_lambda/aws.rb
CHANGED
@@ -27,6 +27,7 @@ module AddyLambda
|
|
27
27
|
response.parameter.value
|
28
28
|
end
|
29
29
|
|
30
|
+
# lambda_client = Aws::Lambda::Client.new
|
30
31
|
def self.invoke_lambda(lambda_client, function_name, payload, syncronous: true)
|
31
32
|
resp = lambda_client.invoke({
|
32
33
|
function_name: function_name,
|
@@ -36,10 +37,10 @@ module AddyLambda
|
|
36
37
|
AddyLambda::Common.valid_json?(resp.payload.string) ? JSON.parse(resp.payload.string) : resp.payload.string
|
37
38
|
end
|
38
39
|
|
39
|
-
#
|
40
|
-
def self.post_slack_message(lambda_client, channel, message, emoji = ':tada', unfurl_links: false)
|
40
|
+
# lambda_client = Aws::Lambda::Client.new
|
41
|
+
def self.post_slack_message(lambda_client, post_as_name, channel, message, emoji = ':tada', unfurl_links: false)
|
41
42
|
input_params = {
|
42
|
-
'user' =>
|
43
|
+
'user' => post_as_name,
|
43
44
|
'channel' => channel,
|
44
45
|
'message' => message,
|
45
46
|
'emoji' => emoji,
|
@@ -51,6 +52,22 @@ module AddyLambda
|
|
51
52
|
logger.error(response_body['error'])
|
52
53
|
end
|
53
54
|
|
55
|
+
# s3_client = Aws::S3::Client.new
|
56
|
+
def self.copy_file_from_bucket_to_bucket(s3_client, src_bucket, src_key, dest_bucket, dest_key)
|
57
|
+
s3_client.copy_object(bucket: dest_bucket, copy_source: "/#{src_bucket}/#{src_key}", key: dest_key)
|
58
|
+
end
|
59
|
+
|
60
|
+
# s3_client = Aws::S3::Client.new
|
61
|
+
def self.list_s3_files(s3_client, bucket, prefix, suffix)
|
62
|
+
files = []
|
63
|
+
objects = s3_client.list_objects_v2({ bucket: bucket, prefix: prefix }).contents
|
64
|
+
objects.each do |o|
|
65
|
+
key = o[:key]
|
66
|
+
files << key if key.start_with?(prefix) && key.end_with?(suffix)
|
67
|
+
end
|
68
|
+
files
|
69
|
+
end
|
70
|
+
|
54
71
|
# s3_client = Aws::S3::Client.new
|
55
72
|
def self.copy_file_from_s3(s3_client, bucket, key, destination)
|
56
73
|
s3_client.get_object({ bucket: bucket, key: key }, target: destination)
|
@@ -64,6 +81,7 @@ module AddyLambda
|
|
64
81
|
end
|
65
82
|
end
|
66
83
|
|
84
|
+
# lambda_client = Aws::Lambda::Client.new
|
67
85
|
def self.send_email(lambda_client, recipient_emails, from_name, from_email, subject, content_html)
|
68
86
|
input_params = {
|
69
87
|
'recipient_list' => recipient_emails,
|
data/lib/addy_lambda/common.rb
CHANGED
@@ -4,6 +4,7 @@ module AddyLambda
|
|
4
4
|
# Generic methods such as logging, error handling HTTP requests etc.
|
5
5
|
class Common
|
6
6
|
VARIABLE_DIRECT = 'direct'.freeze
|
7
|
+
VARIABLE_QUERYSTRING = 'querystring'.freeze
|
7
8
|
|
8
9
|
def self.generic_log(logger, event, context)
|
9
10
|
logger.debug('## EVENT')
|
@@ -13,15 +14,13 @@ module AddyLambda
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.get_body_as_object(event)
|
16
|
-
body_as_object = {}
|
17
|
-
|
18
17
|
if event.key?('body') and event['body'].is_a? String
|
19
|
-
|
18
|
+
JSON.parse(event['body'])
|
20
19
|
elsif event.key?('body')
|
21
|
-
|
20
|
+
event['body']
|
21
|
+
else
|
22
|
+
event
|
22
23
|
end
|
23
|
-
|
24
|
-
body_as_object
|
25
24
|
end
|
26
25
|
|
27
26
|
def self.get_parameter(event, parameter, type, default_value = nil)
|
@@ -30,6 +29,8 @@ module AddyLambda
|
|
30
29
|
case type
|
31
30
|
when VARIABLE_DIRECT
|
32
31
|
event_body.fetch(parameter, default_value)
|
32
|
+
when VARIABLE_QUERYSTRING
|
33
|
+
event['queryStringParameters'].fetch(parameter, default_value)
|
33
34
|
else
|
34
35
|
default_value
|
35
36
|
end
|
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.4
|
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-
|
11
|
+
date: 2022-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-lambda
|