Class: InstanceAgent::Plugins::CodeDeployPlugin::CommandBuilder
- Inherits:
-
Object
- Object
- InstanceAgent::Plugins::CodeDeployPlugin::CommandBuilder
- Defined in:
- lib/instance_agent/plugins/codedeploy/install_instruction.rb
Instance Attribute Summary collapse
-
#command_array ⇒ Object
readonly
Returns the value of attribute command_array.
Instance Method Summary collapse
-
#cleanup ⇒ Object
Clean up explicitly since these can grow to tens of MBs if the deployment archive is large.
- #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.
75 76 77 78 79 80 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 75 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.
74 75 76 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 74 def command_array @command_array end |
Instance Method Details
#cleanup ⇒ Object
Clean up explicitly since these can grow to tens of MBs if the deployment archive is large.
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 173 def cleanup() @command_array.clear @command_array = nil @copy_targets.clear @copy_targets = nil @mkdir_targets.clear @mkdir_targets = nil @permission_targets.clear @permission_targets = nil end |
#copy(source, destination) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 82 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
126 127 128 129 130 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 126 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
168 169 170 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 168 def each(&block) @command_array.each(&block) end |
#find_matches(permission) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 138 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
132 133 134 135 136 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 132 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
91 92 93 94 95 96 97 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 91 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
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 124 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 99 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
163 164 165 166 |
# File 'lib/instance_agent/plugins/codedeploy/install_instruction.rb', line 163 def to_json command_json = @command_array.map(&:to_h) {:instructions => command_json}.to_json end |