Class: InstanceAgent::Plugins::CodeDeployPlugin::ChangeContextCommand

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

Instance Method Summary collapse

Constructor Details

#initialize(object, context) ⇒ ChangeContextCommand

Returns a new instance of ChangeContextCommand.



346
347
348
349
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 346

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

Instance Method Details

#execute(cleanup_file) ⇒ Object



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 351

def execute(cleanup_file)
  if !@context.role.nil?
    raise "Attempt to set role on object, not supported"
  end
  args = "-t #{@context.type}"
  if (!@context.user.nil?)
    args = "-s #{@context.user} " + args
  end
  if (!@context.range.nil?)
    args = args + " -r #{@context.range.get_range}"
  end

  object = File.realpath(@object)
  if !system("semanage fcontext -a #{args} #{object}")
    raise "Unable to set context: semanage fcontext -a #{args} #{object}, exit code: #{$?}"
  end
  if !system("restorecon -v #{object}")
    raise "Unable to apply context: restorcecon -v #{object}, exit code: #{$?}"
  end
  cleanup_file.puts("semanage\0#{object}")
end

#to_hObject



373
374
375
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 373

def to_h
  {:type => :semanage, :context => {:user => @context.user, :role => @context.role, :type => @context.type, :range => @context.range.get_range}, :file => @object}
end