pdk 1.9.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +744 -711
- data/README.md +23 -21
- data/lib/pdk/answer_file.rb +3 -112
- data/lib/pdk/bolt.rb +20 -0
- data/lib/pdk/cli/build.rb +51 -54
- data/lib/pdk/cli/bundle.rb +33 -29
- data/lib/pdk/cli/console.rb +148 -0
- data/lib/pdk/cli/convert.rb +46 -37
- data/lib/pdk/cli/env.rb +51 -0
- data/lib/pdk/cli/errors.rb +4 -3
- data/lib/pdk/cli/exec/command.rb +285 -0
- data/lib/pdk/cli/exec/interactive_command.rb +109 -0
- data/lib/pdk/cli/exec.rb +32 -201
- data/lib/pdk/cli/exec_group.rb +79 -43
- data/lib/pdk/cli/get/config.rb +26 -0
- data/lib/pdk/cli/get.rb +22 -0
- data/lib/pdk/cli/new/class.rb +20 -22
- data/lib/pdk/cli/new/defined_type.rb +21 -21
- data/lib/pdk/cli/new/fact.rb +27 -0
- data/lib/pdk/cli/new/function.rb +27 -0
- data/lib/pdk/cli/new/module.rb +40 -29
- data/lib/pdk/cli/new/provider.rb +18 -18
- data/lib/pdk/cli/new/task.rb +23 -22
- data/lib/pdk/cli/new/test.rb +52 -0
- data/lib/pdk/cli/new/transport.rb +27 -0
- data/lib/pdk/cli/new.rb +15 -9
- data/lib/pdk/cli/release/prep.rb +39 -0
- data/lib/pdk/cli/release/publish.rb +46 -0
- data/lib/pdk/cli/release.rb +185 -0
- data/lib/pdk/cli/remove/config.rb +83 -0
- data/lib/pdk/cli/remove.rb +22 -0
- data/lib/pdk/cli/set/config.rb +121 -0
- data/lib/pdk/cli/set.rb +22 -0
- data/lib/pdk/cli/test/unit.rb +71 -69
- data/lib/pdk/cli/test.rb +9 -8
- data/lib/pdk/cli/update.rb +38 -21
- data/lib/pdk/cli/util/command_redirector.rb +13 -3
- data/lib/pdk/cli/util/interview.rb +25 -9
- data/lib/pdk/cli/util/option_normalizer.rb +6 -6
- data/lib/pdk/cli/util/option_validator.rb +19 -9
- data/lib/pdk/cli/util/spinner.rb +13 -0
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
- data/lib/pdk/cli/util.rb +105 -48
- data/lib/pdk/cli/validate.rb +96 -111
- data/lib/pdk/cli.rb +134 -87
- data/lib/pdk/config/errors.rb +5 -0
- data/lib/pdk/config/ini_file.rb +184 -0
- data/lib/pdk/config/ini_file_setting.rb +35 -0
- data/lib/pdk/config/json.rb +35 -0
- data/lib/pdk/config/json_schema_namespace.rb +137 -0
- data/lib/pdk/config/json_schema_setting.rb +51 -0
- data/lib/pdk/config/json_with_schema.rb +47 -0
- data/lib/pdk/config/namespace.rb +362 -0
- data/lib/pdk/config/setting.rb +134 -0
- data/lib/pdk/config/task_schema.json +116 -0
- data/lib/pdk/config/validator.rb +31 -0
- data/lib/pdk/config/yaml.rb +41 -0
- data/lib/pdk/config/yaml_with_schema.rb +51 -0
- data/lib/pdk/config.rb +304 -0
- data/lib/pdk/context/control_repo.rb +61 -0
- data/lib/pdk/context/module.rb +28 -0
- data/lib/pdk/context/none.rb +22 -0
- data/lib/pdk/context.rb +98 -0
- data/lib/pdk/control_repo.rb +89 -0
- data/lib/pdk/generate/defined_type.rb +27 -33
- data/lib/pdk/generate/fact.rb +26 -0
- data/lib/pdk/generate/function.rb +49 -0
- data/lib/pdk/generate/module.rb +160 -153
- data/lib/pdk/generate/provider.rb +16 -69
- data/lib/pdk/generate/puppet_class.rb +27 -32
- data/lib/pdk/generate/puppet_object.rb +100 -159
- data/lib/pdk/generate/task.rb +34 -51
- data/lib/pdk/generate/transport.rb +34 -0
- data/lib/pdk/generate.rb +21 -8
- data/lib/pdk/logger.rb +24 -6
- data/lib/pdk/module/build.rb +125 -37
- data/lib/pdk/module/convert.rb +146 -65
- data/lib/pdk/module/metadata.rb +72 -71
- data/lib/pdk/module/release.rb +255 -0
- data/lib/pdk/module/update.rb +48 -37
- data/lib/pdk/module/update_manager.rb +75 -39
- data/lib/pdk/module.rb +10 -2
- data/lib/pdk/monkey_patches.rb +268 -0
- data/lib/pdk/report/event.rb +36 -48
- data/lib/pdk/report.rb +35 -22
- data/lib/pdk/template/fetcher/git.rb +84 -0
- data/lib/pdk/template/fetcher/local.rb +29 -0
- data/lib/pdk/template/fetcher.rb +100 -0
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +108 -0
- data/lib/pdk/template/renderer/v1/renderer.rb +131 -0
- data/lib/pdk/template/renderer/v1/template_file.rb +100 -0
- data/lib/pdk/template/renderer/v1.rb +25 -0
- data/lib/pdk/template/renderer.rb +97 -0
- data/lib/pdk/template/template_dir.rb +67 -0
- data/lib/pdk/template.rb +52 -0
- data/lib/pdk/tests/unit.rb +101 -51
- data/lib/pdk/util/bundler.rb +44 -42
- data/lib/pdk/util/changelog_generator.rb +138 -0
- data/lib/pdk/util/env.rb +48 -0
- data/lib/pdk/util/filesystem.rb +139 -2
- data/lib/pdk/util/git.rb +108 -8
- data/lib/pdk/util/json_finder.rb +86 -0
- data/lib/pdk/util/puppet_strings.rb +125 -0
- data/lib/pdk/util/puppet_version.rb +71 -87
- data/lib/pdk/util/ruby_version.rb +49 -25
- data/lib/pdk/util/template_uri.rb +283 -0
- data/lib/pdk/util/vendored_file.rb +34 -42
- data/lib/pdk/util/version.rb +11 -10
- data/lib/pdk/util/windows/api_types.rb +74 -44
- data/lib/pdk/util/windows/file.rb +31 -27
- data/lib/pdk/util/windows/process.rb +74 -0
- data/lib/pdk/util/windows/string.rb +19 -12
- data/lib/pdk/util/windows.rb +2 -0
- data/lib/pdk/util.rb +111 -124
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
- data/lib/pdk/validate/external_command_validator.rb +213 -0
- data/lib/pdk/validate/internal_ruby_validator.rb +101 -0
- data/lib/pdk/validate/invokable_validator.rb +238 -0
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +84 -0
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +76 -0
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +131 -0
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
- data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +38 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +135 -0
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +22 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +79 -0
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +83 -0
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +45 -0
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
- data/lib/pdk/validate/validator.rb +120 -0
- data/lib/pdk/validate/validator_group.rb +107 -0
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +86 -0
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
- data/lib/pdk/validate.rb +86 -12
- data/lib/pdk/version.rb +2 -2
- data/lib/pdk.rb +60 -10
- metadata +138 -100
- data/lib/pdk/cli/module/build.rb +0 -14
- data/lib/pdk/cli/module/generate.rb +0 -45
- data/lib/pdk/cli/module.rb +0 -14
- data/lib/pdk/i18n.rb +0 -4
- data/lib/pdk/module/templatedir.rb +0 -321
- data/lib/pdk/template_file.rb +0 -95
- data/lib/pdk/validate/base_validator.rb +0 -215
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -86
- data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -109
- data/lib/pdk/validate/metadata_validator.rb +0 -30
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -67
- data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -112
- data/lib/pdk/validate/puppet_validator.rb +0 -30
- data/lib/pdk/validate/ruby/rubocop.rb +0 -77
- data/lib/pdk/validate/ruby_validator.rb +0 -29
- data/lib/pdk/validate/tasks/metadata_lint.rb +0 -126
- data/lib/pdk/validate/tasks/name.rb +0 -88
- data/lib/pdk/validate/tasks_validator.rb +0 -33
- data/lib/pdk/validate/yaml/syntax.rb +0 -109
- data/lib/pdk/validate/yaml_validator.rb +0 -31
- data/locales/config.yaml +0 -21
- data/locales/pdk.pot +0 -1291
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
# pdk
|
1
|
+
# pdk
|
2
|
+
|
3
|
+
[![Code Owners](https://img.shields.io/badge/owners-DevX--team-blue)](https://github.com/puppetlabs/pdk/blob/main/CODEOWNERS)
|
4
|
+
[![ci](https://github.com/puppetlabs/pdk/actions/workflows/ci.yml/badge.svg)](https://github.com/puppetlabs/pdk/actions/workflows/ci.yml)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/pdk.svg)](https://badge.fury.io/rb/pdk)
|
2
6
|
|
3
7
|
* [Installation](#installation)
|
4
8
|
* [Basic usage](#basic-usage)
|
@@ -13,15 +17,16 @@ PDK includes testing tools, a complete module skeleton, and command line tools t
|
|
13
17
|
|
14
18
|
PDK includes the following tools:
|
15
19
|
|
16
|
-
Tool
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
puppet-
|
22
|
-
|
23
|
-
|
24
|
-
rspec-puppet
|
20
|
+
|Tool|Description|Owned by Puppet|
|
21
|
+
|----|-----------|---------------|
|
22
|
+
|facterdb|A gem that contains facts for Operating Systems.| N |
|
23
|
+
|metadata-json-lint|Validates and lints `metadata.json` files in modules against Puppet module metadata style guidelines.| N |
|
24
|
+
|pdk|Tool to generate and test modules and module content, such as classes, from the command line.| Y |
|
25
|
+
|puppet-lint|Checks your Puppet code against the recommendations in the Puppet language style guide.| Y |
|
26
|
+
|puppet-syntax|Checks for correct syntax in Puppet manifests, templates, and Hiera YAML.| N |
|
27
|
+
|puppetlabs_spec_helper|Provides classes, methods, and Rake tasks to help with spec testing Puppet code.| Y |
|
28
|
+
|rspec-puppet|Tests the behavior of Puppet when it compiles your manifests into a catalog of Puppet resources.| Y |
|
29
|
+
|rspec-puppet-facts|Adds support for running `rspec-puppet` tests against the facts for your supported operating systems.| N |
|
25
30
|
|
26
31
|
|
27
32
|
## Installation
|
@@ -93,7 +98,7 @@ This command validates the metadata, Puppet code syntax and style, and Ruby synt
|
|
93
98
|
|
94
99
|
### Run unit tests
|
95
100
|
|
96
|
-
PDK's [default template](https://github.com/puppetlabs/pdk-templates) sets up [rspec](http://rspec.info/) for Ruby-level unit testing, and [rspec-puppet](https://github.com/
|
101
|
+
PDK's [default template](https://github.com/puppetlabs/pdk-templates) sets up [rspec](http://rspec.info/) for Ruby-level unit testing, and [rspec-puppet](https://github.com/puppetlabs/rspec-puppet/) for catalog-level unit testing.
|
97
102
|
|
98
103
|
In the module's directory, run unit tests with:
|
99
104
|
|
@@ -103,22 +108,19 @@ pdk test unit
|
|
103
108
|
|
104
109
|
This command runs all available unit tests.
|
105
110
|
|
106
|
-
## Experimental features
|
107
|
-
|
108
|
-
### `pdk bundle` command
|
109
|
-
|
110
|
-
This command executes arbitrary commands in a bundler context within the module you're currently working on. Arguments to this command are passed straight through to bundler. This command is experimental and can lead to errors that can't be resolved by the pdk itself.
|
111
|
-
|
112
|
-
Note that for most uses, you must use the `--` to separate bundler options from pdk options. Compare the following two commands:
|
113
|
-
|
114
111
|
## Module Compatibility
|
115
112
|
|
116
|
-
**PDK Version Compatibility:** Modules created with PDK
|
113
|
+
**PDK Version Compatibility:** Modules created with PDK validate against and run on all Puppet and Ruby version combinations currently under maintenance (see https://docs.puppet.com/puppet/latest/about_agent.html and https://puppet.com/misc/puppet-enterprise-lifecycle)
|
117
114
|
|
118
115
|
## Contributing
|
119
116
|
|
120
117
|
PDK encourages community contributions. See the [CONTRIBUTING.md](CONTRIBUTING.md) file for development notes.
|
121
118
|
|
119
|
+
## License
|
120
|
+
|
121
|
+
This codebase is licensed under Apache 2.0. However, the open source dependencies included in this codebase might be subject to other software licenses such as AGPL, GPL2.0, and MIT.
|
122
|
+
|
122
123
|
## Contact Information
|
123
124
|
|
124
|
-
|
125
|
+
* [For reporting bugs](https://github.com/puppetlabs/pdk/blob/main/CONTRIBUTING.md#reporting-bugs)
|
126
|
+
* To contact us with questions, [join the Puppet Community on Slack](https://slack.puppet.com/)
|
data/lib/pdk/answer_file.rb
CHANGED
@@ -1,121 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
require 'pdk/util/filesystem'
|
1
|
+
require 'pdk'
|
3
2
|
|
4
3
|
module PDK
|
5
|
-
# Singleton accessor to the current answer file being used by the PDK.
|
6
|
-
#
|
7
|
-
# @return [PDK::AnswerFile] The AnswerFile instance currently being used by
|
8
|
-
# the PDK.
|
9
|
-
def self.answers
|
10
|
-
@answer_file ||= PDK::AnswerFile.new
|
11
|
-
end
|
12
|
-
|
13
|
-
# Specify the path to a custom answer file that the PDK should use.
|
14
|
-
#
|
15
|
-
# @param path [String] A path on disk to the file where the PDK should store
|
16
|
-
# answers to interactive questions.
|
17
|
-
def self.answer_file=(path)
|
18
|
-
@answer_file = PDK::AnswerFile.new(path)
|
19
|
-
end
|
20
|
-
|
21
4
|
class AnswerFile
|
22
|
-
attr_reader :answers
|
23
|
-
attr_reader :answer_file_path
|
24
|
-
|
25
|
-
include PDK::Util::Filesystem
|
26
|
-
|
27
|
-
# Initialises the AnswerFile object, which stores the responses to certain
|
28
|
-
# interactive questions.
|
29
|
-
#
|
30
|
-
# @param answer_file_path [String, nil] The path on disk to the file where
|
31
|
-
# the answers will be stored and read from. If not specified (or `nil`),
|
32
|
-
# the default path will be used (see #default_answer_file_path).
|
33
|
-
#
|
34
|
-
# @raise (see #read_from_disk)
|
35
|
-
def initialize(answer_file_path = nil)
|
36
|
-
@answer_file_path = answer_file_path || default_answer_file_path
|
37
|
-
@answers = read_from_disk
|
38
|
-
end
|
39
|
-
|
40
|
-
# Retrieve the stored answer to a question.
|
41
|
-
#
|
42
|
-
# @param question [String] The question name/identifying string.
|
43
|
-
#
|
44
|
-
# @return [Object] The answer to the question, or `nil` if no answer found.
|
45
|
-
def [](question)
|
46
|
-
answers[question]
|
47
|
-
end
|
48
|
-
|
49
|
-
# Update the stored answers in memory and then save them to disk.
|
50
|
-
#
|
51
|
-
# @param new_answers [Hash{String => Object}] The new questions and answers
|
52
|
-
# to be merged into the existing answers.
|
53
|
-
#
|
54
|
-
# @raise [PDK::CLI::FatalError] if the new answers are not provided as
|
55
|
-
# a Hash.
|
56
|
-
# @raise (see #save_to_disk)
|
57
|
-
def update!(new_answers = {})
|
58
|
-
unless new_answers.is_a?(Hash)
|
59
|
-
raise PDK::CLI::FatalError, _('Answer file can be updated only with a Hash')
|
60
|
-
end
|
61
|
-
|
62
|
-
answers.merge!(new_answers)
|
63
|
-
|
64
|
-
save_to_disk
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
5
|
# Determine the default path to the answer file.
|
70
6
|
#
|
71
7
|
# @return [String] The path on disk to the default answer file.
|
72
|
-
def default_answer_file_path
|
73
|
-
File.join(PDK::Util.cachedir, 'answers.json')
|
74
|
-
end
|
75
|
-
|
76
|
-
# Read existing answers into memory from the answer file on disk.
|
77
|
-
#
|
78
|
-
# @raise [PDK::CLI::FatalError] If the answer file exists but can not be
|
79
|
-
# read.
|
80
|
-
#
|
81
|
-
# @return [Hash{String => Object}] The existing questions and answers.
|
82
|
-
def read_from_disk
|
83
|
-
return {} if !File.file?(answer_file_path) || File.zero?(answer_file_path)
|
84
|
-
|
85
|
-
unless File.readable?(answer_file_path)
|
86
|
-
raise PDK::CLI::FatalError, _("Unable to open '%{file}' for reading") % {
|
87
|
-
file: answer_file_path,
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
answers = JSON.parse(File.read(answer_file_path))
|
92
|
-
if answers.is_a?(Hash)
|
93
|
-
answers
|
94
|
-
else
|
95
|
-
PDK.logger.warn _("Answer file '%{path}' did not contain a valid set of answers, recreating it") % {
|
96
|
-
path: answer_file_path,
|
97
|
-
}
|
98
|
-
{}
|
99
|
-
end
|
100
|
-
rescue JSON::JSONError
|
101
|
-
PDK.logger.warn _("Answer file '%{path}' did not contain valid JSON, recreating it") % {
|
102
|
-
path: answer_file_path,
|
103
|
-
}
|
104
|
-
{}
|
105
|
-
end
|
106
|
-
|
107
|
-
# Save the in memory answer set to the answer file on disk.
|
108
|
-
#
|
109
|
-
# @raise [PDK::CLI::FatalError] if the answer file can not be written to.
|
110
|
-
def save_to_disk
|
111
|
-
FileUtils.mkdir_p(File.dirname(answer_file_path))
|
112
|
-
|
113
|
-
write_file(answer_file_path, JSON.pretty_generate(answers))
|
114
|
-
rescue SystemCallError, IOError => e
|
115
|
-
raise PDK::CLI::FatalError, _("Unable to write '%{file}': %{msg}") % {
|
116
|
-
file: answer_file_path,
|
117
|
-
msg: e.message,
|
118
|
-
}
|
8
|
+
def self.default_answer_file_path
|
9
|
+
PDK::Util::Filesystem.expand_path(File.join(PDK::Util.cachedir, 'answers.json'))
|
119
10
|
end
|
120
11
|
end
|
121
12
|
end
|
data/lib/pdk/bolt.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Bolt
|
5
|
+
# Returns true or false depending on if any of the common files and directories in
|
6
|
+
# a Bolt Project are found in the specified directory. If a directory is not specified,
|
7
|
+
# the current working directory is used.
|
8
|
+
#
|
9
|
+
# @see https://puppet.com/docs/bolt/latest/bolt_project_directories.html
|
10
|
+
#
|
11
|
+
# @return [boolean] True if any bolt specific files or directories are present
|
12
|
+
#
|
13
|
+
def bolt_project_root?(path = Dir.pwd)
|
14
|
+
return true if File.basename(path) == 'Boltdir' && PDK::Util::Filesystem.directory?(path)
|
15
|
+
|
16
|
+
PDK::Util::Filesystem.file?(File.join(path, 'bolt.yaml'))
|
17
|
+
end
|
18
|
+
module_function :bolt_project_root?
|
19
|
+
end
|
20
|
+
end
|
data/lib/pdk/cli/build.rb
CHANGED
@@ -1,76 +1,73 @@
|
|
1
|
-
|
1
|
+
module PDK
|
2
|
+
module CLI
|
3
|
+
@build_cmd = @base_cmd.define_command do
|
4
|
+
name 'build'
|
5
|
+
usage 'build [options]'
|
6
|
+
summary 'Builds a package from the module that can be published to the Puppet Forge.'
|
2
7
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
usage _('build [options]')
|
7
|
-
summary _('Builds a package from the module that can be published to the Puppet Forge.')
|
8
|
+
option nil, 'target-dir',
|
9
|
+
'The target directory where you want PDK to write the package.',
|
10
|
+
argument: :required, default: File.join(Dir.pwd, 'pkg')
|
8
11
|
|
9
|
-
|
10
|
-
_('The target directory where you want PDK to write the package.'),
|
11
|
-
argument: :required, default: File.join(Dir.pwd, 'pkg')
|
12
|
+
option nil, 'force', 'Skips the prompts and builds the module package.'
|
12
13
|
|
13
|
-
|
14
|
+
run do |opts, _args, _cmd|
|
15
|
+
require 'pdk/module/build'
|
16
|
+
require 'pdk/module/metadata'
|
17
|
+
require 'pdk/cli/util'
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
# Make sure build is being run in a valid module directory with a metadata.json
|
20
|
+
PDK::CLI::Util.ensure_in_module!(
|
21
|
+
message: '`pdk build` can only be run from inside a valid module with a metadata.json.',
|
22
|
+
log_level: :info
|
23
|
+
)
|
17
24
|
|
18
|
-
|
19
|
-
PDK::CLI::Util.ensure_in_module!(
|
20
|
-
message: _('`pdk build` can only be run from inside a valid module with a metadata.json.'),
|
21
|
-
log_level: :info,
|
22
|
-
)
|
25
|
+
module_metadata = PDK::Module::Metadata.from_file('metadata.json')
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
module_metadata.write!('metadata.json')
|
27
|
+
# TODO: Ensure forge metadata has been set, or call out to interview
|
28
|
+
# to set it.
|
29
|
+
#
|
30
|
+
unless module_metadata.forge_ready?
|
31
|
+
if opts[:force]
|
32
|
+
PDK.logger.warn "This module is missing the following fields in the metadata.json: #{module_metadata.missing_fields.join(', ')}. " \
|
33
|
+
'These missing fields may affect the visibility of the module on the Forge.'
|
34
|
+
else
|
35
|
+
module_metadata.interview_for_forge!
|
36
|
+
module_metadata.write!('metadata.json')
|
37
|
+
end
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
+
builder = PDK::Module::Build.new(opts)
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
unless opts[:force]
|
43
|
+
if builder.package_already_exists?
|
44
|
+
PDK.logger.info format("The file '%{package}' already exists.", package: builder.package_file)
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
unless PDK::CLI::Util.prompt_for_yes('Overwrite?', default: false)
|
47
|
+
PDK.logger.info 'Build cancelled; exiting.'
|
48
|
+
exit 0
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
unless builder.module_pdk_compatible?
|
53
|
+
PDK.logger.info 'This module is not compatible with PDK, so PDK can not validate or test this build. ' \
|
53
54
|
'Unvalidated modules may have errors when uploading to the Forge. ' \
|
54
|
-
'To make this module PDK compatible and use validate features, cancel the build and run `pdk convert`.'
|
55
|
+
'To make this module PDK compatible and use validate features, cancel the build and run `pdk convert`.'
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
unless PDK::CLI::Util.prompt_for_yes('Continue build without converting?')
|
58
|
+
PDK.logger.info 'Build cancelled; exiting.'
|
59
|
+
exit 0
|
60
|
+
end
|
59
61
|
end
|
60
62
|
end
|
61
|
-
end
|
62
63
|
|
63
|
-
|
64
|
-
module_name: module_metadata.data['name'],
|
65
|
-
module_version: module_metadata.data['version'],
|
66
|
-
}
|
64
|
+
PDK.logger.info format('Building %{module_name} version %{module_version}', module_name: module_metadata.data['name'], module_version: module_metadata.data['version'])
|
67
65
|
|
68
|
-
|
66
|
+
builder.build
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}
|
68
|
+
PDK.logger.info format('Build of %{package_name} has completed successfully. Built package can be found here: %{package_path}', package_name: module_metadata.data['name'],
|
69
|
+
package_path: builder.package_file)
|
70
|
+
end
|
74
71
|
end
|
75
72
|
end
|
76
73
|
end
|
data/lib/pdk/cli/bundle.rb
CHANGED
@@ -1,42 +1,46 @@
|
|
1
|
+
module PDK
|
2
|
+
module CLI
|
3
|
+
@bundle_cmd = @base_cmd.define_command do
|
4
|
+
name 'bundle'
|
5
|
+
usage 'bundle [bundler_options]'
|
6
|
+
summary 'Command pass-through to bundler'
|
7
|
+
description <<~EOF
|
8
|
+
For advanced users, pdk bundle runs arbitrary commands in the bundler environment that pdk manages.
|
9
|
+
Careless use of this command can lead to errors that pdk can't help recover from.
|
10
|
+
EOF
|
11
|
+
skip_option_parsing
|
1
12
|
|
2
|
-
|
3
|
-
|
4
|
-
name 'bundle'
|
5
|
-
usage _('bundle [bundler_options]')
|
6
|
-
summary _('(Experimental) Command pass-through to bundler')
|
7
|
-
description _(<<-EOF
|
8
|
-
[experimental] For advanced users, pdk bundle runs arbitrary commands in the bundler environment that pdk manages.
|
9
|
-
Careless use of this command can lead to errors that pdk can't help recover from.
|
13
|
+
run do |_opts, args, _cmd|
|
14
|
+
require 'pdk/util/bundler'
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
skip_option_parsing
|
16
|
+
PDK::CLI::Util.ensure_in_module!(
|
17
|
+
message: '`pdk bundle` can only be run from inside a valid module directory.'
|
18
|
+
)
|
15
19
|
|
16
|
-
|
17
|
-
PDK::CLI::Util.ensure_in_module!(
|
18
|
-
message: _('`pdk bundle` can only be run from inside a valid module directory.'),
|
19
|
-
)
|
20
|
+
PDK::CLI::Util.validate_puppet_version_opts({})
|
20
21
|
|
21
|
-
|
22
|
+
screen_view_name = ['bundle']
|
23
|
+
screen_view_name << args[0] if args.size >= 1
|
24
|
+
screen_view_name << args[1] if args.size >= 2 && args[0] == 'exec'
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
# Ensure that the correct Ruby is activated before running command.
|
27
|
+
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env({})
|
28
|
+
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
|
26
29
|
|
27
|
-
|
30
|
+
gemfile_env = PDK::Util::Bundler::BundleHelper.gemfile_env(puppet_env[:gemset])
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
c.update_environment(gemfile_env)
|
32
|
-
end
|
32
|
+
require 'pdk/cli/exec'
|
33
|
+
require 'pdk/cli/exec/interactive_command'
|
33
34
|
|
34
|
-
|
35
|
+
command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, *args).tap do |c|
|
36
|
+
c.context = :pwd
|
37
|
+
c.update_environment(gemfile_env)
|
38
|
+
end
|
35
39
|
|
36
|
-
|
37
|
-
$stderr.puts result[:stderr]
|
40
|
+
result = command.execute!
|
38
41
|
|
39
|
-
|
42
|
+
exit result[:exit_code]
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module PDK
|
2
|
+
module CLI
|
3
|
+
@console_cmd = @base_cmd.define_command do
|
4
|
+
name 'console'
|
5
|
+
usage 'console [console_options]'
|
6
|
+
summary '(Experimental) Start a session of the puppet debugger console.'
|
7
|
+
default_subcommand 'help'
|
8
|
+
description <<~EOF
|
9
|
+
The pdk console runs a interactive session of the puppet debugger tool to test out snippets of code, run
|
10
|
+
language evaluations, datatype prototyping and much more. A virtual playground for your puppet code!
|
11
|
+
For usage details see the puppet debugger docs at https://docs.puppet-debugger.com.
|
12
|
+
|
13
|
+
EOF
|
14
|
+
|
15
|
+
PDK::CLI.puppet_version_options(self)
|
16
|
+
PDK::CLI.puppet_dev_option(self)
|
17
|
+
# we have to skip option parsing because it is expected the user
|
18
|
+
# will be passing additional args that are passed to the debugger
|
19
|
+
skip_option_parsing
|
20
|
+
|
21
|
+
# TODO: using -h or --help skips the pdk help and passes to puppet debugger help
|
22
|
+
run do |_opts, args, _cmd|
|
23
|
+
require 'pdk/cli/util'
|
24
|
+
require 'pdk/util'
|
25
|
+
|
26
|
+
PDK::CLI::Util.ensure_in_module!(
|
27
|
+
message: 'Console can only be run from inside a valid module directory',
|
28
|
+
log_level: :fatal
|
29
|
+
)
|
30
|
+
|
31
|
+
PDK::CLI::Util.module_version_check
|
32
|
+
|
33
|
+
processed_options, processed_args = process_opts(args)
|
34
|
+
|
35
|
+
PDK::CLI::Util.validate_puppet_version_opts(processed_options)
|
36
|
+
|
37
|
+
# TODO: figure out if we need to remove default configs set by puppet
|
38
|
+
# so it is scoped for the module only
|
39
|
+
# "--environmentpath"...
|
40
|
+
flags = if PDK::Util.in_module_root?
|
41
|
+
["--basemodulepath=#{base_module_path}",
|
42
|
+
"--modulepath=#{base_module_path}"]
|
43
|
+
else
|
44
|
+
[]
|
45
|
+
end
|
46
|
+
debugger_args = ['debugger'] + processed_args + flags
|
47
|
+
result = run_in_module(debugger_args, **processed_options)
|
48
|
+
|
49
|
+
exit result[:exit_code]
|
50
|
+
end
|
51
|
+
|
52
|
+
# Logs a fatal message about the gem missing and how to add it
|
53
|
+
def inform_user_for_missing_gem(gem_name = 'puppet-debugger', version = '~> 0.14')
|
54
|
+
PDK.logger.fatal(<<~EOF
|
55
|
+
Your Gemfile is missing the #{gem_name} gem. You can add the missing gem
|
56
|
+
by updating your #{File.join(PDK::Util.module_root, '.sync.yml')} file with the following
|
57
|
+
and running pdk update.
|
58
|
+
|
59
|
+
Gemfile:
|
60
|
+
required:
|
61
|
+
":development":
|
62
|
+
- gem: #{gem_name}
|
63
|
+
version: "#{version}"
|
64
|
+
|
65
|
+
EOF
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Boolean] - true if the gem was found in the lockfile
|
70
|
+
# @param [String] - name of ruby gem to check in bundle lockfile
|
71
|
+
def gem_in_bundle_lockfile?(gem_name)
|
72
|
+
require 'bundler'
|
73
|
+
require 'pdk/util/bundler'
|
74
|
+
|
75
|
+
lock_file_path = PDK::Util::Bundler::BundleHelper.new.gemfile_lock
|
76
|
+
PDK.logger.debug("Checking lockfile #{lock_file_path} for #{gem_name}")
|
77
|
+
lock_file = ::Bundler::LockfileParser.new(::Bundler.read_file(lock_file_path))
|
78
|
+
!lock_file.specs.find { |spec| spec.name.eql?(gem_name) }.nil?
|
79
|
+
rescue ::Bundler::GemfileNotFound => e
|
80
|
+
PDK.logger.debug e.message
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
def check_fixtures_dir
|
85
|
+
existing_path = base_module_path.split(':').find do |path|
|
86
|
+
PDK::Util::Filesystem.directory?(path) && Dir.entries(path).length > 2
|
87
|
+
end
|
88
|
+
PDK.logger.warn 'Module fixtures not found, please run pdk bundle exec rake spec_prep.' unless existing_path
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [Array] - array of split options [{:"puppet-version"=>"6.9.0"}, ['--loglevel=debug']]
|
92
|
+
# options are for the pdk and debugger pass through
|
93
|
+
def process_opts(opts)
|
94
|
+
args = opts.map do |e|
|
95
|
+
if /\A-{2}puppet|pe-version|dev/.match?(e)
|
96
|
+
value = e.split('=')
|
97
|
+
value.count < 2 ? value + [''] : value
|
98
|
+
end
|
99
|
+
end
|
100
|
+
args = args.compact.to_h
|
101
|
+
# symbolize keys
|
102
|
+
args = args.inject({}) do |memo, (k, v)| # rubocop:disable Style/EachWithObject
|
103
|
+
memo[k.sub('--', '').to_sym] = v
|
104
|
+
memo
|
105
|
+
end
|
106
|
+
# pass through all other args that are bound for puppet debugger
|
107
|
+
processed_args = opts.grep_v(/\A-{2}puppet|pe-version|dev/)
|
108
|
+
[args, processed_args]
|
109
|
+
end
|
110
|
+
|
111
|
+
# @param opts [Hash] - the options passed into the CRI command
|
112
|
+
# @param bundle_args [Array] array of bundle exec args and puppet debugger args
|
113
|
+
# @return [Hash] - a command result hash
|
114
|
+
def run_in_module(bundle_args, opts)
|
115
|
+
require 'pdk/cli/exec'
|
116
|
+
require 'pdk/cli/exec/interactive_command'
|
117
|
+
require 'pdk/util/ruby_version'
|
118
|
+
require 'pdk/util/bundler'
|
119
|
+
|
120
|
+
check_fixtures_dir
|
121
|
+
output = opts[:debug].nil?
|
122
|
+
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts, output)
|
123
|
+
gemfile_env = PDK::Util::Bundler::BundleHelper.gemfile_env(puppet_env[:gemset])
|
124
|
+
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
|
125
|
+
PDK::Util::RubyVersion.instance(puppet_env[:ruby_version])
|
126
|
+
PDK::Util::Bundler.ensure_bundle!(**puppet_env[:gemset])
|
127
|
+
unless gem_in_bundle_lockfile?('puppet-debugger')
|
128
|
+
inform_user_for_missing_gem
|
129
|
+
return { exit_code: 1 }
|
130
|
+
end
|
131
|
+
|
132
|
+
debugger_args = ['exec', 'puppet'] + bundle_args
|
133
|
+
command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, *debugger_args).tap do |c|
|
134
|
+
c.context = :pwd
|
135
|
+
c.update_environment(gemfile_env)
|
136
|
+
end
|
137
|
+
command.execute!
|
138
|
+
end
|
139
|
+
|
140
|
+
# @return [String] - the basemodulepath of the fixtures and modules from the current module
|
141
|
+
# also includes ./modules in case librarian puppet is used
|
142
|
+
def base_module_path
|
143
|
+
base_module_path = File.join(PDK::Util.module_fixtures_dir, 'modules')
|
144
|
+
"#{base_module_path}:#{File.join(PDK::Util.module_root, 'modules')}"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/lib/pdk/cli/convert.rb
CHANGED
@@ -1,41 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
raise PDK::CLI::ExitWithError,
|
1
|
+
module PDK
|
2
|
+
module CLI
|
3
|
+
@convert_cmd = @base_cmd.define_command do
|
4
|
+
name 'convert'
|
5
|
+
usage 'convert [options]'
|
6
|
+
summary 'Convert an existing module to be compatible with the PDK.'
|
7
|
+
|
8
|
+
PDK::CLI.template_url_option(self)
|
9
|
+
PDK::CLI.template_ref_option(self)
|
10
|
+
PDK::CLI.skip_interview_option(self)
|
11
|
+
PDK::CLI.full_interview_option(self)
|
12
|
+
flag nil, :noop, 'Do not convert the module, just output what would be done.'
|
13
|
+
flag nil, :force, 'Convert the module automatically, with no prompts.'
|
14
|
+
flag nil, :'add-tests', 'Add any missing tests while converting the module.'
|
15
|
+
flag nil, :'default-template', 'Convert the module to use the default PDK template.'
|
16
|
+
|
17
|
+
run do |opts, _args, _cmd|
|
18
|
+
# Write the context information to the debug log
|
19
|
+
PDK.context.to_debug_log
|
20
|
+
|
21
|
+
unless PDK.context.is_a?(PDK::Context::Module) || PDK.context.is_a?(PDK::Context::ControlRepo)
|
22
|
+
raise PDK::CLI::ExitWithError, '`pdk convert` can only be run from inside a valid module directory.'
|
23
|
+
end
|
24
|
+
|
25
|
+
raise PDK::CLI::ExitWithError, 'You can not specify --noop and --force when converting a module' if opts[:noop] && opts[:force]
|
26
|
+
|
27
|
+
if opts[:'default-template']
|
28
|
+
raise PDK::CLI::ExitWithError, 'You can not specify --template-url and --default-template.' if opts[:'template-url']
|
29
|
+
|
30
|
+
opts[:'template-url'] = PDK::Util::TemplateURI.default_template_addressable_uri.to_s
|
31
|
+
PDK.config.set(['user', 'module_defaults', 'template-url'], nil)
|
32
|
+
end
|
33
|
+
|
34
|
+
PDK::CLI::Util.validate_template_opts(opts)
|
35
|
+
|
36
|
+
if opts[:'skip-interview'] && opts[:'full-interview']
|
37
|
+
PDK.logger.info 'Ignoring --full-interview and continuing with --skip-interview.'
|
38
|
+
opts[:'full-interview'] = false
|
39
|
+
end
|
40
|
+
|
41
|
+
if opts[:force] && opts[:'full-interview']
|
42
|
+
PDK.logger.info 'Ignoring --full-interview and continuing with --force.'
|
43
|
+
opts[:'full-interview'] = false
|
44
|
+
end
|
45
|
+
|
46
|
+
PDK::Module::Convert.invoke(PDK.context.root_path, opts)
|
26
47
|
end
|
27
|
-
|
28
|
-
if opts[:'skip-interview'] && opts[:'full-interview']
|
29
|
-
PDK.logger.info _('Ignoring --full-interview and continuing with --skip-interview.')
|
30
|
-
opts[:'full-interview'] = false
|
31
|
-
end
|
32
|
-
|
33
|
-
if opts[:force] && opts[:'full-interview']
|
34
|
-
PDK.logger.info _('Ignoring --full-interview and continuing with --force.')
|
35
|
-
opts[:'full-interview'] = false
|
36
|
-
end
|
37
|
-
|
38
|
-
PDK::Module::Convert.invoke(opts)
|
39
48
|
end
|
40
49
|
end
|
41
50
|
end
|