class S3Master::RemotePolicy
Constants
- NO_POLICY_EXCEPTIONS
- POLICIES
- POLICY_TYPES
Attributes
body[R]
Public Class Methods
known_policy_type?(policy)
click to toggle source
# File lib/s3_master/remote_policy.rb, line 123 def self.known_policy_type?(policy) POLICIES.has_key?(policy.to_sym) ; end
new(bucket_name, policy_type, options={})
click to toggle source
# File lib/s3_master/remote_policy.rb, line 50 def initialize(bucket_name, policy_type, options={}) @client = options[:region].nil? ? Aws::S3::Client.new() : Aws::S3::Client.new(region: options[:region]) @bucket_name = bucket_name @policy_type = policy_type.to_sym @options = options raise(RuntimeError, "Policy type #{policy_type} not supported") if !POLICIES.has_key?(@policy_type) load_policy end
Public Instance Methods
base_args()
click to toggle source
# File lib/s3_master/remote_policy.rb, line 115 def base_args args = {bucket: @bucket_name} if POLICIES[@policy_type][:requires_id] args[:id] = @options[:id] end args end
deflate(policy_hash)
click to toggle source
# File lib/s3_master/remote_policy.rb, line 70 def deflate(policy_hash) case @policy_type when :access_policy policy_hash[policy_key] = JSON.generate(policy_hash[policy_key]) end policy_hash end
ensure_versioning!()
click to toggle source
# File lib/s3_master/remote_policy.rb, line 110 def ensure_versioning! bkt = Aws::S3::Bucket.new(@bucket_name, client: @client) bkt.versioning.status == "Enabled" || bkt.versioning.enable end
inflate(read_policy)
click to toggle source
# File lib/s3_master/remote_policy.rb, line 62 def inflate(read_policy) if @policy_type == :access_policy JSON.parse(read_policy[policy_key].string) else read_policy end end
known_policy_type?(policy)
click to toggle source
# File lib/s3_master/remote_policy.rb, line 124 def known_policy_type?(policy) self.class.known_policy_type(policy) ; end
load_policy()
click to toggle source
# File lib/s3_master/remote_policy.rb, line 78 def load_policy begin args = base_args @body = self.inflate(@client.send(POLICIES[@policy_type][:get], args).to_hash) rescue *NO_POLICY_EXCEPTIONS => e # No policy there currently @body = {} end end
parse_as_string()
click to toggle source
# File lib/s3_master/remote_policy.rb, line 60 def parse_as_string() POLICIES[@policy_type][:parse_as_string] || false ; end
policy_key()
click to toggle source
# File lib/s3_master/remote_policy.rb, line 59 def policy_key() POLICIES[@policy_type][:policy_key] ; end
pretty_body()
click to toggle source
# File lib/s3_master/remote_policy.rb, line 88 def pretty_body() JSON.neat_generate(body, sort: true) ; end
write(local_policy)
click to toggle source
# File lib/s3_master/remote_policy.rb, line 90 def write(local_policy) args = base_args if local_policy.empty? && POLICIES[@policy_type].has_key?(:delete) @client.send(POLICIES[@policy_type][:delete], args) else if POLICIES[@policy_type][:ensure_versioning] self.ensure_versioning! end if POLICIES[@policy_type][:policy_merge] args.merge!(local_policy.body) else args[policy_key] = local_policy.body end @client.send(POLICIES[@policy_type][:put], self.deflate(args)) end end