diff options
Diffstat (limited to 'lib/puppet/face')
-rw-r--r-- | lib/puppet/face/ca.rb | 7 | ||||
-rw-r--r-- | lib/puppet/face/file/download.rb | 7 | ||||
-rw-r--r-- | lib/puppet/face/file/store.rb | 2 | ||||
-rw-r--r-- | lib/puppet/face/instrumentation_data.rb | 3 | ||||
-rw-r--r-- | lib/puppet/face/instrumentation_listener.rb | 3 | ||||
-rw-r--r-- | lib/puppet/face/instrumentation_probe.rb | 3 | ||||
-rw-r--r-- | lib/puppet/face/module/build.rb | 4 | ||||
-rw-r--r-- | lib/puppet/face/module/generate.rb | 32 | ||||
-rw-r--r-- | lib/puppet/face/module/install.rb | 7 | ||||
-rw-r--r-- | lib/puppet/face/module/uninstall.rb | 7 | ||||
-rw-r--r-- | lib/puppet/face/module/upgrade.rb | 14 | ||||
-rw-r--r-- | lib/puppet/face/node/clean.rb | 2 | ||||
-rw-r--r-- | lib/puppet/face/parser.rb | 106 |
13 files changed, 163 insertions, 34 deletions
diff --git a/lib/puppet/face/ca.rb b/lib/puppet/face/ca.rb index 55475de87..9b7cc5eae 100644 --- a/lib/puppet/face/ca.rb +++ b/lib/puppet/face/ca.rb @@ -99,6 +99,7 @@ Puppet::Face.define(:ca, '0.1.0') do end action :destroy do + summary "Destroy named certificate or pending certificate request." when_invoked do |host, options| raise "Not a CA" unless Puppet::SSL::CertificateAuthority.ca? unless ca = Puppet::SSL::CertificateAuthority.instance @@ -111,6 +112,7 @@ Puppet::Face.define(:ca, '0.1.0') do end action :revoke do + summary "Add certificate to certificate revocation list." when_invoked do |host, options| raise "Not a CA" unless Puppet::SSL::CertificateAuthority.ca? unless ca = Puppet::SSL::CertificateAuthority.instance @@ -131,6 +133,7 @@ Puppet::Face.define(:ca, '0.1.0') do end action :generate do + summary "Generate a certificate for a named client." option "--dns-alt-names NAMES" do summary "Additional DNS names to add to the certificate request" description Puppet.settings.setting(:dns_alt_names).desc @@ -162,6 +165,7 @@ Puppet::Face.define(:ca, '0.1.0') do end action :sign do + summary "Sign an outstanding certificate request." option("--[no-]allow-dns-alt-names") do summary "Whether or not to accept DNS alt names in the certificate request" end @@ -186,6 +190,7 @@ Puppet::Face.define(:ca, '0.1.0') do end action :print do + summary "Print the full-text version of a host's certificate." when_invoked do |host, options| raise "Not a CA" unless Puppet::SSL::CertificateAuthority.ca? unless ca = Puppet::SSL::CertificateAuthority.instance @@ -198,6 +203,7 @@ Puppet::Face.define(:ca, '0.1.0') do end action :fingerprint do + summary "Print the DIGEST (defaults to the signing algorithm) fingerprint of a host's certificate." option "--digest ALGORITHM" do summary "The hash algorithm to use when displaying the fingerprint" end @@ -218,6 +224,7 @@ Puppet::Face.define(:ca, '0.1.0') do end action :verify do + summary "Verify the named certificate against the local CA certificate." when_invoked do |host, options| raise "Not a CA" unless Puppet::SSL::CertificateAuthority.ca? unless ca = Puppet::SSL::CertificateAuthority.instance diff --git a/lib/puppet/face/file/download.rb b/lib/puppet/face/file/download.rb index aae318565..3ab28b151 100644 --- a/lib/puppet/face/file/download.rb +++ b/lib/puppet/face/file/download.rb @@ -23,8 +23,11 @@ Puppet::Face.define(:file, '0.0.1') do if sum =~ /^puppet:\/\// # it's a puppet url require 'puppet/file_serving' require 'puppet/file_serving/content' - raise "Could not find metadata for #{sum}" unless content = Puppet::FileServing::Content.indirection.find(sum) - file = Puppet::FileBucket::File.new(content.content) + unless content = Puppet::FileServing::Content.indirection.find(sum) + raise "Could not find metadata for #{sum}" + end + pathname = Puppet::FileSystem.pathname(content.full_path()) + file = Puppet::FileBucket::File.new(pathname) else tester = Object.new tester.extend(Puppet::Util::Checksums) diff --git a/lib/puppet/face/file/store.rb b/lib/puppet/face/file/store.rb index dc43fee04..dc4c73b44 100644 --- a/lib/puppet/face/file/store.rb +++ b/lib/puppet/face/file/store.rb @@ -11,7 +11,7 @@ Puppet::Face.define(:file, '0.0.1') do EOT when_invoked do |path, options| - file = Puppet::FileBucket::File.new(Puppet::FileSystem.binread(path)) + file = Puppet::FileBucket::File.new(Puppet::FileSystem.pathname(path)) Puppet::FileBucket::File.indirection.terminus_class = :file Puppet::FileBucket::File.indirection.save file diff --git a/lib/puppet/face/instrumentation_data.rb b/lib/puppet/face/instrumentation_data.rb index c091f5542..05eb4fdb6 100644 --- a/lib/puppet/face/instrumentation_data.rb +++ b/lib/puppet/face/instrumentation_data.rb @@ -5,9 +5,10 @@ Puppet::Indirector::Face.define(:instrumentation_data, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" - summary "Manage instrumentation listener accumulated data." + summary "Manage instrumentation listener accumulated data. DEPRECATED." description <<-EOT This subcommand allows to retrieve the various listener data. + (DEPRECATED) This subcommand will be removed in Puppet 4.0. EOT get_action(:destroy).summary "Invalid for this subcommand." diff --git a/lib/puppet/face/instrumentation_listener.rb b/lib/puppet/face/instrumentation_listener.rb index 53b61bef7..e11ef407f 100644 --- a/lib/puppet/face/instrumentation_listener.rb +++ b/lib/puppet/face/instrumentation_listener.rb @@ -5,9 +5,10 @@ Puppet::Indirector::Face.define(:instrumentation_listener, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" - summary "Manage instrumentation listeners." + summary "Manage instrumentation listeners. DEPRECATED." description <<-EOT This subcommand enables/disables or list instrumentation listeners. + (DEPRECATED) This subcommand will be removed in Puppet 4.0. EOT get_action(:destroy).summary "Invalid for this subcommand." diff --git a/lib/puppet/face/instrumentation_probe.rb b/lib/puppet/face/instrumentation_probe.rb index 840eac70a..b77f5e977 100644 --- a/lib/puppet/face/instrumentation_probe.rb +++ b/lib/puppet/face/instrumentation_probe.rb @@ -5,9 +5,10 @@ Puppet::Indirector::Face.define(:instrumentation_probe, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" - summary "Manage instrumentation probes." + summary "Manage instrumentation probes. Deprecated" description <<-EOT This subcommand enables/disables or list instrumentation listeners. + (DEPRECATED) This subcommand will be removed in Puppet 4.0. EOT get_action(:find).summary "Invalid for this subcommand." diff --git a/lib/puppet/face/module/build.rb b/lib/puppet/face/module/build.rb index f1d006a74..5ee8b2363 100644 --- a/lib/puppet/face/module/build.rb +++ b/lib/puppet/face/module/build.rb @@ -43,11 +43,11 @@ Puppet::Face.define(:module, '1.0.0') do pwd = Dir.pwd module_path = Puppet::ModuleTool.find_module_root(pwd) if module_path.nil? - raise "Unable to find module root at #{pwd} or parent directories" + raise "Unable to find metadata.json or Modulefile in module root #{pwd} or parent directories. See <http://links.puppetlabs.com/modulefile> for required file format." end else unless Puppet::ModuleTool.is_module_root?(module_path) - raise "Unable to find module root at #{module_path}" + raise "Unable to find metadata.json or Modulefile in module root #{module_path}. See <http://links.puppetlabs.com/modulefile> for required file format." end end diff --git a/lib/puppet/face/module/generate.rb b/lib/puppet/face/module/generate.rb index f25e504cb..9b88a8c65 100644 --- a/lib/puppet/face/module/generate.rb +++ b/lib/puppet/face/module/generate.rb @@ -54,7 +54,7 @@ Puppet::Face.define(:module, '1.0.0') do "dependencies": [ { "name": "puppetlabs-stdlib", - "version_range": ">= 1.0.0" + "version_requirement": ">= 1.0.0" } ] } @@ -114,7 +114,7 @@ Puppet::Face.define(:module, '1.0.0') do 'name' => name, 'version' => '0.1.0', 'dependencies' => [ - { :name => 'puppetlabs-stdlib', :version_range => '>= 1.0.0' } + { 'name' => 'puppetlabs-stdlib', 'version_requirement' => '>= 1.0.0' } ] ) rescue ArgumentError @@ -216,21 +216,29 @@ module Puppet::ModuleTool::Generate Puppet.notice "Generating module at #{dest}..." FileUtils.cp_r skeleton_path, dest - populate_erb_templates(metadata, dest) + populate_templates(metadata, dest) return dest end - def populate_erb_templates(metadata, destination) - Puppet.notice "Populating ERB templates..." + def populate_templates(metadata, destination) + Puppet.notice "Populating templates..." - templates = destination + '**/*.erb' - Dir[templates.to_s].each do |erb| - path = Pathname.new(erb) - content = ERB.new(path.read).result(binding) + formatters = { + :erb => proc { |data, ctx| ERB.new(data).result(ctx) }, + :template => proc { |data, _| data }, + } - target = path.parent + path.basename('.erb') - target.open('w') { |f| f.write(content) } - path.unlink + formatters.each do |type, block| + templates = destination + "**/*.#{type}" + + Dir.glob(templates.to_s, File::FNM_DOTMATCH).each do |erb| + path = Pathname.new(erb) + content = block[path.read, binding] + + target = path.parent + path.basename(".#{type}") + target.open('w') { |f| f.write(content) } + path.unlink + end end end diff --git a/lib/puppet/face/module/install.rb b/lib/puppet/face/module/install.rb index 929ff9db8..0644d0518 100644 --- a/lib/puppet/face/module/install.rb +++ b/lib/puppet/face/module/install.rb @@ -84,9 +84,10 @@ Puppet::Face.define(:module, '1.0.0') do arguments "<name>" option "--force", "-f" do - summary "Force overwrite of existing module, if any." + summary "Force overwrite of existing module, if any. (Implies --ignore-dependencies.)" description <<-EOT Force overwrite of existing module, if any. + Implies --ignore-dependencies. EOT end @@ -104,9 +105,9 @@ Puppet::Face.define(:module, '1.0.0') do end option "--ignore-dependencies" do - summary "Do not attempt to install dependencies" + summary "Do not attempt to install dependencies. (Implied by --force.)" description <<-EOT - Do not attempt to install dependencies. (Implied by --force.) + Do not attempt to install dependencies. Implied by --force. EOT end diff --git a/lib/puppet/face/module/uninstall.rb b/lib/puppet/face/module/uninstall.rb index 60db2c2b7..2a5e675b2 100644 --- a/lib/puppet/face/module/uninstall.rb +++ b/lib/puppet/face/module/uninstall.rb @@ -40,6 +40,13 @@ Puppet::Face.define(:module, '1.0.0') do EOT end + option "--ignore-changes", "-c" do + summary "Ignore any local changes made. (Implied by --force.)" + description <<-EOT + Uninstall an installed module even if there are local changes to it. (Implied by --force.) + EOT + end + option "--version=" do summary "The version of the module to uninstall" description <<-EOT diff --git a/lib/puppet/face/module/upgrade.rb b/lib/puppet/face/module/upgrade.rb index fe9dde644..f671887e1 100644 --- a/lib/puppet/face/module/upgrade.rb +++ b/lib/puppet/face/module/upgrade.rb @@ -32,17 +32,25 @@ Puppet::Face.define(:module, '1.0.0') do arguments "<name>" option "--force", "-f" do - summary "Force upgrade of an installed module." + summary "Force upgrade of an installed module. (Implies --ignore-dependencies.)" description <<-EOT Force the upgrade of an installed module even if there are local changes or the possibility of causing broken dependencies. + Implies --ignore-dependencies. EOT end option "--ignore-dependencies" do - summary "Do not attempt to install dependencies" + summary "Do not attempt to install dependencies. (Implied by --force.)" description <<-EOT - Do not attempt to install dependencies. (Implied by --force.) + Do not attempt to install dependencies. Implied by --force. + EOT + end + + option "--ignore-changes", "-c" do + summary "Ignore and overwrite any local changes made. (Implied by --force.)" + description <<-EOT + Upgrade an installed module even if there are local changes to it. (Implied by --force.) EOT end diff --git a/lib/puppet/face/node/clean.rb b/lib/puppet/face/node/clean.rb index 903e93819..f1c3c34b8 100644 --- a/lib/puppet/face/node/clean.rb +++ b/lib/puppet/face/node/clean.rb @@ -144,7 +144,7 @@ Puppet::Face.define(:node, '0.0.1') do end def environment - @environment ||= Puppet.lookup(:environments).get(Puppet[:environment]) + @environment ||= Puppet.lookup(:current_environment) end def type_is_ensurable(resource) diff --git a/lib/puppet/face/parser.rb b/lib/puppet/face/parser.rb index a3835bfa0..b3dec4ed7 100644 --- a/lib/puppet/face/parser.rb +++ b/lib/puppet/face/parser.rb @@ -15,6 +15,13 @@ Puppet::Face.define(:parser, '0.0.1') do This action validates Puppet DSL syntax without compiling a catalog or syncing any resources. If no manifest files are provided, it will validate the default site manifest. + + When validating with --parser current, the validation stops after the first + encountered issue. + + When validating with --parser future, multiple issues per file are reported up + to the settings of max_error, and max_warnings. The processing stops + after having reported issues for the first encountered file with errors. EOT examples <<-'EOT' Validate the default site manifest at /etc/puppet/manifests/site.pp: @@ -44,21 +51,106 @@ Puppet::Face.define(:parser, '0.0.1') do end missing_files = [] files.each do |file| - missing_files << file if ! Puppet::FileSystem.exist?(file) - validate_manifest(file) + if Puppet::FileSystem.exist?(file) + validate_manifest(file) + else + missing_files << file + end + end + unless missing_files.empty? + raise Puppet::Error, "One or more file(s) specified did not exist:\n#{missing_files.collect {|f| " " * 3 + f + "\n"}}" end - raise Puppet::Error, "One or more file(s) specified did not exist:\n#{missing_files.collect {|f| " " * 3 + f + "\n"}}" if ! missing_files.empty? nil end end + + action (:dump) do + summary "Outputs a dump of the internal parse tree for debugging" + arguments "-e <source>| [<manifest> ...] " + returns "A dump of the resulting AST model unless there are syntax or validation errors." + description <<-'EOT' + This action parses and validates the Puppet DSL syntax without compiling a catalog + or syncing any resources. It automatically turns on the future parser for the parsing. + + The command accepts one or more manifests (.pp) files, or an -e followed by the puppet + source text. + If no arguments are given, the stdin is read (unless it is attached to a terminal) + + The output format of the dumped tree is not API, it may change from time to time. + EOT + + option "--e <source>" do + default_to { nil } + summary "dump one source expression given on the command line." + end + + option("--[no-]validate") do + summary "Whether or not to validate the parsed result, if no-validate only syntax errors are reported" + end + + when_invoked do |*args| + require 'puppet/pops' + options = args.pop + if options[:e] + dump_parse(options[:e], 'command-line-string', options, false) + elsif args.empty? + if ! STDIN.tty? + dump_parse(STDIN.read, 'stdin', options, false) + else + raise Puppet::Error, "No input to parse given on command line or stdin" + end + else + missing_files = [] + files = args + available_files = files.select do |file| + Puppet::FileSystem.exist?(file) + end + missing_files = files - available_files + + dumps = available_files.collect do |file| + dump_parse(File.read(file), file, options) + end.join("") + + if missing_files.empty? + dumps + else + dumps + "One or more file(s) specified did not exist:\n" + missing_files.collect { |f| " #{f}" }.join("\n") + end + end + end + end + + def dump_parse(source, filename, options, show_filename = true) + output = "" + dumper = Puppet::Pops::Model::ModelTreeDumper.new + evaluating_parser = Puppet::Pops::Parser::EvaluatingParser.new + begin + if options[:validate] + parse_result = evaluating_parser.parse_string(source, filename) + else + # side step the assert_and_report step + parse_result = evaluating_parser.parser.parse_string(source) + end + if show_filename + output << "--- #{filename}" + end + output << dumper.dump(parse_result) << "\n" + rescue Puppet::ParseError => detail + if show_filename + Puppet.err("--- #{filename}") + end + Puppet.err(detail.message) + "" + end + end + # @api private def validate_manifest(manifest = nil) - configured_environment = Puppet.lookup(:environments).get(Puppet[:environment]) - validation_environment = manifest ? - configured_environment.override_with(:manifest => manifest) : - configured_environment + env = Puppet.lookup(:current_environment) + validation_environment = manifest ? env.override_with(:manifest => manifest) : env + validation_environment.check_for_reparse validation_environment.known_resource_types.clear rescue => detail |