class InstanceAgent::Plugins::CodeDeployPlugin::InstallInstruction

Public Class Methods

generate_commands_from_file(file) click to toggle source
# 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| ... } click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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