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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e813edb9e46e1f1c6e7af77819d0f5ac1b313b99b0ba0c4d26bb729ba749068
4
- data.tar.gz: 1fc81b2cfb959e294c46a42abdf11c2c92f1bd6615da4b98de9f9361ad322090
3
+ metadata.gz: edd02ecf392d417845a391ba9d92361f4a26aedce5826026f752c77bc59e7048
4
+ data.tar.gz: c37b4ee80bbfb56bf62a00374bb98b6a947ea255748b21172ee11cfc05daa1d5
5
5
  SHA512:
6
- metadata.gz: 490b1703c07468e6d331d83dd0d37013a9ee2d8645cc2ff47686230d02fe2f80c6f74828cfa149f762069ae6a5152553fe45d6e93959fc6ffd88e9f5431485e3
7
- data.tar.gz: b22cdc6f22d90019eec62d3ff9abaf6b734cd5ef6c89d55a3f0bc3777e3cf09b716f1f0a35884c1b771078d1d07cb83885ef1780f7fe55b20ce1c8f9da1abcba
6
+ metadata.gz: edcd2c741c2561b935b77002700434bfb2d46fa1d4948da21798b19023916d7e67940471062640ef3438bf25ebaceef6f640a63a7ac5f4abada69597140e0db3
7
+ data.tar.gz: a3d9fdf8ee0655e7d3925b5635b23a02849c95d7e37a3d9fdcb2fc7f5c1b7f937d72285de99af271889e268e085e30ae1135f3042238c1d24fb1b2db3cce852e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- addy_lambda (0.1.2)
4
+ addy_lambda (0.1.4)
5
5
  aws-sdk-lambda
6
6
  aws-sdk-s3
7
7
  aws-sdk-sns
@@ -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
- # Lambda client can be obtained by running: lambda_client = Aws::Lambda::Client.new
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' => 'Signature Request',
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,
@@ -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
- body_as_object = JSON.parse(event['body'])
18
+ JSON.parse(event['body'])
20
19
  elsif event.key?('body')
21
- body_as_object = event['body']
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
@@ -1,3 +1,3 @@
1
1
  module AddyLambda
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
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.3
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-12 00:00:00.000000000 Z
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