pdk 2.7.1 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/README.md +10 -50
- data/lib/pdk/analytics/client/google_analytics.rb +22 -26
- data/lib/pdk/analytics/util.rb +0 -1
- data/lib/pdk/analytics.rb +1 -1
- data/lib/pdk/bolt.rb +1 -0
- data/lib/pdk/cli/build.rb +53 -56
- data/lib/pdk/cli/bundle.rb +34 -33
- data/lib/pdk/cli/console.rb +136 -134
- data/lib/pdk/cli/convert.rb +39 -41
- data/lib/pdk/cli/env.rb +49 -47
- data/lib/pdk/cli/errors.rb +1 -2
- data/lib/pdk/cli/exec/command.rb +23 -29
- data/lib/pdk/cli/exec/interactive_command.rb +7 -12
- data/lib/pdk/cli/exec.rb +4 -11
- data/lib/pdk/cli/exec_group.rb +3 -2
- data/lib/pdk/cli/get/config.rb +21 -19
- data/lib/pdk/cli/get.rb +15 -13
- data/lib/pdk/cli/new/class.rb +22 -22
- data/lib/pdk/cli/new/defined_type.rb +22 -22
- data/lib/pdk/cli/new/fact.rb +19 -19
- data/lib/pdk/cli/new/function.rb +20 -20
- data/lib/pdk/cli/new/module.rb +40 -38
- data/lib/pdk/cli/new/provider.rb +19 -19
- data/lib/pdk/cli/new/task.rb +23 -23
- data/lib/pdk/cli/new/test.rb +50 -48
- data/lib/pdk/cli/new/transport.rb +18 -18
- data/lib/pdk/cli/new.rb +11 -9
- data/lib/pdk/cli/release/prep.rb +27 -25
- data/lib/pdk/cli/release/publish.rb +39 -37
- data/lib/pdk/cli/release.rb +152 -149
- data/lib/pdk/cli/remove/config.rb +63 -60
- data/lib/pdk/cli/remove.rb +15 -13
- data/lib/pdk/cli/set/config.rb +91 -89
- data/lib/pdk/cli/set.rb +15 -13
- data/lib/pdk/cli/test/unit.rb +71 -69
- data/lib/pdk/cli/test.rb +9 -7
- data/lib/pdk/cli/update.rb +33 -38
- data/lib/pdk/cli/util/command_redirector.rb +10 -1
- data/lib/pdk/cli/util/interview.rb +11 -4
- data/lib/pdk/cli/util/option_normalizer.rb +3 -5
- data/lib/pdk/cli/util/option_validator.rb +7 -9
- data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
- data/lib/pdk/cli/util.rb +32 -48
- data/lib/pdk/cli/validate.rb +98 -96
- data/lib/pdk/cli.rb +124 -120
- data/lib/pdk/config/ini_file.rb +4 -3
- data/lib/pdk/config/ini_file_setting.rb +6 -10
- data/lib/pdk/config/json.rb +1 -0
- data/lib/pdk/config/json_schema_namespace.rb +5 -10
- data/lib/pdk/config/json_schema_setting.rb +3 -5
- data/lib/pdk/config/json_with_schema.rb +2 -4
- data/lib/pdk/config/namespace.rb +22 -14
- data/lib/pdk/config/setting.rb +5 -6
- data/lib/pdk/config/task_schema.json +116 -0
- data/lib/pdk/config/validator.rb +4 -4
- data/lib/pdk/config/yaml.rb +3 -8
- data/lib/pdk/config/yaml_with_schema.rb +4 -12
- data/lib/pdk/config.rb +47 -51
- data/lib/pdk/context/control_repo.rb +3 -2
- data/lib/pdk/context/module.rb +2 -2
- data/lib/pdk/context/none.rb +2 -2
- data/lib/pdk/context.rb +4 -5
- data/lib/pdk/control_repo.rb +3 -4
- data/lib/pdk/generate/defined_type.rb +3 -3
- data/lib/pdk/generate/fact.rb +3 -2
- data/lib/pdk/generate/function.rb +5 -4
- data/lib/pdk/generate/module.rb +91 -106
- data/lib/pdk/generate/provider.rb +5 -4
- data/lib/pdk/generate/puppet_class.rb +3 -3
- data/lib/pdk/generate/puppet_object.rb +9 -12
- data/lib/pdk/generate/task.rb +11 -10
- data/lib/pdk/generate/transport.rb +8 -7
- data/lib/pdk/generate.rb +1 -1
- data/lib/pdk/logger.rb +3 -2
- data/lib/pdk/module/build.rb +34 -49
- data/lib/pdk/module/convert.rb +13 -22
- data/lib/pdk/module/metadata.rb +53 -61
- data/lib/pdk/module/release.rb +19 -25
- data/lib/pdk/module/update.rb +4 -13
- data/lib/pdk/module/update_manager.rb +18 -25
- data/lib/pdk/module.rb +1 -1
- data/lib/pdk/monkey_patches.rb +268 -0
- data/lib/pdk/report/event.rb +12 -37
- data/lib/pdk/report.rb +11 -7
- data/lib/pdk/template/fetcher/git.rb +7 -8
- data/lib/pdk/template/fetcher/local.rb +1 -0
- data/lib/pdk/template/fetcher.rb +4 -2
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
- data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
- data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
- data/lib/pdk/template/renderer/v1.rb +1 -1
- data/lib/pdk/template/renderer.rb +1 -0
- data/lib/pdk/template/template_dir.rb +3 -3
- data/lib/pdk/template.rb +2 -6
- data/lib/pdk/tests/unit.rb +36 -25
- data/lib/pdk/util/bundler.rb +10 -14
- data/lib/pdk/util/changelog_generator.rb +15 -12
- data/lib/pdk/util/env.rb +1 -0
- data/lib/pdk/util/filesystem.rb +18 -17
- data/lib/pdk/util/git.rb +16 -21
- data/lib/pdk/util/json_finder.rb +7 -6
- data/lib/pdk/util/puppet_strings.rb +1 -1
- data/lib/pdk/util/puppet_version.rb +21 -68
- data/lib/pdk/util/ruby_version.rb +9 -13
- data/lib/pdk/util/template_uri.rb +17 -29
- data/lib/pdk/util/vendored_file.rb +5 -18
- data/lib/pdk/util/windows/api_types.rb +70 -64
- data/lib/pdk/util/windows/file.rb +31 -27
- data/lib/pdk/util/windows/process.rb +59 -61
- data/lib/pdk/util/windows/string.rb +19 -12
- data/lib/pdk/util.rb +13 -21
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
- data/lib/pdk/validate/external_command_validator.rb +6 -1
- data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
- data/lib/pdk/validate/invokable_validator.rb +30 -20
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
- data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
- data/lib/pdk/validate/validator.rb +4 -2
- data/lib/pdk/validate/validator_group.rb +6 -3
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
- data/lib/pdk/validate.rb +6 -6
- data/lib/pdk/version.rb +2 -2
- data/lib/pdk.rb +12 -12
- metadata +27 -35
- data/lib/pdk/cli/config/get.rb +0 -26
- data/lib/pdk/cli/config.rb +0 -22
- data/lib/pdk/cli/module/build.rb +0 -12
- data/lib/pdk/cli/module/generate.rb +0 -47
- data/lib/pdk/cli/module.rb +0 -14
@@ -1,81 +1,87 @@
|
|
1
1
|
require 'ffi'
|
2
2
|
require 'pdk/util/windows/string'
|
3
3
|
|
4
|
-
module PDK
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module PDK
|
5
|
+
module Util
|
6
|
+
module Windows
|
7
|
+
module APITypes
|
8
|
+
module ::FFI
|
9
|
+
module Library
|
10
|
+
def attach_function_private(*args)
|
11
|
+
attach_function(*args)
|
12
|
+
private args[0]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
11
16
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
module ::FFI
|
18
|
+
class Pointer
|
19
|
+
def self.from_string_to_wide_string(str, &_block)
|
20
|
+
str = PDK::Util::Windows::String.wide_string(str)
|
21
|
+
FFI::MemoryPointer.new(:byte, str.bytesize) do |ptr|
|
22
|
+
# uchar here is synonymous with byte
|
23
|
+
ptr.put_array_of_uchar(0, str.bytes.to_a)
|
18
24
|
|
19
|
-
|
20
|
-
|
25
|
+
yield ptr
|
26
|
+
end
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
# ptr has already had free called, so nothing to return
|
29
|
+
nil
|
30
|
+
end
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
error: e.inspect,
|
35
|
-
}
|
36
|
-
raise
|
37
|
-
end
|
32
|
+
def read_wide_string(char_length, dst_encoding = Encoding::UTF_8, encode_options = {})
|
33
|
+
# char_length is number of wide chars (typically excluding NULLs), *not* bytes
|
34
|
+
str = get_bytes(0, char_length * 2).force_encoding('UTF-16LE')
|
35
|
+
str.encode(dst_encoding, str.encoding, **encode_options)
|
36
|
+
rescue StandardError => e
|
37
|
+
PDK.logger.debug format('Unable to convert value %{string} to encoding %{encoding} due to %{error}', string: str.dump, encoding: dst_encoding, error: e.inspect)
|
38
|
+
raise
|
39
|
+
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def read_arbitrary_wide_string_up_to(max_char_length = 512, null_terminator = :single_null, encode_options = {})
|
42
|
+
unless [:single_null, :double_null].include?(null_terminator)
|
43
|
+
raise ArgumentError,
|
44
|
+
format('Unable to read wide strings with %{null_terminator} terminal nulls', null_terminator: null_terminator)
|
45
|
+
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
+
terminator_width = null_terminator == :single_null ? 1 : 2
|
48
|
+
reader_method = null_terminator == :single_null ? :get_uint16 : :get_uint32
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
# Look for the null_terminator; if found, read up to that null
|
51
|
+
# (exclusive)
|
52
|
+
(0...max_char_length - terminator_width).each do |i|
|
53
|
+
return read_wide_string(i, Encoding::UTF_8, encode_options) if send(reader_method, (i * 2)).zero?
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
# String is longer than the max, read just up to the max
|
57
|
+
read_wide_string(max_char_length, Encoding::UTF_8, encode_options)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
58
61
|
|
59
|
-
|
60
|
-
|
62
|
+
# FFI Types
|
63
|
+
# https://github.com/ffi/ffi/wiki/Types
|
61
64
|
|
62
|
-
|
63
|
-
|
65
|
+
# Windows - Common Data Types
|
66
|
+
# https://msdn.microsoft.com/en-us/library/cc230309.aspx
|
64
67
|
|
65
|
-
|
66
|
-
|
68
|
+
# Windows Data Types
|
69
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
|
67
70
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
FFI.typedef :uint32, :dword
|
72
|
+
# buffer_inout is similar to pointer (platform specific), but optimized for buffers
|
73
|
+
FFI.typedef :buffer_inout, :lpwstr
|
74
|
+
# buffer_in is similar to pointer (platform specific), but optimized for CONST read only buffers
|
75
|
+
FFI.typedef :buffer_in, :lpcwstr
|
76
|
+
# 8 bits per byte
|
77
|
+
FFI.typedef :uchar, :byte
|
78
|
+
FFI.typedef :uint16, :wchar
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
# FFI bool can be only 1 byte at times,
|
81
|
+
# Win32 BOOL is a signed int, and is always 4 bytes, even on x64
|
82
|
+
# https://blogs.msdn.com/b/oldnewthing/archive/2011/03/28/10146459.aspx
|
83
|
+
FFI.typedef :int32, :win32_bool
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
81
87
|
end
|
@@ -1,36 +1,40 @@
|
|
1
1
|
require 'pdk/util/windows'
|
2
2
|
|
3
|
-
module PDK
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module PDK
|
4
|
+
module Util
|
5
|
+
module Windows
|
6
|
+
module File
|
7
|
+
require 'ffi'
|
8
|
+
extend FFI::Library
|
9
|
+
extend PDK::Util::Windows::String
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def get_long_pathname(path)
|
12
|
+
converted = ''
|
13
|
+
FFI::Pointer.from_string_to_wide_string(path) do |path_ptr|
|
14
|
+
# includes terminating NULL
|
15
|
+
buffer_size = GetLongPathNameW(path_ptr, FFI::Pointer::NULL, 0)
|
16
|
+
FFI::MemoryPointer.new(:wchar, buffer_size) do |converted_ptr|
|
17
|
+
raise 'Failed to call GetLongPathName' if GetLongPathNameW(path_ptr, converted_ptr, buffer_size) == PDK::Util::Windows::WIN32_FALSE
|
18
|
+
|
19
|
+
converted = converted_ptr.read_wide_string(buffer_size - 1)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
converted
|
16
24
|
end
|
25
|
+
module_function :get_long_pathname
|
26
|
+
|
27
|
+
ffi_convention :stdcall
|
17
28
|
|
18
|
-
|
29
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa364980(v=vs.85).aspx
|
30
|
+
# DWORD WINAPI GetLongPathName(
|
31
|
+
# _In_ LPCTSTR lpszShortPath,
|
32
|
+
# _Out_ LPTSTR lpszLongPath,
|
33
|
+
# _In_ DWORD cchBuffer
|
34
|
+
# );
|
35
|
+
ffi_lib :kernel32
|
36
|
+
attach_function :GetLongPathNameW, [:lpcwstr, :lpwstr, :dword], :dword
|
19
37
|
end
|
20
38
|
end
|
21
|
-
|
22
|
-
converted
|
23
39
|
end
|
24
|
-
module_function :get_long_pathname
|
25
|
-
|
26
|
-
ffi_convention :stdcall
|
27
|
-
|
28
|
-
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa364980(v=vs.85).aspx
|
29
|
-
# DWORD WINAPI GetLongPathName(
|
30
|
-
# _In_ LPCTSTR lpszShortPath,
|
31
|
-
# _Out_ LPTSTR lpszLongPath,
|
32
|
-
# _In_ DWORD cchBuffer
|
33
|
-
# );
|
34
|
-
ffi_lib :kernel32
|
35
|
-
attach_function :GetLongPathNameW, [:lpcwstr, :lpwstr, :dword], :dword
|
36
40
|
end
|
@@ -1,76 +1,74 @@
|
|
1
1
|
require 'pdk/util/windows'
|
2
2
|
|
3
|
-
module PDK
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module PDK
|
4
|
+
module Util
|
5
|
+
module Windows
|
6
|
+
module Process
|
7
|
+
require 'ffi'
|
8
|
+
extend PDK::Util::Windows::String
|
9
|
+
extend FFI::Library
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
def environment_hash
|
12
|
+
env_ptr = GetEnvironmentStringsW()
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
contains_unicode_replacement = lambda do |string|
|
15
|
+
return false unless string.include?("\uFFFD")
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
PDK.logger.warning "Discarding environment variable #{string} which contains invalid bytes"
|
18
|
+
true
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
module_function :environment_hash
|
21
|
+
# pass :invalid => :replace to the Ruby String#encode to use replacement
|
22
|
+
# characters
|
23
|
+
pairs = env_ptr.read_arbitrary_wide_string_up_to(65_534, :double_null, invalid: :replace)
|
24
|
+
.split(?\x00)
|
25
|
+
.reject { |env_str| env_str.nil? || env_str.empty? || env_str[0] == '=' }
|
26
|
+
.reject { |env_str| contains_unicode_replacement.call(env_str) }
|
27
|
+
.map { |env_pair| env_pair.split('=', 2) }
|
28
|
+
pairs.to_h
|
29
|
+
ensure
|
30
|
+
PDK.logger.debug 'FreeEnvironmentStringsW memory leak' if env_ptr && !env_ptr.null? && (FreeEnvironmentStringsW(env_ptr) == PDK::Util::Windows::WIN32_FALSE)
|
31
|
+
end
|
32
|
+
module_function :environment_hash
|
34
33
|
|
35
|
-
|
36
|
-
|
34
|
+
def set_environment_variable(name, val)
|
35
|
+
raise ArgumentError, 'Environment variable name must not be nil or empty' if name.nil? || name.empty?
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
raise 'Failed to set environment variaible: %{name}' % { name: name }
|
37
|
+
FFI::MemoryPointer.from_string_to_wide_string(name) do |name_ptr|
|
38
|
+
if val.nil?
|
39
|
+
raise format('Failed to remove environment variable: %{name}', name: name) if SetEnvironmentVariableW(name_ptr, FFI::MemoryPointer::NULL) == PDK::Util::Windows::WIN32_FALSE
|
40
|
+
else
|
41
|
+
FFI::MemoryPointer.from_string_to_wide_string(val) do |val_ptr|
|
42
|
+
raise format('Failed to set environment variaible: %{name}', name: name) if SetEnvironmentVariableW(name_ptr, val_ptr) == PDK::Util::Windows::WIN32_FALSE
|
43
|
+
end
|
44
|
+
end
|
47
45
|
end
|
48
46
|
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
module_function :set_environment_variable
|
47
|
+
module_function :set_environment_variable
|
53
48
|
|
54
|
-
|
49
|
+
ffi_convention :stdcall
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms683187(v=vs.85).aspx
|
52
|
+
# LPTCH GetEnvironmentStrings(void);
|
53
|
+
ffi_lib :kernel32
|
54
|
+
attach_function_private :GetEnvironmentStringsW, [], :pointer
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
56
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms683151(v=vs.85).aspx
|
57
|
+
# BOOL FreeEnvironmentStrings(
|
58
|
+
# _In_ LPTCH lpszEnvironmentBlock
|
59
|
+
# );
|
60
|
+
ffi_lib :kernel32
|
61
|
+
attach_function_private :FreeEnvironmentStringsW, [:pointer], :win32_bool
|
67
62
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
63
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms686206(v=vs.85).aspx
|
64
|
+
# BOOL WINAPI SetEnvironmentVariableW(
|
65
|
+
# _In_ LPCTSTR lpName,
|
66
|
+
# _In_opt_ LPCTSTR lpValue
|
67
|
+
# );
|
68
|
+
ffi_lib :kernel32
|
69
|
+
attach_function_private :SetEnvironmentVariableW, [:lpcwstr, :lpcwstr],
|
70
|
+
:win32_bool
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
76
74
|
end
|
@@ -1,16 +1,23 @@
|
|
1
1
|
require 'pdk/util/windows'
|
2
2
|
|
3
|
-
module PDK
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
module PDK
|
4
|
+
module Util
|
5
|
+
module Windows
|
6
|
+
module String
|
7
|
+
def wide_string(str)
|
8
|
+
# if given a nil string, assume caller wants to pass a nil pointer to win32
|
9
|
+
return if str.nil?
|
10
|
+
|
11
|
+
# ruby (< 2.1) does not respect multibyte terminators, so it is possible
|
12
|
+
# for a string to contain a single trailing null byte, followed by garbage
|
13
|
+
# causing buffer overruns.
|
14
|
+
#
|
15
|
+
# See http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?revision=41920&view=revision
|
16
|
+
newstr = str + "\0".encode(str.encoding)
|
17
|
+
newstr.encode!('UTF-16LE')
|
18
|
+
end
|
19
|
+
module_function :wide_string
|
20
|
+
end
|
21
|
+
end
|
14
22
|
end
|
15
|
-
module_function :wide_string
|
16
23
|
end
|
data/lib/pdk/util.rb
CHANGED
@@ -22,18 +22,9 @@ module PDK
|
|
22
22
|
autoload :VendoredFile, 'pdk/util/vendored_file'
|
23
23
|
autoload :Version, 'pdk/util/version'
|
24
24
|
|
25
|
-
MODULE_FOLDERS =
|
26
|
-
|
27
|
-
|
28
|
-
lib/puppet_x
|
29
|
-
lib/facter
|
30
|
-
tasks
|
31
|
-
facts.d
|
32
|
-
functions
|
33
|
-
types
|
34
|
-
].freeze
|
35
|
-
|
36
|
-
#:nocov:
|
25
|
+
MODULE_FOLDERS = ['manifests', 'lib/puppet', 'lib/puppet_x', 'lib/facter', 'tasks', 'facts.d', 'functions', 'types'].freeze
|
26
|
+
|
27
|
+
# :nocov:
|
37
28
|
# This method just wraps core Ruby functionality and
|
38
29
|
# can be ignored for code coverage
|
39
30
|
|
@@ -41,7 +32,7 @@ module PDK
|
|
41
32
|
def exit_process(exit_code)
|
42
33
|
exit exit_code
|
43
34
|
end
|
44
|
-
|
35
|
+
# :nocov:
|
45
36
|
|
46
37
|
# Searches upwards from current working directory for the given target file.
|
47
38
|
#
|
@@ -57,6 +48,7 @@ module PDK
|
|
57
48
|
until !PDK::Util::Filesystem.directory?(current) || current == previous
|
58
49
|
filename = File.join(current, target)
|
59
50
|
return filename if PDK::Util::Filesystem.file?(filename)
|
51
|
+
|
60
52
|
previous = current
|
61
53
|
current = PDK::Util::Filesystem.expand_path('..', current)
|
62
54
|
end
|
@@ -84,9 +76,8 @@ module PDK
|
|
84
76
|
# @return [String] Canonical path
|
85
77
|
def canonical_path(path)
|
86
78
|
if Gem.win_platform?
|
87
|
-
unless PDK::Util::Filesystem.exist?(path)
|
88
|
-
|
89
|
-
end
|
79
|
+
raise PDK::CLI::FatalError, format("Cannot resolve a full path to '%{path}', as it does not currently exist.", path: path) unless PDK::Util::Filesystem.exist?(path)
|
80
|
+
|
90
81
|
PDK::Util::Windows::File.get_long_pathname(path)
|
91
82
|
else
|
92
83
|
PDK::Util::Filesystem.expand_path(path)
|
@@ -104,7 +95,7 @@ module PDK
|
|
104
95
|
def development_mode?
|
105
96
|
require 'pdk/util/version'
|
106
97
|
|
107
|
-
|
98
|
+
!PDK::Util::Version.git_ref.nil? || PDK::VERSION.end_with?('.pre')
|
108
99
|
end
|
109
100
|
module_function :development_mode?
|
110
101
|
|
@@ -115,6 +106,7 @@ module PDK
|
|
115
106
|
|
116
107
|
def pdk_package_basedir
|
117
108
|
raise PDK::CLI::FatalError, 'Package basedir requested for non-package install.' unless package_install?
|
109
|
+
|
118
110
|
require 'pdk/util/version'
|
119
111
|
|
120
112
|
File.dirname(PDK::Util::Version.version_file)
|
@@ -152,6 +144,7 @@ module PDK
|
|
152
144
|
return @system_configdir = File.join(File::SEPARATOR, 'opt', 'puppetlabs', 'pdk', 'config') unless Gem.win_platform?
|
153
145
|
|
154
146
|
return @system_configdir = File.join(PDK::Util::Env['ProgramData'], 'PuppetLabs', 'PDK') unless PDK::Util::Env['ProgramData'].nil?
|
147
|
+
|
155
148
|
@system_configdir = File.join(PDK::Util::Env['AllUsersProfile'], 'PuppetLabs', 'PDK')
|
156
149
|
end
|
157
150
|
module_function :system_configdir
|
@@ -166,8 +159,6 @@ module PDK
|
|
166
159
|
File.dirname(metadata_path)
|
167
160
|
elsif in_module_root?
|
168
161
|
Dir.pwd
|
169
|
-
else
|
170
|
-
nil
|
171
162
|
end
|
172
163
|
end
|
173
164
|
module_function :module_root
|
@@ -263,9 +254,10 @@ module PDK
|
|
263
254
|
# @return [Object] duplicate of the original object
|
264
255
|
# the current working dir does not appear to be within a module.
|
265
256
|
def deep_duplicate(object)
|
266
|
-
|
257
|
+
case object
|
258
|
+
when Array
|
267
259
|
object.map { |item| deep_duplicate(item) }
|
268
|
-
|
260
|
+
when Hash
|
269
261
|
hash = object.dup
|
270
262
|
hash.each_pair { |key, value| hash[key] = deep_duplicate(value) }
|
271
263
|
hash
|
@@ -4,7 +4,7 @@ module PDK
|
|
4
4
|
module Validate
|
5
5
|
module ControlRepo
|
6
6
|
class EnvironmentConfValidator < InternalRubyValidator
|
7
|
-
ALLOWED_SETTINGS =
|
7
|
+
ALLOWED_SETTINGS = ['modulepath', 'manifest', 'config_version', 'environment_timeout'].freeze
|
8
8
|
|
9
9
|
def name
|
10
10
|
'environment-conf'
|
@@ -19,9 +19,7 @@ module PDK
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def spinner_text
|
22
|
-
'Checking Puppet Environment settings (%{patterns}).'
|
23
|
-
patterns: pattern.join(' '),
|
24
|
-
}
|
22
|
+
format('Checking Puppet Environment settings (%{patterns}).', patterns: pattern.join(' '))
|
25
23
|
end
|
26
24
|
|
27
25
|
def validate_target(report, target)
|
@@ -31,7 +29,7 @@ module PDK
|
|
31
29
|
source: name,
|
32
30
|
state: :failure,
|
33
31
|
severity: 'error',
|
34
|
-
message: 'Could not be read.'
|
32
|
+
message: 'Could not be read.'
|
35
33
|
)
|
36
34
|
return 1
|
37
35
|
end
|
@@ -44,19 +42,20 @@ module PDK
|
|
44
42
|
# Remove the 'environment.' setting_name prefix
|
45
43
|
setting_name = setting_name.slice(12..-1)
|
46
44
|
next if ALLOWED_SETTINGS.include?(setting_name)
|
45
|
+
|
47
46
|
# A hash indicates that the ini file has a section in it.
|
48
47
|
message = if setting_value.is_a?(Hash)
|
49
|
-
"Invalid section '%{name}'"
|
48
|
+
format("Invalid section '%{name}'", name: setting_name)
|
50
49
|
else
|
51
|
-
"Invalid setting '%{name}'"
|
50
|
+
format("Invalid setting '%{name}'", name: setting_name)
|
52
51
|
end
|
53
52
|
|
54
53
|
report.add_event(
|
55
|
-
file:
|
56
|
-
source:
|
57
|
-
state:
|
54
|
+
file: target,
|
55
|
+
source: name,
|
56
|
+
state: :failure,
|
58
57
|
severity: 'error',
|
59
|
-
message:
|
58
|
+
message: message
|
60
59
|
)
|
61
60
|
is_valid = false
|
62
61
|
end
|
@@ -64,32 +63,33 @@ module PDK
|
|
64
63
|
timeout = env_conf.fetch('environment_timeout', nil)
|
65
64
|
unless timeout.nil? || timeout == '0' || timeout == 'unlimited'
|
66
65
|
report.add_event(
|
67
|
-
file:
|
68
|
-
source:
|
69
|
-
state:
|
66
|
+
file: target,
|
67
|
+
source: name,
|
68
|
+
state: :failure,
|
70
69
|
severity: 'error',
|
71
|
-
message:
|
70
|
+
message: format("environment_timeout is set to '%{timeout}' but should be 0, 'unlimited' or not set.", timeout: timeout)
|
72
71
|
)
|
73
72
|
is_valid = false
|
74
73
|
end
|
75
74
|
|
76
75
|
return 1 unless is_valid
|
76
|
+
|
77
77
|
report.add_event(
|
78
|
-
file:
|
79
|
-
source:
|
80
|
-
state:
|
81
|
-
severity: 'ok'
|
78
|
+
file: target,
|
79
|
+
source: name,
|
80
|
+
state: :passed,
|
81
|
+
severity: 'ok'
|
82
82
|
)
|
83
|
-
|
83
|
+
0
|
84
84
|
rescue StandardError => e
|
85
85
|
report.add_event(
|
86
|
-
file:
|
87
|
-
source:
|
88
|
-
state:
|
86
|
+
file: target,
|
87
|
+
source: name,
|
88
|
+
state: :failure,
|
89
89
|
severity: 'error',
|
90
|
-
message:
|
90
|
+
message: e.message
|
91
91
|
)
|
92
|
-
|
92
|
+
1
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
@@ -76,7 +76,7 @@ module PDK
|
|
76
76
|
PDK::Util::RubyVersion.bin_path,
|
77
77
|
File.join(PDK::Util::RubyVersion.gem_home, 'bin'),
|
78
78
|
PDK::Util::RubyVersion.gem_paths_raw.map { |gem_path_raw| File.join(gem_path_raw, 'bin') },
|
79
|
-
PDK::Util.package_install? ? File.join(PDK::Util.pdk_package_basedir, 'bin') : nil
|
79
|
+
PDK::Util.package_install? ? File.join(PDK::Util.pdk_package_basedir, 'bin') : nil
|
80
80
|
].flatten.compact
|
81
81
|
end
|
82
82
|
|
@@ -86,14 +86,17 @@ module PDK
|
|
86
86
|
# @api private
|
87
87
|
def cmd_path
|
88
88
|
return @cmd_path unless @cmd_path.nil?
|
89
|
+
|
89
90
|
@cmd_path = File.join(context.root_path, 'bin', cmd)
|
90
91
|
# Return the path to the command if it exists on disk, or we have a gemfile (i.e. Bundled install)
|
91
92
|
# The Bundle may be created after the prepare_invoke so if the file doesn't exist, it may not be an error
|
92
93
|
return @cmd_path if PDK::Util::Filesystem.exist?(@cmd_path) || !PDK::Util::Bundler::BundleHelper.new.gemfile.nil?
|
94
|
+
|
93
95
|
# But if there is no Gemfile AND cmd doesn't exist in the default path, we need to go searching...
|
94
96
|
@cmd_path = alternate_bin_paths.map { |alternate_path| File.join(alternate_path, cmd) }
|
95
97
|
.find { |path| PDK::Util::Filesystem.exist?(path) }
|
96
98
|
return @cmd_path unless @cmd_path.nil?
|
99
|
+
|
97
100
|
# If we can't find it anywhere, just let the OS find it
|
98
101
|
@cmd_path = cmd
|
99
102
|
end
|
@@ -121,6 +124,7 @@ module PDK
|
|
121
124
|
# @see PDK::Validate::Validator.prepare_invoke!
|
122
125
|
def prepare_invoke!
|
123
126
|
return if @prepared
|
127
|
+
|
124
128
|
super
|
125
129
|
|
126
130
|
@targets, @skipped, @invalid = parse_targets
|
@@ -144,6 +148,7 @@ module PDK
|
|
144
148
|
@commands = []
|
145
149
|
target_groups.each do |invokation_targets|
|
146
150
|
next if invokation_targets.empty? && !allow_empty_targets?
|
151
|
+
|
147
152
|
cmd_argv = parse_options(invokation_targets).unshift(cmd_path).compact
|
148
153
|
cmd_argv.unshift(File.join(PDK::Util::RubyVersion.bin_path, 'ruby.exe'), '-W0') if Gem.win_platform?
|
149
154
|
|