octocatalog-diff 0.6.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/README.md +5 -2
  4. data/bin/octocatalog-diff +9 -49
  5. data/doc/CHANGELOG.md +14 -0
  6. data/doc/advanced-filter.md +59 -1
  7. data/doc/advanced-override-enc.md +54 -0
  8. data/doc/advanced-pe-enc.md +1 -1
  9. data/doc/advanced.md +2 -1
  10. data/doc/dev/api.md +5 -0
  11. data/doc/dev/api/v1.md +41 -0
  12. data/doc/dev/api/v1/calls/catalog-diff.md +209 -0
  13. data/doc/dev/api/v1/calls/catalog.md +115 -0
  14. data/doc/dev/api/v1/calls/config.md +37 -0
  15. data/doc/dev/api/v1/objects/catalog.md +127 -0
  16. data/doc/dev/api/v1/objects/diff.md +261 -0
  17. data/doc/dev/api/v1/objects/override.md +30 -0
  18. data/doc/dev/how-to-add-options.md +12 -12
  19. data/doc/optionsref.md +91 -74
  20. data/doc/versions/v1.md +22 -0
  21. data/lib/octocatalog-diff.rb +1 -8
  22. data/lib/octocatalog-diff/api/v1.rb +27 -0
  23. data/lib/octocatalog-diff/api/v1/catalog-compile.rb +40 -0
  24. data/lib/octocatalog-diff/api/v1/catalog-diff.rb +68 -0
  25. data/lib/octocatalog-diff/api/v1/catalog.rb +84 -0
  26. data/lib/octocatalog-diff/api/v1/common.rb +24 -0
  27. data/lib/octocatalog-diff/api/v1/config.rb +125 -0
  28. data/lib/octocatalog-diff/api/v1/diff.rb +194 -0
  29. data/lib/octocatalog-diff/api/v1/override.rb +103 -0
  30. data/lib/octocatalog-diff/catalog-diff/differ.rb +66 -47
  31. data/lib/octocatalog-diff/catalog-diff/display.rb +8 -2
  32. data/lib/octocatalog-diff/catalog-diff/display/json.rb +3 -2
  33. data/lib/octocatalog-diff/catalog-diff/display/legacy_json.rb +28 -0
  34. data/lib/octocatalog-diff/catalog-diff/display/text.rb +64 -9
  35. data/lib/octocatalog-diff/catalog-diff/filter.rb +45 -6
  36. data/lib/octocatalog-diff/catalog-diff/filter/absent_file.rb +65 -0
  37. data/lib/octocatalog-diff/catalog-diff/filter/compilation_dir.rb +78 -0
  38. data/lib/octocatalog-diff/catalog-diff/filter/yaml.rb +10 -7
  39. data/lib/octocatalog-diff/catalog-util/bootstrap.rb +13 -14
  40. data/lib/octocatalog-diff/catalog-util/builddir.rb +1 -0
  41. data/lib/octocatalog-diff/catalog-util/cached_master_directory.rb +2 -2
  42. data/lib/octocatalog-diff/catalog-util/enc.rb +49 -14
  43. data/lib/octocatalog-diff/catalog-util/enc/pe.rb +3 -5
  44. data/lib/octocatalog-diff/catalog-util/enc/pe/v1.rb +3 -1
  45. data/lib/octocatalog-diff/catalog-util/git.rb +36 -24
  46. data/lib/octocatalog-diff/catalog.rb +5 -9
  47. data/lib/octocatalog-diff/catalog/computed.rb +9 -1
  48. data/lib/octocatalog-diff/catalog/puppetdb.rb +4 -3
  49. data/lib/octocatalog-diff/cli.rb +195 -0
  50. data/lib/octocatalog-diff/cli/diffs.rb +40 -0
  51. data/lib/octocatalog-diff/cli/options.rb +183 -0
  52. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/basedir.rb +1 -1
  53. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/bootstrap_current.rb +1 -1
  54. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/bootstrap_environment.rb +1 -1
  55. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/bootstrap_script.rb +1 -1
  56. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/bootstrap_then_exit.rb +1 -1
  57. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/bootstrapped_dirs.rb +1 -1
  58. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/cached_master_dir.rb +1 -1
  59. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/catalog_only.rb +1 -1
  60. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/color.rb +1 -1
  61. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/command_line.rb +2 -2
  62. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/compare_file_text.rb +1 -1
  63. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/create_symlinks.rb +2 -2
  64. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/debug.rb +1 -1
  65. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/debug_bootstrap.rb +1 -1
  66. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/display_datatype_changes.rb +1 -1
  67. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/display_detail_add.rb +1 -1
  68. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/display_source_file_line.rb +1 -1
  69. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/enc.rb +1 -1
  70. data/lib/octocatalog-diff/cli/options/enc_override.rb +21 -0
  71. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/environment.rb +2 -2
  72. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/existing_catalogs.rb +1 -1
  73. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/fact_file.rb +1 -1
  74. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/fact_override.rb +2 -2
  75. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/facts_terminus.rb +1 -1
  76. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/filters.rb +5 -2
  77. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/from_puppetdb.rb +1 -1
  78. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/header.rb +1 -1
  79. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/hiera_config.rb +1 -1
  80. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/hiera_path.rb +1 -1
  81. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/hiera_path_strip.rb +1 -1
  82. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/hostname.rb +1 -1
  83. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/ignore.rb +1 -1
  84. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/ignore_attr.rb +1 -1
  85. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/ignore_tags.rb +1 -1
  86. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/include_tags.rb +1 -1
  87. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/master_cache_branch.rb +1 -1
  88. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/output_file.rb +1 -1
  89. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/output_format.rb +5 -3
  90. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/parallel.rb +1 -1
  91. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/parser.rb +1 -1
  92. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/pass_env_vars.rb +1 -1
  93. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/pe_enc_ssl_ca.rb +1 -1
  94. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/pe_enc_ssl_client_cert.rb +1 -1
  95. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/pe_enc_ssl_client_key.rb +1 -1
  96. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/pe_enc_token.rb +1 -1
  97. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/pe_enc_token_file.rb +1 -1
  98. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/pe_enc_url.rb +1 -1
  99. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/preserve_environments.rb +1 -1
  100. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppet_binary.rb +2 -2
  101. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppet_master.rb +2 -2
  102. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppet_master_api_version.rb +2 -2
  103. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppet_master_ssl_ca.rb +2 -2
  104. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppet_master_ssl_client_cert.rb +2 -2
  105. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppet_master_ssl_client_key.rb +2 -2
  106. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppetdb_api_version.rb +1 -1
  107. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppetdb_ssl_ca.rb +1 -1
  108. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppetdb_ssl_client_cert.rb +1 -1
  109. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppetdb_ssl_client_key.rb +1 -1
  110. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppetdb_ssl_client_password.rb +1 -1
  111. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppetdb_ssl_client_password_file.rb +1 -1
  112. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/puppetdb_url.rb +1 -1
  113. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/quiet.rb +1 -1
  114. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/retry_failed_catalog.rb +1 -1
  115. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/safe_to_delete_cached_master_dir.rb +1 -1
  116. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/storeconfigs.rb +1 -1
  117. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/suppress_absent_file_details.rb +2 -1
  118. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/to_from_branch.rb +1 -1
  119. data/lib/octocatalog-diff/{catalog-diff/cli → cli}/options/validate_references.rb +1 -1
  120. data/lib/octocatalog-diff/cli/printer.rb +52 -0
  121. data/lib/octocatalog-diff/errors.rb +33 -0
  122. data/lib/octocatalog-diff/facts.rb +1 -4
  123. data/lib/octocatalog-diff/facts/puppetdb.rb +8 -7
  124. data/lib/octocatalog-diff/puppetdb.rb +5 -9
  125. data/lib/octocatalog-diff/util/catalogs.rb +242 -0
  126. metadata +97 -75
  127. data/lib/octocatalog-diff/catalog-diff/cli.rb +0 -211
  128. data/lib/octocatalog-diff/catalog-diff/cli/catalogs.rb +0 -246
  129. data/lib/octocatalog-diff/catalog-diff/cli/diffs.rb +0 -147
  130. data/lib/octocatalog-diff/catalog-diff/cli/helpers/fact_override.rb +0 -100
  131. data/lib/octocatalog-diff/catalog-diff/cli/options.rb +0 -185
  132. data/lib/octocatalog-diff/catalog-diff/cli/printer.rb +0 -54
@@ -0,0 +1,115 @@
1
+ # octocatalog-diff v1 API documentation: catalog
2
+
3
+ ## Overview
4
+
5
+ `catalog` returns an `OctocatalogDiff::Catalog` object built with the octocatalog-diff compiler, obtained from a Puppet server, or read in from a file. This is analogous to using the `--catalog-only` option with the octocatalog-diff command-line script.
6
+
7
+ ```
8
+ catalog_obj = OctocatalogDiff::API::V1.catalog(<Hash>)
9
+ #=> OctocatalogDiff::API::V1::Catalog
10
+ ```
11
+
12
+ The return value is an [`OctocatalogDiff::API::V1::Catalog`](/doc/dev/api/v1/objects/catalog.md) object.
13
+
14
+ For an example, see [catalog-builder-local-files.rb](/examples/api/v1/catalog-builder-local-files.rb).
15
+
16
+ ## Parameters
17
+
18
+ The `catalog` method takes one argument, which is a Hash containing parameters.
19
+
20
+ The list of parameters here is not exhaustive. The `.catalog` method accepts most parameters described in [Configuration](/doc/configuration.md), [Building catalogs instead of diffing catalogs](/doc/advanced-catalog-only.md), and [Command line options reference](/doc/optionsref.md).
21
+
22
+ It is also possible to use the parameters from [OctocatalogDiff::API::V1.config](/doc/dev/api/v1/calls/config.md) for the catalog compilation. Simply combine the hash returned by `.config` with any additional keys, and pass the merged hash to the `.catalog` method.
23
+
24
+ ### Global parameters
25
+
26
+ #### `:logger` (Logger, Optional)
27
+
28
+ Debugging and informational messages will be logged to this object as the catalog is built.
29
+
30
+ If no Logger object is passed, these messages will be silently discarded.
31
+
32
+ #### `:node` (String, Required)
33
+
34
+ The node name whose catalog is to be compiled or obtained. This should be the fully qualified domain name that matches the node's name as seen in Puppet.
35
+
36
+ ### Computed catalog parameters
37
+
38
+ #### `:basedir` (String, Optional)
39
+
40
+ Directory that contains a git repository with the Puppet code. Use in conjunction with `:to_branch` to specify the branch name that should be checked out.
41
+
42
+ If your Puppet code is not in a git repository, or you already have the branch checked out via some other process, use `:bootstrapped_to_dir` instead.
43
+
44
+ #### `:bootstrap_script` (String, Optional)
45
+
46
+ Path to a script to run after checking out the selected branch of Puppet code from the git repository. See [Bootstrapping your Puppet checkout](/doc/advanced-bootstrap.md) for details.
47
+
48
+ #### `:bootstrapped_to_dir` (String, Optional)
49
+
50
+ Directory that is already prepared ("bootstrapped") and can have Puppet run against its contents to compile the catalog.
51
+
52
+ Often this means that you have done the following to this directory:
53
+
54
+ - Checked out the necessary branch of Puppet code from your version control system
55
+ - Installed any third party modules (e.g. with librarian-puppet or r10k)
56
+
57
+ #### `:enc` (String, Optional)
58
+
59
+ File path to your External Node Classifier.
60
+
61
+ See [Configuring octocatalog-diff to use ENC](/doc/configuration-enc.md) for details on using octocatalog-diff with an External Node Classifier.
62
+
63
+ #### `:fact_file` (String, Optional)
64
+
65
+ Path to the file that contains the facts for the node whose catalog you are going to compile.
66
+
67
+ Generally, must either specify the fact file, or [configure octocatalog-diff to use PuppetDB](/doc/configuration-puppetdb.md) to retrieve node facts.
68
+
69
+ #### `:hiera_config` (String, Optional)
70
+
71
+ Path to the Hiera configuration file (generally named `hiera.yaml`) for your Puppet installation. Please see [Configuring octocatalog-diff to use Hiera](/doc/configuration-hiera.md) for details on Hiera configuration.
72
+
73
+ #### `:hiera_path` (String, Optional)
74
+
75
+ Directory within your Puppet installation where Hiera data is stored. Please see [Configuring octocatalog-diff to use Hiera](/doc/configuration-hiera.md) for details on Hiera configuration.
76
+
77
+ If your Puppet setup is modeled after the [Puppet control repository template](https://github.com/puppetlabs/control-repo), the correct setting for `:hiera_path` is `'hieradata'`.
78
+
79
+ #### `:puppet_binary` (String, Required)
80
+
81
+ Path to the Puppet binary on your system.
82
+
83
+ Please refer to [Configuring octocatalog-diff to use Puppet](/doc/configuration-puppet.md) for details of connecting octocatalog-diff to your Puppet installation.
84
+
85
+ #### `:puppetdb_url` (String, Optional)
86
+
87
+ URL to PuppetDB. See [Configuring octocatalog-diff to use PuppetDB](/doc/configuration-puppetdb.md) for instructions on this setting, and other settings that may be needed in your environment.
88
+
89
+ #### `:to_branch` (String, Optional)
90
+
91
+ Branch name in git repository to use for Puppet code. This option must be used in conjunction with `:basedir` so that code can be located.
92
+
93
+ ## Exceptions
94
+
95
+ The following exceptions may occur during the compilation of a catalog:
96
+
97
+ - `OctocatalogDiff::Errors::BootstrapError`
98
+
99
+ Bootstrapping failed.
100
+
101
+ - `OctocatalogDiff::Errors::CatalogError`
102
+
103
+ Catalog failed to compile. Please note that whenever possible, a `OctocatalogDiff::API::V1::Catalog` object is still constructed for a failed catalog, with `#valid?` returning false.
104
+
105
+ - `OctocatalogDiff::Errors::GitCheckoutError`
106
+
107
+ Git checkout failed.
108
+
109
+ - `OctocatalogDiff::Errors::PuppetVersionError`
110
+
111
+ The version of Puppet could not be determined, generally because the Puppet binary was not found, or does not respond as expected to `puppet version`.
112
+
113
+ - `OctocatalogDiff::Errors::ReferenceValidationError`
114
+
115
+ See [Catalog validation](/doc/advanced-catalog-validation.md).
@@ -0,0 +1,37 @@
1
+ # octocatalog-diff v1 API documentation: config
2
+
3
+ ## Overview
4
+
5
+ `config` reads and parses an [octocatalog-diff configuration file](/doc/configuration.md).
6
+
7
+ ```
8
+ options = OctocatalogDiff::API::V1.config(
9
+ filename: "String",
10
+ logger: Logger,
11
+ test: <true|false>
12
+ )
13
+ ```
14
+
15
+ ## Options
16
+
17
+ - **`:filename`** (String, optional): Full path to configuration file to read. If not provided, the configuration file will be searched as described in [Configuration](/doc/configuration.md).
18
+
19
+ - **`:logger`** (Logger, optional): Logger object. If provided, debug messages and fatal errors will be logged to this object.
20
+
21
+ - **`:test`** (Boolean, optional): Test mode, defaults to false. If true, the value of the configuration settings will be logged to the logger (with priority DEBUG) and an exception will be raised if the configuration file cannot be located.
22
+
23
+ ## Return value
24
+
25
+ If the configuration file is located and valid, the return value is a Hash consisting of the options defined in the configuration file.
26
+
27
+ If the configuration file cannot be found, the return value is an empty Hash (`{}`). Except, with `:test => true`, an exception will be raised.
28
+
29
+ ## Exceptions
30
+
31
+ - `OctocatalogDiff::Errors::ConfigurationFileContentError`
32
+
33
+ Raised if the configuration file could not be evaluated. A more specific error message will help identify the cause. Possible causes include the file not being valid ruby, the file not containing the expected structure or methods, or the method returning something other than a Hash.
34
+
35
+ - `OctocatalogDiff::Errors::ConfigurationFileNotFoundError`
36
+
37
+ Raised if the configuration file could not be found, *and* `:test => true` was supplied. (Note, if no configuration file is found, but `:test => false`, no error is raised, and `{}` is returned.)
@@ -0,0 +1,127 @@
1
+ # octocatalog-diff v1 API documentation: OctocatalogDiff::API::V1::Catalog
2
+
3
+ ## Overview
4
+
5
+ `OctocatalogDiff::API::V1::Catalog` is an object that represents a compiled catalog.
6
+
7
+ It wraps the [`OctocatalogDiff::Catalog`](/lib/octocatalog-diff/catalog.rb) object.
8
+
9
+ This object is the return value from the [`catalog`](/doc/dev/api/v1/calls/catalog.md) API call, and the `to` and `from` catalogs computed by the [`catalog-diff`](/doc/dev/api/v1/calls/catalog-diff.md) API call.
10
+
11
+ ## Methods
12
+
13
+ #### `#builder` (String)
14
+
15
+ Returns the name of the class the built the catalog.
16
+
17
+ ```
18
+ catalog.builder #=> 'OctocatalogDiff::Catalog::JSON'
19
+ ```
20
+
21
+ #### `#compilation_dir` (String)
22
+
23
+ Returns the temporary directory in which the catalog was compiled.
24
+
25
+ ```
26
+ catalog.compilation_dir #=> '/var/folders/dw/5ftmkqk972j_kw2fdjyzdqdw0000gn/T/d20170108-95774-1r4ohjd'
27
+ ```
28
+
29
+ This is only applicable for catalogs compiled by `OctocatalogDiff::Catalog::Computed`. This method will return `nil` for catalogs generated by other backends.
30
+
31
+ #### `#error_message` (String)
32
+
33
+ Returns the error message for a failed catalog. (If the catalog is valid, this returns `nil`.)
34
+
35
+ ```
36
+ good_catalog.valid? #=> true
37
+ good_catalog.error_message #=> nil
38
+
39
+ bad_catalog.valid? #=> false
40
+ bad_catalog.error_message #=> 'Failed to compile catalog for node ...'
41
+ ```
42
+
43
+ #### `#puppet_version` (String)
44
+
45
+ Returns the Puppet version used to compile the catalog.
46
+
47
+ ```
48
+ catalog.puppet_version #=> '3.8.7'
49
+ ```
50
+
51
+ This is only applicable for catalogs compiled by `OctocatalogDiff::Catalog::Computed`. This method will return `nil` for catalogs generated by other backends.
52
+
53
+ #### `#resource(<Hash>)` (Hash)
54
+
55
+ Returns the hash representation of the object identified by the type and title supplied.
56
+
57
+ This method requires 1 argument, which is a hash containing `:type` and `:title` keys.
58
+
59
+ ```
60
+ catalog.resource(type: 'File', title: '/etc/foo')
61
+ #=> {"title"=>"/etc/foo", "type"=>"File",
62
+ "parameters"=>{"content"=>"This is the file", "owner"=>"root"},
63
+ "file"=>"/etc/puppetlabs/code/environments/production/manifests/site.pp", "line"=>25}
64
+ ```
65
+
66
+ Returns `nil` if the type+title resource was not present in the catalog.
67
+
68
+ ##### Notes
69
+
70
+ 1. The first call to this method will build a hash table (`O(N)` operation) from the resource array. Thereafter, each call to this method will look up the value in that hash table (`O(1)` operation). To perform lookups of known types and titles, it is faster to use this method than to use `#resources` with array operations when performing multiple lookups.
71
+
72
+ 2. The structure of the returned hash is dependent on the representation of the resource in the Puppet catalog. It is therefore possible that different versions of Puppet could cause different data structures. It is the author's experience that Puppet 3.8.7 and Puppet 4.x produce similar (if not indistinguishable) resource representations.
73
+
74
+ 3. This method will also locate a resource that was named using an alias.
75
+
76
+ ```
77
+ # Puppet code
78
+ file { '/etc/foo':
79
+ alias => 'foo file for the win',
80
+ ...
81
+ }
82
+
83
+ # octocatalog-diff API
84
+ catalog.resource(type: 'File', title: 'foo file for the win')
85
+ #=> {"title"=>"/etc/foo", "type"=>"File", ...}
86
+ ```
87
+
88
+ #### `#resources` (Array&lt;Hash&gt;)
89
+
90
+ Returns an array of catalog resources in a successful catalog. (If the catalog is not valid, this returns `nil`.)
91
+
92
+ ```
93
+ bad_catalog.valid? #=> false
94
+ bad_catalog.resources #=> nil
95
+
96
+ good_catalog.valid? #=> true
97
+ good_catalog.resources
98
+ #=> [
99
+ { "title"=>"/etc/foo", "type"=>"File", ... },
100
+ { "title"=>"/bin/true", "type"=>"Exec", ... }
101
+ ]
102
+ ```
103
+
104
+ The structure of the returned hash is dependent on the representation of the resource in the Puppet catalog. It is therefore possible that different versions of Puppet could cause different data structures. It is the author's experience that Puppet 3.8.7 and Puppet 4.x produce similar (if not indistinguishable) resource representations.
105
+
106
+ #### `#to_json` (String)
107
+
108
+ Returns the JSON representation of a successful catalog. (If the catalog is not valid, this returns `nil`.)
109
+
110
+ ```
111
+ bad_catalog.valid? #=> false
112
+ bad_catalog.to_json #=> nil
113
+
114
+ good_catalog.valid? #=> true
115
+ good_catalog.to_json #=> '{ "document_type": "Catalog", ... }'
116
+ ```
117
+
118
+ #### `#valid?` (Boolean)
119
+
120
+ Returns `true` if the catalog is valid, and `false` if the catalog is not valid.
121
+
122
+ ## Other methods
123
+
124
+ These methods are available for debugging or development purposes but are not guaranteed to remain consistent between versions:
125
+
126
+ - `#to_h` (Hash): Returns hash representation of parsed JSON catalog
127
+ - `#raw` (OctocatalogDiff::Catalog): Returns underlying internal catalog object
@@ -0,0 +1,261 @@
1
+ # octocatalog-diff v1 API documentation: OctocatalogDiff::API::V1::Diff
2
+
3
+ ## Overview
4
+
5
+ `OctocatalogDiff::API::V1::Diff` is an object that represents a single difference between two catalogs.
6
+
7
+ The return value from the `diffs` computed by the [`catalog-diff`](/doc/dev/api/v1/calls/catalog-diff.md) API call is an Array of these `OctocatalogDiff::API::V1::Diff` objects.
8
+
9
+ ## Methods
10
+
11
+ #### `#addition?` (Boolean)
12
+
13
+ Returns true if this diff is an addition (resource exists in new catalog but not old catalog).
14
+
15
+ #### `#change?` (Boolean)
16
+
17
+ Returns true if this diff is a change (resource exists in both catalogs but is different between them).
18
+
19
+ #### `#diff_type` (String)
20
+
21
+ Returns the type of difference, which is one of the following characters:
22
+
23
+ - `+` for addition (resource exists in new catalog but not old catalog)
24
+ - `-` for removal (resource exists in old catalog but not new catalog)
25
+ - `~` or `!` for change (resource exists in both catalogs but is different between them)
26
+
27
+ See also: `#addition?`, `#change?`, `#removal?`
28
+
29
+ Note: Internally `~` and `!` represent different types of changes, but when presenting the output, these can generally be considered equivalent.
30
+
31
+ #### `#new_file` (String)
32
+
33
+ Returns the filename of the Puppet manifest giving rise to the resource as it exists in the new catalog.
34
+
35
+ Note that this is a pass-through of information provided in the Puppet catalog, and is not calculated by octocatalog-diff. If the Puppet catalog does not contain this information, this method will return `nil`.
36
+
37
+ Note also that if the diff represents removal of a resource, this will return `nil`, because the resource does not exist in the new catalog.
38
+
39
+ #### `#new_line` (String)
40
+
41
+ Returns the line number within the Puppet manifest giving rise to the resource as it exists in the new catalog. (See `#new_file` for the filename of the Puppet manifest.)
42
+
43
+ Note that this is a pass-through of information provided in the Puppet catalog, and is not calculated by octocatalog-diff. If the Puppet catalog does not contain this information, this method will return `nil`.
44
+
45
+ Note also that if the diff represents removal of a resource, this will return `nil`, because the resource does not exist in the new catalog.
46
+
47
+ #### `#new_location` (Hash)
48
+
49
+ Returns a hash containing `:file` (equal to `#new_file`) and `:line` (equal to `#new_line`) when either is defined. Returns `nil` if both are undefined.
50
+
51
+ #### `#new_value` (Object)
52
+
53
+ Returns the value of the resource from the new catalog.
54
+
55
+ - If a resource was added, this returns the data structure associated with the resource in the Puppet catalog. For example, if the resource was created as follows in the Puppet catalog, the `new_value` is as indicated.
56
+
57
+ ```
58
+ # Resource in New Catalog
59
+ {
60
+ "type": "File",
61
+ "title": "/etc/foo",
62
+ "parameters": {
63
+ "owner": "root",
64
+ "content": "hello new world"
65
+ }
66
+ }
67
+
68
+ # Demonstrates new_value
69
+ diff.new_value #=> { 'parameters' => { 'owner' => 'root', 'content' => 'hello new world' } }
70
+ ```
71
+
72
+ - If a resource was removed, this returns `nil` because there was no value of this resource in the new catalog.
73
+
74
+ - If a resource was changed, this returns the portion of the data structure that is indicated by the `.structure` method. For example, if the resource existed as follows in both the old and new Puppet catalogs, the `new_value` is as indicated.
75
+
76
+ ```
77
+ # Resource in Old Catalog
78
+ {
79
+ "type": "File",
80
+ "title": "/etc/foo",
81
+ "parameters": {
82
+ "owner": "root",
83
+ "content": "This is the old file"
84
+ }
85
+ }
86
+
87
+ # Resource in New Catalog
88
+ {
89
+ "type": "File",
90
+ "title": "/etc/foo",
91
+ "parameters": {
92
+ "owner": "root",
93
+ "content": "This is the NEW FILE!!!!!"
94
+ }
95
+ }
96
+
97
+ # Demonstrates structure and old_value
98
+ diff.structure #=> ['parameters', 'content']
99
+ diff.old_value #=> 'This is the NEW FILE!!!!!'
100
+ ```
101
+
102
+ #### `#old_file` (String)
103
+
104
+ Returns the filename of the Puppet manifest giving rise to the resource as it exists in the old catalog.
105
+
106
+ Note that this is a pass-through of information provided in the Puppet catalog, and is not calculated by octocatalog-diff. If the Puppet catalog does not contain this information, this method will return `nil`.
107
+
108
+ Note also that if the diff represents addition of a resource, this will return `nil`, because the resource does not exist in the old catalog.
109
+
110
+ #### `#old_file` (String)
111
+
112
+ Returns the line number within the Puppet manifest giving rise to the resource as it exists in the old catalog. (See `#old_file` for the filename of the Puppet manifest.)
113
+
114
+ Note that this is a pass-through of information provided in the Puppet catalog, and is not calculated by octocatalog-diff. If the Puppet catalog does not contain this information, this method will return `nil`.
115
+
116
+ Note also that if the diff represents addition of a resource, this will return `nil`, because the resource does not exist in the old catalog.
117
+
118
+ #### `#old_location` (Hash)
119
+
120
+ Returns a hash containing `:file` (equal to `#old_file`) and `:line` (equal to `#old_line`) when either is defined. Returns `nil` if both are undefined.
121
+
122
+ #### `#old_value` (Object)
123
+
124
+ Returns the value of the resource from the old catalog.
125
+
126
+ - If a resource was added, this returns `nil` because there was no value of this resource in the old catalog.
127
+
128
+ - If a resource was removed, this returns the data structure associated with the resource in the Puppet catalog. For example, if the resource existed as follows in the Puppet catalog, the `old_value` is as indicated.
129
+
130
+ ```
131
+ # Resource in Old Catalog
132
+ {
133
+ "type": "File",
134
+ "title": "/etc/foo",
135
+ "parameters": {
136
+ "owner": "root",
137
+ "content": "hello old world"
138
+ }
139
+ }
140
+
141
+ # Demonstrates old_value
142
+ diff.old_value #=> { 'parameters' => { 'owner' => 'root', 'content' => 'hello old world' } }
143
+ ```
144
+
145
+ - If a resource was changed, this returns the portion of the data structure that is indicated by the `.structure` method. For example, if the resource existed as follows in both the old and new Puppet catalogs, the `old_value` is as indicated.
146
+
147
+ ```
148
+ # Resource in Old Catalog
149
+ {
150
+ "type": "File",
151
+ "title": "/etc/foo",
152
+ "parameters": {
153
+ "owner": "root",
154
+ "content": "This is the old file"
155
+ }
156
+ }
157
+
158
+ # Resource in New Catalog
159
+ {
160
+ "type": "File",
161
+ "title": "/etc/foo",
162
+ "parameters": {
163
+ "owner": "root",
164
+ "content": "This is the NEW FILE!!!!!"
165
+ }
166
+ }
167
+
168
+ # Demonstrates structure and old_value
169
+ diff.structure #=> ['parameters', 'content']
170
+ diff.old_value #=> 'This is the old file'
171
+ ```
172
+
173
+ #### `#removal?` (Boolean)
174
+
175
+ Returns true if this diff is a removal (resource exists in old catalog but not new catalog).
176
+
177
+ #### `#structure` (Array)
178
+
179
+ Returns the structure that has been changed, as an array.
180
+
181
+ When a resource was added or removed, the result is an empty array. That's because all of the parameters and other metadata from the resource exist entirely in one catalog but not the other.
182
+
183
+ When a resource has changed, one diff is created for each parameter that changed. For example, both the old and new catalogs contain the file resource `/etc/foo` but just the content has changed:
184
+
185
+ ```
186
+ # Old
187
+ file { '/etc/foo':
188
+ owner => 'root',
189
+ content => 'This is the old file',
190
+ }
191
+
192
+ # New
193
+ file { '/etc/foo':
194
+ owner => 'root',
195
+ content => 'This is the NEW FILE!!!!!',
196
+ }
197
+ ```
198
+
199
+ Internally, the Puppet catalog for this resource will look like this in the catalogs (this has been abbreviated a bit for clarity):
200
+
201
+ ```
202
+ # Old
203
+ {
204
+ "type": "File",
205
+ "title": "/etc/foo",
206
+ "exported": false,
207
+ "parameters": {
208
+ "owner": "root",
209
+ "content": "This is the old file"
210
+ }
211
+ }
212
+
213
+ # New
214
+ {
215
+ "type": "File",
216
+ "title": "/etc/foo",
217
+ "exported": false,
218
+ "parameters": {
219
+ "owner": "root",
220
+ "content": "This is the NEW FILE!!!!!"
221
+ }
222
+ }
223
+ ```
224
+
225
+ One diff will be generated to represent the change to the content of the file (which in the catalog is nested in the 'parameters' hash). The diff will be structured as follows:
226
+
227
+ ```
228
+ diff.type #=> 'File'
229
+ diff.title #=> '/etc/foo'
230
+ diff.structure #=> ['parameters', 'content']
231
+ ```
232
+
233
+ #### `#title` (String)
234
+
235
+ Returns the title of the resource from the Puppet catalog.
236
+
237
+ For example, a diff involving `File['/etc/passwd']` would have:
238
+
239
+ - `diff.title #=> '/etc/passwd'`
240
+ - `diff.type #=> 'File'`
241
+
242
+ #### `#type` (String)
243
+
244
+ Returns the type of the resource from the Puppet catalog.
245
+
246
+ For example, a diff involving `File['/etc/passwd']` would have:
247
+
248
+ - `diff.title #=> '/etc/passwd'`
249
+ - `diff.type #=> 'File'`
250
+
251
+ Note that the type will be capitalized because Puppet capitalizes this in catalogs.
252
+
253
+ ## Other methods
254
+
255
+ These methods are available for debugging or development purposes but are not guaranteed to remain consistent between versions:
256
+
257
+ - `#inspect` (String): Returns inspection of object
258
+ - `#raw` (Array): Returns internal array data structure of the "diff"
259
+ - `#to_h` (Hash): Returns object as a hash, where keys are above described methods
260
+ - `#to_h_with_string_keys` (Hash): Returns object as a hash, where keys are above described methods; keys are strings, not symbols
261
+ - `#[]` (Object): Retrieve indexed array elements from raw internal array object