bolt 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bolt might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +1 -1
- data/lib/bolt/config.rb +14 -10
- data/lib/bolt/executor.rb +10 -4
- data/lib/bolt/inventory.rb +11 -10
- data/lib/bolt/node/errors.rb +8 -1
- data/lib/bolt/target.rb +25 -2
- data/lib/bolt/task.rb +13 -2
- data/lib/bolt/task/remote.rb +25 -0
- data/lib/bolt/transport/base.rb +22 -6
- data/lib/bolt/transport/docker.rb +6 -0
- data/lib/bolt/transport/local.rb +64 -20
- data/lib/bolt/transport/powershell.rb +330 -0
- data/lib/bolt/transport/remote.rb +53 -0
- data/lib/bolt/transport/ssh.rb +1 -2
- data/lib/bolt/transport/winrm.rb +16 -89
- data/lib/bolt/transport/winrm/connection.rb +5 -216
- data/lib/bolt/version.rb +1 -1
- data/lib/bolt_server/file_cache.rb +1 -1
- metadata +19 -2
@@ -97,195 +97,7 @@ module Bolt
|
|
97
97
|
|
98
98
|
def shell_init
|
99
99
|
return nil if @shell_initialized
|
100
|
-
result = execute(
|
101
|
-
$ENV:PATH += ";${ENV:ProgramFiles}\\Puppet Labs\\Puppet\\bin\\;" +
|
102
|
-
"${ENV:ProgramFiles}\\Puppet Labs\\Puppet\\puppet\\bin;" +
|
103
|
-
"${ENV:ProgramFiles}\\Puppet Labs\\Puppet\\sys\\ruby\\bin\\"
|
104
|
-
$ENV:RUBYLIB = "${ENV:ProgramFiles}\\Puppet Labs\\Puppet\\puppet\\lib;" +
|
105
|
-
"${ENV:ProgramFiles}\\Puppet Labs\\Puppet\\facter\\lib;" +
|
106
|
-
"${ENV:ProgramFiles}\\Puppet Labs\\Puppet\\hiera\\lib;" +
|
107
|
-
$ENV:RUBYLIB
|
108
|
-
|
109
|
-
Add-Type -AssemblyName System.ServiceModel.Web, System.Runtime.Serialization
|
110
|
-
$utf8 = [System.Text.Encoding]::UTF8
|
111
|
-
|
112
|
-
function Write-Stream {
|
113
|
-
PARAM(
|
114
|
-
[Parameter(Position=0)] $stream,
|
115
|
-
[Parameter(ValueFromPipeline=$true)] $string
|
116
|
-
)
|
117
|
-
PROCESS {
|
118
|
-
$bytes = $utf8.GetBytes($string)
|
119
|
-
$stream.Write( $bytes, 0, $bytes.Length )
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
function Convert-JsonToXml {
|
124
|
-
PARAM([Parameter(ValueFromPipeline=$true)] [string[]] $json)
|
125
|
-
BEGIN {
|
126
|
-
$mStream = New-Object System.IO.MemoryStream
|
127
|
-
}
|
128
|
-
PROCESS {
|
129
|
-
$json | Write-Stream -Stream $mStream
|
130
|
-
}
|
131
|
-
END {
|
132
|
-
$mStream.Position = 0
|
133
|
-
try {
|
134
|
-
$jsonReader = [System.Runtime.Serialization.Json.JsonReaderWriterFactory]::CreateJsonReader($mStream,[System.Xml.XmlDictionaryReaderQuotas]::Max)
|
135
|
-
$xml = New-Object Xml.XmlDocument
|
136
|
-
$xml.Load($jsonReader)
|
137
|
-
$xml
|
138
|
-
} finally {
|
139
|
-
$jsonReader.Close()
|
140
|
-
$mStream.Dispose()
|
141
|
-
}
|
142
|
-
}
|
143
|
-
}
|
144
|
-
|
145
|
-
Function ConvertFrom-Xml {
|
146
|
-
[CmdletBinding(DefaultParameterSetName="AutoType")]
|
147
|
-
PARAM(
|
148
|
-
[Parameter(ValueFromPipeline=$true,Mandatory=$true,Position=1)] [Xml.XmlNode] $xml,
|
149
|
-
[Parameter(Mandatory=$true,ParameterSetName="ManualType")] [Type] $Type,
|
150
|
-
[Switch] $ForceType
|
151
|
-
)
|
152
|
-
PROCESS{
|
153
|
-
if (Get-Member -InputObject $xml -Name root) {
|
154
|
-
return $xml.root.Objects | ConvertFrom-Xml
|
155
|
-
} elseif (Get-Member -InputObject $xml -Name Objects) {
|
156
|
-
return $xml.Objects | ConvertFrom-Xml
|
157
|
-
}
|
158
|
-
$propbag = @{}
|
159
|
-
foreach ($name in Get-Member -InputObject $xml -MemberType Properties | Where-Object{$_.Name -notmatch "^__|type"} | Select-Object -ExpandProperty name) {
|
160
|
-
Write-Debug "$Name Type: $($xml.$Name.type)" -Debug:$false
|
161
|
-
$propbag."$Name" = Convert-Properties $xml."$name"
|
162
|
-
}
|
163
|
-
if (!$Type -and $xml.HasAttribute("__type")) { $Type = $xml.__Type }
|
164
|
-
if ($ForceType -and $Type) {
|
165
|
-
try {
|
166
|
-
$output = New-Object $Type -Property $propbag
|
167
|
-
} catch {
|
168
|
-
$output = New-Object PSObject -Property $propbag
|
169
|
-
$output.PsTypeNames.Insert(0, $xml.__type)
|
170
|
-
}
|
171
|
-
} elseif ($propbag.Count -ne 0) {
|
172
|
-
$output = New-Object PSObject -Property $propbag
|
173
|
-
if ($Type) {
|
174
|
-
$output.PsTypeNames.Insert(0, $Type)
|
175
|
-
}
|
176
|
-
}
|
177
|
-
return $output
|
178
|
-
}
|
179
|
-
}
|
180
|
-
|
181
|
-
Function Convert-Properties {
|
182
|
-
PARAM($InputObject)
|
183
|
-
switch ($InputObject.type) {
|
184
|
-
"object" {
|
185
|
-
return (ConvertFrom-Xml -Xml $InputObject)
|
186
|
-
}
|
187
|
-
"string" {
|
188
|
-
$MightBeADate = $InputObject.get_InnerText() -as [DateTime]
|
189
|
-
## Strings that are actually dates (*grumble* JSON is crap)
|
190
|
-
if ($MightBeADate -and $propbag."$Name" -eq $MightBeADate.ToString("G")) {
|
191
|
-
return $MightBeADate
|
192
|
-
} else {
|
193
|
-
return $InputObject.get_InnerText()
|
194
|
-
}
|
195
|
-
}
|
196
|
-
"number" {
|
197
|
-
$number = $InputObject.get_InnerText()
|
198
|
-
if ($number -eq ($number -as [int])) {
|
199
|
-
return $number -as [int]
|
200
|
-
} elseif ($number -eq ($number -as [double])) {
|
201
|
-
return $number -as [double]
|
202
|
-
} else {
|
203
|
-
return $number -as [decimal]
|
204
|
-
}
|
205
|
-
}
|
206
|
-
"boolean" {
|
207
|
-
return [bool]::parse($InputObject.get_InnerText())
|
208
|
-
}
|
209
|
-
"null" {
|
210
|
-
return $null
|
211
|
-
}
|
212
|
-
"array" {
|
213
|
-
[object[]]$Items = $(foreach( $item in $InputObject.GetEnumerator() ) {
|
214
|
-
Convert-Properties $item
|
215
|
-
})
|
216
|
-
return $Items
|
217
|
-
}
|
218
|
-
default {
|
219
|
-
return $InputObject
|
220
|
-
}
|
221
|
-
}
|
222
|
-
}
|
223
|
-
|
224
|
-
Function ConvertFrom-Json2 {
|
225
|
-
[CmdletBinding()]
|
226
|
-
PARAM(
|
227
|
-
[Parameter(ValueFromPipeline=$true,Mandatory=$true,Position=1)] [string] $InputObject,
|
228
|
-
[Parameter(Mandatory=$true)] [Type] $Type,
|
229
|
-
[Switch] $ForceType
|
230
|
-
)
|
231
|
-
PROCESS {
|
232
|
-
$null = $PSBoundParameters.Remove("InputObject")
|
233
|
-
[Xml.XmlElement]$xml = (Convert-JsonToXml $InputObject).Root
|
234
|
-
if ($xml) {
|
235
|
-
if ($xml.Objects) {
|
236
|
-
$xml.Objects.Item.GetEnumerator() | ConvertFrom-Xml @PSBoundParameters
|
237
|
-
} elseif ($xml.Item -and $xml.Item -isnot [System.Management.Automation.PSParameterizedProperty]) {
|
238
|
-
$xml.Item | ConvertFrom-Xml @PSBoundParameters
|
239
|
-
} else {
|
240
|
-
$xml | ConvertFrom-Xml @PSBoundParameters
|
241
|
-
}
|
242
|
-
} else {
|
243
|
-
Write-Error "Failed to parse JSON with JsonReader" -Debug:$false
|
244
|
-
}
|
245
|
-
}
|
246
|
-
}
|
247
|
-
|
248
|
-
function ConvertFrom-PSCustomObject
|
249
|
-
{
|
250
|
-
PARAM([Parameter(ValueFromPipeline = $true)] $InputObject)
|
251
|
-
PROCESS {
|
252
|
-
if ($null -eq $InputObject) { return $null }
|
253
|
-
|
254
|
-
if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string]) {
|
255
|
-
$collection = @(
|
256
|
-
foreach ($object in $InputObject) { ConvertFrom-PSCustomObject $object }
|
257
|
-
)
|
258
|
-
|
259
|
-
$collection
|
260
|
-
} elseif ($InputObject -is [System.Management.Automation.PSCustomObject]) {
|
261
|
-
$hash = @{}
|
262
|
-
foreach ($property in $InputObject.PSObject.Properties) {
|
263
|
-
$hash[$property.Name] = ConvertFrom-PSCustomObject $property.Value
|
264
|
-
}
|
265
|
-
|
266
|
-
$hash
|
267
|
-
} else {
|
268
|
-
$InputObject
|
269
|
-
}
|
270
|
-
}
|
271
|
-
}
|
272
|
-
|
273
|
-
function Get-ContentAsJson
|
274
|
-
{
|
275
|
-
[CmdletBinding()]
|
276
|
-
PARAM(
|
277
|
-
[Parameter(Mandatory = $true)] $Text,
|
278
|
-
[Parameter(Mandatory = $false)] [Text.Encoding] $Encoding = [Text.Encoding]::UTF8
|
279
|
-
)
|
280
|
-
|
281
|
-
# using polyfill cmdlet on PS2, so pass type info
|
282
|
-
if ($PSVersionTable.PSVersion -lt [Version]'3.0') {
|
283
|
-
$Text | ConvertFrom-Json2 -Type PSObject | ConvertFrom-PSCustomObject
|
284
|
-
} else {
|
285
|
-
$Text | ConvertFrom-Json | ConvertFrom-PSCustomObject
|
286
|
-
}
|
287
|
-
}
|
288
|
-
PS
|
100
|
+
result = execute(Powershell.shell_init)
|
289
101
|
if result.exit_code != 0
|
290
102
|
raise BaseError.new("Could not initialize shell: #{result.stderr.string}", "SHELL_INIT_ERROR")
|
291
103
|
end
|
@@ -316,26 +128,11 @@ PS
|
|
316
128
|
end
|
317
129
|
|
318
130
|
def execute_process(path = '', arguments = [], stdin = nil)
|
319
|
-
|
320
|
-
"'" + arg.gsub("'", "''") + "'"
|
321
|
-
end.join(' ')
|
322
|
-
|
323
|
-
exec_cmd =
|
324
|
-
if stdin.nil?
|
325
|
-
"& #{path} #{quoted_args}"
|
326
|
-
else
|
327
|
-
"@'\n#{stdin}\n'@ | & #{path} #{quoted_args}"
|
328
|
-
end
|
329
|
-
execute(<<-PS)
|
330
|
-
$OutputEncoding = [Console]::OutputEncoding
|
331
|
-
#{exec_cmd}
|
332
|
-
if (-not $? -and ($LASTEXITCODE -eq $null)) { exit 1 }
|
333
|
-
exit $LASTEXITCODE
|
334
|
-
PS
|
131
|
+
execute(Powershell.execute_process(path, arguments, stdin))
|
335
132
|
end
|
336
133
|
|
337
134
|
def mkdirs(dirs)
|
338
|
-
result = execute(
|
135
|
+
result = execute(Powershell.mkdirs(dirs))
|
339
136
|
if result.exit_code != 0
|
340
137
|
message = "Could not create directories: #{result.stderr}"
|
341
138
|
raise Bolt::Node::FileError.new(message, 'MKDIR_ERROR')
|
@@ -351,13 +148,7 @@ PS
|
|
351
148
|
|
352
149
|
def make_tempdir
|
353
150
|
find_parent = target.options['tmpdir'] ? "\"#{target.options['tmpdir']}\"" : '[System.IO.Path]::GetTempPath()'
|
354
|
-
result = execute(
|
355
|
-
$parent = #{find_parent}
|
356
|
-
$name = [System.IO.Path]::GetRandomFileName()
|
357
|
-
$path = Join-Path $parent $name
|
358
|
-
New-Item -ItemType Directory -Path $path | Out-Null
|
359
|
-
$path
|
360
|
-
PS
|
151
|
+
result = execute(Powershell.make_tempdir(find_parent))
|
361
152
|
if result.exit_code != 0
|
362
153
|
raise Bolt::Node::FileError.new("Could not make tempdir: #{result.stderr}", 'TEMPDIR_ERROR')
|
363
154
|
end
|
@@ -368,9 +159,7 @@ PS
|
|
368
159
|
dir = make_tempdir
|
369
160
|
yield dir
|
370
161
|
ensure
|
371
|
-
execute(
|
372
|
-
Remove-Item -Force -Recurse -Path "#{dir}"
|
373
|
-
PS
|
162
|
+
execute(Powershell.rmdir(dir))
|
374
163
|
end
|
375
164
|
|
376
165
|
def validate_extensions(ext)
|
data/lib/bolt/version.rb
CHANGED
@@ -166,7 +166,7 @@ module BoltServer
|
|
166
166
|
expired_time = Time.now - purge_ttl
|
167
167
|
@cache_dir_mutex.with_write_lock do
|
168
168
|
Dir.glob(File.join(@cache_dir, '*')).select { |f| File.directory?(f) }.each do |dir|
|
169
|
-
if (mtime = File.mtime(dir)) < expired_time
|
169
|
+
if (mtime = File.mtime(dir)) < expired_time && dir != tmppath
|
170
170
|
@logger.debug("Removing #{dir}, last used at #{mtime}")
|
171
171
|
FileUtils.remove_dir(dir)
|
172
172
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bolt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -156,6 +156,20 @@ dependencies:
|
|
156
156
|
- - "<"
|
157
157
|
- !ruby/object:Gem::Version
|
158
158
|
version: '7'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: puppet-resource_api
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
159
173
|
- !ruby/object:Gem::Dependency
|
160
174
|
name: r10k
|
161
175
|
requirement: !ruby/object:Gem::Requirement
|
@@ -338,6 +352,7 @@ files:
|
|
338
352
|
- lib/bolt/target.rb
|
339
353
|
- lib/bolt/task.rb
|
340
354
|
- lib/bolt/task/puppet_server.rb
|
355
|
+
- lib/bolt/task/remote.rb
|
341
356
|
- lib/bolt/transport/base.rb
|
342
357
|
- lib/bolt/transport/docker.rb
|
343
358
|
- lib/bolt/transport/docker/connection.rb
|
@@ -345,6 +360,8 @@ files:
|
|
345
360
|
- lib/bolt/transport/local/shell.rb
|
346
361
|
- lib/bolt/transport/orch.rb
|
347
362
|
- lib/bolt/transport/orch/connection.rb
|
363
|
+
- lib/bolt/transport/powershell.rb
|
364
|
+
- lib/bolt/transport/remote.rb
|
348
365
|
- lib/bolt/transport/ssh.rb
|
349
366
|
- lib/bolt/transport/ssh/connection.rb
|
350
367
|
- lib/bolt/transport/winrm.rb
|