Sha256: 2f4480f72891900422317ced404351cb86523614a033b0acbdbf18ccc2b703bd

Contents?: true

Size: 926 Bytes

Versions: 1

Compression:

Stored size: 926 Bytes

Contents

class S3Secure::Lifecycle
  class Show < Base
    RULE_ID = Base::RULE_ID

    def run
      if any?
        say "This S3 bucket has lifecycle rules"
      else
        say "This S3 bucket does not have lifecycle rules"
      end

      if any?
        say "Bucket lifecycle details: "
        pp get_lifecycle(@bucket).to_h
      end
    end

    def any?
      rules = get_lifecycle_rules(@bucket)
      !!(rules && !rules.empty?)
    end

    def has?(rule_id)
      rules = get_lifecycle_rules(@bucket)
      rules && rules.detect { |rule| rule[:id] == rule_id }
    end

    def get_lifecycle(bucket)
      s3.get_bucket_lifecycle_configuration(bucket: bucket) # resp
    rescue Aws::S3::Errors::NoSuchLifecycleConfiguration
    end
    memoize :get_lifecycle

    # Also used by add and remove
    def get_lifecycle_rules(bucket)
      resp = get_lifecycle(bucket)
      resp.rules.map(&:to_h) if resp
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
s3-secure-0.5.1 lib/s3_secure/lifecycle/show.rb