Class: InstanceAgent::CodeDeployPlugin::CommandBuilder
- Inherits:
-
Object
- Object
- InstanceAgent::CodeDeployPlugin::CommandBuilder
- Defined in:
- lib/instance_agent/codedeploy_plugin/install_instruction.rb
Instance Attribute Summary collapse
-
#command_array ⇒ Object
readonly
Returns the value of attribute command_array.
Instance Method Summary collapse
- #copy(source, destination) ⇒ Object
- #copying_file?(file) ⇒ Boolean
- #each(&block) ⇒ Object
- #find_matches(permission) ⇒ Object
-
#initialize ⇒ CommandBuilder
constructor
A new instance of CommandBuilder.
- #making_directory?(dir) ⇒ Boolean
- #mkdir(destination) ⇒ Object
- #set_permissions(object, permission) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize ⇒ CommandBuilder
Returns a new instance of CommandBuilder.
74 75 76 77 78 79 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 74 def initialize() @command_array = [] @copy_targets = Hash.new @mkdir_targets = Set.new @permission_targets = Set.new end |
Instance Attribute Details
#command_array ⇒ Object (readonly)
Returns the value of attribute command_array.
73 74 75 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 73 def command_array @command_array end |
Instance Method Details
#copy(source, destination) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 81 def copy(source, destination) destination = sanitize_dir_path(destination) log(:debug, "Copying #{source} to #{destination}") raise "Duplicate copy instruction to #{destination} from #{source} and #{@copy_targets[destination]}" if @copy_targets.has_key?(destination) raise "Duplicate copy instruction to #{destination} from #{source} which is already being installed as a directory" if @mkdir_targets.include?(destination) @command_array << CopyCommand.new(source, destination) @copy_targets[destination] = source end |
#copying_file?(file) ⇒ Boolean
125 126 127 128 129 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 125 def (file) file = sanitize_dir_path(file) log(:debug, "Checking for #{file} in #{@copy_targets.keys.inspect}") @copy_targets.has_key?(file) end |
#each(&block) ⇒ Object
167 168 169 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 167 def each(&block) @command_array.each(&block) end |
#find_matches(permission) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 137 def find_matches() log(:debug, "Finding matches for #{.object}") matches = [] if .type.include?("file") @copy_targets.keys.each do |object| log(:debug, "Checking #{object}") if (.matches_pattern?(object) && !.matches_except?(object)) log(:debug, "Found match #{object}") .validate_file_acl(object) matches << object end end end if .type.include?("directory") @mkdir_targets.each do |object| log(:debug, "Checking #{object}") if (.matches_pattern?(object) && !.matches_except?(object)) log(:debug, "Found match #{object}") matches << object end end end matches end |
#making_directory?(dir) ⇒ Boolean
131 132 133 134 135 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 131 def making_directory?(dir) dir = sanitize_dir_path(dir) log(:debug, "Checking for #{dir} in #{@mkdir_targets.inspect}") @mkdir_targets.include?(dir) end |
#mkdir(destination) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 90 def mkdir(destination) destination = sanitize_dir_path(destination) log(:debug, "Making directory #{destination}") raise "Duplicate mkdir instruction for #{destination} which is already being copied from #{@copy_targets[destination]}" if @copy_targets.has_key?(destination) @command_array << MakeDirectoryCommand.new(destination) unless @mkdir_targets.include?(destination) @mkdir_targets.add(destination) end |
#set_permissions(object, permission) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 98 def (object, ) object = sanitize_dir_path(object) log(:debug, "Setting permissions on #{object}") raise "Duplicate permission setting instructions for #{object}" if @permission_targets.include?(object) @permission_targets.add(object) if !.mode.nil? log(:debug, "Setting mode on #{object}") @command_array << ChangeModeCommand.new(object, .mode.mode) end if !.acls.nil? log(:debug, "Setting acl on #{object}") @command_array << ChangeAclCommand.new(object, .acls) end if !.context.nil? log(:debug, "Setting context on #{object}") @command_array << ChangeContextCommand.new(object, .context) end if !.owner.nil? || !.group.nil? log(:debug, "Setting ownership of #{object}") @command_array << ChangeOwnerCommand.new(object, .owner, .group) end end |
#to_json ⇒ Object
162 163 164 165 |
# File 'lib/instance_agent/codedeploy_plugin/install_instruction.rb', line 162 def to_json command_json = @command_array.map(&:to_h) {"instructions" => command_json}.to_json end |