Class: Cumulus::S3::NotificationConfig
- Inherits:
-
Object
- Object
- Cumulus::S3::NotificationConfig
- Defined in:
- lib/s3/models/NotificationConfig.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#triggers ⇒ Object
readonly
Returns the value of attribute triggers.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#!=(other) ⇒ Object
Public: Check if this NotificationConfig is not equal to the other object.
-
#==(other) ⇒ Object
Public: Check NotificationConfig equality with other objects.
-
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS.
-
#initialize(json = nil) ⇒ NotificationConfig
constructor
Public: Constructor.
-
#populate!(aws) ⇒ Object
Public: Populate this NotificationConfig with the values in an AWS configuration of events.
-
#to_aws ⇒ Object
Public: Produce an AWS compatible hash for this NotificationConfig.
-
#to_h ⇒ Object
Public: Produce an AWS compatible hash for this NotificationConfig.
Constructor Details
#initialize(json = nil) ⇒ NotificationConfig
Public: Constructor
json - a hash representing the JSON configuration. Expects to be passed
an object from the "notifications" array of S3 bucket configuration.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/s3/models/NotificationConfig.rb', line 20 def initialize(json = nil) if json @name = json["name"] @prefix = json["prefix"] @suffix = json["suffix"] @target = json["target"] @triggers = (json["triggers"] || []).map { |t| "s3:#{t}" } @type = json["type"] end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/s3/models/NotificationConfig.rb', line 9 def name @name end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/s3/models/NotificationConfig.rb', line 10 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
11 12 13 |
# File 'lib/s3/models/NotificationConfig.rb', line 11 def suffix @suffix end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
12 13 14 |
# File 'lib/s3/models/NotificationConfig.rb', line 12 def target @target end |
#triggers ⇒ Object (readonly)
Returns the value of attribute triggers.
13 14 15 |
# File 'lib/s3/models/NotificationConfig.rb', line 13 def triggers @triggers end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/s3/models/NotificationConfig.rb', line 14 def type @type end |
Instance Method Details
#!=(other) ⇒ Object
Public: Check if this NotificationConfig is not equal to the other object
other - the other object to check
Returns whether this NotificationConfig is not equal to ‘other`
152 153 154 |
# File 'lib/s3/models/NotificationConfig.rb', line 152 def !=(other) !(self == other) end |
#==(other) ⇒ Object
Public: Check NotificationConfig equality with other objects.
other - the other object to check
Returns whether this NotificationConfig is equal to ‘other`
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/s3/models/NotificationConfig.rb', line 133 def ==(other) if !other.is_a? NotificationConfig or @name != other.name or @prefix != other.prefix or @suffix != other.suffix or @target != other.target or @triggers.sort != other.triggers.sort or @type != other.type false else true end end |
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS
aws - the AWS resource
Returns an array of the NotificationDiffs that were found
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/s3/models/NotificationConfig.rb', line 106 def diff(aws) diffs = [] if @prefix != aws.prefix diffs << NotificationDiff.new(NotificationChange::PREFIX, aws, self) end if @suffix != aws.suffix diffs << NotificationDiff.new(NotificationChange::SUFFIX, aws, self) end if @triggers.sort != aws.triggers.sort diffs << NotificationDiff.new(NotificationChange::TRIGGERS, aws, self) end if @type != aws.type diffs << NotificationDiff.new(NotificationChange::TYPE, aws, self) end if @target != aws.target diffs << NotificationDiff.new(NotificationChange::TARGET, aws, self) end diffs end |
#populate!(aws) ⇒ Object
Public: Populate this NotificationConfig with the values in an AWS configuration of events.
aws - the aws object to populate from
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/s3/models/NotificationConfig.rb', line 35 def populate!(aws) @name = aws.id @prefix = aws.filter.key.filter_rules.find { |r| r.name.downcase == "prefix" }.value rescue nil @suffix = aws.filter.key.filter_rules.find { |r| r.name.downcase == "suffix" }.value rescue nil @triggers = aws.events if aws.respond_to? "queue_arn" @type = "sqs" @target = aws.queue_arn[(aws.queue_arn.rindex(":") + 1)..-1] elsif aws.respond_to? "lambda_function_arn" @type = "lambda" @target = aws.lambda_function_arn[(aws.lambda_function_arn.rindex(":") + 1)..-1] else @type = "sns" @target = aws.topic_arn[(aws.topic_arn.rindex(":") + 1)..-1] end end |
#to_aws ⇒ Object
Public: Produce an AWS compatible hash for this NotificationConfig.
Returns the hash.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/s3/models/NotificationConfig.rb', line 55 def to_aws if @type == "sns" topic_arn = SNS.get_aws(@target) elsif @type == "sqs" queue_arn = SQS.get_arn(@target) elsif @type == "lambda" lambda_function_arn = Lambda.get_aws(@target).function_arn end { id: @name, events: @triggers, topic_arn: topic_arn, queue_arn: queue_arn, lambda_function_arn: lambda_function_arn, filter: { key: { filter_rules: [ if @prefix then { name: "prefix", value: @prefix } end, if @suffix then { name: "suffix", value: @suffix } end ].reject { |e| e.nil? } }.reject { |k, v| v.nil? or v.empty? } }.reject { |k, v| v.nil? or v.empty? } }.reject { |k, v| v.nil? or v.empty? } end |
#to_h ⇒ Object
Public: Produce an AWS compatible hash for this NotificationConfig.
Returns the hash
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/s3/models/NotificationConfig.rb', line 89 def to_h { name: @name, triggers: @triggers.map { |t| t[3..-1] }, # substring off the "s3:" prefix: @prefix, suffix: @suffix, type: @type, target: @target, }.reject { |k, v| v.nil? } end |