class Cumulus::S3::BucketDiff

Public: Represents a single difference between local configuration and AWS S3 bucket configuration

Attributes

default_encryption[RW]
grants[RW]
lifecycle[RW]
notifications[RW]
replication[RW]

Public Class Methods

default_encryption_changes(default_encryption, local) click to toggle source
# File lib/s3/models/BucketDiff.rb, line 87
def self.default_encryption_changes(default_encryption, local)
  diff = BucketDiff.new(ENCRYPTION, nil, local)
  diff.default_encryption = default_encryption
  diff
end
grant_changes(grants, local) click to toggle source

Public: Static method that will create a diff representing changes in grants

grants - the grant changes local - the local configuration

Returns the diff

# File lib/s3/models/BucketDiff.rb, line 42
def self.grant_changes(grants, local)
  diff = BucketDiff.new(GRANTS, nil, local)
  diff.grants = grants
  diff
end
lifecycle_changes(lifecycle, local) click to toggle source

Public: Static method that will create a diff representing changes in lifecycle rules.

lifecycle - the lifecycle changes local - the local configuration

Returns the diff

# File lib/s3/models/BucketDiff.rb, line 68
def self.lifecycle_changes(lifecycle, local)
  diff = BucketDiff.new(LIFECYCLE, nil, local)
  diff.lifecycle = lifecycle
  diff
end
notification_changes(notifications, local) click to toggle source

Public: Static method that will create a diff representing changes in notifications.

notifications - the notification changes local - the local configuration

Returns the diff

# File lib/s3/models/BucketDiff.rb, line 55
def self.notification_changes(notifications, local)
  diff = BucketDiff.new(NOTIFICATIONS, nil, local)
  diff.notifications = notifications
  diff
end
replication_changes(replication, local) click to toggle source

Public: Static method that will create a diff representing changes in replication configuration.

replication - the replication configuration local - the local configuration

Returns the diff

# File lib/s3/models/BucketDiff.rb, line 81
def self.replication_changes(replication, local)
  diff = BucketDiff.new(REPLICATION, nil, local)
  diff.replication = replication
  diff
end

Public Instance Methods

added_cors() click to toggle source

Public: Get the CORS rules to add.

Returns an array of CORSRules.

# File lib/s3/models/BucketDiff.rb, line 169
def added_cors
  (@local.cors || []) - @aws.cors.rules
end
asset_type() click to toggle source
# File lib/s3/models/BucketDiff.rb, line 151
def asset_type
  "Bucket"
end
aws_name() click to toggle source
# File lib/s3/models/BucketDiff.rb, line 155
def aws_name
  @aws.name
end
diff_string() click to toggle source
# File lib/s3/models/BucketDiff.rb, line 93
def diff_string
  case @type
  when CORS
    [
      "CORS Rules:",
      removed_cors.map { |cors| Colors.removed("\t#{cors}") },
      added_cors.map { |cors| Colors.added("\t#{cors}") }
    ].flatten.join("\n")
  when GRANTS
    [
      "Grants:",
      grants.flat_map { |g| g.to_s.lines.map { |s| "\t#{s}" }.join },
    ].flatten.join("\n")
  when LIFECYCLE
    [
      "Lifecycle Rules:",
      lifecycle.flat_map { |n| n.to_s.lines.map { |s| "\t#{s}" }.join },
    ].flatten.join("\n")
  when LOGGING
    [
      "Logging Settings:",
      Colors.aws_changes("\tAWS\t- #{if @aws.logging.to_cumulus then @aws.logging.to_cumulus else "Not enabled" end}"),
      Colors.local_changes("\tLocal\t- #{if @local.logging then @local.logging else "Not enabled" end}")
    ].join("\n")
  when NOTIFICATIONS
    [
      "Notifications:",
      notifications.flat_map { |n| n.to_s.lines.map { |s| "\t#{s}" }.join },
    ].flatten.join("\n")
  when POLICY
    [
      "Bucket Policy:",
      Colors.aws_changes("\tAWS\t- #{@aws.policy.policy_string}"),
      Colors.local_changes("\tLocal\t- #{@local.policy}")
    ].join("\n")
  when REPLICATION
    [
      "Replication:",
      replication.flat_map { |r| r.to_s.lines.map { |s| "\t#{s}" }.join },
    ].flatten.join("\n")
  when TAGS
    tags_diff_string
  when VERSIONING
    "Versioning: AWS - #{Colors.aws_changes(@aws.versioning.enabled)}, Local - #{Colors.local_changes(@local.versioning)}"
  when WEBSITE
    [
      "S3 Website Settings:",
      Colors.aws_changes("\tAWS\t- #{if @aws.website.to_cumulus then @aws.website.to_cumulus else "Not enabled" end}"),
      Colors.local_changes("\tLocal\t- #{if @local.website then @local.website else "Not enabled" end}"),
    ].join("\n")
  when ENCRYPTION
    [
      "Default Encryption:",
      default_encryption.flat_map { |r| r.to_s.lines.map { |s| "\t#{s}" }.join },
    ].flatten.join("\n")
  end
end
removed_cors() click to toggle source

Public: Get the CORS rules to remove.

Returns an array of CORSRules

# File lib/s3/models/BucketDiff.rb, line 162
def removed_cors
  @aws.cors.rules - (@local.cors || [])
end

Private Instance Methods

aws_tags_list() click to toggle source
# File lib/s3/models/BucketDiff.rb, line 175
def aws_tags_list
  @aws.tagging.safe_tags
end