Class: S3Secure::Lifecycle::Show

Inherits:
Base show all
Defined in:
lib/s3_secure/lifecycle/show.rb

Constant Summary collapse

RULE_ID =
Base::RULE_ID

Instance Method Summary collapse

Methods inherited from CLI::Base

#buckets, #initialize

Methods included from CLI::Say

#say

Methods included from AwsServices

#sts

Methods included from AwsServices::S3

#check_bucket!, #new_s3_regional_client, #region, #region_map, #s3, #s3_client, #s3_regional_client

Constructor Details

This class inherits a constructor from S3Secure::CLI::Base

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/s3_secure/lifecycle/show.rb', line 18

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

#get_lifecycle(bucket) ⇒ Object



28
29
30
31
# File 'lib/s3_secure/lifecycle/show.rb', line 28

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

#get_lifecycle_rules(bucket) ⇒ Object

Also used by add and remove



35
36
37
38
# File 'lib/s3_secure/lifecycle/show.rb', line 35

def get_lifecycle_rules(bucket)
  resp = get_lifecycle(bucket)
  resp.rules.map(&:to_h) if resp
end

#has?(rule_id) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/s3_secure/lifecycle/show.rb', line 23

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

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/s3_secure/lifecycle/show.rb', line 5

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