Sha256: 0209eca6e6a76d7947460d4b05c1a0d878e19e10e61994ea15faa7ec2e62dd27

Contents?: true

Size: 1017 Bytes

Versions: 3

Compression:

Stored size: 1017 Bytes

Contents

module S3Secure::Lifecycle
  class Add < Base
    RULE_ID = Base::RULE_ID

    def run
      show = Show.new(@options)
      if @options[:additive]
        current_rules = show.get_lifecycle_rules(@bucket)
        builder = Builder.new(current_rules)
        rules = builder.rules_with_addition(@options[:prefix])
        if current_rules.size == rules.size
          say "WARN: rule wasnt added because a #{RULE_ID} already exists".color(:yellow)
        else
          s3.put_bucket_lifecycle_configuration(
            bucket: @bucket, # required
            lifecycle_configuration: {rules: rules}
          )
        end
      elsif show.any?
        say "Bucket #{@bucket} is has a lifecycle policy already."
        return
      else
        options = {
          bucket: @bucket, # required
          lifecycle_configuration: {rules: [Builder::DEFAULT_RULE]}
        }
        s3.put_bucket_lifecycle_configuration(options)
      end

      say "Added lifecycle policy to bucket #{@bucket}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
s3-secure-0.7.0 lib/s3_secure/lifecycle/add.rb
s3-secure-0.6.1 lib/s3_secure/lifecycle/add.rb
s3-secure-0.6.0 lib/s3_secure/lifecycle/add.rb