hammer_cli 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hammer +2 -1
  3. data/config/cli_config.template.yml +1 -1
  4. data/doc/release_notes.md +4 -0
  5. data/lib/hammer_cli/ca_cert_fetcher.rb +43 -28
  6. data/lib/hammer_cli/ca_cert_manager.rb +71 -0
  7. data/lib/hammer_cli/ssloptions.rb +7 -0
  8. data/lib/hammer_cli/version.rb +1 -1
  9. data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
  10. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  11. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  12. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  13. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  14. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  15. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  16. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  17. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  18. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  19. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  20. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  21. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  22. data/man/hammer.1.gz +0 -0
  23. data/test/reports/TEST-Fields-ContainerField-display-.xml +7 -0
  24. data/test/reports/TEST-Fields-ContainerField-display-blank-is-allowed.xml +15 -0
  25. data/test/reports/TEST-Fields-ContainerField-display-blank-is-not-allowed.xml +15 -0
  26. data/test/reports/TEST-Fields-ContainerField.xml +7 -0
  27. data/test/reports/TEST-Fields-Field-display-.xml +7 -0
  28. data/test/reports/TEST-Fields-Field-display-blank-is-allowed.xml +11 -0
  29. data/test/reports/TEST-Fields-Field-display-blank-is-not-allowed.xml +11 -0
  30. data/test/reports/TEST-Fields-Field-hide-blank-.xml +11 -0
  31. data/test/reports/TEST-Fields-Field-parameters.xml +9 -0
  32. data/test/reports/TEST-Fields-Field.xml +13 -0
  33. data/test/reports/TEST-HammerCLI-AbstractCommand-build-options.xml +15 -0
  34. data/test/reports/TEST-HammerCLI-AbstractCommand-exception-handler.xml +13 -0
  35. data/test/reports/TEST-HammerCLI-AbstractCommand-logging.xml +21 -0
  36. data/test/reports/TEST-HammerCLI-AbstractCommand-option-builder.xml +11 -0
  37. data/test/reports/TEST-HammerCLI-AbstractCommand-options.xml +11 -0
  38. data/test/reports/TEST-HammerCLI-AbstractCommand-output.xml +19 -0
  39. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-remove-subcommand.xml +11 -0
  40. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand-.xml +13 -0
  41. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand.xml +11 -0
  42. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior.xml +7 -0
  43. data/test/reports/TEST-HammerCLI-AbstractCommand.xml +11 -0
  44. data/test/reports/TEST-HammerCLI-Apipie-Command-options.xml +11 -0
  45. data/test/reports/TEST-HammerCLI-Apipie-Command-resource-defined.xml +9 -0
  46. data/test/reports/TEST-HammerCLI-Apipie-Command-setting-resources.xml +19 -0
  47. data/test/reports/TEST-HammerCLI-Apipie-Command.xml +9 -0
  48. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-aliasing-resources.xml +13 -0
  49. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-filtering-options.xml +15 -0
  50. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-required-options.xml +11 -0
  51. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-correct-normalizers.xml +9 -0
  52. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-hash-params.xml +11 -0
  53. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-one-simple-param.xml +15 -0
  54. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder.xml +7 -0
  55. data/test/reports/TEST-HammerCLI-Completer-command-completion.xml +29 -0
  56. data/test/reports/TEST-HammerCLI-Completer-option-value-completion.xml +17 -0
  57. data/test/reports/TEST-HammerCLI-Completer-subcommand-completion.xml +19 -0
  58. data/test/reports/TEST-HammerCLI-Completer.xml +7 -0
  59. data/test/reports/TEST-HammerCLI-CompleterLine-line-complete.xml +25 -0
  60. data/test/reports/TEST-HammerCLI-CompleterLine-splitting-words.xml +29 -0
  61. data/test/reports/TEST-HammerCLI-CompleterLine.xml +7 -0
  62. data/test/reports/TEST-HammerCLI-CompleterWord-complete-.xml +23 -0
  63. data/test/reports/TEST-HammerCLI-CompleterWord-quote.xml +15 -0
  64. data/test/reports/TEST-HammerCLI-CompleterWord-quoted-.xml +13 -0
  65. data/test/reports/TEST-HammerCLI-CompleterWord.xml +7 -0
  66. data/test/reports/TEST-HammerCLI-Connection.xml +21 -0
  67. data/test/reports/TEST-HammerCLI-ExceptionHandler.xml +21 -0
  68. data/test/reports/TEST-HammerCLI-I18n.xml +11 -0
  69. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-password.xml +11 -0
  70. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-username.xml +11 -0
  71. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-verbose.xml +9 -0
  72. data/test/reports/TEST-HammerCLI-MainCommand-loading-context.xml +7 -0
  73. data/test/reports/TEST-HammerCLI-MainCommand.xml +7 -0
  74. data/test/reports/TEST-HammerCLI-Modules-find-by-name.xml +13 -0
  75. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-not-found.xml +13 -0
  76. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-runtime-exception.xml +13 -0
  77. data/test/reports/TEST-HammerCLI-Modules-load-a-module-success.xml +15 -0
  78. data/test/reports/TEST-HammerCLI-Modules-load-a-module.xml +7 -0
  79. data/test/reports/TEST-HammerCLI-Modules-load-all-modules.xml +9 -0
  80. data/test/reports/TEST-HammerCLI-Modules-names.xml +13 -0
  81. data/test/reports/TEST-HammerCLI-Modules.xml +7 -0
  82. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.0.xml +7 -0
  83. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.xml +11 -0
  84. data/test/reports/TEST-HammerCLI-Options-Normalizers-abstract.xml +9 -0
  85. data/test/reports/TEST-HammerCLI-Options-Normalizers-bool.xml +31 -0
  86. data/test/reports/TEST-HammerCLI-Options-Normalizers-datetime.xml +17 -0
  87. data/test/reports/TEST-HammerCLI-Options-Normalizers-enum.xml +15 -0
  88. data/test/reports/TEST-HammerCLI-Options-Normalizers-enumlist.xml +21 -0
  89. data/test/reports/TEST-HammerCLI-Options-Normalizers-json-input.xml +15 -0
  90. data/test/reports/TEST-HammerCLI-Options-Normalizers-key-value-list.xml +17 -0
  91. data/test/reports/TEST-HammerCLI-Options-Normalizers-list.xml +15 -0
  92. data/test/reports/TEST-HammerCLI-Options-Normalizers.xml +7 -0
  93. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-context.xml +9 -0
  94. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-formatters.xml +11 -0
  95. data/test/reports/TEST-HammerCLI-Options-OptionDefinition.xml +7 -0
  96. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-error-messages.xml +15 -0
  97. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-messages.xml +11 -0
  98. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-test-data-for-field.xml +15 -0
  99. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract.xml +17 -0
  100. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection-show-ids.xml +9 -0
  101. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection.xml +27 -0
  102. data/test/reports/TEST-HammerCLI-Output-Adapter-Base.xml +7 -0
  103. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-formatters.xml +11 -0
  104. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-collections.xml +13 -0
  105. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-containers.xml +11 -0
  106. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-ids.xml +11 -0
  107. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection.xml +11 -0
  108. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-message.xml +11 -0
  109. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues.xml +7 -0
  110. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-column-width.xml +15 -0
  111. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-formatters.xml +11 -0
  112. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-handle-ids.xml +11 -0
  113. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-sort-columns.xml +9 -0
  114. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection.xml +11 -0
  115. data/test/reports/TEST-HammerCLI-Output-Adapter-Table.xml +7 -0
  116. data/test/reports/TEST-HammerCLI-Output-Definition-empty-.xml +11 -0
  117. data/test/reports/TEST-HammerCLI-Output-Definition.xml +11 -0
  118. data/test/reports/TEST-HammerCLI-Output-Dsl-collection.xml +13 -0
  119. data/test/reports/TEST-HammerCLI-Output-Dsl-custom-fields.xml +11 -0
  120. data/test/reports/TEST-HammerCLI-Output-Dsl-fields.xml +15 -0
  121. data/test/reports/TEST-HammerCLI-Output-Dsl-label.xml +13 -0
  122. data/test/reports/TEST-HammerCLI-Output-Dsl-path-definition.xml +13 -0
  123. data/test/reports/TEST-HammerCLI-Output-Dsl.xml +9 -0
  124. data/test/reports/TEST-HammerCLI-Output-FieldFilter.xml +13 -0
  125. data/test/reports/TEST-HammerCLI-Output-Formatters-BooleanFormatter.xml +11 -0
  126. data/test/reports/TEST-HammerCLI-Output-Formatters-ColorFormatter.xml +9 -0
  127. data/test/reports/TEST-HammerCLI-Output-Formatters-DateFormatter.xml +11 -0
  128. data/test/reports/TEST-HammerCLI-Output-Formatters-FieldFormatter.xml +13 -0
  129. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterContainer.xml +13 -0
  130. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterLibrary.xml +11 -0
  131. data/test/reports/TEST-HammerCLI-Output-Formatters-KeyValueFormatter.xml +13 -0
  132. data/test/reports/TEST-HammerCLI-Output-Formatters-ListFormatter.xml +13 -0
  133. data/test/reports/TEST-HammerCLI-Output-Formatters-LongTextFormatter.xml +13 -0
  134. data/test/reports/TEST-HammerCLI-Output-Output-adapters.xml +17 -0
  135. data/test/reports/TEST-HammerCLI-Output-Output-data.xml +15 -0
  136. data/test/reports/TEST-HammerCLI-Output-Output-formatters.xml +9 -0
  137. data/test/reports/TEST-HammerCLI-Output-Output-messages.xml +19 -0
  138. data/test/reports/TEST-HammerCLI-Output-Output.xml +7 -0
  139. data/test/reports/TEST-HammerCLI-Output-RecordCollection.xml +13 -0
  140. data/test/reports/TEST-HammerCLI-Settings-load-from-paths.xml +15 -0
  141. data/test/reports/TEST-HammerCLI-Settings.xml +25 -0
  142. data/test/reports/TEST-HammerCLI-ShellHistory-loading-old-history.xml +11 -0
  143. data/test/reports/TEST-HammerCLI-ShellHistory-saving-history.xml +15 -0
  144. data/test/reports/TEST-HammerCLI-ShellHistory.xml +7 -0
  145. data/test/reports/TEST-MiniTest-Spec.xml +7 -0
  146. data/test/reports/TEST-String-camelize.xml +11 -0
  147. data/test/reports/TEST-String-formatting.xml +17 -0
  148. data/test/reports/TEST-String-indent.xml +11 -0
  149. data/test/reports/TEST-String-interactive-.xml +13 -0
  150. data/test/reports/TEST-String.xml +7 -0
  151. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint-exist-.xml +13 -0
  152. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint.xml +7 -0
  153. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint-exist-.xml +13 -0
  154. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint.xml +7 -0
  155. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-exist-.xml +9 -0
  156. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-rejected.xml +13 -0
  157. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-required.xml +13 -0
  158. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint.xml +7 -0
  159. data/test/reports/TEST-constraints.xml +7 -0
  160. data/test/unit/apipie/api_connection_test.rb +1 -0
  161. data/test/unit/ca_cert_manager_test.rb +64 -0
  162. data/test/unit/fixtures/certs/ca_cert.pem +21 -0
  163. metadata +327 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef7854e6b8f65d3432b1f748a1bd300d4ab2274e
4
- data.tar.gz: 09a8c5faa16658f072ebde9a0ca6493e0044dc8b
3
+ metadata.gz: a51bb0421b077ec5f6b58516eb36bfb36593543a
4
+ data.tar.gz: e10795cc718d474a9b71e084472c2e9455bcc208
5
5
  SHA512:
6
- metadata.gz: 398fa3c73cab657f5fa0afb2b9a255427fc7bcbca0a2d7488d74ddc1daca9b93bf237173ce644358529b26caffe0577abff3a9f03567343b565d23026009bbeb
7
- data.tar.gz: 302c34a77aa5cffbf6bee3d2975e393c9ba5afdd08f9e820ae30e354010f5495ee2316acfb1fd9534489e2f5af1b5854fb7501c747aa30fb5acc8621e0645bb2
6
+ metadata.gz: 177b9fe7bcfc57623a87fe32890a44ffe8ce2ed9c25bdcde061c87670fb8a1a6e5cf5993046262eabbf993984621e119fda6ec72ce880531f998893da80c6a9d
7
+ data.tar.gz: 37f64d084f60e2e87fa99ac7f1b2ffe670a7577ec715e349439dce07432d9deee7e2193b16be8b35c896d75777a7dd0e55360b2c8e529b2ffbebb8adf2ac2df4
data/bin/hammer CHANGED
@@ -125,7 +125,8 @@ require 'hammer_cli'
125
125
 
126
126
  if preparser.fetch_ca_cert
127
127
  require 'hammer_cli/ca_cert_fetcher'
128
- exit HammerCLI::CACertFetcher.fetch_ca_cert(preparser.fetch_ca_cert)
128
+ ca_path = HammerCLI::SSLOptions.get_options[:ssl_ca_path]
129
+ exit HammerCLI::CACertFetcher.new.fetch_ca_cert(preparser.fetch_ca_cert, ca_path)
129
130
  end
130
131
 
131
132
  # load modules set in config
@@ -38,7 +38,7 @@
38
38
  #:ssl_ca_file: '/path/to/ca_certificate.pem'
39
39
 
40
40
  # Path to a direcotry with ca file
41
- #:ssl_ca_path: '/path/to/ca/'
41
+ #:ssl_ca_path: '~/.hammer/certs'
42
42
 
43
43
  # Turn SSL verification on/off
44
44
  #:verify_ssl: true
data/doc/release_notes.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Release notes
2
2
  =============
3
3
 
4
+ ### 0.10.1 (2017-04-24)
5
+ * Require apipie-bindings >= 0.2.0 ([#19083](http://projects.theforeman.org/issues/19083))
6
+ * Install server CA cert without root access ([#19083](http://projects.theforeman.org/issues/19083))
7
+
4
8
  ### 0.10.0 (2017-03-28)
5
9
  * Defaults match on option switch name (#233) ([#17920](http://projects.theforeman.org/issues/17920))
6
10
  * Add support for client certificate authentication ([#12401](http://projects.theforeman.org/issues/12401))
@@ -1,39 +1,66 @@
1
+ require 'hammer_cli/ca_cert_manager'
1
2
  module HammerCLI
2
3
  class CACertFetcher
3
- def self.fetch_ca_cert(host)
4
- CACertFetcher.new.fetch_ca_cert(host)
5
- end
6
-
7
- def fetch_ca_cert(host)
4
+ def fetch_ca_cert(service_uri, ca_path)
8
5
  begin
9
- uri = URI.parse(host)
6
+ uri = URI.parse(service_uri)
7
+ raise URI::InvalidURIError.new(_("Unable to find hostname in #{service_uri}")) if uri.host.nil?
8
+ raise URI::InvalidURIError.new(scheme_error(uri)) unless uri.scheme == 'https'
9
+ ca_cert_manager = HammerCLI::CACertManager.new(ca_path)
10
+ raw_cert = HammerCLI::CACertDownloader.new.download(uri)
11
+ cert_file = ca_cert_manager.cert_file_name(uri)
12
+ ca_cert_manager.store_ca_cert(raw_cert, cert_file)
10
13
 
11
- hostname = uri.host
12
- port = uri.port || 443
14
+ rh_install_path = "/etc/pki/ca-trust/source/anchors/"
15
+ rh_update_cmd = "update-ca-trust"
16
+ deb_install_path = "/usr/local/share/ca-certificates/"
17
+ deb_update_cmd = "update-ca-certificates"
18
+ cert_file = ca_cert_manager.cert_file_name(uri)
13
19
 
14
- if hostname.nil?
15
- $stderr.puts _("Couldn't parse URI '%s'.") % host
16
- $stderr.puts scheme_error(uri)
17
- return HammerCLI::EX_SOFTWARE
18
- end
20
+ puts _("CA certificate for #{service_uri} was stored to #{cert_file}")
21
+ puts _("Now hammer can use the downloaded certificate to verify SSL connection to the server.")
22
+ puts
23
+ puts _("Be aware that hammer cannot verify whether the certificate is correct and you should verify its authenticity.")
24
+ puts
25
+ puts _("You can display the certificate content with")
26
+ puts " $ openssl x509 -text -in #{cert_file}"
27
+ puts
19
28
 
20
- puts get_ca_cert(hostname, port)
29
+ cert_install_msg = _("As root you can also install the certificate and update the system-wide list of trusted CA certificates as follows:") + "\n"
30
+
31
+ if File.directory?(rh_install_path)
32
+ puts cert_install_msg
33
+ puts " $ install #{cert_file} #{rh_install_path}"
34
+ puts " $ #{rh_update_cmd}"
35
+ elsif File.directory?(deb_install_path)
36
+ puts cert_install_msg
37
+ puts " $ install #{cert_file} #{deb_install_path}"
38
+ puts " $ #{deb_update_cmd}"
39
+ end
40
+ puts
21
41
  return HammerCLI::EX_OK
42
+
43
+ rescue URI::InvalidURIError => e
44
+ $stderr.puts _("Couldn't parse URI '%s'.") % service_uri
45
+ $stderr.puts e.message
46
+ return HammerCLI::EX_SOFTWARE
22
47
  rescue StandardError => e
48
+ logger = Logging.logger['CACertFetcher']
23
49
  msg = [_('Fetching the CA certificate failed:')]
24
50
 
25
51
  if e.is_a?(OpenSSL::SSL::SSLError) && e.message.include?('unknown protocol')
26
52
  msg << _('The service at the given URI does not accept SSL connections')
27
- msg << scheme_error(uri) if uri.scheme == 'http'
53
+ msg << scheme_error if uri.scheme == 'http'
28
54
  else
29
55
  msg << e.message
30
56
  end
31
57
  $stderr.puts msg.join("\n")
58
+ logger.error(e.backtrace.join("\n "))
32
59
  return HammerCLI::EX_SOFTWARE
33
60
  end
34
61
  end
35
62
 
36
- protected
63
+ private
37
64
 
38
65
  def scheme_error(uri)
39
66
  _("Perhaps you meant to connect to '%s'?") % uri_to_https(uri)
@@ -51,17 +78,5 @@ module HammerCLI
51
78
  end
52
79
  https_uri
53
80
  end
54
-
55
- def get_ca_cert(hostname, port)
56
- noverify_ssl_connection = OpenSSL::SSL::SSLSocket.new(TCPSocket.new(hostname, port), noverify_ssl_context)
57
- noverify_ssl_connection.connect
58
- noverify_ssl_connection.peer_cert_chain.last
59
- end
60
-
61
- def noverify_ssl_context
62
- noverify_ssl_context = OpenSSL::SSL::SSLContext.new
63
- noverify_ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
64
- noverify_ssl_context
65
- end
66
81
  end
67
82
  end
@@ -0,0 +1,71 @@
1
+ require 'fileutils'
2
+
3
+ module HammerCLI
4
+ class CACertManager
5
+ attr_reader :ca_path
6
+
7
+ def initialize(ca_path)
8
+ @ca_path = ca_path
9
+ end
10
+
11
+ def store_ca_cert(raw_cert, cert_file)
12
+ ensure_ca_path_exist
13
+ File.write(cert_file, raw_cert)
14
+ hash = cert_hash(raw_cert)
15
+ create_link(hash, cert_file)
16
+ cert_file
17
+ end
18
+
19
+ def cert_hash(raw_cert)
20
+ cert = OpenSSL::X509::Certificate.new(raw_cert)
21
+ subject = OpenSSL::X509::Name.new(cert.subject)
22
+ subject.hash
23
+ end
24
+
25
+ def create_link(hash, cert_file)
26
+ ensure_ca_path_exist
27
+ cert_link = File.join(ca_path, "#{hash.to_s(16)}.%s")
28
+ count = 0
29
+ # increase hash index if file or link to different target already exist
30
+ while plain_file?(cert_link % count) || link_to_different_target?(cert_link % count, cert_file) do
31
+ count += 1
32
+ end
33
+ File.symlink(cert_file, cert_link % count) unless File.symlink?(cert_link % count)
34
+ end
35
+
36
+ def cert_file_name(uri)
37
+ File.join(ca_path, "#{uri.host}.pem")
38
+ end
39
+
40
+ protected
41
+
42
+
43
+ def ensure_ca_path_exist
44
+ FileUtils.mkpath(ca_path) unless File.directory?(ca_path)
45
+ end
46
+
47
+ def plain_file?(path)
48
+ File.exist?(path) && !File.symlink?(path)
49
+ end
50
+
51
+ def link_to_different_target?(path, target)
52
+ File.symlink?(path) && File.expand_path(File.readlink(path)) != File.expand_path(target)
53
+ end
54
+ end
55
+
56
+ class CACertDownloader
57
+ def download(uri)
58
+ noverify_ssl_connection = OpenSSL::SSL::SSLSocket.new(TCPSocket.new(uri.host, uri.port), noverify_ssl_context)
59
+ noverify_ssl_connection.connect
60
+ noverify_ssl_connection.peer_cert_chain.last
61
+ end
62
+
63
+ private
64
+
65
+ def noverify_ssl_context
66
+ noverify_ssl_context = OpenSSL::SSL::SSLContext.new
67
+ noverify_ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
68
+ noverify_ssl_context
69
+ end
70
+ end
71
+ end
@@ -1,5 +1,7 @@
1
1
  module HammerCLI
2
2
  class SSLOptions
3
+ DEFAULT_SSL_CA_PATH = "~/.hammer/certs"
4
+
3
5
  def initialize(settings = HammerCLI::Settings, logger = Logging.logger['SSLoptions'])
4
6
  @settings = settings
5
7
  @logger = logger
@@ -17,6 +19,11 @@ module HammerCLI
17
19
  end
18
20
  ssl_options.merge!(cert_key_options)
19
21
 
22
+ ssl_options[:ssl_ca_path] = DEFAULT_SSL_CA_PATH if ssl_options[:ssl_ca_path].nil?
23
+ [:ssl_ca_file, :ssl_ca_path].each do |opt|
24
+ ssl_options[opt] = File.expand_path(ssl_options[opt]) unless ssl_options[opt].nil?
25
+ end
26
+
20
27
  # enable ssl verification
21
28
  ssl_options[:verify_ssl] = true if ssl_options[:verify_ssl].nil?
22
29
  @logger.debug("SSL options: #{ApipieBindings::Utils::inspect_data(ssl_options)}")
@@ -1,5 +1,5 @@
1
1
  module HammerCLI
2
2
  def self.version
3
- @version ||= Gem::Version.new '0.10.0'
3
+ @version ||= Gem::Version.new '0.10.1'
4
4
  end
5
5
  end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/man/hammer.1.gz CHANGED
Binary file
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::ContainerField::display?" tests="0" time="0.000195743" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::ContainerField::display?::blank is allowed" tests="4" time="0.000514044" failures="0" errors="0" skipped="0" assertions="4">
3
+ <testcase name="test_0001_returns false the value is nil" time="0.000160735" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0003_returns false the value is empty hash" time="5.924e-05" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0004_returns true when there is some data under the path" time="5.1533e-05" assertions="1">
8
+ </testcase>
9
+ <testcase name="test_0002_returns false the value is empty array" time="4.7909e-05" assertions="1">
10
+ </testcase>
11
+ <system-out>
12
+ </system-out>
13
+ <system-err>
14
+ </system-err>
15
+ </testsuite>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::ContainerField::display?::blank is not allowed" tests="4" time="0.00050542" failures="0" errors="0" skipped="0" assertions="4">
3
+ <testcase name="test_0001_returns false the value is nil" time="0.000104095" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0004_returns true when there is some data under the path" time="5.5074e-05" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0002_returns false the value is empty array" time="4.9163e-05" assertions="1">
8
+ </testcase>
9
+ <testcase name="test_0003_returns false the value is empty hash" time="4.4524e-05" assertions="1">
10
+ </testcase>
11
+ <system-out>
12
+ </system-out>
13
+ <system-err>
14
+ </system-err>
15
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::ContainerField" tests="0" time="0.000180394" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::Field::display?" tests="0" time="0.000177184" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::Field::display?::blank is allowed" tests="2" time="0.000346718" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0002_returns true when there is some data under the path" time="9.5291e-05" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0001_returns false the value is nil" time="5.3478e-05" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::Field::display?::blank is not allowed" tests="2" time="0.000332031" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0002_returns true when there is some data under the path" time="8.2527e-05" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0001_returns false the value is nil" time="5.4331e-05" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::Field::hide_blank?" tests="2" time="0.000327248" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0001_defaults to false" time="7.399e-05" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_can be set to true in the constructor" time="5.3648e-05" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::Field::parameters" tests="1" time="0.000281758" failures="0" errors="0" skipped="0" assertions="1">
3
+ <testcase name="test_0001_returns all parameters passed to a filed" time="0.00010987" assertions="1">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Fields::Field" tests="3" time="0.000378872" failures="0" errors="0" skipped="0" assertions="3">
3
+ <testcase name="test_0001_stores label from constructor" time="8.5904e-05" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_stores path from constructor" time="5.3075e-05" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0003_default path should be empty array" time="4.294e-05" assertions="1">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::build options" tests="4" time="0.001351635" failures="0" errors="0" skipped="0" assertions="4">
3
+ <testcase name="test_0004_accepts block" time="0.000477899" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0003_passes params to the builders" time="0.00028496" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0002_should skip options that already exist" time="0.000216207" assertions="1">
8
+ </testcase>
9
+ <testcase name="test_0001_should use option builder" time="0.000177748" assertions="1">
10
+ </testcase>
11
+ <system-out>
12
+ </system-out>
13
+ <system-err>
14
+ </system-err>
15
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::exception handler" tests="3" time="0.001065241" failures="0" errors="0" skipped="0" assertions="5">
3
+ <testcase name="test_0003_should return instance of exception handler class defined deeper in a module hierrarchy" time="0.00029177" assertions="2">
4
+ </testcase>
5
+ <testcase name="test_0002_should return instance of exception handler class defined in a module" time="0.000228844" assertions="2">
6
+ </testcase>
7
+ <testcase name="test_0001_should return instance of hammer cli exception handler by default" time="0.000359925" assertions="1">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::logging" tests="7" time="0.005629746" failures="0" errors="0" skipped="0" assertions="12">
3
+ <testcase name="test_0007_should have logger.watch colorized output switch in settings" time="0.001215608" assertions="2">
4
+ </testcase>
5
+ <testcase name="test_0003_should have logger named by the class by default" time="0.00071257" assertions="2">
6
+ </testcase>
7
+ <testcase name="test_0002_password should be hidden in logs" time="0.000708892" assertions="1">
8
+ </testcase>
9
+ <testcase name="test_0004_should have logger that accepts custom name" time="0.000841507" assertions="2">
10
+ </testcase>
11
+ <testcase name="test_0005_should have logger that can inspect object" time="0.000748318" assertions="2">
12
+ </testcase>
13
+ <testcase name="test_0001_should log what has been executed" time="0.000352436" assertions="1">
14
+ </testcase>
15
+ <testcase name="test_0006_should have logger.watch output without colors" time="0.000799178" assertions="2">
16
+ </testcase>
17
+ <system-out>
18
+ </system-out>
19
+ <system-err>
20
+ </system-err>
21
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::option builder" tests="2" time="0.000349776" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0001_uses builder container as default" time="9.1626e-05" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_Default builder container is empty" time="4.5179e-05" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::options" tests="2" time="0.000433705" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0002_should set options' formatters" time="0.000197632" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0001_should create instances of hammer options" time="5.6937e-05" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::output" tests="6" time="0.000637574" failures="0" errors="0" skipped="0" assertions="6">
3
+ <testcase name="test_0006_can define fields" time="0.000126013" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0005_can append existing definition without passing a block" time="6.2427e-05" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0001_should define adapter" time="5.3792e-05" assertions="1">
8
+ </testcase>
9
+ <testcase name="test_0004_can append existing definition" time="5.6941e-05" assertions="1">
10
+ </testcase>
11
+ <testcase name="test_0002_should provide instance of output with default adapter set" time="5.4734e-05" assertions="1">
12
+ </testcase>
13
+ <testcase name="test_0003_should hold instance of output definition" time="5.7944e-05" assertions="1">
14
+ </testcase>
15
+ <system-out>
16
+ </system-out>
17
+ <system-err>
18
+ </system-err>
19
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::subcommand behavior::remove_subcommand" tests="2" time="0.001167359" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0002_should write a message to log when removing subcommand" time="0.000669956" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0001_should remove the subcommand" time="0.000316383" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::subcommand behavior::subcommand!" tests="3" time="0.001481618" failures="0" errors="0" skipped="0" assertions="10">
3
+ <testcase name="test_0001_should replace commands with the same name" time="0.000501831" assertions="4">
4
+ </testcase>
5
+ <testcase name="test_0003_should add the subcommand" time="0.000336002" assertions="4">
6
+ </testcase>
7
+ <testcase name="test_0002_should write a message to log when replacing subcommand" time="0.00044575" assertions="2">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::subcommand behavior::subcommand" tests="2" time="0.000599816" failures="0" errors="0" skipped="0" assertions="5">
3
+ <testcase name="test_0001_should throw an exception for conflicting commands" time="0.000221174" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_should add the subcommand" time="0.000199028" assertions="4">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand::subcommand behavior" tests="0" time="0.000161068" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::AbstractCommand" tests="2" time="0.00037477" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0001_should inherit command_name" time="9.8291e-05" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_should inherit output definition" time="0.000103826" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::Apipie::Command::options" tests="2" time="0.000493282" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0001_should collect method options from given options" time="0.000190569" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_should collect method options from methods" time="0.000108589" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::Apipie::Command::resource defined" tests="1" time="0.001214277" failures="0" errors="0" skipped="0" assertions="1">
3
+ <testcase name="test_0001_should perform a call to api when resource is defined" time="0.001036574" assertions="1">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::Apipie::Command::setting resources" tests="6" time="0.00156057" failures="0" errors="0" skipped="0" assertions="18">
3
+ <testcase name="test_0005_looks up resource in the class' modules" time="0.000118112" assertions="2">
4
+ </testcase>
5
+ <testcase name="test_0002_should set resource alone" time="0.000380061" assertions="4">
6
+ </testcase>
7
+ <testcase name="test_0004_inherits action from a parent class" time="7.3797e-05" assertions="2">
8
+ </testcase>
9
+ <testcase name="test_0006_looks up resource in the superclass" time="6.228e-05" assertions="2">
10
+ </testcase>
11
+ <testcase name="test_0001_should set resource and action together" time="0.000357962" assertions="4">
12
+ </testcase>
13
+ <testcase name="test_0003_should set resource and action alone" time="0.000357822" assertions="4">
14
+ </testcase>
15
+ <system-out>
16
+ </system-out>
17
+ <system-err>
18
+ </system-err>
19
+ </testsuite>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::Apipie::Command" tests="1" time="0.001103687" failures="0" errors="0" skipped="0" assertions="1">
3
+ <testcase name="test_0001_should raise exception when no action is defined" time="0.000928014" assertions="1">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>