Class: InstanceAgent::Plugins::CodeDeployPlugin::InstallInstruction
- Inherits:
-
Object
- Object
- InstanceAgent::Plugins::CodeDeployPlugin::InstallInstruction
- Defined in:
- lib/instance_agent/plugins/codedeploy/install_instruction.rb
Class Method Summary collapse
- .generate_commands_from_file(file) ⇒ Object
- .generate_instructions {|command_builder| ... } ⇒ Object
- .parse_install_commands(contents) ⇒ Object
- .parse_remove_commands(contents) ⇒ Object
Class Method Details
.generate_commands_from_file(file) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 9 def self.generate_commands_from_file(file) name = File.basename(file.path) file = File.open(file.path, 'r') contents = file.read file.close if name =~ /^*-install.json/ parse_install_commands(contents) elsif name =~ /^*-cleanup/ parse_remove_commands(contents) end end |
.generate_instructions {|command_builder| ... } ⇒ Object
66 67 68 69 70 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 66 def self.generate_instructions() command_builder = CommandBuilder.new() yield(command_builder) command_builder end |
.parse_install_commands(contents) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 21 def self.parse_install_commands(contents) instructions = JSON.parse(contents)['instructions'] commands = [] instructions.each do |mapping| case mapping['type'] when "copy" commands << CopyCommand.new(mapping["source"], mapping["destination"]) when "mkdir" commands << MakeDirectoryCommand.new(mapping["directory"]) when "chmod" commands << ChangeModeCommand.new(mapping['file'], mapping['mode']) when "chown" commands << ChangeOwnerCommand.new(mapping['file'], mapping['owner'], mapping['group']) when "setfacl" commands << ChangeAclCommand.new(mapping['file'], InstanceAgent::Plugins::CodeDeployPlugin::ApplicationSpecification::AclInfo.new(mapping['acl'])) when "semanage" if !mapping['context']['role'].nil? raise "Attempt to set role on object, not supported" end commands << ChangeContextCommand.new(mapping['file'], InstanceAgent::Plugins::CodeDeployPlugin::ApplicationSpecification::ContextInfo.new(mapping['context'])) else raise "Unknown command: #{mapping}" end end commands end |
.parse_remove_commands(contents) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 48 def self.parse_remove_commands(contents) return [] if contents.empty? #remove the unfinished paths lines = contents.lines.to_a if lines.last[lines.last.length-1] != "\n" lines.pop end commands = [] lines.each do |command| if command.start_with?("semanage\0") commands << RemoveContextCommand.new(command.split("\0",2)[1].strip) else commands << RemoveCommand.new(command.strip) end end commands.reverse end |