Class: S3Antivirus::Notifier

Inherits:
Object
  • Object
show all
Includes:
AwsServices, Conf
Defined in:
lib/s3_antivirus/notifier.rb

Instance Method Summary collapse

Methods included from Conf

#conf

Methods included from AwsServices

#s3, #sns

Constructor Details

#initialize(s3_record) ⇒ Notifier

Returns a new instance of Notifier.



6
7
8
9
# File 'lib/s3_antivirus/notifier.rb', line 6

def initialize(s3_record)
  @s3_record = s3_record
  @bucket, @key, @version = s3_record.bucket, s3_record.key, s3_record.version
end

Instance Method Details

#notify(status:, action:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/s3_antivirus/notifier.rb', line 11

def notify(status:, action:)
  data = {
    action: action,
    bucket: @bucket,
    key: @key,
    status: status,
  }
  data[:version] = @version if @version
  message_attributes = data.inject({}) do |result, (k,v)|
    result.merge(
      k => {
        data_type: "String",
        string_value: v
      }
    )
  end
  sns.publish(
    topic_arn: conf['topic'],
    message: "#{@s3_record.human_key} is #{status}, #{action} action executed",
    subject: "s3-antivirus s3://#{@bucket}",
    message_attributes: message_attributes
  )
end