25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/s3_master/cli.rb', line 25
def diff(bucket, policy_type, policy_id=nil)
config = S3Master::Config.new(options[:"config-file"])
remote_policy = S3Master::RemotePolicy.new(bucket, policy_type, {id: policy_id, region: config.region(bucket)})
local_policy = S3Master::LocalPolicy.new(config, bucket, policy_type, options.merge(id: policy_id).symbolize_keys)
if options[:debug]
bkt = Aws::S3::Bucket.new(bucket)
puts "%s: %s" % [bkt.name, bkt.url]
puts "=== Remote Policy:\n%s" % [JSON.neat_generate(remote_policy.body, sort: true)]
puts "=== Local Policy:\n%s" % [JSON.neat_generate(local_policy.body, sort: true)]
end
policy_diff = S3Master::PolicyDiffer.new(remote_policy.body, local_policy.body)
prefix = "#{bucket}/#{policy_type}"
prefix += "/#{policy_id}" if policy_id
if policy_diff.identical?
puts "#{prefix}: Local and remote policies match."
else
puts "#{prefix} diff:\n%s" % [policy_diff.to_s]
end
policy_diff
end
|