kitchen-inspector 1.1.0 → 1.2.0

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: 4146d1e7d37eab22555d357517ac7a44a43f1213
4
- data.tar.gz: e9ac2ee18b946515038713a5261265280856e52d
3
+ metadata.gz: 68e23844d77116a23b08ba739b8ed04569aaa82f
4
+ data.tar.gz: a5e820d914562944de16eaf98053fa9dee7051e0
5
5
  SHA512:
6
- metadata.gz: 20e92986432fb382af3db7928902cfca6c0337911ed395d3bcc6310ca51ef2169038255a8b7163162a1fb98c3c4eb1783728ffa78ec7dad3a60f7d91be2fec29
7
- data.tar.gz: 0415842acfdb0e434d6e8c019de5a3bd45d24c3bcf2fbc860956c358a0ff474ef9f67e48e00c7307b7b430cffbe6478719e05e3689a8a89af1d53bfb7b03b0cd
6
+ metadata.gz: 154b8702208b8d647427e985a7c26674180663b82cfd6656b2fb2c71072b9e5d54eae281ac48617caa8c475d16c2a3d6f0f5d30394aa2a68272363d21e3e2d2d
7
+ data.tar.gz: 498cbbc3e0cfc33836211b7e7d16849ec6b42676ff1c995ddef4f27b7f85a109d357807051ba710146f857a750cf36bcda16592c016ed904f8042d6a40a8e98e
@@ -6,4 +6,4 @@ rvm:
6
6
  script: bundle exec rspec spec
7
7
  env:
8
8
  global:
9
- secure: ox+FSwU2Ue7t3Yq/XKiUvvY5kZ6H2BTAza3zQdHgKq3hhqF9xowp1QSB2BybVSreVgy+dMPivsk5ZPX67aZwfH0tYOJRkaZODVYTxbu/gygTAkcpf9qqGTsS9ISXn6EGqXfAWHXAPsuhjDbMgGBbuAxj0k/HagDSrd7mKvqsrgc=
9
+ secure: QquzUUCraIbBpzZbihr2LEdbnTVxUyBYNgHMvc5Z94HUh8R8ShITRz1zWUvTXQ41IA71/ML1loF8BFHFEE0+Zli6wi8ctoA+/CdH14lFHA6mBaT0o4JRGenAcnG2/1PFVj7CfCjlJe2EBJ/DHpR6bOaiDH4tL42O6fAWu6CDfyQ=
@@ -1,5 +1,23 @@
1
1
  Changes
2
2
  ==
3
+
4
+ 12 Feb 2014 (1.2.0)
5
+ --
6
+
7
+ FEATURES:
8
+
9
+ * Fallback to *knife.rb* for Chef Server configuration
10
+
11
+ FIXES:
12
+
13
+ * Detect when inspectors are not configured at all
14
+ * Blacklist metadata.rb's fields instead of using a whitelist
15
+ * Fix cache key for changelog
16
+
17
+ CHANGES:
18
+
19
+ * Show 'inspect' in help instead of 'investigate'
20
+
3
21
  17 Dec 2013 (1.1.0)
4
22
  --
5
23
 
data/README.md CHANGED
@@ -130,6 +130,9 @@ In order to turn off recursive analysis, simply use _--recursive false_.
130
130
 
131
131
  By default *${HOME}/.chef/kitchen_inspector.rb* is picked, but _--config_ can be used to override that setting.
132
132
 
133
+ Valid Repository Manager and Chef Server configurations must be provided.
134
+ When a Chef Server configuration is not specified in *kitchen_inspector.rb* it fallbacks to *${HOME}/.chef/knife.rb*, if present.
135
+
133
136
  ```
134
137
  $ kitchen-inspector --config config_example.rb
135
138
  ```
@@ -167,6 +170,9 @@ host the cookbooks you're interested in.
167
170
  So, even though a *token* is not strictly required, it's better to configure it as well.
168
171
  From [GitHub's Applications page](https://github.com/settings/applications) go to "Personal Access Tokens" and generate a new token.
169
172
 
173
+ Due to the huge search space, searches against GitHub are restricted to profiles owned by *allowed_users* (aka GitHub usernames).
174
+ Cookbooks are thus searched only within those users' repositories, comparing cookbooks' names with repositories' names (Pattern "one repo per cookbook").
175
+
170
176
  Example:
171
177
 
172
178
  ```ruby
@@ -34,7 +34,9 @@ require 'googl'
34
34
  require 'kitchen-inspector/inspector/common'
35
35
  require 'kitchen-inspector/inspector/mixin/utils'
36
36
  require 'kitchen-inspector/inspector/cli'
37
- require 'kitchen-inspector/inspector/dependency'
37
+
38
+ require 'kitchen-inspector/inspector/models/dependency'
39
+ require 'kitchen-inspector/inspector/models/repo_cookbook'
38
40
 
39
41
  require 'kitchen-inspector/inspector/chef_inspector'
40
42
  require 'kitchen-inspector/inspector/repository_inspector'
@@ -49,16 +49,15 @@ module KitchenInspector
49
49
  default: false,
50
50
  aliases: '--remarks'
51
51
 
52
- desc 'investigate (COOKBOOK_PATH)', 'Check Repository Manager/Chef Server status of dependent cookbooks'
53
-
54
- map 'inspect' => :investigate
52
+ desc 'inspect (COOKBOOK_PATH)', 'Check Repository Manager/Chef Server status of dependent cookbooks'
53
+ map 'inspect' => :investigate
55
54
  def investigate(path=Dir.pwd)
56
55
  inspector = HealthBureau.new options[:config]
57
56
 
58
57
  dependencies = inspector.investigate(path, options[:recursive])
59
58
 
60
59
  if dependencies.empty?
61
- puts 'No dependent cookbooks'.yellow
60
+ puts 'No dependent cookbooks.'.yellow
62
61
  status_code = :'warning-nodependencies'
63
62
  else
64
63
  output, status_code = Report.generate(dependencies, options[:format], options)
@@ -69,10 +68,10 @@ module KitchenInspector
69
68
  puts e.message.red
70
69
  exit STATUS_TO_RETURN_CODES[:'error-config']
71
70
  rescue NotACookbookError
72
- puts 'The path is not a cookbook path'.red
71
+ puts 'The path is not a cookbook path.'.red
73
72
  exit STATUS_TO_RETURN_CODES[:'error-notacookbook']
74
73
  rescue UnsupportedReportFormatError
75
- puts "The report format #{options[:format]} is not supported".red
74
+ puts "The report format #{options[:format]} is not supported.".red
76
75
  exit STATUS_TO_RETURN_CODES[:'error-reportformat']
77
76
  end
78
77
  end
@@ -38,8 +38,14 @@ module KitchenInspector
38
38
  begin
39
39
  self.instance_eval configuration
40
40
  rescue NoMethodError => e
41
- raise ConfigurationError, "Unsupported configuration: #{e.name}"
41
+ raise ConfigurationError, "Unsupported configuration: #{e.name}."
42
42
  end
43
+
44
+ raise ConfigurationError, "Chef Server is not configured properly, " \
45
+ "please check your 'chef_server' configuration." unless validate_chef_inspector
46
+
47
+ raise ConfigurationError, "Repository Manager is not configured properly, " \
48
+ "please check your 'repository_manager' configuration." unless @repo_inspector
43
49
  end
44
50
 
45
51
  # Inspect your kitchen!
@@ -54,7 +60,7 @@ module KitchenInspector
54
60
 
55
61
  metadata = Ridley::Chef::Cookbook::Metadata.from_file(File.join(path, 'metadata.rb'))
56
62
  metadata.dependencies.collect do |name, version|
57
- analyze_dependency(Dependency.new(name, version), recursive)
63
+ analyze_dependency(Models::Dependency.new(name, version), recursive)
58
64
  end.flatten
59
65
  end
60
66
 
@@ -176,6 +182,24 @@ module KitchenInspector
176
182
  def repository_manager(config)
177
183
  @repo_inspector = RepositoryInspector.new config
178
184
  end
185
+
186
+ # Initialize a Chef Inspector using knife.rb settings if not already
187
+ # initialized
188
+ #
189
+ # @return [ChefInspector]
190
+ def validate_chef_inspector
191
+ @chef_inspector ||= begin
192
+ # Fallback to knife.rb if possible
193
+ knife_cfg = "#{Dir.home}/.chef/knife.rb"
194
+ if File.exists?(knife_cfg)
195
+ Chef::Config.from_file knife_cfg
196
+ chef_server({ :username => Chef::Config.node_name,
197
+ :url => Chef::Config.chef_server_url,
198
+ :client_pem => Chef::Config.client_key
199
+ })
200
+ end
201
+ end
202
+ end
179
203
  end
180
204
  end
181
205
  end
@@ -71,7 +71,7 @@ module KitchenInspector
71
71
  def eval_metadata(raw_response)
72
72
  clean_response = raw_response.split("\n").select do |line|
73
73
  line.strip!
74
- line =~ /^depends|^name|^version/
74
+ line !~ /^(long_)*description|^recipe|^maintainer.*|^license/
75
75
  end
76
76
 
77
77
  metadata = Ridley::Chef::Cookbook::Metadata.new
@@ -0,0 +1,89 @@
1
+ #
2
+ # Copyright (c) 2013 Stefano Tortarolo <stefano.tortarolo@gmail.com>
3
+ #
4
+ # MIT License
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #
25
+
26
+ module KitchenInspector
27
+ module Inspector
28
+ module Models
29
+ # The class that contains information about a dependent cookbook
30
+ class Dependency
31
+ include Comparable
32
+
33
+ # The name of the dependency
34
+ attr_reader :name
35
+
36
+ # The requirement for the dependency
37
+ attr_reader :requirement
38
+
39
+ # Info from Chef Server
40
+ attr_accessor :chef
41
+
42
+ # Info from the Repository Manager
43
+ attr_accessor :repomanager
44
+
45
+ # The status of the dependency
46
+ attr_accessor :status
47
+
48
+ # The dependencies of a cookbook
49
+ attr_accessor :dependencies
50
+
51
+ # Remarks field
52
+ attr_accessor :remarks
53
+
54
+ # Dependency's parents (if transitive)
55
+ attr_accessor :parents
56
+
57
+ def initialize(name, requirement)
58
+ @name = name
59
+ @requirement = requirement
60
+ @chef = {}
61
+ @repomanager = {}
62
+ @status = nil
63
+ @remarks = []
64
+ @dependencies = []
65
+ @parents = []
66
+ end
67
+
68
+ def ==(anOther)
69
+ name == anOther.name && requirement == anOther.requirement
70
+ end
71
+
72
+ def to_hash
73
+ {}.tap do |hash|
74
+ hash[:name] = name
75
+ hash[:requirement] = requirement
76
+ hash[:status] = status
77
+ hash[:remarks] = remarks
78
+ hash[:dependencies] = dependencies
79
+ hash[:chef] = chef
80
+ hash[:chef][:latest_version] = hash[:chef][:latest_version].to_s if hash[:chef][:latest_version]
81
+ hash[:repomanager] = repomanager
82
+ hash[:repomanager][:latest_tag] = hash[:repomanager][:latest_tag].to_s if hash[:repomanager][:latest_tag]
83
+ hash[:repomanager][:latest_metadata] = hash[:repomanager][:latest_metadata].to_s if hash[:repomanager][:latest_metadata]
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright (c) 2013 Stefano Tortarolo <stefano.tortarolo@gmail.com>
3
+ #
4
+ # MIT License
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #
25
+
26
+ module KitchenInspector
27
+ module Inspector
28
+ module Models
29
+ # The class that contains information about a cookbook on Repository Manager
30
+ class RepoCookbook
31
+ include Comparable
32
+
33
+ # The ID of the cookbook on Repository Manager
34
+ attr_reader :id
35
+
36
+ # The name of the cookbook
37
+ attr_reader :name
38
+
39
+ # Path to metadata.rb
40
+ attr_accessor :metadata_path
41
+
42
+ def initialize(id, name, metadata_path)
43
+ @id = id
44
+ @name = name
45
+ @metadata_path = metadata_path
46
+ end
47
+
48
+ def ==(anOther)
49
+ name == anOther.name && metadata_path == anOther.metadata_path
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -35,7 +35,7 @@ module KitchenInspector
35
35
  require "kitchen-inspector/inspector/repository_managers/#{config[:type].downcase}"
36
36
  manager_cls = "KitchenInspector::Inspector::#{config[:type]}Manager".constantize
37
37
  rescue LoadError, NameError => e
38
- raise RepositoryManagerError, "Repository Manager '#{config[:type]}' not supported"
38
+ raise RepositoryManagerError, "Repository Manager '#{config[:type]}' not supported."
39
39
  end
40
40
 
41
41
  @manager = manager_cls.new config
@@ -60,7 +60,7 @@ module KitchenInspector
60
60
  repo_info[:not_unique] = projects.size > 1
61
61
 
62
62
  # Inherit only shallow information from dependency
63
- prj_dependency = Dependency.new(dependency.name, dependency.requirement)
63
+ prj_dependency = Models::Dependency.new(dependency.name, dependency.requirement)
64
64
  prj_dependency.parents = dependency.parents
65
65
 
66
66
  prj_dependency.parents.each do |parent|
@@ -65,7 +65,7 @@ module KitchenInspector
65
65
  metadata = project_metadata(project, revId)
66
66
 
67
67
  if metadata
68
- metadata.dependencies.collect{|dep, constraint| Dependency.new(dep, constraint)}
68
+ metadata.dependencies.collect{|dep, constraint| Models::Dependency.new(dep, constraint)}
69
69
  end
70
70
  end
71
71
 
@@ -98,7 +98,7 @@ module KitchenInspector
98
98
  # Return a shortened url to the commits between two revisions
99
99
  def changelog(project_url, revId, otherRevId)
100
100
  return unless project_url && revId && otherRevId
101
- cache_key = "#{project_url}-#{revId}-otherRevId"
101
+ cache_key = "#{project_url}-#{revId}-#{otherRevId}"
102
102
 
103
103
  @changelogs_cache[cache_key] ||=
104
104
  begin
@@ -52,8 +52,8 @@ module KitchenInspector
52
52
 
53
53
  # Given a project and a revision retrieve its metadata
54
54
  def retrieve_metadata(project, revId)
55
- response = Octokit.contents(project.full_name,
56
- {:ref => revId, :path => "metadata.rb" })
55
+ response = Octokit.contents(project.name,
56
+ {:ref => revId, :path => project.metadata_path })
57
57
 
58
58
  if response && response.respond_to?(:content)
59
59
  eval_metadata Base64.decode64(response.content)
@@ -64,7 +64,7 @@ module KitchenInspector
64
64
 
65
65
  # Return the full URL for a given project
66
66
  def source_url(project)
67
- "github.com/#{project.full_name}"
67
+ "github.com/#{project.name}"
68
68
  end
69
69
 
70
70
  # Retrieve projects by name
@@ -76,14 +76,15 @@ module KitchenInspector
76
76
  repos = repos.items.select do |repo|
77
77
  repo.name == name
78
78
  end
79
- repos
79
+
80
+ repos.collect{|repo| Models::RepoCookbook.new(repo.id, repo.full_name, "metadata.rb")}
80
81
  end
81
82
  end
82
83
 
83
84
  # Given a project return the tags on GitHub
84
85
  def retrieve_tags(project)
85
86
  tags = {}
86
- Octokit.tags(project.full_name).collect do |tag|
87
+ Octokit.tags(project.name).collect do |tag|
87
88
  tags[fix_version_name(tag.name)] = tag.commit.sha
88
89
  end
89
90
  tags
@@ -58,17 +58,18 @@ module KitchenInspector
58
58
 
59
59
  # Return the full URL for a given project
60
60
  def source_url(project)
61
- "#{@gitlab_base_url}/#{project.path_with_namespace}"
61
+ "#{@gitlab_base_url}/#{project.name}"
62
62
  end
63
63
 
64
64
  # Retrieve projects by name
65
65
  def projects_by_name(name)
66
- projects.select{|prj| prj.path == name }
66
+ repos = projects.select{|prj| prj.path == name }
67
+ repos.collect{|repo| Models::RepoCookbook.new(repo.id, repo.path_with_namespace, "metadata.rb")}
67
68
  end
68
69
 
69
70
  # Given a project and a revision retrieve its metadata
70
71
  def retrieve_metadata(project, revId)
71
- response = HTTParty.get("#{Gitlab.endpoint}/projects/#{project.id}/repository/blobs/#{revId}?filepath=metadata.rb",
72
+ response = HTTParty.get("#{Gitlab.endpoint}/projects/#{project.id}/repository/blobs/#{revId}?filepath=#{project.metadata_path}",
72
73
  headers: {"PRIVATE-TOKEN" => Gitlab.private_token})
73
74
 
74
75
  if response.code == 200
@@ -24,6 +24,6 @@
24
24
  #
25
25
  module KitchenInspector
26
26
  module Inspector
27
- VERSION = '1.1.0'
27
+ VERSION = '1.2.0'
28
28
  end
29
29
  end
@@ -2,7 +2,9 @@ require_relative 'support/spec_helper'
2
2
 
3
3
  describe GitHubManager do
4
4
  let(:manager) do
5
- config = {:type => "GitHub", :allowed_users => ["astratto"]}
5
+ config = {:type => "GitHub",
6
+ :allowed_users => ["kitchen-inspector"],
7
+ :token => ENV['GITHUB_TOKEN']}
6
8
 
7
9
  manager = GitHubManager.new config
8
10
  manager
@@ -22,7 +24,7 @@ describe GitHubManager do
22
24
  it "creates a valid Manager" do
23
25
  config = {:type => "GitHub",
24
26
  :token => ENV['GITHUB_TOKEN'],
25
- :allowed_users => ["astratto"]
27
+ :allowed_users => ["kitchen-inspector"]
26
28
  }
27
29
 
28
30
  manager = GitHubManager.new config
@@ -42,36 +44,35 @@ describe GitHubManager do
42
44
  end
43
45
 
44
46
  describe "#projects_by_name" do
45
- it "returns the correct project for astratto/kitchen-inspector", :type => :external do
46
- projects = manager.projects_by_name "kitchen-inspector"
47
+ it "returns the correct project for kitchen-inspector/cook-test", :type => :external do
48
+ projects = manager.projects_by_name "cook-test"
47
49
  expect(projects).not_to eq(nil)
48
50
  end
49
51
  end
50
52
 
51
53
  describe "#tags" do
52
- let(:project) { manager.projects_by_name("kitchen-inspector").first }
53
-
54
- it "returns the correct tags for astratto/kitchen-inspector", :type => :external do
54
+ let(:project) { manager.projects_by_name("cook-test").first }
55
55
 
56
- expect(manager.tags(project)["1.0.1"]).to eq("b935719a532c8042b51de560db09881803fbb511")
56
+ it "returns the correct tags for kitchen-inspector/cook-test", :type => :external do
57
+ expect(manager.tags(project)["1.1.0"]).to eq("5c430684e34415df07f3178dff96f2cf23a59452")
57
58
  end
58
59
  end
59
60
 
60
61
  describe "#project_metadata" do
61
62
  let(:project) { manager.projects_by_name("cook-test").first }
62
- it "returns the correct metadata for github.com/astratto/cook-test v.1.0.0", :type => :external do
63
+ it "returns the correct metadata for github.com/kitchen-inspector/cook-test v.1.1.0", :type => :external do
63
64
 
64
- metadata = manager.project_metadata(project, "689dcf42e0cc0710fd337ebd1fee3d2ee8e7dca4")
65
+ metadata = manager.project_metadata(project, "5c430684e34415df07f3178dff96f2cf23a59452")
65
66
  expect(metadata.name).to eq("cook-test")
66
67
  end
67
68
 
68
- it "returns the correct version for github.com/astratto/cook-test v.1.0.0", :type => :external do
69
- version = manager.project_metadata_version(project, "689dcf42e0cc0710fd337ebd1fee3d2ee8e7dca4")
70
- expect(version).to eq("1.0.0")
69
+ it "returns the correct version for github.com/kitchen-inspector/cook-test v.1.1.0", :type => :external do
70
+ version = manager.project_metadata_version(project, "5c430684e34415df07f3178dff96f2cf23a59452")
71
+ expect(version).to eq("1.1.0")
71
72
  end
72
73
 
73
- it "returns the correct dependencies for github.com/astratto/cook-test v.1.0.0", :type => :external do
74
- dependencies = manager.project_dependencies(project, "689dcf42e0cc0710fd337ebd1fee3d2ee8e7dca4")
74
+ it "returns the correct dependencies for github.com/kitchen-inspector/cook-test v.1.1.0", :type => :external do
75
+ dependencies = manager.project_dependencies(project, "5c430684e34415df07f3178dff96f2cf23a59452")
75
76
 
76
77
  expect(dependencies.collect(&:name)).to eq(["openssl", "build-essential"])
77
78
  end
@@ -41,7 +41,8 @@ describe GitLabManager do
41
41
 
42
42
  expect do
43
43
  GitLabManager.new config
44
- end.to raise_error(GitLabAccessNotConfiguredError)
44
+ end.to raise_error(GitLabAccessNotConfiguredError, "GitLab Private Token not configured. " \
45
+ "Please set token in your config file.")
45
46
  end
46
47
 
47
48
  it "raises an error when GitLab Base Url is not configured" do
@@ -51,7 +52,8 @@ describe GitLabManager do
51
52
 
52
53
  expect do
53
54
  GitLabManager.new config
54
- end.to raise_error(GitLabAccessNotConfiguredError)
55
+ end.to raise_error(GitLabAccessNotConfiguredError, "GitLab base url not configured. " \
56
+ "Please set base_url in your config file.")
55
57
  end
56
58
  end
57
59
  end
@@ -1,6 +1,13 @@
1
1
  require_relative 'support/spec_helper'
2
2
 
3
3
  describe HealthBureau do
4
+ before(:each) do
5
+ # Ignore existing knife.rb configuration
6
+ orig_file = File.method(:exists?)
7
+ File.stub(:exists?).with(anything()) { |*args| orig_file.call(*args) }
8
+ File.stub(:exists?).with("#{Dir.home}/.chef/knife.rb").and_return(false)
9
+ end
10
+
4
11
  let(:health_bureau) { generate_health_bureau }
5
12
 
6
13
  let(:repomanager_info) do
@@ -16,6 +23,28 @@ describe HealthBureau do
16
23
  end
17
24
 
18
25
  describe "#initialize" do
26
+ context "Incomplete configuration" do
27
+ it "raises an error if a Repository Manager is not configured" do
28
+ config = StringIO.new
29
+ config.puts "chef_server :url => 'http://localhost:4000', :client_pem => 'testclient.pem', :username => 'test_user'"
30
+
31
+ expect do
32
+ HealthBureau.new config
33
+ end.to raise_error(ConfigurationError, "Repository Manager is not configured properly, "\
34
+ "please check your 'repository_manager' configuration.")
35
+ end
36
+
37
+ it "raises an error if a Chef Server is not configured" do
38
+ config = StringIO.new
39
+ config.puts "repository_manager :type => 'GitLab', :base_url => 'http://localhost:8080', :token =>'test_token'"
40
+
41
+ expect do
42
+ HealthBureau.new config
43
+ end.to raise_error(ConfigurationError, "Chef Server is not configured properly, "\
44
+ "please check your 'chef_server' configuration.")
45
+ end
46
+ end
47
+
19
48
  context "Repository Manager" do
20
49
  it "raises an error if an unsupported Repository Manager is specified" do
21
50
  config = StringIO.new
@@ -24,7 +53,7 @@ describe HealthBureau do
24
53
 
25
54
  expect do
26
55
  HealthBureau.new config
27
- end.to raise_error(RepositoryManagerError)
56
+ end.to raise_error(RepositoryManagerError, "Repository Manager 'Unknown' not supported.")
28
57
  end
29
58
 
30
59
  it "raises an error if an unsupported field is specified" do
@@ -35,7 +64,7 @@ describe HealthBureau do
35
64
 
36
65
  expect do
37
66
  HealthBureau.new config
38
- end.to raise_error(ConfigurationError)
67
+ end.to raise_error(ConfigurationError, "Unsupported configuration: invalid_field.")
39
68
  end
40
69
 
41
70
  context "GitLab" do
@@ -58,7 +87,8 @@ describe HealthBureau do
58
87
 
59
88
  expect do
60
89
  HealthBureau.new config
61
- end.to raise_error(GitLabAccessNotConfiguredError)
90
+ end.to raise_error(GitLabAccessNotConfiguredError, "GitLab Private Token not configured. " \
91
+ "Please set token in your config file.")
62
92
  end
63
93
 
64
94
  it "raises an error when GitLab Base Url is not configured" do
@@ -68,7 +98,8 @@ describe HealthBureau do
68
98
 
69
99
  expect do
70
100
  HealthBureau.new config
71
- end.to raise_error(GitLabAccessNotConfiguredError)
101
+ end.to raise_error(GitLabAccessNotConfiguredError, "GitLab base url not configured. " \
102
+ "Please set base_url in your config file.")
72
103
  end
73
104
  end
74
105
  end
@@ -82,7 +113,8 @@ describe HealthBureau do
82
113
 
83
114
  expect do
84
115
  HealthBureau.new config
85
- end.to raise_error(ChefAccessNotConfiguredError)
116
+ end.to raise_error(ChefAccessNotConfiguredError, "Chef Server url not configured. " \
117
+ "Please set :url in your config file.")
86
118
  end
87
119
 
88
120
  it "raises an error when Client PEM is not configured" do
@@ -92,7 +124,8 @@ describe HealthBureau do
92
124
 
93
125
  expect do
94
126
  HealthBureau.new config
95
- end.to raise_error(ChefAccessNotConfiguredError)
127
+ end.to raise_error(ChefAccessNotConfiguredError, "Chef client PEM not configured. " \
128
+ "Please set :client_pem in your config file.")
96
129
  end
97
130
 
98
131
  it "raises an error when Username is not configured" do
@@ -102,14 +135,15 @@ describe HealthBureau do
102
135
 
103
136
  expect do
104
137
  HealthBureau.new config
105
- end.to raise_error(ChefAccessNotConfiguredError)
138
+ end.to raise_error(ChefAccessNotConfiguredError, "Chef username not configured. " \
139
+ "Please set :username in your config file.")
106
140
  end
107
141
  end
108
142
  end
109
143
 
110
144
  describe "#update_dependency" do
111
145
  before(:each) do
112
- @dep = Dependency.new("test", ">= 0")
146
+ @dep = Models::Dependency.new("test", ">= 0")
113
147
  end
114
148
 
115
149
  it "returns a success for correct versions on both servers" do
@@ -265,7 +299,7 @@ describe HealthBureau do
265
299
  project = double()
266
300
 
267
301
  allow(project).to receive(:id).and_return(1)
268
- allow(project).to receive(:path_with_namespace).and_return("group/project")
302
+ allow(project).to receive(:name).and_return("group/project")
269
303
 
270
304
  GitLabManager.any_instance.stub(:projects_by_name).and_return([
271
305
  project
@@ -18,7 +18,7 @@ describe Report do
18
18
  describe ".generate" do
19
19
  context "global status" do
20
20
  before(:each) do
21
- dep1 = Dependency.new("Test", "~> 1.0.0")
21
+ dep1 = Models::Dependency.new("Test", "~> 1.0.0")
22
22
  health_bureau.update_dependency(dep1, chef_info, repomanager_info)
23
23
 
24
24
  @dependencies = [dep1]
@@ -111,7 +111,7 @@ describe Report do
111
111
  end
112
112
 
113
113
  it "warn_req" do
114
- dep1 = Dependency.new("Test", "= 1.0.0")
114
+ dep1 = Models::Dependency.new("Test", "= 1.0.0")
115
115
  chef = {:versions => ["1.0.0", "1.0.1"],
116
116
  :latest_version => Solve::Version.new("1.0.1"),
117
117
  :version_used => "1.0.0"}
@@ -214,7 +214,7 @@ describe Report do
214
214
 
215
215
  it "shows nested dependencies" do
216
216
  dep1 = @dependencies.first
217
- dep2 = Dependency.new("Nested", "~> 1.0.0")
217
+ dep2 = Models::Dependency.new("Nested", "~> 1.0.0")
218
218
  dep2.parents << dep1
219
219
  dep1.dependencies << dep2
220
220
  health_bureau.update_dependency(dep2, chef_info, repomanager_info)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-inspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Tortarolo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-17 00:00:00.000000000 Z
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -256,9 +256,10 @@ files:
256
256
  - lib/kitchen-inspector/inspector/chef_inspector.rb
257
257
  - lib/kitchen-inspector/inspector/cli.rb
258
258
  - lib/kitchen-inspector/inspector/common.rb
259
- - lib/kitchen-inspector/inspector/dependency.rb
260
259
  - lib/kitchen-inspector/inspector/health_bureau.rb
261
260
  - lib/kitchen-inspector/inspector/mixin/utils.rb
261
+ - lib/kitchen-inspector/inspector/models/dependency.rb
262
+ - lib/kitchen-inspector/inspector/models/repo_cookbook.rb
262
263
  - lib/kitchen-inspector/inspector/report/report.rb
263
264
  - lib/kitchen-inspector/inspector/report/status_reporter.rb
264
265
  - lib/kitchen-inspector/inspector/repository_inspector.rb
@@ -272,9 +273,9 @@ files:
272
273
  - spec/data/test_client.pem
273
274
  - spec/data/test_config_invalid.rb
274
275
  - spec/data/test_config_valid.rb
275
- - spec/dependency_inspector_spec.rb
276
276
  - spec/github_manager_spec.rb
277
277
  - spec/gitlab_manager_spec.rb
278
+ - spec/health_bureau_spec.rb
278
279
  - spec/report_spec.rb
279
280
  - spec/support/spec_helper.rb
280
281
  - spec/utils_spec.rb
@@ -309,9 +310,10 @@ test_files:
309
310
  - spec/data/test_client.pem
310
311
  - spec/data/test_config_invalid.rb
311
312
  - spec/data/test_config_valid.rb
312
- - spec/dependency_inspector_spec.rb
313
313
  - spec/github_manager_spec.rb
314
314
  - spec/gitlab_manager_spec.rb
315
+ - spec/health_bureau_spec.rb
315
316
  - spec/report_spec.rb
316
317
  - spec/support/spec_helper.rb
317
318
  - spec/utils_spec.rb
319
+ has_rdoc:
@@ -1,87 +0,0 @@
1
- #
2
- # Copyright (c) 2013 Stefano Tortarolo <stefano.tortarolo@gmail.com>
3
- #
4
- # MIT License
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining
7
- # a copy of this software and associated documentation files (the
8
- # "Software"), to deal in the Software without restriction, including
9
- # without limitation the rights to use, copy, modify, merge, publish,
10
- # distribute, sublicense, and/or sell copies of the Software, and to
11
- # permit persons to whom the Software is furnished to do so, subject to
12
- # the following conditions:
13
- #
14
- # The above copyright notice and this permission notice shall be
15
- # included in all copies or substantial portions of the Software.
16
- #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
- #
25
-
26
- module KitchenInspector
27
- module Inspector
28
- # The class that contains information about a dependent cookbook
29
- class Dependency
30
- include Comparable
31
-
32
- # The name of the dependency
33
- attr_reader :name
34
-
35
- # The requirement for the dependency
36
- attr_reader :requirement
37
-
38
- # Info from Chef Server
39
- attr_accessor :chef
40
-
41
- # Info from the Repository Manager
42
- attr_accessor :repomanager
43
-
44
- # The status of the dependency
45
- attr_accessor :status
46
-
47
- # The dependencies of a cookbook
48
- attr_accessor :dependencies
49
-
50
- # Remarks field
51
- attr_accessor :remarks
52
-
53
- # Dependency's parents (if transitive)
54
- attr_accessor :parents
55
-
56
- def initialize(name, requirement)
57
- @name = name
58
- @requirement = requirement
59
- @chef = {}
60
- @repomanager = {}
61
- @status = nil
62
- @remarks = []
63
- @dependencies = []
64
- @parents = []
65
- end
66
-
67
- def ==(anOther)
68
- name == anOther.name && requirement == anOther.requirement
69
- end
70
-
71
- def to_hash
72
- {}.tap do |hash|
73
- hash[:name] = name
74
- hash[:requirement] = requirement
75
- hash[:status] = status
76
- hash[:remarks] = remarks
77
- hash[:dependencies] = dependencies
78
- hash[:chef] = chef
79
- hash[:chef][:latest_version] = hash[:chef][:latest_version].to_s if hash[:chef][:latest_version]
80
- hash[:repomanager] = repomanager
81
- hash[:repomanager][:latest_tag] = hash[:repomanager][:latest_tag].to_s if hash[:repomanager][:latest_tag]
82
- hash[:repomanager][:latest_metadata] = hash[:repomanager][:latest_metadata].to_s if hash[:repomanager][:latest_metadata]
83
- end
84
- end
85
- end
86
- end
87
- end