pdk 1.3.2 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +63 -1
- data/lib/pdk/cli.rb +6 -0
- data/lib/pdk/cli/build.rb +76 -0
- data/lib/pdk/cli/convert.rb +11 -0
- data/lib/pdk/cli/module.rb +1 -0
- data/lib/pdk/cli/module/build.rb +14 -0
- data/lib/pdk/cli/new.rb +1 -0
- data/lib/pdk/cli/new/module.rb +6 -0
- data/lib/pdk/cli/new/provider.rb +27 -0
- data/lib/pdk/cli/update.rb +32 -0
- data/lib/pdk/cli/util.rb +1 -0
- data/lib/pdk/cli/util/option_normalizer.rb +0 -19
- data/lib/pdk/cli/util/option_validator.rb +4 -27
- data/lib/pdk/generate.rb +2 -1
- data/lib/pdk/generate/module.rb +63 -37
- data/lib/pdk/generate/provider.rb +80 -0
- data/lib/pdk/generate/puppet_object.rb +25 -6
- data/lib/pdk/module/build.rb +208 -0
- data/lib/pdk/module/convert.rb +81 -50
- data/lib/pdk/module/metadata.rb +13 -0
- data/lib/pdk/module/templatedir.rb +12 -8
- data/lib/pdk/module/update.rb +111 -0
- data/lib/pdk/module/update_manager.rb +27 -21
- data/lib/pdk/util.rb +13 -1
- data/lib/pdk/util/git.rb +15 -0
- data/lib/pdk/validate/puppet/puppet_syntax.rb +44 -25
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +279 -95
- metadata +37 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3c5a5c1229e58da80498533964f4d7ae26cd5e7
|
4
|
+
data.tar.gz: 656f786a2d964d6ee08da649d7649580a9ea24d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de547cceb59992ac724afbfd57888c9aea06bb875dff612d5f4fab63e52b25f39fead90fb9720fc9915c4bff40774efe1d03174742884c2903f44555b8a03a5f
|
7
|
+
data.tar.gz: c716798699ba50f829f8b444b41706c12d0f4310ae0ad80efd000f893ef82dd34cde7c193dcef98c059ad79f9d011cd9a4d77f625eb6eab0b0bd99cfa73e9adc
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,68 @@ All changes to this repo will be documented in this file.
|
|
4
4
|
See the [release notes](https://puppet.com/docs/pdk/latest/release_notes.html) for a high-level summary.
|
5
5
|
|
6
6
|
|
7
|
-
## [v1.
|
7
|
+
## [v1.4.1](https://github.com/puppetlabs/pdk/tree/v1.4.1) (2018-02-26)
|
8
|
+
[Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.4.0...v1.4.1)
|
9
|
+
|
10
|
+
**Fixed bugs:**
|
11
|
+
|
12
|
+
- pdk update and convert fixes [\#433](https://github.com/puppetlabs/pdk/pull/433) ([bmjen](https://github.com/bmjen))
|
13
|
+
|
14
|
+
**Merged pull requests:**
|
15
|
+
|
16
|
+
- Updates msg in pdk update on unconverted module [\#442](https://github.com/puppetlabs/pdk/pull/442) ([bmjen](https://github.com/bmjen))
|
17
|
+
- Release 1.4.1 amend [\#441](https://github.com/puppetlabs/pdk/pull/441) ([bmjen](https://github.com/bmjen))
|
18
|
+
- \(maint\) pdk update checks if module is pdk compat [\#440](https://github.com/puppetlabs/pdk/pull/440) ([bmjen](https://github.com/bmjen))
|
19
|
+
- Release 1.4.1 amend [\#439](https://github.com/puppetlabs/pdk/pull/439) ([bmjen](https://github.com/bmjen))
|
20
|
+
- \(maint\) add a `pdk module build` command to point to `pdk build` [\#438](https://github.com/puppetlabs/pdk/pull/438) ([DavidS](https://github.com/DavidS))
|
21
|
+
- \(maint\) unhide the `update` command [\#437](https://github.com/puppetlabs/pdk/pull/437) ([DavidS](https://github.com/DavidS))
|
22
|
+
- \(maint\) update: don't mention deleted Gemfile.lock and .bundle/config [\#436](https://github.com/puppetlabs/pdk/pull/436) ([DavidS](https://github.com/DavidS))
|
23
|
+
- Release 1.4.1 [\#435](https://github.com/puppetlabs/pdk/pull/435) ([bmjen](https://github.com/bmjen))
|
24
|
+
|
25
|
+
## [v1.4.0](https://github.com/puppetlabs/pdk/tree/v1.4.0) (2018-02-21)
|
26
|
+
[Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.3.2...v1.4.0)
|
27
|
+
|
28
|
+
**Implemented enhancements:**
|
29
|
+
|
30
|
+
- \(PDK-771\) Wireframe `pdk update` CLI [\#419](https://github.com/puppetlabs/pdk/pull/419) ([rodjek](https://github.com/rodjek))
|
31
|
+
- \(PDK-550\) Removes unrequired questions from module interview [\#410](https://github.com/puppetlabs/pdk/pull/410) ([bmjen](https://github.com/bmjen))
|
32
|
+
- \(PDK-506\) pdk new provider [\#409](https://github.com/puppetlabs/pdk/pull/409) ([DavidS](https://github.com/DavidS))
|
33
|
+
- \(PDK-748\) Wireframe `pdk build` CLI [\#407](https://github.com/puppetlabs/pdk/pull/407) ([rodjek](https://github.com/rodjek))
|
34
|
+
|
35
|
+
**Fixed bugs:**
|
36
|
+
|
37
|
+
- if a newer rubocop version is installed, pdk should fall-back to safe defaults [\#420](https://github.com/puppetlabs/pdk/issues/420)
|
38
|
+
- Update validation regex and error message for module name question [\#430](https://github.com/puppetlabs/pdk/pull/430) ([ardrigh](https://github.com/ardrigh))
|
39
|
+
- \(PDK-789\) Add pdk metadata to all generated templatedirs. [\#428](https://github.com/puppetlabs/pdk/pull/428) ([bmjen](https://github.com/bmjen))
|
40
|
+
|
41
|
+
**Closed issues:**
|
42
|
+
|
43
|
+
- WS1.Reputation - Symantec Endpoint Protection [\#403](https://github.com/puppetlabs/pdk/issues/403)
|
44
|
+
- task input\_method 'powershell' fails validation [\#369](https://github.com/puppetlabs/pdk/issues/369)
|
45
|
+
- PDK should have an option to disable progress indicator to make it usable in CI [\#323](https://github.com/puppetlabs/pdk/issues/323)
|
46
|
+
|
47
|
+
**Merged pull requests:**
|
48
|
+
|
49
|
+
- Release 1.4.0 [\#432](https://github.com/puppetlabs/pdk/pull/432) ([bmjen](https://github.com/bmjen))
|
50
|
+
- \(PDK-808\) Fix to pdk update when there are sync.yml changes [\#431](https://github.com/puppetlabs/pdk/pull/431) ([bmjen](https://github.com/bmjen))
|
51
|
+
- \(PDK-806\) Update metadata interview text if metadata.json already exists [\#429](https://github.com/puppetlabs/pdk/pull/429) ([rodjek](https://github.com/rodjek))
|
52
|
+
- \(FIXUP\) Make `pdk build` overwrite prompt consistent [\#427](https://github.com/puppetlabs/pdk/pull/427) ([scotje](https://github.com/scotje))
|
53
|
+
- \(maint\) Update unit tests to use exit\_zero/exit\_nonzero matchers [\#426](https://github.com/puppetlabs/pdk/pull/426) ([rodjek](https://github.com/rodjek))
|
54
|
+
- \(PDK-804\) Fixes error in build without ignore file [\#425](https://github.com/puppetlabs/pdk/pull/425) ([bmjen](https://github.com/bmjen))
|
55
|
+
- \(PDK-799\) Adds unit tests for the UX validation [\#423](https://github.com/puppetlabs/pdk/pull/423) ([bmjen](https://github.com/bmjen))
|
56
|
+
- \(PDK-754\) Interview for missing or Forge only metadata before build [\#422](https://github.com/puppetlabs/pdk/pull/422) ([bmjen](https://github.com/bmjen))
|
57
|
+
- \(PDK-772\) Refactor PDK::Module::Convert for re-use in PDK::Module::Update [\#421](https://github.com/puppetlabs/pdk/pull/421) ([rodjek](https://github.com/rodjek))
|
58
|
+
- Revert "\(maint\) pin pdk-templates version ref to workaround puppet 5.… [\#418](https://github.com/puppetlabs/pdk/pull/418) ([bmjen](https://github.com/bmjen))
|
59
|
+
- \(PDK-799\) Adds validations and checks to pdk build workflow [\#416](https://github.com/puppetlabs/pdk/pull/416) ([bmjen](https://github.com/bmjen))
|
60
|
+
- Small fixes [\#415](https://github.com/puppetlabs/pdk/pull/415) ([DavidS](https://github.com/DavidS))
|
61
|
+
- \(maint\) Make sure we use pdk-templates master if in development [\#414](https://github.com/puppetlabs/pdk/pull/414) ([bmjen](https://github.com/bmjen))
|
62
|
+
- \(maint\) bump version for dev. [\#412](https://github.com/puppetlabs/pdk/pull/412) ([bmjen](https://github.com/bmjen))
|
63
|
+
- \(PDK-758\) Initial port & cleanup of the module build code [\#411](https://github.com/puppetlabs/pdk/pull/411) ([rodjek](https://github.com/rodjek))
|
64
|
+
- \(maint\) Fix error templatedir error message [\#408](https://github.com/puppetlabs/pdk/pull/408) ([DavidS](https://github.com/DavidS))
|
65
|
+
- \(MAINT\) remove dead code [\#406](https://github.com/puppetlabs/pdk/pull/406) ([DavidS](https://github.com/DavidS))
|
66
|
+
- \(PDK-575\) Run puppet parser validate with an dummy empty puppet.conf [\#402](https://github.com/puppetlabs/pdk/pull/402) ([rodjek](https://github.com/rodjek))
|
67
|
+
|
68
|
+
## [v1.3.2](https://github.com/puppetlabs/pdk/tree/v1.3.2) (2018-01-17)
|
8
69
|
[Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.3.1...v1.3.2)
|
9
70
|
|
10
71
|
**Closed issues:**
|
@@ -15,6 +76,7 @@ See the [release notes](https://puppet.com/docs/pdk/latest/release_notes.html) f
|
|
15
76
|
**Merged pull requests:**
|
16
77
|
|
17
78
|
- \(maint\) Default PDK::TEMPLATE\_REF to PDK::VERSION [\#405](https://github.com/puppetlabs/pdk/pull/405) ([rodjek](https://github.com/rodjek))
|
79
|
+
- 1.3.2 Release Prep [\#404](https://github.com/puppetlabs/pdk/pull/404) ([HelenCampbell](https://github.com/HelenCampbell))
|
18
80
|
- \(PDK-552\) Soften PDK::CLI::Util.ensure\_in\_module! error messages [\#401](https://github.com/puppetlabs/pdk/pull/401) ([rodjek](https://github.com/rodjek))
|
19
81
|
- \(PDK-739\) Fall back to default template if necessary [\#400](https://github.com/puppetlabs/pdk/pull/400) ([rodjek](https://github.com/rodjek))
|
20
82
|
|
data/lib/pdk/cli.rb
CHANGED
@@ -45,6 +45,10 @@ module PDK::CLI
|
|
45
45
|
dsl.option nil, 'skip-interview', _('When specified, skips interactive querying of metadata.')
|
46
46
|
end
|
47
47
|
|
48
|
+
def self.full_interview_option(dsl)
|
49
|
+
dsl.option nil, 'full-interview', _('When specified, interactive querying of metadata will include all optional questions.')
|
50
|
+
end
|
51
|
+
|
48
52
|
@base_cmd = Cri::Command.define do
|
49
53
|
name 'pdk'
|
50
54
|
usage _('pdk command [options]')
|
@@ -83,9 +87,11 @@ module PDK::CLI
|
|
83
87
|
end
|
84
88
|
|
85
89
|
require 'pdk/cli/bundle'
|
90
|
+
require 'pdk/cli/build'
|
86
91
|
require 'pdk/cli/convert'
|
87
92
|
require 'pdk/cli/new'
|
88
93
|
require 'pdk/cli/test'
|
94
|
+
require 'pdk/cli/update'
|
89
95
|
require 'pdk/cli/validate'
|
90
96
|
require 'pdk/cli/module'
|
91
97
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'pdk/cli/util'
|
2
|
+
|
3
|
+
module PDK::CLI
|
4
|
+
@build_cmd = @base_cmd.define_command do
|
5
|
+
name 'build'
|
6
|
+
usage _('build [options]')
|
7
|
+
summary _('Builds a package from the module that can be published to the Puppet Forge.')
|
8
|
+
|
9
|
+
option nil, 'target-dir',
|
10
|
+
_('The target directory where you want PDK to write the package.'),
|
11
|
+
argument: :required, default: File.join(Dir.pwd, 'pkg')
|
12
|
+
|
13
|
+
option nil, 'force', _('Skips the prompts and builds the module package.')
|
14
|
+
|
15
|
+
run do |opts, _args, _cmd|
|
16
|
+
require 'pdk/module/build'
|
17
|
+
|
18
|
+
# Make sure build is being run in a valid module directory with a metadata.json
|
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
|
+
)
|
23
|
+
|
24
|
+
module_metadata = PDK::Module::Metadata.from_file('metadata.json')
|
25
|
+
|
26
|
+
# TODO: Ensure forge metadata has been set, or call out to interview
|
27
|
+
# to set it.
|
28
|
+
#
|
29
|
+
unless module_metadata.forge_ready?
|
30
|
+
if opts[:force]
|
31
|
+
PDK.logger.error _('This module is missing required fields in the metadata.json. Re-run the build command without --force to add this information.')
|
32
|
+
exit 1
|
33
|
+
else
|
34
|
+
module_metadata.interview_for_forge!
|
35
|
+
module_metadata.write!('metadata.json')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
builder = PDK::Module::Build.new(opts)
|
40
|
+
|
41
|
+
unless opts[:force]
|
42
|
+
if builder.package_already_exists?
|
43
|
+
PDK.logger.info _("The file '%{package}' already exists.") % { package: builder.package_file }
|
44
|
+
|
45
|
+
unless PDK::CLI::Util.prompt_for_yes(_('Overwrite?'), default: false)
|
46
|
+
PDK.logger.info _('Build cancelled; exiting.')
|
47
|
+
exit 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
unless builder.module_pdk_compatible?
|
52
|
+
PDK.logger.info _('This module is not compatible with PDK, so PDK can not validate or test this build. ' \
|
53
|
+
'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
|
+
|
56
|
+
unless PDK::CLI::Util.prompt_for_yes(_('Continue build without converting?'))
|
57
|
+
PDK.logger.info _('Build cancelled; exiting.')
|
58
|
+
exit 0
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
PDK.logger.info _('Building %{module_name} version %{module_version}') % {
|
64
|
+
module_name: module_metadata.data['name'],
|
65
|
+
module_version: module_metadata.data['version'],
|
66
|
+
}
|
67
|
+
|
68
|
+
builder.build
|
69
|
+
|
70
|
+
PDK.logger.info _('Build of %{package_name} has completed successfully. Built package can be found here: %{package_path}') % {
|
71
|
+
package_name: module_metadata.data['name'],
|
72
|
+
package_path: builder.package_file,
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/pdk/cli/convert.rb
CHANGED
@@ -8,6 +8,7 @@ module PDK::CLI
|
|
8
8
|
|
9
9
|
PDK::CLI.template_url_option(self)
|
10
10
|
PDK::CLI.skip_interview_option(self)
|
11
|
+
PDK::CLI.full_interview_option(self)
|
11
12
|
flag nil, :noop, _('Do not convert the module, just output what would be done.')
|
12
13
|
flag nil, :force, _('Convert the module automatically, with no prompts.')
|
13
14
|
|
@@ -24,6 +25,16 @@ module PDK::CLI
|
|
24
25
|
raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when converting a module')
|
25
26
|
end
|
26
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
|
+
|
27
38
|
PDK::Module::Convert.invoke(opts)
|
28
39
|
end
|
29
40
|
end
|
data/lib/pdk/cli/module.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'tty-prompt'
|
2
|
+
|
3
|
+
module PDK::CLI
|
4
|
+
@module_build_cmd = @module_cmd.define_command do
|
5
|
+
name 'build'
|
6
|
+
usage _('build')
|
7
|
+
summary _('This command is now \'pdk build\'.')
|
8
|
+
|
9
|
+
run do |_opts, _args, _cmd|
|
10
|
+
PDK.logger.warn(_('Modules are built using the ‘pdk build’ command.'))
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/pdk/cli/new.rb
CHANGED
data/lib/pdk/cli/new/module.rb
CHANGED
@@ -6,6 +6,7 @@ module PDK::CLI
|
|
6
6
|
|
7
7
|
PDK::CLI.template_url_option(self)
|
8
8
|
PDK::CLI.skip_interview_option(self)
|
9
|
+
PDK::CLI.full_interview_option(self)
|
9
10
|
|
10
11
|
option nil, 'license', _('Specifies the license this module is written under. ' \
|
11
12
|
"This should be a identifier from https://spdx.org/licenses/. Common values are 'Apache-2.0', 'MIT', or 'proprietary'."), argument: :required
|
@@ -16,6 +17,11 @@ module PDK::CLI
|
|
16
17
|
module_name = args[0]
|
17
18
|
target_dir = args[1]
|
18
19
|
|
20
|
+
if opts[:'skip-interview'] && opts[:'full-interview']
|
21
|
+
PDK.logger.info _('Ignoring --full-interview and continuing with --skip-interview.')
|
22
|
+
opts[:'full-interview'] = false
|
23
|
+
end
|
24
|
+
|
19
25
|
unless module_name.nil? || module_name.empty?
|
20
26
|
module_name_parts = module_name.split('-', 2)
|
21
27
|
if module_name_parts.size > 1
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module PDK::CLI
|
2
|
+
@new_provider_cmd = @new_cmd.define_command do
|
3
|
+
name 'provider'
|
4
|
+
usage _('provider [options] <name>')
|
5
|
+
summary _('[experimental] Create a new ruby provider named <name> using given options')
|
6
|
+
|
7
|
+
PDK::CLI.template_url_option(self)
|
8
|
+
|
9
|
+
run do |opts, args, _cmd|
|
10
|
+
PDK::CLI::Util.ensure_in_module!
|
11
|
+
|
12
|
+
provider_name = args[0]
|
13
|
+
module_dir = Dir.pwd
|
14
|
+
|
15
|
+
if provider_name.nil? || provider_name.empty?
|
16
|
+
puts command.help
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
unless Util::OptionValidator.valid_provider_name?(provider_name)
|
21
|
+
raise PDK::CLI::ExitWithError, _("'%{name}' is not a valid provider name") % { name: provider_name }
|
22
|
+
end
|
23
|
+
|
24
|
+
PDK::Generate::Provider.new(module_dir, provider_name, opts).run
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'pdk/cli/util'
|
2
|
+
require 'pdk/util'
|
3
|
+
|
4
|
+
module PDK::CLI
|
5
|
+
@update_cmd = @base_cmd.define_command do
|
6
|
+
name 'update'
|
7
|
+
usage _('update [options]')
|
8
|
+
summary _('Update a module that has been created by or converted for use by PDK.')
|
9
|
+
|
10
|
+
flag nil, :noop, _('Do not update the module, just output what would be done.')
|
11
|
+
flag nil, :force, _('Update the module automatically, with no prompts.')
|
12
|
+
|
13
|
+
run do |opts, _args, _cmd|
|
14
|
+
require 'pdk/module/update'
|
15
|
+
|
16
|
+
PDK::CLI::Util.ensure_in_module!(
|
17
|
+
message: _('`pdk update` can only be run from inside a valid module directory.'),
|
18
|
+
log_level: :info,
|
19
|
+
)
|
20
|
+
|
21
|
+
raise PDK::CLI::ExitWithError, _('This module does not appear to be PDK compatible. To make the module compatible with PDK, run `pdk convert`.') unless PDK::Util.module_pdk_compatible?
|
22
|
+
|
23
|
+
if opts[:noop] && opts[:force]
|
24
|
+
raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when updating a module')
|
25
|
+
end
|
26
|
+
|
27
|
+
updater = PDK::Module::Update.new(opts)
|
28
|
+
|
29
|
+
updater.run
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/pdk/cli/util.rb
CHANGED
@@ -47,25 +47,6 @@ module PDK
|
|
47
47
|
{ method: "write_#{format}".to_sym, target: target }
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
51
|
-
def self.parameter_specification(value)
|
52
|
-
param_name, param_type = value.split(':', 2)
|
53
|
-
param_type = 'String' if param_type.nil?
|
54
|
-
|
55
|
-
unless PDK::CLI::Util::OptionValidator.valid_param_name?(param_name)
|
56
|
-
raise PDK::CLI::ExitWithError, _("'%{name}' is not a valid parameter name") % {
|
57
|
-
name: param_name,
|
58
|
-
}
|
59
|
-
end
|
60
|
-
|
61
|
-
unless PDK::CLI::Util::OptionValidator.valid_data_type?(param_type)
|
62
|
-
raise PDK::CLI::ExitWithError, _("'%{type}' is not a valid data type") % {
|
63
|
-
type: param_type,
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
{ name: param_name, type: param_type }
|
68
|
-
end
|
69
50
|
end
|
70
51
|
end
|
71
52
|
end
|
@@ -24,6 +24,10 @@ module PDK
|
|
24
24
|
end
|
25
25
|
singleton_class.send(:alias_method, :valid_task_name?, :valid_module_name?)
|
26
26
|
|
27
|
+
# https://puppet.com/docs/puppet/5.3/custom_types.html#creating-a-type only says the name has to be a ruby symbol.
|
28
|
+
# Let's assume that only strings similar to module names can actually be resolved by the puppet language.
|
29
|
+
singleton_class.send(:alias_method, :valid_provider_name?, :valid_module_name?)
|
30
|
+
|
27
31
|
# Validate a Puppet namespace against the regular expression in the
|
28
32
|
# documentation: https://docs.puppet.com/puppet/4.10/lang_reserved.html#classes-and-defined-resource-types
|
29
33
|
def self.valid_namespace?(string)
|
@@ -46,33 +50,6 @@ module PDK
|
|
46
50
|
|
47
51
|
!(string =~ %r{\A[a-z][a-zA-Z0-9_]*\Z}).nil?
|
48
52
|
end
|
49
|
-
|
50
|
-
# Naive validation of a data type declaration. Extracts all the bare
|
51
|
-
# words and compares them against a list of known data types.
|
52
|
-
#
|
53
|
-
# @todo This prevents the use of dynamic data types like TypeReferences
|
54
|
-
# but that shouldn't be a problem for the current feature set. This
|
55
|
-
# should be replaced eventually by something better (or just call
|
56
|
-
# Puppet::Pops::Types::TypesParser)
|
57
|
-
def self.valid_data_type?(string)
|
58
|
-
valid_types = %w[
|
59
|
-
String Integer Float Numeric Boolean Array Hash Regexp Undef
|
60
|
-
Default Class Resource Scalar Collection Variant Data Pattern Enum
|
61
|
-
Tuple Struct Optional Catalogentry Type Any Callable NotUndef
|
62
|
-
].freeze
|
63
|
-
|
64
|
-
string.scan(%r{\b(([a-zA-Z0-9_]+)(,|\[|\]|\Z))}) do |result|
|
65
|
-
type = result[1]
|
66
|
-
|
67
|
-
return false unless string =~ %r{\A[A-Z]}
|
68
|
-
|
69
|
-
unless valid_types.include?(type)
|
70
|
-
PDK.logger.warn(_("Non-standard data type '%{type}', make sure the type is available in your code, or dependencies") % { type: type })
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
true
|
75
|
-
end
|
76
53
|
end
|
77
54
|
end
|
78
55
|
end
|
data/lib/pdk/generate.rb
CHANGED
data/lib/pdk/generate/module.rb
CHANGED
@@ -98,7 +98,7 @@ module PDK
|
|
98
98
|
login_clean = 'username' if login_clean.empty?
|
99
99
|
|
100
100
|
if login_clean != login
|
101
|
-
PDK.logger.
|
101
|
+
PDK.logger.debug _('Your username is not a valid Forge username. Proceeding with the username %{username}. You can fix this later in metadata.json.') % {
|
102
102
|
username: login_clean,
|
103
103
|
}
|
104
104
|
end
|
@@ -125,8 +125,6 @@ module PDK
|
|
125
125
|
metadata = PDK::Module::Metadata.new(defaults)
|
126
126
|
module_interview(metadata, opts) unless opts[:'skip-interview']
|
127
127
|
|
128
|
-
metadata.update!('pdk-version' => PDK::Util::Version.version_string)
|
129
|
-
|
130
128
|
metadata
|
131
129
|
end
|
132
130
|
|
@@ -156,8 +154,8 @@ module PDK
|
|
156
154
|
question: _('If you have a name for your module, add it here.'),
|
157
155
|
help: _('This is the name that will be associated with your module, it should be relevant to the modules content.'),
|
158
156
|
required: true,
|
159
|
-
validate_pattern: %r{\A[a-z0-
|
160
|
-
validate_message: _('Module names can only
|
157
|
+
validate_pattern: %r{\A[a-z][a-z0-9_]*\Z}i,
|
158
|
+
validate_message: _('Module names must begin with a lowercase letter and can only include lowercase letters, numbers, and underscores.'),
|
161
159
|
},
|
162
160
|
{
|
163
161
|
name: 'forge_username',
|
@@ -176,6 +174,7 @@ module PDK
|
|
176
174
|
validate_pattern: %r{\A[0-9]+\.[0-9]+\.[0-9]+},
|
177
175
|
validate_message: _('Semantic Version numbers must be in the form MAJOR.MINOR.PATCH'),
|
178
176
|
default: metadata.data['version'],
|
177
|
+
forge_only: true,
|
179
178
|
},
|
180
179
|
{
|
181
180
|
name: 'author',
|
@@ -249,30 +248,34 @@ module PDK
|
|
249
248
|
default: [1, 2, 7],
|
250
249
|
},
|
251
250
|
{
|
252
|
-
name:
|
253
|
-
question:
|
254
|
-
help:
|
255
|
-
required:
|
256
|
-
default:
|
251
|
+
name: 'summary',
|
252
|
+
question: _('Summarize the purpose of this module in a single sentence.'),
|
253
|
+
help: _('This helps other Puppet users understand what the module does.'),
|
254
|
+
required: true,
|
255
|
+
default: metadata.data['summary'],
|
256
|
+
forge_only: true,
|
257
257
|
},
|
258
258
|
{
|
259
|
-
name:
|
260
|
-
question:
|
261
|
-
help:
|
262
|
-
required:
|
263
|
-
default:
|
259
|
+
name: 'source',
|
260
|
+
question: _('If there is a source code repository for this module, enter the URL here.'),
|
261
|
+
help: _('Skip this if no repository exists yet. You can update this later in the metadata.json.'),
|
262
|
+
required: true,
|
263
|
+
default: metadata.data['source'],
|
264
|
+
forge_only: true,
|
264
265
|
},
|
265
266
|
{
|
266
|
-
name:
|
267
|
-
question:
|
268
|
-
help:
|
269
|
-
default:
|
267
|
+
name: 'project_page',
|
268
|
+
question: _('If there is a URL where others can learn more about this module, enter it here.'),
|
269
|
+
help: _('Optional. You can update this later in the metadata.json.'),
|
270
|
+
default: metadata.data['project_page'],
|
271
|
+
forge_only: true,
|
270
272
|
},
|
271
273
|
{
|
272
|
-
name:
|
273
|
-
question:
|
274
|
-
help:
|
275
|
-
default:
|
274
|
+
name: 'issues_url',
|
275
|
+
question: _('If there is a public issue tracker for this module, enter its URL here.'),
|
276
|
+
help: _('Optional. You can update this later in the metadata.json.'),
|
277
|
+
default: metadata.data['issues_url'],
|
278
|
+
forge_only: true,
|
276
279
|
},
|
277
280
|
]
|
278
281
|
|
@@ -280,18 +283,33 @@ module PDK
|
|
280
283
|
|
281
284
|
interview = PDK::CLI::Util::Interview.new(prompt)
|
282
285
|
|
283
|
-
|
284
|
-
|
286
|
+
if opts[:only_ask]
|
287
|
+
questions.reject! do |question|
|
288
|
+
if %w[module_name forge_username].include?(question[:name])
|
289
|
+
metadata.data['name'] && metadata.data['name'] =~ %r{\A[a-z0-9]+-[a-z0-9]+\Z}i
|
290
|
+
else
|
291
|
+
!opts[:only_ask].include?(question[:name])
|
292
|
+
end
|
293
|
+
end
|
294
|
+
else
|
295
|
+
questions.reject! { |q| q[:name] == 'module_name' } if opts.key?(:module_name)
|
296
|
+
questions.reject! { |q| q[:name] == 'license' } if opts.key?(:license)
|
297
|
+
questions.reject! { |q| q[:forge_only] } unless opts.key?(:'full-interview')
|
298
|
+
end
|
285
299
|
|
286
300
|
interview.add_questions(questions)
|
287
301
|
|
302
|
+
action = File.file?('metadata.json') ? _('update') : _('create')
|
288
303
|
puts _(
|
289
|
-
"\nWe need to
|
304
|
+
"\nWe need to %{action} the metadata.json file for this module, so we\'re going to ask you %{count} " \
|
290
305
|
"questions.\n" \
|
291
306
|
'If the question is not applicable to this module, accept the default option ' \
|
292
307
|
'shown after each question. You can modify any answers at any time by manually updating ' \
|
293
308
|
"the metadata.json file.\n\n",
|
294
|
-
) % {
|
309
|
+
) % {
|
310
|
+
count: interview.num_questions,
|
311
|
+
action: action,
|
312
|
+
}
|
295
313
|
|
296
314
|
answers = interview.run
|
297
315
|
|
@@ -300,15 +318,21 @@ module PDK
|
|
300
318
|
exit 0
|
301
319
|
end
|
302
320
|
|
303
|
-
|
304
|
-
|
321
|
+
unless answers['forge_username'].nil?
|
322
|
+
opts[:username] = answers['forge_username']
|
305
323
|
|
306
|
-
|
307
|
-
|
308
|
-
|
324
|
+
unless answers['module_name'].nil?
|
325
|
+
opts[:module_name] = answers['module_name']
|
326
|
+
|
327
|
+
answers.delete('module_name')
|
328
|
+
end
|
309
329
|
|
310
|
-
|
311
|
-
|
330
|
+
answers['name'] = "#{opts[:username]}-" + (opts[:module_name])
|
331
|
+
answers.delete('forge_username')
|
332
|
+
end
|
333
|
+
|
334
|
+
answers['license'] = opts[:license] if opts.key?(:license)
|
335
|
+
answers['operatingsystem_support'].flatten! if answers.key?('operatingsystem_support')
|
312
336
|
|
313
337
|
metadata.update!(answers)
|
314
338
|
|
@@ -326,9 +350,11 @@ module PDK
|
|
326
350
|
end
|
327
351
|
|
328
352
|
PDK.answers.update!(
|
329
|
-
|
330
|
-
|
331
|
-
|
353
|
+
{
|
354
|
+
'forge_username' => opts[:username],
|
355
|
+
'author' => answers['author'],
|
356
|
+
'license' => answers['license'],
|
357
|
+
}.delete_if { |_key, value| value.nil? },
|
332
358
|
)
|
333
359
|
end
|
334
360
|
end
|