Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #194 from ripienaar/191
Browse files Browse the repository at this point in the history
(#191) Add a 'mco choria show_config' command to inspect running config
  • Loading branch information
ripienaar committed Feb 14, 2017
2 parents 62749b2 + 26a68d8 commit ea88a17
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
|Date |Issue |Description |
|----------|------|---------------------------------------------------------------------------------------------------------|
|2017/02/14|191 |Add the `mco choria show_config` command to inspect active Choria configuration |
|2017/02/13|187 |Support *{{ ... }}* as well as *{{{ ... }}}* in templates |
|2017/02/13|177 |Add a shell script based data store |
|2017/02/12| |Release 0.0.22 |
Expand Down
66 changes: 65 additions & 1 deletion lib/mcollective/application/choria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Choria < Application
plan - view the plan for a specific environment
run - run a the plan for a specific environment
request_cert - requests a certificate from the Puppet CA
show_config - shows the active configuration parameters
The environment is chosen using --environment and the concurrent
runs may be limited using --batch.
Expand Down Expand Up @@ -69,7 +70,7 @@ def validate_configuration(configuration)
abort("Unknown command %s, valid commands are: %s" % [configuration[:command], valid_commands.join(", ")])
end

if !choria.has_client_public_cert? && configuration[:command] != "request_cert"
if !choria.has_client_public_cert? && !["request_cert", "show_config"].include?(configuration[:command])
abort("A certificate is needed from the Puppet CA for `%s`, please use the `request_cert` command" % choria.certname)
end
end
Expand Down Expand Up @@ -148,6 +149,69 @@ def run_command
end
end

def show_config_command # rubocop:disable Metrics/MethodLength
puppet_server = "%s:%s" % [choria.puppet_server[:target], choria.puppet_server[:port]]
puppetca_server = "%s:%s" % [choria.puppetca_server[:target], choria.puppetca_server[:port]]
puppetdb_server = "%s:%s" % [choria.puppetca_server[:target], choria.puppetca_server[:port]]
choria_settings = Config.instance.pluginconf.select {|k, _| k.start_with?("choria")}
middleware_servers = choria.middleware_servers("puppet", 42222).map {|s, p| "%s:%s" % [s, p]}.join(", ")
padding = choria_settings.keys.map(&:length).max + 2

begin
choria.check_ssl_setup(false)
valid_ssl = true
rescue
valid_ssl = false
end

puts "Active Choria configuration:"
puts
puts "The active configuration used in Choria comes from using Puppet AIO defaults, querying SRV"
puts "records and reading configuration files. The below information shows the completely resolved"
puts "configuration that will be used when running MCollective commands"
puts
puts "Puppet related:"
puts
puts " Puppet Server: %s" % puppet_server
puts " PuppetCA Server: %s" % puppetca_server
puts " PuppetDB Server: %s" % puppetdb_server
puts " Facter Command: %s" % choria.facter_cmd
puts " Facter Domain: %s" % choria.facter_domain
puts

puts "SSL setup:"
puts
if valid_ssl
puts " Valid SSL Setup: %s" % [Util.colorize(:green, "yes")]
else
puts " Valid SSL Setup: %s run 'mco choria request_cert'" % [Util.colorize(:red, "no")]
end
puts " Certname: %s" % choria.certname
puts " SSL Directory: %s (%s)" % [choria.ssl_dir, File.exist?(choria.ssl_dir) ? Util.colorize(:green, "found") : Util.colorize(:red, "absent")]
puts " Client Public Cert: %s (%s)" % [choria.client_public_cert, choria.has_client_public_cert? ? Util.colorize(:green, "found") : Util.colorize(:red, "absent")]
puts " Client Private Key: %s (%s)" % [choria.client_private_key, choria.has_client_private_key? ? Util.colorize(:green, "found") : Util.colorize(:red, "absent")]
puts " CA Path: %s (%s)" % [choria.ca_path, choria.has_ca? ? Util.colorize(:green, "found") : Util.colorize(:red, "absent")]
puts " CSR Path: %s (%s)" % [choria.csr_path, choria.has_csr? ? Util.colorize(:green, "found") : Util.colorize(:red, "absent")]
puts

puts "MCollective selated:"
puts
puts " MCollective Version: %s" % MCollective::VERSION
puts " Client Config File: %s" % Util.config_file_for_user
puts " Middleware Servers: %s" % middleware_servers
puts " SRV Domain: %s" % choria.srv_domain
puts

puts "Active Choria configuration settings as found in configuration files:"
puts

choria_settings.each do |k, v|
puts "%#{padding}s: %s" % [k, v]
end

puts
end

# Creates and cache a client to the Puppet RPC Agent
#
# @return [RPC::Client]
Expand Down
7 changes: 4 additions & 3 deletions lib/mcollective/util/choria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,17 @@ def fetch_environment

# Checks all the required SSL files exist
#
# @return [boolean]
# @param log [Boolean] log warnings when true
# @return [Boolean]
# @raise [StandardError] on failure
def check_ssl_setup
def check_ssl_setup(log=true)
valid = [client_public_cert, client_private_key, ca_path].map do |path|
Log.debug("Checking for SSL file %s" % path)

if File.exist?(path)
true
else
Log.warn("Cannot find SSL file %s" % path)
Log.warn("Cannot find SSL file %s" % path) if log
false
end
end.all?
Expand Down

0 comments on commit ea88a17

Please sign in to comment.