Class: InstanceAgent::CodeDeployPlugin::ChangeContextCommand
- Inherits:
-
Object
- Object
- InstanceAgent::CodeDeployPlugin::ChangeContextCommand
- Defined in:
- lib/instance_agent/codedeploy_plugin/install_instruction.rb
Instance Method Summary collapse
- #execute(cleanup_file) ⇒ Object
-
#initialize(object, context) ⇒ ChangeContextCommand
constructor
A new instance of ChangeContextCommand.
- #to_h ⇒ Object
Constructor Details
#initialize(object, context) ⇒ ChangeContextCommand
Returns a new instance of ChangeContextCommand.
332 333 334 335 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 332 def initialize(object, context) @object = object @context = context end |
Instance Method Details
#execute(cleanup_file) ⇒ Object
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 337 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_h ⇒ Object
359 360 361 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 359 def to_h {"type" => "semanage", "context" => {"user" => @context.user, "role" => @context.role, "type" => @context.type, "range" => @context.range.get_range}, "file" => @object} end |