pdk 2.3.0 → 2.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1329 -1321
- data/LICENSE +201 -201
- data/README.md +163 -163
- data/exe/pdk +10 -10
- data/lib/pdk/analytics/client/google_analytics.rb +143 -143
- data/lib/pdk/analytics/client/noop.rb +25 -25
- data/lib/pdk/analytics/util.rb +19 -19
- data/lib/pdk/analytics.rb +30 -30
- data/lib/pdk/answer_file.rb +12 -12
- data/lib/pdk/bolt.rb +19 -19
- data/lib/pdk/cli/build.rb +82 -82
- data/lib/pdk/cli/bundle.rb +48 -48
- data/lib/pdk/cli/config/get.rb +26 -26
- data/lib/pdk/cli/config.rb +22 -22
- data/lib/pdk/cli/console.rb +148 -148
- data/lib/pdk/cli/convert.rb +52 -52
- data/lib/pdk/cli/env.rb +52 -52
- data/lib/pdk/cli/errors.rb +25 -25
- data/lib/pdk/cli/exec/command.rb +293 -293
- data/lib/pdk/cli/exec/interactive_command.rb +114 -114
- data/lib/pdk/cli/exec.rb +84 -84
- data/lib/pdk/cli/exec_group.rb +104 -104
- data/lib/pdk/cli/get/config.rb +24 -24
- data/lib/pdk/cli/get.rb +20 -20
- data/lib/pdk/cli/module/build.rb +12 -12
- data/lib/pdk/cli/module/generate.rb +47 -47
- data/lib/pdk/cli/module.rb +14 -14
- data/lib/pdk/cli/new/class.rb +32 -32
- data/lib/pdk/cli/new/defined_type.rb +32 -32
- data/lib/pdk/cli/new/fact.rb +29 -29
- data/lib/pdk/cli/new/function.rb +29 -29
- data/lib/pdk/cli/new/module.rb +53 -53
- data/lib/pdk/cli/new/provider.rb +29 -29
- data/lib/pdk/cli/new/task.rb +34 -34
- data/lib/pdk/cli/new/test.rb +52 -52
- data/lib/pdk/cli/new/transport.rb +27 -27
- data/lib/pdk/cli/new.rb +21 -21
- data/lib/pdk/cli/release/prep.rb +39 -39
- data/lib/pdk/cli/release/publish.rb +50 -50
- data/lib/pdk/cli/release.rb +194 -194
- data/lib/pdk/cli/remove/config.rb +80 -80
- data/lib/pdk/cli/remove.rb +20 -20
- data/lib/pdk/cli/set/config.rb +119 -119
- data/lib/pdk/cli/set.rb +20 -20
- data/lib/pdk/cli/test/unit.rb +90 -90
- data/lib/pdk/cli/test.rb +11 -11
- data/lib/pdk/cli/update.rb +64 -64
- data/lib/pdk/cli/util/command_redirector.rb +27 -27
- data/lib/pdk/cli/util/interview.rb +72 -72
- data/lib/pdk/cli/util/option_normalizer.rb +55 -55
- data/lib/pdk/cli/util/option_validator.rb +68 -68
- data/lib/pdk/cli/util/spinner.rb +13 -13
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
- data/lib/pdk/cli/util.rb +305 -305
- data/lib/pdk/cli/validate.rb +116 -116
- data/lib/pdk/cli.rb +175 -175
- data/lib/pdk/config/analytics_schema.json +26 -26
- data/lib/pdk/config/errors.rb +5 -5
- data/lib/pdk/config/ini_file.rb +183 -183
- data/lib/pdk/config/ini_file_setting.rb +39 -39
- data/lib/pdk/config/json.rb +34 -34
- data/lib/pdk/config/json_schema_namespace.rb +142 -142
- data/lib/pdk/config/json_schema_setting.rb +53 -53
- data/lib/pdk/config/json_with_schema.rb +49 -49
- data/lib/pdk/config/namespace.rb +354 -354
- data/lib/pdk/config/setting.rb +135 -135
- data/lib/pdk/config/validator.rb +31 -31
- data/lib/pdk/config/yaml.rb +46 -46
- data/lib/pdk/config/yaml_with_schema.rb +59 -59
- data/lib/pdk/config.rb +390 -390
- data/lib/pdk/context/control_repo.rb +60 -60
- data/lib/pdk/context/module.rb +28 -28
- data/lib/pdk/context/none.rb +22 -22
- data/lib/pdk/context.rb +99 -99
- data/lib/pdk/control_repo.rb +90 -90
- data/lib/pdk/generate/defined_type.rb +43 -43
- data/lib/pdk/generate/fact.rb +25 -25
- data/lib/pdk/generate/function.rb +48 -48
- data/lib/pdk/generate/module.rb +352 -352
- data/lib/pdk/generate/provider.rb +28 -28
- data/lib/pdk/generate/puppet_class.rb +43 -43
- data/lib/pdk/generate/puppet_object.rb +232 -232
- data/lib/pdk/generate/task.rb +68 -68
- data/lib/pdk/generate/transport.rb +33 -33
- data/lib/pdk/generate.rb +24 -24
- data/lib/pdk/i18n.rb +4 -4
- data/lib/pdk/logger.rb +45 -45
- data/lib/pdk/module/build.rb +322 -322
- data/lib/pdk/module/convert.rb +296 -296
- data/lib/pdk/module/metadata.rb +202 -202
- data/lib/pdk/module/release.rb +260 -260
- data/lib/pdk/module/update.rb +131 -131
- data/lib/pdk/module/update_manager.rb +227 -227
- data/lib/pdk/module.rb +30 -30
- data/lib/pdk/report/event.rb +370 -370
- data/lib/pdk/report.rb +121 -121
- data/lib/pdk/template/fetcher/git.rb +85 -85
- data/lib/pdk/template/fetcher/local.rb +28 -28
- data/lib/pdk/template/fetcher.rb +98 -98
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
- data/lib/pdk/template/renderer/v1.rb +25 -25
- data/lib/pdk/template/renderer.rb +96 -96
- data/lib/pdk/template/template_dir.rb +67 -67
- data/lib/pdk/template.rb +59 -59
- data/lib/pdk/tests/unit.rb +252 -252
- data/lib/pdk/util/bundler.rb +259 -259
- data/lib/pdk/util/changelog_generator.rb +137 -137
- data/lib/pdk/util/env.rb +47 -47
- data/lib/pdk/util/filesystem.rb +138 -138
- data/lib/pdk/util/git.rb +179 -179
- data/lib/pdk/util/json_finder.rb +85 -85
- data/lib/pdk/util/puppet_strings.rb +125 -125
- data/lib/pdk/util/puppet_version.rb +266 -266
- data/lib/pdk/util/ruby_version.rb +179 -179
- data/lib/pdk/util/template_uri.rb +295 -295
- data/lib/pdk/util/vendored_file.rb +93 -93
- data/lib/pdk/util/version.rb +43 -43
- data/lib/pdk/util/windows/api_types.rb +82 -82
- data/lib/pdk/util/windows/file.rb +36 -36
- data/lib/pdk/util/windows/process.rb +79 -79
- data/lib/pdk/util/windows/string.rb +16 -16
- data/lib/pdk/util/windows.rb +15 -15
- data/lib/pdk/util.rb +278 -277
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
- data/lib/pdk/validate/external_command_validator.rb +208 -208
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
- data/lib/pdk/validate/invokable_validator.rb +228 -228
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
- data/lib/pdk/validate/validator.rb +118 -118
- data/lib/pdk/validate/validator_group.rb +104 -104
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
- data/lib/pdk/validate.rb +94 -94
- data/lib/pdk/version.rb +4 -4
- data/lib/pdk.rb +76 -76
- data/locales/config.yaml +21 -21
- data/locales/pdk.pot +2094 -2094
- metadata +5 -6
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
require 'pdk'
|
|
2
|
-
|
|
3
|
-
module PDK
|
|
4
|
-
module Context
|
|
5
|
-
# Represents a context for a directory based Control Repository
|
|
6
|
-
class ControlRepo < PDK::Context::AbstractContext
|
|
7
|
-
# @param repo_root [String] The root path for the control repo.
|
|
8
|
-
# @param context_path [String] The path where this context was created from e.g. Dir.pwd
|
|
9
|
-
# @see PDK::Context::AbstractContext
|
|
10
|
-
def initialize(repo_root, context_path)
|
|
11
|
-
super(context_path)
|
|
12
|
-
@root_path = repo_root
|
|
13
|
-
@environment_conf = nil
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# @see PDK::Context::AbstractContext.pdk_compatible?
|
|
17
|
-
def pdk_compatible?
|
|
18
|
-
# Currently there is nothing to determine compatibility with the PDK for a
|
|
19
|
-
# Control Repo. For now assume everything is compatible
|
|
20
|
-
true
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# The modulepath setting for this control repository as an array of strings. These paths are relative
|
|
24
|
-
# and may contain interpolation strings (e.g. $basemodulepath)
|
|
25
|
-
# @see https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
|
|
26
|
-
# @return [Array[String]] The modulepath setting for this control repository
|
|
27
|
-
def module_paths
|
|
28
|
-
return @module_paths unless @module_paths.nil?
|
|
29
|
-
value = environment_conf['modulepath'] || ''
|
|
30
|
-
# We have to use a hardcoded value here because File::PATH_SEPARATOR is ';' on Windows.
|
|
31
|
-
# As the environment.conf is only used on Puppet Server, it's always ':'
|
|
32
|
-
# Based on - https://github.com/puppetlabs/puppet/blob/f3e6d7e6d87f46408943a8e2176afb82ff6ea096/lib/puppet/settings/environment_conf.rb#L98-L106
|
|
33
|
-
@module_paths = value.split(':')
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# The relative module_paths that exist on disk.
|
|
37
|
-
# @see https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
|
|
38
|
-
# @return [Array[String]] The relative module paths on disk
|
|
39
|
-
def actualized_module_paths
|
|
40
|
-
@actualized_module_paths ||= module_paths.reject { |path| path.start_with?('$') }
|
|
41
|
-
.select { |path| PDK::Util::Filesystem.directory?(PDK::Util::Filesystem.expand_path(File.join(root_path, path))) }
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
#:nocov:
|
|
45
|
-
# @see PDK::Context::AbstractContext.display_name
|
|
46
|
-
def display_name
|
|
47
|
-
_('a Control Repository context')
|
|
48
|
-
end
|
|
49
|
-
#:nocov:
|
|
50
|
-
|
|
51
|
-
private
|
|
52
|
-
|
|
53
|
-
# Memoization helper to read the environment.conf file.
|
|
54
|
-
# @return [PDK::Config::IniFile]
|
|
55
|
-
def environment_conf
|
|
56
|
-
@environment_conf ||= PDK::ControlRepo.environment_conf_as_config(File.join(root_path, 'environment.conf'))
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
1
|
+
require 'pdk'
|
|
2
|
+
|
|
3
|
+
module PDK
|
|
4
|
+
module Context
|
|
5
|
+
# Represents a context for a directory based Control Repository
|
|
6
|
+
class ControlRepo < PDK::Context::AbstractContext
|
|
7
|
+
# @param repo_root [String] The root path for the control repo.
|
|
8
|
+
# @param context_path [String] The path where this context was created from e.g. Dir.pwd
|
|
9
|
+
# @see PDK::Context::AbstractContext
|
|
10
|
+
def initialize(repo_root, context_path)
|
|
11
|
+
super(context_path)
|
|
12
|
+
@root_path = repo_root
|
|
13
|
+
@environment_conf = nil
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @see PDK::Context::AbstractContext.pdk_compatible?
|
|
17
|
+
def pdk_compatible?
|
|
18
|
+
# Currently there is nothing to determine compatibility with the PDK for a
|
|
19
|
+
# Control Repo. For now assume everything is compatible
|
|
20
|
+
true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# The modulepath setting for this control repository as an array of strings. These paths are relative
|
|
24
|
+
# and may contain interpolation strings (e.g. $basemodulepath)
|
|
25
|
+
# @see https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
|
|
26
|
+
# @return [Array[String]] The modulepath setting for this control repository
|
|
27
|
+
def module_paths
|
|
28
|
+
return @module_paths unless @module_paths.nil?
|
|
29
|
+
value = environment_conf['modulepath'] || ''
|
|
30
|
+
# We have to use a hardcoded value here because File::PATH_SEPARATOR is ';' on Windows.
|
|
31
|
+
# As the environment.conf is only used on Puppet Server, it's always ':'
|
|
32
|
+
# Based on - https://github.com/puppetlabs/puppet/blob/f3e6d7e6d87f46408943a8e2176afb82ff6ea096/lib/puppet/settings/environment_conf.rb#L98-L106
|
|
33
|
+
@module_paths = value.split(':')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The relative module_paths that exist on disk.
|
|
37
|
+
# @see https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
|
|
38
|
+
# @return [Array[String]] The relative module paths on disk
|
|
39
|
+
def actualized_module_paths
|
|
40
|
+
@actualized_module_paths ||= module_paths.reject { |path| path.start_with?('$') }
|
|
41
|
+
.select { |path| PDK::Util::Filesystem.directory?(PDK::Util::Filesystem.expand_path(File.join(root_path, path))) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#:nocov:
|
|
45
|
+
# @see PDK::Context::AbstractContext.display_name
|
|
46
|
+
def display_name
|
|
47
|
+
_('a Control Repository context')
|
|
48
|
+
end
|
|
49
|
+
#:nocov:
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
# Memoization helper to read the environment.conf file.
|
|
54
|
+
# @return [PDK::Config::IniFile]
|
|
55
|
+
def environment_conf
|
|
56
|
+
@environment_conf ||= PDK::ControlRepo.environment_conf_as_config(File.join(root_path, 'environment.conf'))
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
data/lib/pdk/context/module.rb
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
require 'pdk'
|
|
2
|
-
|
|
3
|
-
module PDK
|
|
4
|
-
module Context
|
|
5
|
-
# Represents a context for a Puppet Module
|
|
6
|
-
class Module < PDK::Context::AbstractContext
|
|
7
|
-
# @param module_root [String] The root path for the module.
|
|
8
|
-
# @param context_path [String] The path where this context was created from e.g. Dir.pwd
|
|
9
|
-
# @see PDK::Context::AbstractContext
|
|
10
|
-
def initialize(module_root, context_path)
|
|
11
|
-
super(context_path)
|
|
12
|
-
@root_path = module_root
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# @see PDK::Context::AbstractContext.pdk_compatible?
|
|
16
|
-
def pdk_compatible?
|
|
17
|
-
PDK::Util.module_pdk_compatible?(root_path)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
#:nocov:
|
|
21
|
-
# @see PDK::Context::AbstractContext.display_name
|
|
22
|
-
def display_name
|
|
23
|
-
_('a Puppet Module context')
|
|
24
|
-
end
|
|
25
|
-
#:nocov:
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
require 'pdk'
|
|
2
|
+
|
|
3
|
+
module PDK
|
|
4
|
+
module Context
|
|
5
|
+
# Represents a context for a Puppet Module
|
|
6
|
+
class Module < PDK::Context::AbstractContext
|
|
7
|
+
# @param module_root [String] The root path for the module.
|
|
8
|
+
# @param context_path [String] The path where this context was created from e.g. Dir.pwd
|
|
9
|
+
# @see PDK::Context::AbstractContext
|
|
10
|
+
def initialize(module_root, context_path)
|
|
11
|
+
super(context_path)
|
|
12
|
+
@root_path = module_root
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @see PDK::Context::AbstractContext.pdk_compatible?
|
|
16
|
+
def pdk_compatible?
|
|
17
|
+
PDK::Util.module_pdk_compatible?(root_path)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#:nocov:
|
|
21
|
+
# @see PDK::Context::AbstractContext.display_name
|
|
22
|
+
def display_name
|
|
23
|
+
_('a Puppet Module context')
|
|
24
|
+
end
|
|
25
|
+
#:nocov:
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/lib/pdk/context/none.rb
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
require 'pdk'
|
|
2
|
-
|
|
3
|
-
module PDK
|
|
4
|
-
module Context
|
|
5
|
-
# Represents a context which the PDK does not know. For example
|
|
6
|
-
# an empty directory
|
|
7
|
-
class None < PDK::Context::AbstractContext
|
|
8
|
-
#:nocov:
|
|
9
|
-
# @see PDK::Context::AbstractContext.display_name
|
|
10
|
-
def display_name
|
|
11
|
-
_('an unknown context')
|
|
12
|
-
end
|
|
13
|
-
#:nocov:
|
|
14
|
-
|
|
15
|
-
# @see PDK::Context::AbstractContext.parent_context
|
|
16
|
-
def parent_context
|
|
17
|
-
# An unknown context has no parent
|
|
18
|
-
nil
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
1
|
+
require 'pdk'
|
|
2
|
+
|
|
3
|
+
module PDK
|
|
4
|
+
module Context
|
|
5
|
+
# Represents a context which the PDK does not know. For example
|
|
6
|
+
# an empty directory
|
|
7
|
+
class None < PDK::Context::AbstractContext
|
|
8
|
+
#:nocov:
|
|
9
|
+
# @see PDK::Context::AbstractContext.display_name
|
|
10
|
+
def display_name
|
|
11
|
+
_('an unknown context')
|
|
12
|
+
end
|
|
13
|
+
#:nocov:
|
|
14
|
+
|
|
15
|
+
# @see PDK::Context::AbstractContext.parent_context
|
|
16
|
+
def parent_context
|
|
17
|
+
# An unknown context has no parent
|
|
18
|
+
nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/pdk/context.rb
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
require 'pdk'
|
|
2
|
-
|
|
3
|
-
module PDK
|
|
4
|
-
module Context
|
|
5
|
-
autoload :None, 'pdk/context/none'
|
|
6
|
-
autoload :Module, 'pdk/context/module'
|
|
7
|
-
autoload :ControlRepo, 'pdk/context/control_repo'
|
|
8
|
-
|
|
9
|
-
# Automatically determines the PDK Context given a path. Create will continue up the directory tree until it
|
|
10
|
-
# finds a valid context
|
|
11
|
-
# @return [PDK::Context::AbstractContext] Returns a PDK::Context::None if the context could not be determined
|
|
12
|
-
def self.create(context_path)
|
|
13
|
-
return PDK::Context::None.new(context_path) unless PDK::Util::Filesystem.directory?(context_path)
|
|
14
|
-
|
|
15
|
-
previous = nil
|
|
16
|
-
current = PDK::Util::Filesystem.expand_path(context_path)
|
|
17
|
-
until !PDK::Util::Filesystem.directory?(current) || current == previous
|
|
18
|
-
# Control Repo detection
|
|
19
|
-
return PDK::Context::ControlRepo.new(current, context_path) if PDK.feature_flag?('controlrepo') && PDK::ControlRepo.control_repo_root?(current)
|
|
20
|
-
|
|
21
|
-
# Puppet Module detection
|
|
22
|
-
metadata_file = File.join(current, 'metadata.json')
|
|
23
|
-
if PDK::Util::Filesystem.file?(metadata_file) || PDK::Util.in_module_root?(context_path)
|
|
24
|
-
return PDK::Context::Module.new(current, context_path)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
previous = current
|
|
28
|
-
current = PDK::Util::Filesystem.expand_path('..', current)
|
|
29
|
-
end
|
|
30
|
-
PDK::Context::None.new(context_path)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Abstract class which all PDK Contexts will subclass from.
|
|
34
|
-
# @abstract
|
|
35
|
-
class AbstractContext
|
|
36
|
-
# The root of this context, for example the module root when inside a module. This can be different from context_path
|
|
37
|
-
# For example a Module context_path could be /path/to/module/manifests/ but the root_path will be /path/to/module as
|
|
38
|
-
# that is the root of the Module context. Defaults to the context_path if not set.
|
|
39
|
-
# @return [String]
|
|
40
|
-
def root_path
|
|
41
|
-
@root_path || @context_path
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# The path used to create this context, for example the current working directory. This can be different from root_path
|
|
45
|
-
# For example a Module context_path could be /path/to/module/manifests/ but the root_path will be /path/to/module as
|
|
46
|
-
# that is the root of the Module context
|
|
47
|
-
# @return [String]
|
|
48
|
-
attr_reader :context_path
|
|
49
|
-
|
|
50
|
-
# @param context_path [String] The path where this context was created from e.g. Dir.pwd
|
|
51
|
-
def initialize(context_path)
|
|
52
|
-
@context_path = context_path
|
|
53
|
-
@root_path = nil
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Whether the current context is compatible with the PDK e.g. in a Module context, whether it has the correct metadata.json content
|
|
57
|
-
# @return [Boolean] Default is not compatible
|
|
58
|
-
def pdk_compatible?
|
|
59
|
-
false
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# The friendly name to display for this context
|
|
63
|
-
# @api private
|
|
64
|
-
# @abstract
|
|
65
|
-
def display_name; end
|
|
66
|
-
|
|
67
|
-
# The context which this context is in. For example a Module Context (/controlrepo/site/profile) can be inside of a Control Repo context (/controlrepo)
|
|
68
|
-
# The default is to search in the parent directory of this context
|
|
69
|
-
# @return [PDK::Context::AbstractContext, Nil] Returns the parent context or nil if there is no parent.
|
|
70
|
-
def parent_context
|
|
71
|
-
# Default detection is just look for the context in the parent directory of this context
|
|
72
|
-
@parent_context || PDK::Context.create(File.dirname(root_path))
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Writes the current context information, and parent contexts, to the PDK Debug Logger.
|
|
76
|
-
# This is mainly used by the PDK CLI when in debug mode to assist users to figure out why the PDK is misbehaving.
|
|
77
|
-
# @api private
|
|
78
|
-
def to_debug_log
|
|
79
|
-
current = self
|
|
80
|
-
depth = 1
|
|
81
|
-
loop do
|
|
82
|
-
PDK.logger.debug("Detected #{current.display_name} at #{current.root_path.nil? ? current.context_path : current.root_path}")
|
|
83
|
-
current = current.parent_context
|
|
84
|
-
break if current.nil?
|
|
85
|
-
depth += 1
|
|
86
|
-
# Circuit breaker in case there are circular references
|
|
87
|
-
break if depth > 20
|
|
88
|
-
end
|
|
89
|
-
nil
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
#:nocov: There's nothing to test here
|
|
93
|
-
def to_s
|
|
94
|
-
"#<#{self.class}:#{object_id}>#{context_path}"
|
|
95
|
-
end
|
|
96
|
-
#:nocov:
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
1
|
+
require 'pdk'
|
|
2
|
+
|
|
3
|
+
module PDK
|
|
4
|
+
module Context
|
|
5
|
+
autoload :None, 'pdk/context/none'
|
|
6
|
+
autoload :Module, 'pdk/context/module'
|
|
7
|
+
autoload :ControlRepo, 'pdk/context/control_repo'
|
|
8
|
+
|
|
9
|
+
# Automatically determines the PDK Context given a path. Create will continue up the directory tree until it
|
|
10
|
+
# finds a valid context
|
|
11
|
+
# @return [PDK::Context::AbstractContext] Returns a PDK::Context::None if the context could not be determined
|
|
12
|
+
def self.create(context_path)
|
|
13
|
+
return PDK::Context::None.new(context_path) unless PDK::Util::Filesystem.directory?(context_path)
|
|
14
|
+
|
|
15
|
+
previous = nil
|
|
16
|
+
current = PDK::Util::Filesystem.expand_path(context_path)
|
|
17
|
+
until !PDK::Util::Filesystem.directory?(current) || current == previous
|
|
18
|
+
# Control Repo detection
|
|
19
|
+
return PDK::Context::ControlRepo.new(current, context_path) if PDK.feature_flag?('controlrepo') && PDK::ControlRepo.control_repo_root?(current)
|
|
20
|
+
|
|
21
|
+
# Puppet Module detection
|
|
22
|
+
metadata_file = File.join(current, 'metadata.json')
|
|
23
|
+
if PDK::Util::Filesystem.file?(metadata_file) || PDK::Util.in_module_root?(context_path)
|
|
24
|
+
return PDK::Context::Module.new(current, context_path)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
previous = current
|
|
28
|
+
current = PDK::Util::Filesystem.expand_path('..', current)
|
|
29
|
+
end
|
|
30
|
+
PDK::Context::None.new(context_path)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Abstract class which all PDK Contexts will subclass from.
|
|
34
|
+
# @abstract
|
|
35
|
+
class AbstractContext
|
|
36
|
+
# The root of this context, for example the module root when inside a module. This can be different from context_path
|
|
37
|
+
# For example a Module context_path could be /path/to/module/manifests/ but the root_path will be /path/to/module as
|
|
38
|
+
# that is the root of the Module context. Defaults to the context_path if not set.
|
|
39
|
+
# @return [String]
|
|
40
|
+
def root_path
|
|
41
|
+
@root_path || @context_path
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The path used to create this context, for example the current working directory. This can be different from root_path
|
|
45
|
+
# For example a Module context_path could be /path/to/module/manifests/ but the root_path will be /path/to/module as
|
|
46
|
+
# that is the root of the Module context
|
|
47
|
+
# @return [String]
|
|
48
|
+
attr_reader :context_path
|
|
49
|
+
|
|
50
|
+
# @param context_path [String] The path where this context was created from e.g. Dir.pwd
|
|
51
|
+
def initialize(context_path)
|
|
52
|
+
@context_path = context_path
|
|
53
|
+
@root_path = nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Whether the current context is compatible with the PDK e.g. in a Module context, whether it has the correct metadata.json content
|
|
57
|
+
# @return [Boolean] Default is not compatible
|
|
58
|
+
def pdk_compatible?
|
|
59
|
+
false
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# The friendly name to display for this context
|
|
63
|
+
# @api private
|
|
64
|
+
# @abstract
|
|
65
|
+
def display_name; end
|
|
66
|
+
|
|
67
|
+
# The context which this context is in. For example a Module Context (/controlrepo/site/profile) can be inside of a Control Repo context (/controlrepo)
|
|
68
|
+
# The default is to search in the parent directory of this context
|
|
69
|
+
# @return [PDK::Context::AbstractContext, Nil] Returns the parent context or nil if there is no parent.
|
|
70
|
+
def parent_context
|
|
71
|
+
# Default detection is just look for the context in the parent directory of this context
|
|
72
|
+
@parent_context || PDK::Context.create(File.dirname(root_path))
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Writes the current context information, and parent contexts, to the PDK Debug Logger.
|
|
76
|
+
# This is mainly used by the PDK CLI when in debug mode to assist users to figure out why the PDK is misbehaving.
|
|
77
|
+
# @api private
|
|
78
|
+
def to_debug_log
|
|
79
|
+
current = self
|
|
80
|
+
depth = 1
|
|
81
|
+
loop do
|
|
82
|
+
PDK.logger.debug("Detected #{current.display_name} at #{current.root_path.nil? ? current.context_path : current.root_path}")
|
|
83
|
+
current = current.parent_context
|
|
84
|
+
break if current.nil?
|
|
85
|
+
depth += 1
|
|
86
|
+
# Circuit breaker in case there are circular references
|
|
87
|
+
break if depth > 20
|
|
88
|
+
end
|
|
89
|
+
nil
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
#:nocov: There's nothing to test here
|
|
93
|
+
def to_s
|
|
94
|
+
"#<#{self.class}:#{object_id}>#{context_path}"
|
|
95
|
+
end
|
|
96
|
+
#:nocov:
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/pdk/control_repo.rb
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
require 'pdk'
|
|
2
|
-
|
|
3
|
-
module PDK
|
|
4
|
-
module ControlRepo
|
|
5
|
-
CONTROL_REPO_FILES = %w[environment.conf Puppetfile].freeze
|
|
6
|
-
|
|
7
|
-
DEFAULT_IGNORED = [
|
|
8
|
-
'/pkg/',
|
|
9
|
-
'~*',
|
|
10
|
-
'/coverage',
|
|
11
|
-
# Strictly speaking this isn't default but if people have tricked older PDK into thinking that a
|
|
12
|
-
# Control Repo is a module, they may have recursive symlinks in spec/fixtures/modules
|
|
13
|
-
'/spec/fixtures/modules/',
|
|
14
|
-
'/vendor/',
|
|
15
|
-
].freeze
|
|
16
|
-
|
|
17
|
-
# Returns path to the root of the Control Repo being worked on.
|
|
18
|
-
#
|
|
19
|
-
# An environment.conf is required for a PDK compatible Control Repo,
|
|
20
|
-
# whereas Puppetfile is optional.
|
|
21
|
-
#
|
|
22
|
-
# Note - A Bolt Project can also be a Control Repo.
|
|
23
|
-
#
|
|
24
|
-
# Note - Non-Directory environments can exist however directory based
|
|
25
|
-
# environments are the supported/preferred way.
|
|
26
|
-
#
|
|
27
|
-
# @see https://puppet.com/docs/pe/latest/control_repo.html
|
|
28
|
-
#
|
|
29
|
-
# @param strict_check [Boolean] When strict_check is true, only return the path
|
|
30
|
-
# if the Control Repo is strictly _only_ a control repository. For example,
|
|
31
|
-
# not also a Puppet Bolt project directory Default is false.
|
|
32
|
-
#
|
|
33
|
-
# @return [String, nil] Fully qualified base path to Control Repo, or nil if
|
|
34
|
-
# the current working dir does not appear to be within a Control Repo.
|
|
35
|
-
def find_control_repo_root(strict_check = false)
|
|
36
|
-
environment_conf_path = PDK::Util.find_upwards('environment.conf')
|
|
37
|
-
path = if environment_conf_path
|
|
38
|
-
File.dirname(environment_conf_path)
|
|
39
|
-
elsif control_repo_root?(Dir.pwd)
|
|
40
|
-
Dir.pwd
|
|
41
|
-
else
|
|
42
|
-
nil
|
|
43
|
-
end
|
|
44
|
-
return path if path.nil? || !strict_check
|
|
45
|
-
PDK::Bolt.bolt_project_root?(path) ? nil : path
|
|
46
|
-
end
|
|
47
|
-
module_function :find_control_repo_root
|
|
48
|
-
|
|
49
|
-
# Returns true or false depending on if any of the common files in a Control Repo
|
|
50
|
-
# are found in the specified directory. If a directory is not specified, the current
|
|
51
|
-
# working directory is used.
|
|
52
|
-
#
|
|
53
|
-
# @return [boolean] True if any folders from CONTROL_REPO_FILES are found in the current dir,
|
|
54
|
-
# false otherwise.
|
|
55
|
-
def control_repo_root?(path = Dir.pwd)
|
|
56
|
-
CONTROL_REPO_FILES.any? { |file| PDK::Util::Filesystem.file?(File.join(path, file)) }
|
|
57
|
-
end
|
|
58
|
-
module_function :control_repo_root?
|
|
59
|
-
|
|
60
|
-
# Returns a PDK::Config::Namespace for the specified environment.conf file.
|
|
61
|
-
# Note there is no validation of the path.
|
|
62
|
-
#
|
|
63
|
-
# @param path [String] The path to the environment.conf file
|
|
64
|
-
#
|
|
65
|
-
# @return [PDK::Config::IniFile] The configuration file
|
|
66
|
-
def environment_conf_as_config(path)
|
|
67
|
-
PDK::Config::IniFile.new('environment', file: path) do
|
|
68
|
-
setting :modulepath do
|
|
69
|
-
# As per https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
|
|
70
|
-
default_to { 'modules:$basemodulepath' }
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
setting :manifest do
|
|
74
|
-
# As per https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
|
|
75
|
-
default_to { 'manifests/' }
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
module_function :environment_conf_as_config
|
|
80
|
-
|
|
81
|
-
def default_ignored_pathspec(ignore_dotfiles = true)
|
|
82
|
-
require 'pathspec'
|
|
83
|
-
|
|
84
|
-
PathSpec.new(DEFAULT_IGNORED).tap do |ps|
|
|
85
|
-
ps.add('.*') if ignore_dotfiles
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
module_function :default_ignored_pathspec
|
|
89
|
-
end
|
|
90
|
-
end
|
|
1
|
+
require 'pdk'
|
|
2
|
+
|
|
3
|
+
module PDK
|
|
4
|
+
module ControlRepo
|
|
5
|
+
CONTROL_REPO_FILES = %w[environment.conf Puppetfile].freeze
|
|
6
|
+
|
|
7
|
+
DEFAULT_IGNORED = [
|
|
8
|
+
'/pkg/',
|
|
9
|
+
'~*',
|
|
10
|
+
'/coverage',
|
|
11
|
+
# Strictly speaking this isn't default but if people have tricked older PDK into thinking that a
|
|
12
|
+
# Control Repo is a module, they may have recursive symlinks in spec/fixtures/modules
|
|
13
|
+
'/spec/fixtures/modules/',
|
|
14
|
+
'/vendor/',
|
|
15
|
+
].freeze
|
|
16
|
+
|
|
17
|
+
# Returns path to the root of the Control Repo being worked on.
|
|
18
|
+
#
|
|
19
|
+
# An environment.conf is required for a PDK compatible Control Repo,
|
|
20
|
+
# whereas Puppetfile is optional.
|
|
21
|
+
#
|
|
22
|
+
# Note - A Bolt Project can also be a Control Repo.
|
|
23
|
+
#
|
|
24
|
+
# Note - Non-Directory environments can exist however directory based
|
|
25
|
+
# environments are the supported/preferred way.
|
|
26
|
+
#
|
|
27
|
+
# @see https://puppet.com/docs/pe/latest/control_repo.html
|
|
28
|
+
#
|
|
29
|
+
# @param strict_check [Boolean] When strict_check is true, only return the path
|
|
30
|
+
# if the Control Repo is strictly _only_ a control repository. For example,
|
|
31
|
+
# not also a Puppet Bolt project directory Default is false.
|
|
32
|
+
#
|
|
33
|
+
# @return [String, nil] Fully qualified base path to Control Repo, or nil if
|
|
34
|
+
# the current working dir does not appear to be within a Control Repo.
|
|
35
|
+
def find_control_repo_root(strict_check = false)
|
|
36
|
+
environment_conf_path = PDK::Util.find_upwards('environment.conf')
|
|
37
|
+
path = if environment_conf_path
|
|
38
|
+
File.dirname(environment_conf_path)
|
|
39
|
+
elsif control_repo_root?(Dir.pwd)
|
|
40
|
+
Dir.pwd
|
|
41
|
+
else
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
return path if path.nil? || !strict_check
|
|
45
|
+
PDK::Bolt.bolt_project_root?(path) ? nil : path
|
|
46
|
+
end
|
|
47
|
+
module_function :find_control_repo_root
|
|
48
|
+
|
|
49
|
+
# Returns true or false depending on if any of the common files in a Control Repo
|
|
50
|
+
# are found in the specified directory. If a directory is not specified, the current
|
|
51
|
+
# working directory is used.
|
|
52
|
+
#
|
|
53
|
+
# @return [boolean] True if any folders from CONTROL_REPO_FILES are found in the current dir,
|
|
54
|
+
# false otherwise.
|
|
55
|
+
def control_repo_root?(path = Dir.pwd)
|
|
56
|
+
CONTROL_REPO_FILES.any? { |file| PDK::Util::Filesystem.file?(File.join(path, file)) }
|
|
57
|
+
end
|
|
58
|
+
module_function :control_repo_root?
|
|
59
|
+
|
|
60
|
+
# Returns a PDK::Config::Namespace for the specified environment.conf file.
|
|
61
|
+
# Note there is no validation of the path.
|
|
62
|
+
#
|
|
63
|
+
# @param path [String] The path to the environment.conf file
|
|
64
|
+
#
|
|
65
|
+
# @return [PDK::Config::IniFile] The configuration file
|
|
66
|
+
def environment_conf_as_config(path)
|
|
67
|
+
PDK::Config::IniFile.new('environment', file: path) do
|
|
68
|
+
setting :modulepath do
|
|
69
|
+
# As per https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
|
|
70
|
+
default_to { 'modules:$basemodulepath' }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
setting :manifest do
|
|
74
|
+
# As per https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
|
|
75
|
+
default_to { 'manifests/' }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
module_function :environment_conf_as_config
|
|
80
|
+
|
|
81
|
+
def default_ignored_pathspec(ignore_dotfiles = true)
|
|
82
|
+
require 'pathspec'
|
|
83
|
+
|
|
84
|
+
PathSpec.new(DEFAULT_IGNORED).tap do |ps|
|
|
85
|
+
ps.add('.*') if ignore_dotfiles
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
module_function :default_ignored_pathspec
|
|
89
|
+
end
|
|
90
|
+
end
|