class S3Master::LocalPolicy
Attributes
body[R]
Public Class Methods
new(cfg, bucket_name, policy_type, options={})
click to toggle source
# File lib/s3_master/local_policy.rb, line 5 def initialize(cfg, bucket_name, policy_type, options={}) @config = cfg @bucket_name = bucket_name @policy_type = policy_type.to_sym @options = options @policy_id = options[:id] if @config["buckets"][@bucket_name].nil? raise(RuntimeError, "No bucket named '#{@bucket_name}' found in loaded config.") end load_policy if !options[:skip_load] end
Public Instance Methods
basename()
click to toggle source
# File lib/s3_master/local_policy.rb, line 23 def basename() @config.template_relname(@bucket_name, @policy_type, @policy_id) ; end
empty?()
click to toggle source
# File lib/s3_master/local_policy.rb, line 20 def empty?() @body.nil? || @body.empty? ; end
load_policy()
click to toggle source
# File lib/s3_master/local_policy.rb, line 26 def load_policy @body = if basename.nil? || basename == false # Empty policy {} else JSON.parse(File.binread(path)) end if ! self.preserve_keys? @body.deep_transform_keys!{|k| k.underscore.to_sym } end @body end
path()
click to toggle source
# File lib/s3_master/local_policy.rb, line 24 def path() File.join(@options[:"policy-dir"], self.basename) ; end
preserve_keys?()
click to toggle source
# File lib/s3_master/local_policy.rb, line 19 def preserve_keys?() S3Master::RemotePolicy::POLICIES[@policy_type][:preserve_keys] ; end
pretty_body()
click to toggle source
# File lib/s3_master/local_policy.rb, line 21 def pretty_body() JSON.neat_generate(body, sort: (self.preserve_keys? ? false : true)) ; end
write(other_policy)
click to toggle source
# File lib/s3_master/local_policy.rb, line 41 def write(other_policy) File.open(self.path, "wb") do |fh| fh.puts other_policy.pretty_body end end