Sha256: e31ba1d5c63bad48e0a0b58a63381775597207ca93ecde59946b57ce3380f0e0

Contents?: true

Size: 714 Bytes

Versions: 3

Compression:

Stored size: 714 Bytes

Contents

module ChefAPI
  module AclAble
    def acl_path
      self.resource_path + '/_acl'
    end

    def load_acl
      data = self.class.connection.get(acl_path)
      # make deep copy
      @orig_acl_data = Marshal.load(Marshal.dump(data))
      data.freeze
      @acl = data
    end

    def acl
      unless @acl
        self.load_acl
      end
      @acl
    end

    def save!
      super
      if @acl != @orig_acl_data
        %w(create update grant read delete).each{|action|
          if @acl[action] != @orig_acl_data[action]
            url = "#{self.acl_path}/#{action}"
            self.class.connection.put(url, {action => @acl[action]}.to_json)
          end
        }
      end
    end
  end
    
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
chef-infra-api-0.10.0 lib/chef-api/aclable.rb
chef-api-0.10.0 lib/chef-api/aclable.rb
chef-infra-api-0.9.1 lib/chef-api/aclable.rb