s3-secure 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e1f48e9f8af3b66318cc9bbb69c7689e6973f10979e0adc5d2274fa0e3fc1a6
4
- data.tar.gz: 72c7e5845cdf8438a785bc5310ed25ce82b7c73d29c2891430492d817dd9159f
3
+ metadata.gz: 2fe4cf360f3085cd6d3a6432163e48446163b3fb4c873594198009a9eca48352
4
+ data.tar.gz: 74458fbc45b76b221c51dd75120f75c0122cd32aee9efc1a2516fcba8eaeaebb
5
5
  SHA512:
6
- metadata.gz: 5cf2fe5bf3f6e8d889eb9fe3bf912782e819e65d423bf2ef12b63bb480b6ac6d6849d061c87cc46988e1fb3f9c5be71ee293c59a73566cd70e976aec39d84f0f
7
- data.tar.gz: 6e41d083dd57a83be7b33a23b49c430f63803403ce8ba97a7fd5b25ca764d38a99c16a0dc2d9d6ff054a00aebb39bca0b1cc3ecbb9eb5e796bb19a57bb819032
6
+ metadata.gz: 3a657388018a9a0aac3b396e6d7480e210871cd2a0f6a7a85cc31a22f9b1caa7ef0e536bfe2dbbf7a921fc1c5f98366c36f388a36330b55cb9ca740fc0ffa56f
7
+ data.tar.gz: c52d3846e952af1438bb9f776d66e976a9645b5ec2c8ba8cfec18ae2ce9e24526d69f9c07951b25aaa26cc74c56da25585083c57f9d9775c2f0bd5f78ea89107
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.5.1]
7
+ - #3 add quiet option
8
+
6
9
  ## [0.5.0]
7
10
  - add commands: access_logs, lifecycle, versioning, remediate_all
8
11
  - s3 client is smarter and switches regions on a per-bucket basis
@@ -1,7 +1,8 @@
1
1
  module S3Secure
2
2
  class AbstractBase
3
- include S3Secure::AwsServices
4
3
  extend Memoist
4
+ include S3Secure::AwsServices
5
+ include Say
5
6
 
6
7
  def initialize(options={})
7
8
  @options = options
@@ -1,5 +1,7 @@
1
1
  module S3Secure
2
2
  class AccessLogs < Command
3
+ class_option :quiet, type: :boolean
4
+
3
5
  desc "list", "List bucket access_logs setting"
4
6
  long_desc Help.text("access_logs/list")
5
7
  option :format, desc: "Format options: #{CliFormat.formats.join(', ')}"
@@ -9,7 +9,7 @@ class S3Secure::AccessLogs
9
9
 
10
10
  def remove_access_logging
11
11
  unless @show.logging_enabled?
12
- puts "Bucket #{@bucket} is not configured with access logging. So nothing to remove."
12
+ say "Bucket #{@bucket} is not configured with access logging. So nothing to remove."
13
13
  return
14
14
  end
15
15
 
@@ -17,12 +17,12 @@ class S3Secure::AccessLogs
17
17
  bucket: @bucket, # source
18
18
  bucket_logging_status: {}, # empty hash to remove
19
19
  )
20
- puts "Bucket #{@bucket} access logging removed"
20
+ say "Bucket #{@bucket} access logging removed"
21
21
  end
22
22
 
23
23
  def remove_bucket_acl
24
24
  unless @show.acl_enabled?
25
- puts "Bucket #{@bucket} is not configured the log delivery ACL. So nothing to remove."
25
+ say "Bucket #{@bucket} is not configured the log delivery ACL. So nothing to remove."
26
26
  return
27
27
  end
28
28
 
@@ -31,7 +31,7 @@ class S3Secure::AccessLogs
31
31
  bucket: @bucket,
32
32
  access_control_policy: access_control_policy,
33
33
  )
34
- puts "Bucket #{@bucket} ACL Log Delivery removed"
34
+ say "Bucket #{@bucket} ACL Log Delivery removed"
35
35
  end
36
36
  end
37
37
  end
@@ -9,7 +9,7 @@ class S3Secure::AccessLogs
9
9
  # Bucket ACL applies on the target bucket only
10
10
  def add_bucket_acl
11
11
  if @show.acl_enabled?
12
- puts "Bucket acl already has log delivery ACL"
12
+ say "Bucket acl already has log delivery ACL"
13
13
  return
14
14
  end
15
15
 
@@ -17,12 +17,12 @@ class S3Secure::AccessLogs
17
17
  bucket: @bucket,
18
18
  access_control_policy: @show.access_control_policy_with_log_delivery_permissions,
19
19
  )
20
- puts "Added to bucket acl that grants log delivery"
20
+ say "Added to bucket acl that grants log delivery"
21
21
  end
22
22
 
23
23
  def enable_access_logging
24
24
  if @show.logging_enabled?
25
- puts "Bucket access logging already enabled"
25
+ say "Bucket access logging already enabled"
26
26
  return
27
27
  end
28
28
 
@@ -35,7 +35,7 @@ class S3Secure::AccessLogs
35
35
  },
36
36
  },
37
37
  )
38
- puts "Enabled access logging on the source bucket #{@bucket} to be delivered to the target bucket #{@show.target_bucket}"
38
+ say "Enabled access logging on the source bucket #{@bucket} to be delivered to the target bucket #{@show.target_bucket}"
39
39
  end
40
40
  end
41
41
  end
@@ -1,9 +1,9 @@
1
1
  class S3Secure::AccessLogs
2
2
  class Show < Base
3
3
  def run
4
- puts "Bucket ACL:"
4
+ say "Bucket ACL:"
5
5
  pp bucket_acl_grants
6
- puts "Bucket Logging:"
6
+ say "Bucket Logging:"
7
7
  pp bucket_logging
8
8
  end
9
9
 
@@ -1,6 +1,6 @@
1
1
  module S3Secure
2
2
  class CLI < Command
3
- class_option :verbose, type: :boolean
3
+ class_option :quiet, type: :boolean
4
4
  class_option :noop, type: :boolean
5
5
 
6
6
  desc "access_logs SUBCOMMAND", "access_logs subcommands"
@@ -23,7 +23,7 @@ module S3Secure
23
23
  long_desc Help.text(:lifecycle)
24
24
  subcommand "lifecycle", Lifecycle
25
25
 
26
- desc "remediate_all", "Remediate all. For more fine-grain control use each of the commands directly."
26
+ desc "remediate_all BUCKET", "Remediate all. For more fine-grain control use each of the commands directly."
27
27
  long_desc Help.text("remediate_all")
28
28
  def remediate_all(bucket)
29
29
  RemediateAll.new(options.merge(bucket: bucket)).run
@@ -1,5 +1,7 @@
1
1
  module S3Secure
2
2
  class Encryption < Command
3
+ class_option :quiet, type: :boolean
4
+
3
5
  desc "list", "List bucket encryptions"
4
6
  long_desc Help.text("encryption/list")
5
7
  option :format, desc: "Format options: #{CliFormat.formats.join(', ')}"
@@ -5,9 +5,9 @@ class S3Secure::Encryption
5
5
 
6
6
  if show.enabled?
7
7
  s3.delete_bucket_encryption(bucket: @bucket) # returns resp = #<struct Aws::EmptyStructure>
8
- puts "Bucket #{@bucket} encryption has been removed"
8
+ say "Bucket #{@bucket} encryption has been removed"
9
9
  else
10
- puts "Bucket #{@bucket} is not configured with encryption at the bucket level"
10
+ say "Bucket #{@bucket} is not configured with encryption at the bucket level"
11
11
  end
12
12
  end
13
13
  end
@@ -5,8 +5,7 @@ class S3Secure::Encryption
5
5
 
6
6
  if show.enabled?
7
7
  # check rules to see if encryption is already set of some sort
8
- puts "Bucket #{@bucket} already has encryption rules:"
9
- puts show.rules.map(&:to_h)
8
+ say "Bucket #{@bucket} already has encryption rules:"
10
9
  else
11
10
  # Set encryption rules
12
11
  # Ruby docs: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#put_bucket_encryption-instance_method
@@ -18,8 +17,7 @@ class S3Secure::Encryption
18
17
  bucket: @bucket,
19
18
  server_side_encryption_configuration: {
20
19
  rules: [rule]})
21
- puts "Encyption enabled on bucket #{@bucket} with rules:"
22
- pp rule
20
+ say "Encyption enabled on bucket #{@bucket} with rules:"
23
21
  end
24
22
  end
25
23
 
@@ -2,10 +2,10 @@ class S3Secure::Encryption
2
2
  class Show < Base
3
3
  def run
4
4
  if rules
5
- puts "Bucket #{@bucket} is configured with these encryption rules:"
6
- puts rules.map(&:to_h)
5
+ say "Bucket #{@bucket} is configured with these encryption rules:"
6
+ say rules.map(&:to_h)
7
7
  else
8
- puts "Bucket #{@bucket} is not configured with encryption at the bucket level"
8
+ say "Bucket #{@bucket} is not configured with encryption at the bucket level"
9
9
  end
10
10
  end
11
11
 
@@ -1,5 +1,7 @@
1
1
  module S3Secure
2
2
  class Lifecycle < Command
3
+ class_option :quiet, type: :boolean
4
+
3
5
  desc "list", "List bucket lifecycles"
4
6
  long_desc Help.text("lifecycle/list")
5
7
  option :format, desc: "Format options: #{CliFormat.formats.join(', ')}"
@@ -9,7 +9,7 @@ class S3Secure::Lifecycle
9
9
  builder = Builder.new(current_rules)
10
10
  rules = builder.rules_with_addition(@options[:prefix])
11
11
  if current_rules.size == rules.size
12
- puts "WARN: rule wasnt added because a #{RULE_ID} already exists".color(:yellow)
12
+ say "WARN: rule wasnt added because a #{RULE_ID} already exists".color(:yellow)
13
13
  else
14
14
  s3.put_bucket_lifecycle_configuration(
15
15
  bucket: @bucket, # required
@@ -17,7 +17,7 @@ class S3Secure::Lifecycle
17
17
  )
18
18
  end
19
19
  elsif show.any?
20
- puts "Bucket #{@bucket} is has a lifecycle policy already."
20
+ say "Bucket #{@bucket} is has a lifecycle policy already."
21
21
  return
22
22
  else
23
23
  options = {
@@ -27,7 +27,7 @@ class S3Secure::Lifecycle
27
27
  s3.put_bucket_lifecycle_configuration(options)
28
28
  end
29
29
 
30
- puts "Added lifecycle policy to bucket #{@bucket}"
30
+ say "Added lifecycle policy to bucket #{@bucket}"
31
31
  end
32
32
  end
33
33
  end
@@ -5,7 +5,7 @@ class S3Secure::Lifecycle
5
5
  def run
6
6
  show = Show.new(@options)
7
7
  unless show.has?(RULE_ID)
8
- puts "Bucket #{@bucket} already does not have the #{RULE_ID} lifecycle rule."
8
+ say "Bucket #{@bucket} already does not have the #{RULE_ID} lifecycle rule."
9
9
  return
10
10
  end
11
11
 
@@ -22,7 +22,7 @@ class S3Secure::Lifecycle
22
22
  )
23
23
  end
24
24
 
25
- puts "Removed the #{RULE_ID} lifecycle rule on bucket #{@bucket}"
25
+ say "Removed the #{RULE_ID} lifecycle rule on bucket #{@bucket}"
26
26
  end
27
27
  end
28
28
  end
@@ -4,13 +4,13 @@ class S3Secure::Lifecycle
4
4
 
5
5
  def run
6
6
  if any?
7
- puts "This S3 bucket has lifecycle rules"
7
+ say "This S3 bucket has lifecycle rules"
8
8
  else
9
- puts "This S3 bucket does not have lifecycle rules"
9
+ say "This S3 bucket does not have lifecycle rules"
10
10
  end
11
11
 
12
12
  if any?
13
- puts "Bucket lifecycle details: "
13
+ say "Bucket lifecycle details: "
14
14
  pp get_lifecycle(@bucket).to_h
15
15
  end
16
16
  end
@@ -1,5 +1,7 @@
1
1
  module S3Secure
2
2
  class Policy < Command
3
+ class_option :quiet, type: :boolean
4
+
3
5
  desc "list", "List bucket policies"
4
6
  long_desc Help.text("policy/list")
5
7
  option :format, desc: "Format options: #{CliFormat.formats.join(', ')}"
@@ -11,8 +11,8 @@ class S3Secure::Policy
11
11
  bucket_policy = show.policy
12
12
  document = Document.new(@bucket, bucket_policy)
13
13
  if document.has?(@sid)
14
- puts "Bucket policy for #{@bucket} has ForceSSLOnlyAccess policy statement already:"
15
- puts bucket_policy
14
+ say "Bucket policy for #{@bucket} has ForceSSLOnlyAccess policy statement already:"
15
+ say bucket_policy
16
16
  else
17
17
  # Set encryption rules
18
18
  # Ruby docs: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#put_bucket_policy-instance_method
@@ -25,8 +25,7 @@ class S3Secure::Policy
25
25
  bucket: @bucket,
26
26
  policy: policy_document,
27
27
  )
28
- puts "Add bucket policy to bucket #{@bucket}:"
29
- puts policy_document
28
+ say "Add bucket policy to bucket #{@bucket}:"
30
29
  end
31
30
  end
32
31
  end
@@ -2,11 +2,10 @@ class S3Secure::Policy
2
2
  class Show < Base
3
3
  def run
4
4
  if policy
5
- puts "Bucket #{@bucket} is configured with this policy:"
6
- puts policy
7
- # puts policy.map(&:to_h)
5
+ say "Bucket #{@bucket} is configured with this policy:"
6
+ say policy
8
7
  else
9
- puts "Bucket #{@bucket} is not configured bucket policy"
8
+ say "Bucket #{@bucket} is not configured bucket policy"
10
9
  end
11
10
  end
12
11
 
@@ -28,10 +28,10 @@ class S3Secure::Policy
28
28
  s3.delete_bucket_policy(bucket: @bucket)
29
29
  end
30
30
 
31
- puts "Remove bucket policy statement from bucket #{@bucket}:"
32
- puts policy_document if policy_document
31
+ say "Remove bucket policy statement from bucket #{@bucket}:"
32
+ say policy_document if policy_document
33
33
  else
34
- puts "Bucket policy for #{@bucket} does not have ForceSSLOnlyAccess policy statement. Nothing to be done."
34
+ say "Bucket policy for #{@bucket} does not have ForceSSLOnlyAccess policy statement. Nothing to be done."
35
35
  end
36
36
  end
37
37
  end
@@ -1,11 +1,12 @@
1
1
  module S3Secure
2
2
  class RemediateAll < AbstractBase
3
3
  def run
4
- Encryption::Enable.new(bucket: @bucket).run
5
- Policy::Enforce.new(bucket: @bucket, sid: "ForceSSLOnlyAccess").run
6
- Versioning::Enable.new(bucket: @bucket).run
7
- Lifecycle::Add.new(bucket: @bucket).run
8
- AccessLogs::Enable.new(bucket: @bucket).run
4
+ o = @options.merge(bucket: @bucket)
5
+ Encryption::Enable.new(o).run
6
+ Policy::Enforce.new(o.merge(sid: "ForceSSLOnlyAccess")).run
7
+ Versioning::Enable.new(o).run
8
+ Lifecycle::Add.new(o).run
9
+ AccessLogs::Enable.new(o).run
9
10
  end
10
11
  end
11
12
  end
@@ -0,0 +1,7 @@
1
+ module S3Secure
2
+ module Say
3
+ def say(msg)
4
+ puts msg unless @options[:quiet]
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module S3Secure
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -1,5 +1,7 @@
1
1
  module S3Secure
2
2
  class Versioning < Command
3
+ class_option :quiet, type: :boolean
4
+
3
5
  desc "list", "List bucket versionings"
4
6
  long_desc Help.text("versioning/list")
5
7
  option :format, desc: "Format options: #{CliFormat.formats.join(', ')}"
@@ -10,9 +10,9 @@ class S3Secure::Versioning
10
10
  status: "Suspended",
11
11
  },
12
12
  )
13
- puts "Versioning Suspended on bucket #{@bucket}"
13
+ say "Versioning Suspended on bucket #{@bucket}"
14
14
  else
15
- puts "Bucket #{@bucket} is already has versioning already Suspended or not Enabled."
15
+ say "Bucket #{@bucket} is already has versioning already Suspended or not Enabled."
16
16
  end
17
17
  end
18
18
  end
@@ -3,7 +3,7 @@ class S3Secure::Versioning
3
3
  def run
4
4
  show = Show.new(@options)
5
5
  if show.enabled?
6
- puts "Bucket #{@bucket} is has versioning already enabled."
6
+ say "Bucket #{@bucket} is has versioning already enabled."
7
7
  else
8
8
  s3.put_bucket_versioning(
9
9
  bucket: @bucket,
@@ -12,7 +12,7 @@ class S3Secure::Versioning
12
12
  status: "Enabled",
13
13
  },
14
14
  )
15
- puts "Versioning enabled on bucket #{@bucket}"
15
+ say "Versioning enabled on bucket #{@bucket}"
16
16
  end
17
17
  end
18
18
  end
@@ -2,13 +2,13 @@ class S3Secure::Versioning
2
2
  class Show < Base
3
3
  def run
4
4
  if enabled?
5
- puts "This S3 bucket has versioning enabled"
5
+ say "This S3 bucket has versioning enabled"
6
6
  else
7
- puts "This S3 bucket does not have versioning enabled"
7
+ say "This S3 bucket does not have versioning enabled"
8
8
  end
9
9
  details = get_versioning(@bucket).to_h
10
10
  unless details.empty?
11
- puts "Bucket versioning details: "
11
+ say "Bucket versioning details: "
12
12
  pp details
13
13
  end
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3-secure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-31 00:00:00.000000000 Z
11
+ date: 2020-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -267,6 +267,7 @@ files:
267
267
  - lib/s3_secure/policy/show.rb
268
268
  - lib/s3_secure/policy/unforce.rb
269
269
  - lib/s3_secure/remediate_all.rb
270
+ - lib/s3_secure/say.rb
270
271
  - lib/s3_secure/summary.rb
271
272
  - lib/s3_secure/summary/item.rb
272
273
  - lib/s3_secure/summary/items.rb