pdk 2.7.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +2 -48
  4. data/lib/pdk/analytics/client/google_analytics.rb +22 -26
  5. data/lib/pdk/analytics/util.rb +0 -1
  6. data/lib/pdk/analytics.rb +1 -1
  7. data/lib/pdk/bolt.rb +1 -0
  8. data/lib/pdk/cli/build.rb +53 -56
  9. data/lib/pdk/cli/bundle.rb +34 -33
  10. data/lib/pdk/cli/console.rb +136 -134
  11. data/lib/pdk/cli/convert.rb +39 -41
  12. data/lib/pdk/cli/env.rb +49 -47
  13. data/lib/pdk/cli/errors.rb +1 -2
  14. data/lib/pdk/cli/exec/command.rb +23 -29
  15. data/lib/pdk/cli/exec/interactive_command.rb +7 -12
  16. data/lib/pdk/cli/exec.rb +4 -11
  17. data/lib/pdk/cli/exec_group.rb +3 -2
  18. data/lib/pdk/cli/get/config.rb +21 -19
  19. data/lib/pdk/cli/get.rb +15 -13
  20. data/lib/pdk/cli/new/class.rb +22 -22
  21. data/lib/pdk/cli/new/defined_type.rb +22 -22
  22. data/lib/pdk/cli/new/fact.rb +19 -19
  23. data/lib/pdk/cli/new/function.rb +20 -20
  24. data/lib/pdk/cli/new/module.rb +40 -38
  25. data/lib/pdk/cli/new/provider.rb +19 -19
  26. data/lib/pdk/cli/new/task.rb +23 -23
  27. data/lib/pdk/cli/new/test.rb +50 -48
  28. data/lib/pdk/cli/new/transport.rb +18 -18
  29. data/lib/pdk/cli/new.rb +11 -9
  30. data/lib/pdk/cli/release/prep.rb +27 -25
  31. data/lib/pdk/cli/release/publish.rb +39 -37
  32. data/lib/pdk/cli/release.rb +152 -149
  33. data/lib/pdk/cli/remove/config.rb +63 -60
  34. data/lib/pdk/cli/remove.rb +15 -13
  35. data/lib/pdk/cli/set/config.rb +91 -89
  36. data/lib/pdk/cli/set.rb +15 -13
  37. data/lib/pdk/cli/test/unit.rb +71 -69
  38. data/lib/pdk/cli/test.rb +9 -7
  39. data/lib/pdk/cli/update.rb +33 -38
  40. data/lib/pdk/cli/util/command_redirector.rb +10 -1
  41. data/lib/pdk/cli/util/interview.rb +11 -4
  42. data/lib/pdk/cli/util/option_normalizer.rb +2 -4
  43. data/lib/pdk/cli/util/option_validator.rb +7 -9
  44. data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
  45. data/lib/pdk/cli/util.rb +32 -48
  46. data/lib/pdk/cli/validate.rb +98 -96
  47. data/lib/pdk/cli.rb +124 -120
  48. data/lib/pdk/config/ini_file.rb +4 -3
  49. data/lib/pdk/config/ini_file_setting.rb +6 -10
  50. data/lib/pdk/config/json.rb +1 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +5 -10
  52. data/lib/pdk/config/json_schema_setting.rb +3 -5
  53. data/lib/pdk/config/json_with_schema.rb +2 -4
  54. data/lib/pdk/config/namespace.rb +19 -13
  55. data/lib/pdk/config/setting.rb +5 -6
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +4 -4
  58. data/lib/pdk/config/yaml.rb +3 -8
  59. data/lib/pdk/config/yaml_with_schema.rb +4 -12
  60. data/lib/pdk/config.rb +47 -51
  61. data/lib/pdk/context/control_repo.rb +3 -2
  62. data/lib/pdk/context/module.rb +2 -2
  63. data/lib/pdk/context/none.rb +2 -2
  64. data/lib/pdk/context.rb +4 -5
  65. data/lib/pdk/control_repo.rb +3 -4
  66. data/lib/pdk/generate/defined_type.rb +3 -3
  67. data/lib/pdk/generate/fact.rb +3 -2
  68. data/lib/pdk/generate/function.rb +5 -4
  69. data/lib/pdk/generate/module.rb +91 -106
  70. data/lib/pdk/generate/provider.rb +5 -4
  71. data/lib/pdk/generate/puppet_class.rb +3 -3
  72. data/lib/pdk/generate/puppet_object.rb +9 -12
  73. data/lib/pdk/generate/task.rb +11 -10
  74. data/lib/pdk/generate/transport.rb +8 -7
  75. data/lib/pdk/generate.rb +1 -1
  76. data/lib/pdk/logger.rb +3 -2
  77. data/lib/pdk/module/build.rb +34 -49
  78. data/lib/pdk/module/convert.rb +13 -22
  79. data/lib/pdk/module/metadata.rb +53 -61
  80. data/lib/pdk/module/release.rb +19 -25
  81. data/lib/pdk/module/update.rb +4 -13
  82. data/lib/pdk/module/update_manager.rb +18 -25
  83. data/lib/pdk/module.rb +1 -1
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +12 -37
  86. data/lib/pdk/report.rb +4 -4
  87. data/lib/pdk/template/fetcher/git.rb +7 -8
  88. data/lib/pdk/template/fetcher/local.rb +1 -0
  89. data/lib/pdk/template/fetcher.rb +4 -2
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
  91. data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
  92. data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
  93. data/lib/pdk/template/renderer/v1.rb +1 -1
  94. data/lib/pdk/template/renderer.rb +1 -0
  95. data/lib/pdk/template/template_dir.rb +3 -3
  96. data/lib/pdk/template.rb +2 -6
  97. data/lib/pdk/tests/unit.rb +36 -25
  98. data/lib/pdk/util/bundler.rb +10 -14
  99. data/lib/pdk/util/changelog_generator.rb +15 -12
  100. data/lib/pdk/util/env.rb +1 -0
  101. data/lib/pdk/util/filesystem.rb +18 -17
  102. data/lib/pdk/util/git.rb +16 -21
  103. data/lib/pdk/util/json_finder.rb +7 -6
  104. data/lib/pdk/util/puppet_strings.rb +1 -1
  105. data/lib/pdk/util/puppet_version.rb +16 -67
  106. data/lib/pdk/util/ruby_version.rb +9 -13
  107. data/lib/pdk/util/template_uri.rb +17 -29
  108. data/lib/pdk/util/vendored_file.rb +5 -18
  109. data/lib/pdk/util/windows/api_types.rb +70 -64
  110. data/lib/pdk/util/windows/file.rb +31 -27
  111. data/lib/pdk/util/windows/process.rb +59 -61
  112. data/lib/pdk/util/windows/string.rb +19 -12
  113. data/lib/pdk/util.rb +12 -20
  114. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
  115. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
  116. data/lib/pdk/validate/external_command_validator.rb +6 -1
  117. data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
  118. data/lib/pdk/validate/invokable_validator.rb +30 -20
  119. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
  120. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
  121. data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
  122. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
  123. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
  124. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
  125. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
  126. data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
  127. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
  128. data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
  129. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
  130. data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
  131. data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
  132. data/lib/pdk/validate/validator.rb +4 -2
  133. data/lib/pdk/validate/validator_group.rb +6 -3
  134. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
  135. data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
  136. data/lib/pdk/validate.rb +6 -6
  137. data/lib/pdk/version.rb +2 -2
  138. data/lib/pdk.rb +12 -12
  139. metadata +27 -35
  140. data/lib/pdk/cli/config/get.rb +0 -26
  141. data/lib/pdk/cli/config.rb +0 -22
  142. data/lib/pdk/cli/module/build.rb +0 -12
  143. data/lib/pdk/cli/module/generate.rb +0 -47
  144. 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::Util::Windows::APITypes
5
- module ::FFI::Library
6
- def attach_function_private(*args)
7
- attach_function(*args)
8
- private args[0]
9
- end
10
- end
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
- class ::FFI::Pointer
13
- def self.from_string_to_wide_string(str, &_block)
14
- str = PDK::Util::Windows::String.wide_string(str)
15
- FFI::MemoryPointer.new(:byte, str.bytesize) do |ptr|
16
- # uchar here is synonymous with byte
17
- ptr.put_array_of_uchar(0, str.bytes.to_a)
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
- yield ptr
20
- end
25
+ yield ptr
26
+ end
21
27
 
22
- # ptr has already had free called, so nothing to return
23
- nil
24
- end
28
+ # ptr has already had free called, so nothing to return
29
+ nil
30
+ end
25
31
 
26
- def read_wide_string(char_length, dst_encoding = Encoding::UTF_8, encode_options = {})
27
- # char_length is number of wide chars (typically excluding NULLs), *not* bytes
28
- str = get_bytes(0, char_length * 2).force_encoding('UTF-16LE')
29
- str.encode(dst_encoding, str.encoding, **encode_options)
30
- rescue StandardError => e
31
- PDK.logger.debug 'Unable to convert value %{string} to encoding %{encoding} due to %{error}' % {
32
- string: str.dump,
33
- encoding: dst_encoding,
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
- def read_arbitrary_wide_string_up_to(max_char_length = 512, null_terminator = :single_null, encode_options = {})
40
- unless [:single_null, :double_null].include?(null_terminator)
41
- raise ArgumentError,
42
- 'Unable to read wide strings with %{null_terminator} terminal nulls' % { null_terminator: null_terminator }
43
- end
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
- terminator_width = (null_terminator == :single_null) ? 1 : 2
46
- reader_method = (null_terminator == :single_null) ? :get_uint16 : :get_uint32
47
+ terminator_width = null_terminator == :single_null ? 1 : 2
48
+ reader_method = null_terminator == :single_null ? :get_uint16 : :get_uint32
47
49
 
48
- # Look for the null_terminator; if found, read up to that null
49
- # (exclusive)
50
- (0...max_char_length - terminator_width).each do |i|
51
- return read_wide_string(i, Encoding::UTF_8, encode_options) if send(reader_method, (i * 2)).zero?
52
- end
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
- # String is longer than the max, read just up to the max
55
- read_wide_string(max_char_length, Encoding::UTF_8, encode_options)
56
- end
57
- end
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
- # FFI Types
60
- # https://github.com/ffi/ffi/wiki/Types
62
+ # FFI Types
63
+ # https://github.com/ffi/ffi/wiki/Types
61
64
 
62
- # Windows - Common Data Types
63
- # https://msdn.microsoft.com/en-us/library/cc230309.aspx
65
+ # Windows - Common Data Types
66
+ # https://msdn.microsoft.com/en-us/library/cc230309.aspx
64
67
 
65
- # Windows Data Types
66
- # https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
68
+ # Windows Data Types
69
+ # https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
67
70
 
68
- FFI.typedef :uint32, :dword
69
- # buffer_inout is similar to pointer (platform specific), but optimized for buffers
70
- FFI.typedef :buffer_inout, :lpwstr
71
- # buffer_in is similar to pointer (platform specific), but optimized for CONST read only buffers
72
- FFI.typedef :buffer_in, :lpcwstr
73
- # 8 bits per byte
74
- FFI.typedef :uchar, :byte
75
- FFI.typedef :uint16, :wchar
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
- # FFI bool can be only 1 byte at times,
78
- # Win32 BOOL is a signed int, and is always 4 bytes, even on x64
79
- # https://blogs.msdn.com/b/oldnewthing/archive/2011/03/28/10146459.aspx
80
- FFI.typedef :int32, :win32_bool
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::Util::Windows::File
4
- require 'ffi'
5
- extend FFI::Library
6
- extend PDK::Util::Windows::String
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
- def get_long_pathname(path)
9
- converted = ''
10
- FFI::Pointer.from_string_to_wide_string(path) do |path_ptr|
11
- # includes terminating NULL
12
- buffer_size = GetLongPathNameW(path_ptr, FFI::Pointer::NULL, 0)
13
- FFI::MemoryPointer.new(:wchar, buffer_size) do |converted_ptr|
14
- if GetLongPathNameW(path_ptr, converted_ptr, buffer_size) == PDK::Util::Windows::WIN32_FALSE
15
- raise 'Failed to call GetLongPathName'
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
- converted = converted_ptr.read_wide_string(buffer_size - 1)
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::Util::Windows::Process
4
- require 'ffi'
5
- extend PDK::Util::Windows::String
6
- extend FFI::Library
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
- def environment_hash
9
- env_ptr = GetEnvironmentStringsW()
11
+ def environment_hash
12
+ env_ptr = GetEnvironmentStringsW()
10
13
 
11
- contains_unicode_replacement = ->(string) do
12
- return false unless string.include?("\uFFFD")
14
+ contains_unicode_replacement = lambda do |string|
15
+ return false unless string.include?("\uFFFD")
13
16
 
14
- PDK.logger.warning "Discarding environment variable #{string} which contains invalid bytes"
15
- true
16
- end
17
+ PDK.logger.warning "Discarding environment variable #{string} which contains invalid bytes"
18
+ true
19
+ end
17
20
 
18
- # pass :invalid => :replace to the Ruby String#encode to use replacement
19
- # characters
20
- pairs = env_ptr.read_arbitrary_wide_string_up_to(65_534, :double_null, invalid: :replace)
21
- .split(?\x00)
22
- .reject { |env_str| env_str.nil? || env_str.empty? || env_str[0] == '=' }
23
- .reject { |env_str| contains_unicode_replacement.call(env_str) }
24
- .map { |env_pair| env_pair.split('=', 2) }
25
- Hash[pairs]
26
- ensure
27
- if env_ptr && !env_ptr.null?
28
- if FreeEnvironmentStringsW(env_ptr) == PDK::Util::Windows::WIN32_FALSE
29
- PDK.logger.debug 'FreeEnvironmentStringsW memory leak'
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
- def set_environment_variable(name, val)
36
- raise ArgumentError, 'Environment variable name must not be nil or empty' if name.nil? || name.empty?
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
- FFI::MemoryPointer.from_string_to_wide_string(name) do |name_ptr|
39
- if val.nil?
40
- if SetEnvironmentVariableW(name_ptr, FFI::MemoryPointer::NULL) == PDK::Util::Windows::WIN32_FALSE
41
- raise 'Failed to remove environment variable: %{name}' % { name: name }
42
- end
43
- else
44
- FFI::MemoryPointer.from_string_to_wide_string(val) do |val_ptr|
45
- if SetEnvironmentVariableW(name_ptr, val_ptr) == PDK::Util::Windows::WIN32_FALSE
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
- end
50
- end
51
- end
52
- module_function :set_environment_variable
47
+ module_function :set_environment_variable
53
48
 
54
- ffi_convention :stdcall
49
+ ffi_convention :stdcall
55
50
 
56
- # https://msdn.microsoft.com/en-us/library/windows/desktop/ms683187(v=vs.85).aspx
57
- # LPTCH GetEnvironmentStrings(void);
58
- ffi_lib :kernel32
59
- attach_function_private :GetEnvironmentStringsW, [], :pointer
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
- # https://msdn.microsoft.com/en-us/library/windows/desktop/ms683151(v=vs.85).aspx
62
- # BOOL FreeEnvironmentStrings(
63
- # _In_ LPTCH lpszEnvironmentBlock
64
- # );
65
- ffi_lib :kernel32
66
- attach_function_private :FreeEnvironmentStringsW, [:pointer], :win32_bool
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
- # https://msdn.microsoft.com/en-us/library/windows/desktop/ms686206(v=vs.85).aspx
69
- # BOOL WINAPI SetEnvironmentVariableW(
70
- # _In_ LPCTSTR lpName,
71
- # _In_opt_ LPCTSTR lpValue
72
- # );
73
- ffi_lib :kernel32
74
- attach_function_private :SetEnvironmentVariableW, [:lpcwstr, :lpcwstr],
75
- :win32_bool
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::Util::Windows::String
4
- def wide_string(str)
5
- # if given a nil string, assume caller wants to pass a nil pointer to win32
6
- return if str.nil?
7
- # ruby (< 2.1) does not respect multibyte terminators, so it is possible
8
- # for a string to contain a single trailing null byte, followed by garbage
9
- # causing buffer overruns.
10
- #
11
- # See http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?revision=41920&view=revision
12
- newstr = str + "\0".encode(str.encoding)
13
- newstr.encode!('UTF-16LE')
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 = %w[
26
- manifests
27
- lib/puppet
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
- #:nocov:
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
- raise PDK::CLI::FatalError, "Cannot resolve a full path to '%{path}', as it does not currently exist." % { path: path }
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)
@@ -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
- if object.is_a?(Array)
257
+ case object
258
+ when Array
267
259
  object.map { |item| deep_duplicate(item) }
268
- elsif object.is_a?(Hash)
260
+ when Hash
269
261
  hash = object.dup
270
262
  hash.each_pair { |key, value| hash[key] = deep_duplicate(value) }
271
263
  hash
@@ -14,7 +14,7 @@ module PDK
14
14
 
15
15
  def validators
16
16
  [
17
- EnvironmentConfValidator,
17
+ EnvironmentConfValidator
18
18
  ].freeze
19
19
  end
20
20
  end
@@ -4,7 +4,7 @@ module PDK
4
4
  module Validate
5
5
  module ControlRepo
6
6
  class EnvironmentConfValidator < InternalRubyValidator
7
- ALLOWED_SETTINGS = %w[modulepath manifest config_version environment_timeout].freeze
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}'" % { name: setting_name }
48
+ format("Invalid section '%{name}'", name: setting_name)
50
49
  else
51
- "Invalid setting '%{name}'" % { name: setting_name }
50
+ format("Invalid setting '%{name}'", name: setting_name)
52
51
  end
53
52
 
54
53
  report.add_event(
55
- file: target,
56
- source: name,
57
- state: :failure,
54
+ file: target,
55
+ source: name,
56
+ state: :failure,
58
57
  severity: 'error',
59
- message: 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: target,
68
- source: name,
69
- state: :failure,
66
+ file: target,
67
+ source: name,
68
+ state: :failure,
70
69
  severity: 'error',
71
- message: "environment_timeout is set to '%{timeout}' but should be 0, 'unlimited' or not set." % { timeout: timeout },
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: target,
79
- source: name,
80
- state: :passed,
81
- severity: 'ok',
78
+ file: target,
79
+ source: name,
80
+ state: :passed,
81
+ severity: 'ok'
82
82
  )
83
- return 0
83
+ 0
84
84
  rescue StandardError => e
85
85
  report.add_event(
86
- file: target,
87
- source: name,
88
- state: :failure,
86
+ file: target,
87
+ source: name,
88
+ state: :failure,
89
89
  severity: 'error',
90
- message: e.message,
90
+ message: e.message
91
91
  )
92
- return 1
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