Class: InstanceAgent::CodeDeployPlugin::InstallInstruction

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

Class Method Summary collapse

Class Method Details

.generate_commands_from_file(file) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 8

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

Yields:

  • (command_builder)


65
66
67
68
69
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 65

def self.generate_instructions()
  command_builder = CommandBuilder.new()
  yield(command_builder)
  command_builder
end

.parse_install_commands(contents) ⇒ Object



20
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
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 20

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::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::CodeDeployPlugin::ApplicationSpecification::ContextInfo.new(mapping['context']))
      else
        raise "Unknown command: #{mapping}"
    end
  end
  commands
end

.parse_remove_commands(contents) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 47

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