Class: Cumulus::S3::ReplicationConfig
- Inherits:
-
Object
- Object
- Cumulus::S3::ReplicationConfig
- Defined in:
- lib/s3/models/ReplicationConfig.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#iam_role ⇒ Object
readonly
Returns the value of attribute iam_role.
-
#prefixes ⇒ Object
readonly
Returns the value of attribute prefixes.
Instance Method Summary collapse
-
#!=(other) ⇒ Object
Public: Check if this ReplicationConfig is not equal to the other object.
-
#==(other) ⇒ Object
Public: Check ReplicationConfig 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) ⇒ ReplicationConfig
constructor
Public: Constructor.
-
#populate!(aws) ⇒ Object
Public: Populate this ReplicationConfig with the values in an AWS replication configuration.
-
#to_aws ⇒ Object
Public: Produce an AWS hash representing this ReplicationConfig.
-
#to_h ⇒ Object
Public: Converts this ReplicationConfig to a hash that matches Cumulus configuration.
Constructor Details
#initialize(json = nil) ⇒ ReplicationConfig
Public: Constructor
json - a hash representing the JSON configuration. Expects to be passed the “replication” node of S3 bucket configuration.
16 17 18 19 20 21 22 |
# File 'lib/s3/models/ReplicationConfig.rb', line 16 def initialize(json = nil) if json @destination = json["destination"] @iam_role = json["iam-role"] @prefixes = json["prefixes"] || [] end end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
8 9 10 |
# File 'lib/s3/models/ReplicationConfig.rb', line 8 def destination @destination end |
#iam_role ⇒ Object (readonly)
Returns the value of attribute iam_role.
9 10 11 |
# File 'lib/s3/models/ReplicationConfig.rb', line 9 def iam_role @iam_role end |
#prefixes ⇒ Object (readonly)
Returns the value of attribute prefixes.
10 11 12 |
# File 'lib/s3/models/ReplicationConfig.rb', line 10 def prefixes @prefixes end |
Instance Method Details
#!=(other) ⇒ Object
Public: Check if this ReplicationConfig is not equal to the other object
other - the other object to check
Returns whether this ReplicationConfig is not equal to ‘other`
128 129 130 |
# File 'lib/s3/models/ReplicationConfig.rb', line 128 def !=(other) !(self == other) end |
#==(other) ⇒ Object
Public: Check ReplicationConfig equality with other objects.
other - the other object to check
Returns whether this ReplicationConfig is equal to ‘other`
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/s3/models/ReplicationConfig.rb', line 112 def ==(other) if !other.is_a? ReplicationConfig or @destination != other.destination or @iam_role != other.iam_role or @prefixes.sort != other.prefix.sort 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 ReplicationDiff that were found
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/s3/models/ReplicationConfig.rb', line 76 def diff(aws) diffs = [] if @destination != aws.destination diffs << ReplicationDiff.new(ReplicationChange::DESTINATION, aws, self) end if @iam_role != aws.iam_role diffs << ReplicationDiff.new(ReplicationChange::ROLE, aws, self) end if @prefixes.sort != aws.prefixes diffs << ReplicationDiff.new(ReplicationChange::PREFIX, aws, self) end diffs end |
#populate!(aws) ⇒ Object
Public: Populate this ReplicationConfig with the values in an AWS replication configuration.
aws - the aws object to populate from
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/s3/models/ReplicationConfig.rb', line 96 def populate!(aws) @destination = aws.rules[0].destination.bucket @destination = @destination[(@destination.rindex(":") + 1)..-1] @iam_role = aws.role[(aws.role.rindex("/") + 1)..-1] @prefixes = aws.rules.map(&:prefix) if @prefixes.size == 1 and @prefixes[0] == "" @prefixes = [] end end |
#to_aws ⇒ Object
Public: Produce an AWS hash representing this ReplicationConfig
Returns the hash
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/s3/models/ReplicationConfig.rb', line 27 def to_aws role_arn = IAM.get_role_arn(@iam_role) if role_arn.nil? puts Colors.red("No IAM role named #{name}") exit end { role: role_arn, rules: if @prefixes.empty? [{ prefix: "", status: "Enabled", destination: { bucket: "arn:aws:s3:::#{@destination}" } }] else @prefixes.map do |prefix| { prefix: prefix, status: "Enabled", destination: { bucket: "arn:aws:s3:::#{@destination}" } } end end } end |
#to_h ⇒ Object
Public: Converts this ReplicationConfig to a hash that matches Cumulus configuration.
Returns the hash
62 63 64 65 66 67 68 |
# File 'lib/s3/models/ReplicationConfig.rb', line 62 def to_h { "iam-role" => @iam_role, "prefixes" => if !@prefixes.empty? then @prefixes end, "destination" => @destination, }.reject { |k, v| v.nil? } end |