octocatalog-diff 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94e2cf0a922da25cff91452ca8e2a3631cc1d97c
4
- data.tar.gz: 6fbf668920f43516ccae0cd58095187e9d78f8d9
3
+ metadata.gz: c315a978c543c665c37c9e3d8baee4cd51bd8ad0
4
+ data.tar.gz: b3ea77a256af869d688f3792aee560f9f582979c
5
5
  SHA512:
6
- metadata.gz: 616ac7fe5586015dd0afa7511074db94358ae09150e183392ab68aba81d1ade9750594ec3d4d7a62ad333b088ef758aa094bfa4392457f800a41dbf3d1a78b51
7
- data.tar.gz: afaa669b726b5f983be6fefd0ded47e14fc649c25e459a2d286a7b28d378908c1081309f788ce9d45e7674b590295b4562a93ac7b3c5d27538c30cd10431f1f5
6
+ metadata.gz: eb2810e2f011003b2cf5a99ea043936a990e97311de88d401142965a34450c1b29147bc2d151f8bf7f410a168758b4b10a97700a2ec5cafa354fe8f7d5f0fe6e
7
+ data.tar.gz: 2977a910bd86d03b634178b5333d33f3694d6a90b97890cfaaa7351169c84b1da83d6c3858a12c7d27c31597deb6c483a847e28f1bd9b88aa7873ddb9f2fda69
data/.version CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/doc/CHANGELOG.md CHANGED
@@ -8,6 +8,15 @@
8
8
  </tr>
9
9
  </thead><tbody>
10
10
  <tr valign=top>
11
+ <td>1.0.1</td>
12
+ <td>2017-02-14</td>
13
+ <td>
14
+ <li><a href="https://github.com/github/octocatalog-diff/pull/84">#84</a>: Add JSON equivalence filter</li>
15
+ <li><a href="https://github.com/github/octocatalog-diff/pull/83">#83</a>: Retries for Puppet Master retrieval</li>
16
+ <li><a href="https://github.com/github/octocatalog-diff/pull/82">#82</a>: Command line option for Puppet Master timeout</li>
17
+ </td>
18
+ </tr>
19
+ <tr valign=top>
11
20
  <td>1.0.0</td>
12
21
  <td>2017-02-06</td>
13
22
  <td>
@@ -10,6 +10,7 @@ Please note that there are other options to ignore specified diffs, including:
10
10
  Here is the list of available filters and an explanation of each:
11
11
 
12
12
  - [Absent File](/doc/advanced-filter.md#absent-file) - Ignore parameter changes of a file that is declared to be absent
13
+ - [JSON](/doc/advanced-filter.md#json) - Ignore whitespace differences if JSON parses to the same object
13
14
  - [YAML](/doc/advanced-filter.md#yaml) - Ignore whitespace/comment differences if YAML parses to the same object
14
15
 
15
16
  ## Absent File
@@ -69,6 +70,20 @@ Wouldn't it be nice if the meaningless information didn't appear, and all you sa
69
70
  + absent
70
71
  ```
71
72
 
73
+ ## JSON
74
+
75
+ #### Usage
76
+
77
+ ```
78
+ --filters JSON
79
+ ```
80
+
81
+ #### Description
82
+
83
+ If a file resource has extension `.json` and a difference in its content is observed, JSON objects are constructed from the previous and new values. If these JSON objects are identical, the difference is ignored.
84
+
85
+ This allows you to ignore changes in whitespace, comments, etc., that are not meaningful to a machine parsing the file. Note that changes to files may still trigger Puppet to restart services even though these changes are not displayed in the octocatalog-diff output.
86
+
72
87
  ## YAML
73
88
 
74
89
  #### Usage
@@ -81,4 +96,4 @@ Wouldn't it be nice if the meaningless information didn't appear, and all you sa
81
96
 
82
97
  If a file resource has extension `.yml` or `.yaml` and a difference in its content is observed, YAML objects are constructed from the previous and new values. If these YAML objects are identical, the difference is ignored.
83
98
 
84
- This allows you to ignore changes in whitespace, comments, etc., that are not meaningful to a machine parsing the file. Please note that by filtering these changes, you are ignoring changes to comments, which may be meaningful to humans.
99
+ This allows you to ignore changes in whitespace, comments, etc., that are not meaningful to a machine parsing the file. Please note that by filtering these changes, you are ignoring changes to comments, which may be meaningful to humans. Also, changes to files may still trigger Puppet to restart services even though these changes are not displayed in the octocatalog-diff output.
data/doc/optionsref.md CHANGED
@@ -124,6 +124,12 @@ Usage: octocatalog-diff [command line options]
124
124
  Override parameter from ENC for the to branch
125
125
  --from-enc-override STRING1[,STRING2[,...]]
126
126
  Override parameter from ENC for the from branch
127
+ --puppet-master-timeout STRING
128
+ Puppet Master catalog retrieval timeout in seconds globally
129
+ --to-puppet-master-timeout STRING
130
+ Puppet Master catalog retrieval timeout in seconds for the to branch
131
+ --from-puppet-master-timeout STRING
132
+ Puppet Master catalog retrieval timeout in seconds for the from branch
127
133
  --pe-enc-url URL Base URL for Puppet Enterprise ENC endpoint
128
134
  --pe-enc-token TOKEN Token to access the Puppet Enterprise ENC API
129
135
  --pe-enc-token-file PATH Path containing token for PE node classifier, relative or absolute
@@ -1,6 +1,7 @@
1
1
  require_relative '../api/v1/diff'
2
2
  require_relative 'filter/absent_file'
3
3
  require_relative 'filter/compilation_dir'
4
+ require_relative 'filter/json'
4
5
  require_relative 'filter/yaml'
5
6
 
6
7
  require 'stringio'
@@ -12,7 +13,7 @@ module OctocatalogDiff
12
13
  attr_accessor :logger
13
14
 
14
15
  # List the available filters here (by class name) for use in the validator method.
15
- AVAILABLE_FILTERS = %w(AbsentFile CompilationDir YAML).freeze
16
+ AVAILABLE_FILTERS = %w(AbsentFile CompilationDir JSON YAML).freeze
16
17
 
17
18
  # Public: Determine whether a particular filter exists. This can be used to validate
18
19
  # a user-submitted filter.
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../filter'
4
+
5
+ require 'json'
6
+
7
+ module OctocatalogDiff
8
+ module CatalogDiff
9
+ class Filter
10
+ # Filter based on equivalence of JSON objects for file resources with named extensions.
11
+ class JSON < OctocatalogDiff::CatalogDiff::Filter
12
+ # Public: Actually do the comparison of JSON objects for appropriate resources.
13
+ # Return true if the JSON objects are known to be equivalent. Return false if they
14
+ # are not equivalent, or if equivalence cannot be determined.
15
+ #
16
+ # @param diff_in [OctocatalogDiff::API::V1::Diff] Difference
17
+ # @param _options [Hash] Additional options (there are none for this filter)
18
+ # @return [Boolean] true if this difference is a JSON file with identical objects, false otherwise
19
+ def filtered?(diff, _options = {})
20
+ # Skip additions or removals - focus only on changes
21
+ return false unless diff.change?
22
+
23
+ # Make sure we are comparing file content for a file ending in .json extension
24
+ return false unless diff.type == 'File' && diff.structure == %w(parameters content)
25
+ return false unless diff.title =~ /\.json\z/i
26
+
27
+ # Attempt to convert the old value and new value into JSON objects. Assuming
28
+ # that doesn't error out, the return value is whether or not they're equal.
29
+ obj_old = ::JSON.parse(diff.old_value)
30
+ obj_new = ::JSON.parse(diff.new_value)
31
+ obj_old == obj_new
32
+ rescue # Rescue everything - if something failed, we aren't sure what's going on, so we'll return false.
33
+ false
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -13,7 +13,7 @@ module OctocatalogDiff
13
13
  # Represents a Puppet catalog that is obtained by contacting the Puppet Master.
14
14
  class PuppetMaster
15
15
  attr_accessor :node
16
- attr_reader :error_message, :catalog, :catalog_json, :convert_file_resources, :options
16
+ attr_reader :error_message, :catalog, :catalog_json, :convert_file_resources, :options, :retries
17
17
 
18
18
  # Defaults
19
19
  DEFAULT_PUPPET_PORT_NUMBER = 8140
@@ -22,7 +22,7 @@ module OctocatalogDiff
22
22
 
23
23
  # Constructor
24
24
  # @param :node [String] Node name
25
- # @param :retry [Fixnum] Number of retries, if fetch fails
25
+ # @param :retry_failed_catalog [Fixnum] Number of retries, if fetch fails
26
26
  # @param :branch [String] Environment to fetch from Puppet Master
27
27
  # @param :puppet_master [String] Puppet server and port number (assumed to be DEFAULT_PUPPET_PORT_NUMBER if not given)
28
28
  # @param :puppet_master_api_version [Fixnum] Puppet server API (default DEFAULT_PUPPET_SERVER_API)
@@ -47,7 +47,8 @@ module OctocatalogDiff
47
47
  @catalog = nil
48
48
  @error_message = nil
49
49
  @retries = nil
50
- @timeout = options.fetch(:timeout, PUPPET_MASTER_TIMEOUT)
50
+ @timeout = options.fetch(:puppet_master_timeout, options.fetch(:timeout, PUPPET_MASTER_TIMEOUT))
51
+ @retry_failed_catalog = options.fetch(:retry_failed_catalog, 0)
51
52
 
52
53
  # Cannot convert file resources from this type of catalog right now.
53
54
  # FIXME: This is possible with additional API calls but is current unimplemented.
@@ -103,13 +104,20 @@ module OctocatalogDiff
103
104
  api = puppet_catalog_api[api_version]
104
105
  raise ArgumentError, "Unsupported or invalid API version #{api_version}" unless api.is_a?(Hash)
105
106
 
106
- logger.debug "Retrieve catalog from #{api[:url]} environment #{@options[:branch]}"
107
-
108
107
  more_options = { headers: { 'Accept' => 'text/pson' }, timeout: @timeout }
109
108
  post_hash = api[:parameters]
110
- response = OctocatalogDiff::Util::HTTParty.post(api[:url], @options.merge(more_options), post_hash, 'puppet_master')
111
109
 
112
- logger.debug "Response from #{api[:url]} environment #{@options[:branch]} was #{response[:code]}"
110
+ response = nil
111
+ 0.upto(@retry_failed_catalog) do |retry_num|
112
+ @retries = retry_num
113
+ logger.debug "Retrieve catalog from #{api[:url]} environment #{@options[:branch]}"
114
+
115
+ response = OctocatalogDiff::Util::HTTParty.post(api[:url], @options.merge(more_options), post_hash, 'puppet_master')
116
+
117
+ logger.debug "Response from #{api[:url]} environment #{@options[:branch]} was #{response[:code]}"
118
+
119
+ break if response[:code] == 200
120
+ end
113
121
 
114
122
  unless response[:code] == 200
115
123
  @error_message = "Failed to retrieve catalog from #{api[:url]}: #{response[:code]} #{response[:body]}"
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Specify a timeout for retrieving a catalog from a Puppet master / Puppet server.
4
+ # This timeout is specified in seconds.
5
+ # @param parser [OptionParser object] The OptionParser argument
6
+ # @param options [Hash] Options hash being constructed; this is modified in this method.
7
+ OctocatalogDiff::Cli::Options::Option.newoption(:puppet_master_timeout) do
8
+ has_weight 329
9
+
10
+ def parse(parser, options)
11
+ OctocatalogDiff::Cli::Options.option_globally_or_per_branch(
12
+ parser: parser,
13
+ options: options,
14
+ cli_name: 'puppet-master-timeout',
15
+ option_name: 'puppet_master_timeout',
16
+ desc: 'Puppet Master catalog retrieval timeout in seconds',
17
+ validator: ->(x) { x.to_i > 0 || raise(ArgumentError, 'Specify timeout as a integer greater than 0') },
18
+ translator: ->(x) { x.to_i }
19
+ )
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octocatalog-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-06 00:00:00.000000000 Z
12
+ date: 2017-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: diffy
@@ -290,6 +290,7 @@ files:
290
290
  - lib/octocatalog-diff/catalog-diff/filter.rb
291
291
  - lib/octocatalog-diff/catalog-diff/filter/absent_file.rb
292
292
  - lib/octocatalog-diff/catalog-diff/filter/compilation_dir.rb
293
+ - lib/octocatalog-diff/catalog-diff/filter/json.rb
293
294
  - lib/octocatalog-diff/catalog-diff/filter/yaml.rb
294
295
  - lib/octocatalog-diff/catalog-util/bootstrap.rb
295
296
  - lib/octocatalog-diff/catalog-util/builddir.rb
@@ -366,6 +367,7 @@ files:
366
367
  - lib/octocatalog-diff/cli/options/puppet_master_ssl_ca.rb
367
368
  - lib/octocatalog-diff/cli/options/puppet_master_ssl_client_cert.rb
368
369
  - lib/octocatalog-diff/cli/options/puppet_master_ssl_client_key.rb
370
+ - lib/octocatalog-diff/cli/options/puppet_master_timeout.rb
369
371
  - lib/octocatalog-diff/cli/options/puppetdb_api_version.rb
370
372
  - lib/octocatalog-diff/cli/options/puppetdb_ssl_ca.rb
371
373
  - lib/octocatalog-diff/cli/options/puppetdb_ssl_client_cert.rb