Class: InstanceAgent::CodeDeployPlugin::ChangeAclCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/instance_agent/codedeploy_plugin/install_instruction.rb

Instance Method Summary collapse

Constructor Details

#initialize(object, acl) ⇒ ChangeAclCommand

Returns a new instance of ChangeAclCommand.



262
263
264
265
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 262

def initialize(object, acl)
  @object = object
  @acl = acl
end

Instance Method Details

#clear_full_aclObject



279
280
281
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 279

def clear_full_acl
  @acl.clear_additional
end

#execute(cleanup_file) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 267

def execute(cleanup_file)
  begin
    get_full_acl
    acl = @acl.get_acl.join(",")
    if !system("setfacl --set #{acl} #{@object}")
      raise "Unable to set acl correctly: setfacl --set #{acl} #{@object}, exit code: #{$?}"
    end
  ensure
    clear_full_acl
  end
end

#get_full_aclObject



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 283

def get_full_acl()
  perm = "%o" % File.stat(@object).mode
  perm = perm[-3,3]
  @acl.add_ace(":#{perm[0]}")
  @acl.add_ace("g::#{perm[1]}")
  @acl.add_ace("o::#{perm[2]}")
  if @acl.has_base_named? && !@acl.has_base_mask?
    @acl.add_ace("m::#{perm[1]}")
  end
  if @acl.has_default?
    if !@acl.has_default_user?
      @acl.add_ace("d::#{perm[0]}")
    end
    if !@acl.has_default_group?
      @acl.add_ace("d:g::#{perm[1]}")
    end
    if !@acl.has_default_other?
      @acl.add_ace("d:o:#{perm[2]}")
    end
    if @acl.has_default_named? && !@acl.has_default_mask?
      @acl.add_ace(@acl.get_default_group_ace.sub("group:","mask"))
    end
  end
end

#to_hObject



308
309
310
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 308

def to_h
  {"type" => "setfacl", "acl" => @acl.get_acl, "file" => @object}
end