octocatalog-diff 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4632d74c4bd84807f92cb770854c95124c8c0ae8
4
- data.tar.gz: 4f58f8e014f209089125a4c8dacdcd0320f0c9a6
3
+ metadata.gz: 373d19f3ac425f068b91f3fc3a32185375fbe13e
4
+ data.tar.gz: 344a4e7024b88ed9e1e75b60639269fa38cb5033
5
5
  SHA512:
6
- metadata.gz: e68c927375de0a95e3c1e034febfa341228bfabb413b7cb1fcd506306d74a9d9ace8d2fd2ef39b48c2ed13b945094566146d1c8d86d4c71f9ccab15e678a20c6
7
- data.tar.gz: 8004544d6fbb3b0d1c985d2994f98d8b22382179038ff60c5ea5c9c06e3b196edf37fa3a202fe6d3982c40e2b6e87b3dfa0646cf42b5ead0f3d45a976d0ff529
6
+ metadata.gz: 50a77d5680032271a238a60ba1b33263a5f0797fdd2aad8bef18b643221e03b803b9c480e8b4da850eae74f2648aa6baf9dd6d6d6d430c257d6861a61efb78dc
7
+ data.tar.gz: 40f1df38c8b0f4ac1c7cd648bbf238b4b21f881291de9a8960c8773c9cf93339e1fddc597f4a4a954c3a0e85fde4979ee897610113b774a33ca371e914d7e429
data/.version CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.5.6
@@ -8,6 +8,22 @@
8
8
  </tr>
9
9
  </thead><tbody>
10
10
  <tr valign=top>
11
+ <td>0.5.6</td>
12
+ <td>2016-11-16</td>
13
+ <td>
14
+ <ul>
15
+ <li><a href="https://github.com/github/octocatalog-diff/pull/20">https://github.com/github/octocatalog-diff/pull/20</a>: Use modulepath from environment.conf to inform lookup directories for <code>--compare-file-text</code> feature</li>
16
+ </ul>
17
+ </td>
18
+ </tr>
19
+ <tr valign=top>
20
+ <td>0.5.5</td>
21
+ <td>-</td>
22
+ <td>
23
+ Unreleased internal version
24
+ </td>
25
+ </tr>
26
+ <tr valign=top>
11
27
  <td>0.5.4</td>
12
28
  <td>2016-11-07</td>
13
29
  <td>
@@ -21,6 +21,45 @@ module OctocatalogDiff
21
21
  end
22
22
  end
23
23
 
24
+ # Internal method: Locate a file that is referenced at puppet:///modules/xxx/yyy using the
25
+ # module path that is specified within the environment.conf file (assuming the default 'modules'
26
+ # directory doesn't exist or the module isn't found in there). If the file can't be found then
27
+ # this returns nil which may trigger an error.
28
+ # @param src [String] A file reference: puppet:///modules/xxx/yyy
29
+ # @param modulepaths [Array] Cached module path
30
+ # @return [String] File system path to referenced file
31
+ def self.file_path(src, modulepaths)
32
+ unless src =~ %r{^puppet:///modules/([^/]+)/(.+)}
33
+ raise ArgumentError, "Bad parameter source #{src}"
34
+ end
35
+
36
+ path = File.join(Regexp.last_match(1), 'files', Regexp.last_match(2))
37
+ modulepaths.each do |mp|
38
+ file = File.join(mp, path)
39
+ return file if File.exist?(file)
40
+ end
41
+
42
+ nil
43
+ end
44
+
45
+ # Internal method: Parse environment.conf to find the modulepath
46
+ # @param compilation_dir [String] Compilation directory
47
+ # @return [Array] Module paths
48
+ def self.module_path(compilation_dir)
49
+ environment_conf = File.join(compilation_dir, 'environment.conf')
50
+ unless File.file?(environment_conf)
51
+ return [File.join(compilation_dir, 'modules')]
52
+ end
53
+
54
+ # This doesn't support multi-line, continuations with backslash, etc.
55
+ # Does it need to??
56
+ if File.read(environment_conf) =~ /^modulepath\s*=\s*(.+)/
57
+ Regexp.last_match(1).split(/:/).map(&:strip).reject { |x| x =~ /^\$/ }.map { |x| File.join(compilation_dir, x) }
58
+ else
59
+ [File.join(compilation_dir, 'modules')]
60
+ end
61
+ end
62
+
24
63
  # Internal method: Static method to convert file resources. The compilation directory is
25
64
  # required, or else this is a no-op. The passed-in array of resources is modified by this method.
26
65
  # @param resources [Array<Hash>] Array of catalog resources
@@ -34,18 +73,15 @@ module OctocatalogDiff
34
73
  # that compilation_dir/environments/production is pointing at the right place). Otherwise, try to find
35
74
  # compilation_dir/modules. If neither of those exist, this code can't run.
36
75
  env_dir = File.join(compilation_dir, 'environments', 'production')
37
- unless File.directory?(File.join(env_dir, 'modules'))
38
- return unless File.directory?(File.join(compilation_dir, 'modules'))
39
- env_dir = compilation_dir
40
- end
76
+ modulepaths = module_path(env_dir) + module_path(compilation_dir)
77
+ modulepaths.select! { |x| File.directory?(x) }
78
+ return if modulepaths.empty?
41
79
 
42
- # Modify the resources
80
+ # At least one existing module path was found! Run the code to modify the resources.
43
81
  resources.map! do |resource|
44
82
  if resource_convertible?(resource)
45
- # Parse the 'source' parameter into a file on disk
46
- src = resource['parameters']['source']
47
- raise "Bad parameter source #{src}" unless src =~ %r{^puppet:///modules/([^/]+)/(.+)}
48
- path = File.join(env_dir, 'modules', Regexp.last_match(1), 'files', Regexp.last_match(2))
83
+ path = file_path(resource['parameters']['source'], modulepaths)
84
+ raise Errno::ENOENT, "Unable to resolve '#{resource['parameters']['source']}'!" if path.nil?
49
85
 
50
86
  if File.file?(path)
51
87
  # If the file is found, read its content. If the content is all ASCII, substitute it into
@@ -60,7 +96,10 @@ module OctocatalogDiff
60
96
  # However, the fact that we found *something* at this location indicates that the catalog
61
97
  # is probably correct. Hence, the very general .exist? check.
62
98
  else
63
- raise Errno::ENOENT, "Unable to find '#{src}' at #{path}!"
99
+ # This is probably a bug
100
+ # :nocov:
101
+ raise "Unable to find '#{resource['parameters']['source']}' at #{path}!"
102
+ # :nocov:
64
103
  end
65
104
  end
66
105
  resource
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: 0.5.4
4
+ version: 0.5.6
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: 2016-11-07 00:00:00.000000000 Z
12
+ date: 2016-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: diffy