knife-block 0.1.1 → 0.2.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8125038f02b6706bb26ab1398318190de497b629
4
+ data.tar.gz: ca88ab7af3a2ed0432c277a063fba765d6593785
5
+ SHA512:
6
+ metadata.gz: c23baa601cc3712904cbbb7b2125d29f6f73b5e0d82591f1b42d56da897b3e6c195df402f8323cc35bdd9e555b58e0d5ab28f4d80ba09429c855e9c8bce2817b
7
+ data.tar.gz: 29579dc6f087ceefa743c5321ba5762a4d4ce25883f0d891fdc3bc640b8aced7d35853a8390c8ea2233506b5e4582d9839321f9919cae380de8f309c124fc3e9
@@ -1,4 +1,17 @@
1
1
  language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 1.8.7
2
+ before_install:
3
+ - sudo apt-get update -qq
4
+ - sudo apt-get install -y apt-transport-https
5
+ matrix:
6
+ include:
7
+ - rvm: "2.0"
8
+ - rvm: "2.1"
9
+ env: CHEF_DK=true
10
+ - rvm: "2.1"
11
+ env: CHEF_DK=false
12
+ - rvm: "2.2"
13
+ cache:
14
+ - bundler
15
+ - apt
16
+ script:
17
+ - ./test/bin/tests.sh $CHEF_DK
data/Gemfile CHANGED
@@ -1,5 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :test do
4
+ gem 'rubocop'
5
+ end
3
6
 
4
7
  gem 'rake'
5
8
  gem 'chef'
data/README.md CHANGED
@@ -1,19 +1,25 @@
1
1
  # Knife Block
2
2
 
3
- Green and Secure IT Limited often have a need to work with multiple chef servers at the same time, be it due to testing/development/live scenarios or purely through working for a number of clients at once.
4
-
5
3
  The knife block plugin has been created to enable the use of multiple knife.rb files against multiple chef servers.
6
4
 
7
5
  The premise is that you have a "block" in which you store all your "knives" and you can choose the one best suited to the task.
8
6
 
7
+ ![Knife Block](/assets/knife-block.png)
8
+
9
9
  ## Requirements
10
10
 
11
11
  At present, knife-block requires ruby 1.9.2 or above. This is owing to the use of "Dir.home()" to find a user's home directory.
12
12
 
13
13
  ## Installation
14
14
 
15
+ If you've installed Chef via rubygems, homebrew, etc, then install using
16
+
15
17
  gem install knife-block
16
18
 
19
+ If you've installed Chef via ChefDK, then install using
20
+
21
+ chef gem install knife-block
22
+
17
23
  ### How does it work?
18
24
 
19
25
  Knife looks for knife.rb in ~/.chef - all this script does is create a symlink from the required configuration to knife.rb so that knife can act on the appropriate server.
@@ -55,6 +61,8 @@ The code requires far more tests than the simple one that currently exists.
55
61
 
56
62
  Having said all of that, it works for us!
57
63
 
58
- Copyright: Green and Secure IT Limited 2012
64
+ Copyright:
65
+ - Brandon Burton, 2015
66
+ - Green and Secure IT Limited, 2012 - 2015
59
67
 
60
68
  License: Apache 2 (http://apache.org/licenses/LICENSE-2.0.html)
data/Rakefile CHANGED
@@ -1,11 +1,22 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
3
  require 'rake/testtask'
4
+ require 'rubocop/rake_task'
4
5
 
6
+ desc "Run rubocop"
7
+ task :rubocop do
8
+ puts "Running Rubocop checks"
9
+ RuboCop::RakeTask.new
10
+ puts "Rubocop Finished"
11
+ puts "==============="
12
+ end
5
13
 
6
14
  desc "Run Unit Tests"
15
+ puts "Running Unit Tests"
7
16
  Rake::TestTask.new("default") do |t|
8
17
  t.pattern = "test/unit/*_test.rb"
9
18
  t.verbose = true
10
19
  t.warning = true
20
+ puts "Unit Tests finished"
21
+ puts "==================="
11
22
  end
Binary file
@@ -2,11 +2,11 @@
2
2
  require File.expand_path('../lib/knife-block/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["proffalken"]
6
- gem.email = ["theprofessor@threedrunkensysadsonthe.net"]
7
- gem.description = %q{Create and manage knife.rb files for OpsCodes' Chef}
8
- gem.summary = %q{Create and manage knife.rb files for OpsCodes' Chef}
9
- gem.homepage = "https://github.com/greenandsecure/knife-block"
5
+ gem.authors = ["solarce"]
6
+ gem.email = ["brandon@inatree.org"]
7
+ gem.description = %q{Create and manage knife.rb files for Chef}
8
+ gem.summary = %q{Create and manage knife.rb files for Chef}
9
+ gem.homepage = "https://github.com/knife-block/knife-block"
10
10
  gem.license = "MIT"
11
11
 
12
12
  gem.files = `git ls-files`.split($\)
@@ -15,4 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.name = "knife-block"
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = Knife::Block::VERSION
18
+
19
+ gem.add_dependency('test-unit', '~> 2.5')
18
20
  end
@@ -11,12 +11,15 @@
11
11
  class Chef
12
12
  class Knife
13
13
  def get_config_file
14
- # locate_config_file is only compatible with Chef 11
15
- if GreenAndSecure.current_chef_version >= ::Gem::Version.new('11.8.0')
16
- config[:config_file] ||= ::Chef::Knife.locate_config_file
17
- elsif GreenAndSecure.current_chef_version >= ::Gem::Version.new('11.0.0')
18
- locate_config_file
19
- else
14
+ case
15
+ when GreenAndSecure.current_chef_version >= ::Gem::Version.new('12.0.0')
16
+ config[:config_file] ||= ::Chef::Knife.config_loader.config_location
17
+ when ((GreenAndSecure.current_chef_version < ::Gem::Version.new('12.0.0')) && \
18
+ (GreenAndSecure.current_chef_version >= ::Gem::Version.new('11.8.0')))
19
+ config[:config_file] ||= ::Chef::Knife.locate_config_file
20
+ when GreenAndSecure.current_chef_version >= ::Gem::Version.new('11.0.0')
21
+ locate_config_file
22
+ else
20
23
  GreenAndSecure.locate_config_file config
21
24
  end
22
25
 
@@ -76,7 +79,7 @@ module GreenAndSecure
76
79
  if File.exists?(base+"/knife.rb") then
77
80
  unless File.symlink?(base+"/knife.rb")
78
81
  puts "#{base}/knife.rb is NOT a symlink."
79
- puts "Please copy the file to #{base}/knife-<servername>.rb and re-run this command."
82
+ puts "Please move the file to #{base}/knife-<servername>.rb and re-run this command."
80
83
  exit 3
81
84
  end
82
85
  end
@@ -230,5 +233,15 @@ module GreenAndSecure
230
233
  use.run
231
234
  end
232
235
  end
233
- end
234
236
 
237
+ # Shows the currently selected knife block
238
+ class BlockShow < Chef::Knife
239
+ banner "knife block show"
240
+
241
+ def run
242
+ GreenAndSecure::check_block_setup
243
+ list = GreenAndSecure::BlockList.new
244
+ puts list.current_server
245
+ end
246
+ end
247
+ end
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Block
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # helper script to install chefdk for testing on travis-ci
4
+
5
+ ubuntu_check(){
6
+ grep 'Ubuntu' /etc/issue
7
+
8
+ if [[ $? != 0 ]]; then
9
+ echo "This is only meant to run on Ubuntu!"
10
+ exit 1
11
+ fi
12
+ }
13
+
14
+ install_chefdk() {
15
+ ubuntu_check
16
+
17
+ curl -s https://packagecloud.io/gpg.key | sudo apt-key add -
18
+ echo "deb https://packagecloud.io/chef/stable/ubuntu/ precise main" \
19
+ | sudo tee -a /etc/apt/sources.list.d/chef.list
20
+ sudo apt-get update -qq
21
+ sudo apt-get install -yqq chefdk
22
+ chef verify > /dev/null 2>&1
23
+ chefdk_installed_correctly=$?
24
+ if [[ $chefdk_installed_correctly != 0 ]]; then
25
+ echo "ChefDK not installed correctly, failing"
26
+ exit 1
27
+ fi
28
+ eval "$(chef shell-init bash)"
29
+ }
30
+
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Check if there is an argument for chefdk, if there is
4
+ # install chefdk and use it's ruby, otherwise use the
5
+ # one provided by travis-ci
6
+
7
+ if [[ -n $1 ]]; then
8
+ CHEF_DK_INSTALL=$1
9
+ if [[ $CHEF_DK_INSTALL == true ]]; then
10
+ source ./bin/chef_dk_install.sh
11
+
12
+ echo "Installing chefdk"
13
+ install_chefdk
14
+ fi
15
+ fi
16
+
17
+ # Run our tests
18
+ bundle install --jobs=3 --retry=3
19
+ bundle exec rake rubocop
20
+ bundle exec rake
21
+
22
+ mkdir ~/.chef
23
+ echo 1 > ~/.chef/knife-my-cool-server.rb
24
+
25
+ echo "Testing knife block list"
26
+ bundle exec knife block list > /tmp/knife_block_list.txt
27
+ echo "Output of knife block list"
28
+ cat /tmp/knife_block_list.txt
29
+
30
+ echo "Testing if knife block list worked as expected"
31
+ grep 'my-cool-server' /tmp/knife_block_list.txt
32
+ if [[ $? != 0 ]]
33
+ then
34
+ echo "No knife config found and it should have found it"
35
+ exit 1
36
+ fi
@@ -18,15 +18,15 @@ class TestGreenAndSecureModule < Test::Unit::TestCase
18
18
  ENV['WORKSPACE'] ? (@chef_path ||= "#{ENV['WORKSPACE']}/.chef") : @chef_path = "#{ENV['HOME']}/.chef"
19
19
  if ENV['TRAVIS']
20
20
  @knife_ci = "#{@chef_path}/knife-ci.rb"
21
- FileUtils.mkpath(@chef_path) unless File.exists?(@chef_path)
22
- FileUtils.touch("#{@knife_ci}") unless File.exists?("#{@knife_ci}")
23
- FileUtils.ln_s("#{@knife_ci}","#{@chef_path}/knife.rb") unless File.exists?("#{@chef_path}/knife.rb")
21
+ FileUtils.mkpath(@chef_path) unless File.exist?(@chef_path)
22
+ FileUtils.touch("#{@knife_ci}") unless File.exist?("#{@knife_ci}")
23
+ FileUtils.ln_s("#{@knife_ci}","#{@chef_path}/knife.rb") unless File.exist?("#{@chef_path}/knife.rb")
24
24
  end
25
25
  end
26
26
 
27
27
  def teardown
28
28
  if ENV['TRAVIS']
29
- FileUtils.remove_entry_secure(@chef_path, force = true) if File.exists?(@chef_path)
29
+ FileUtils.remove_entry_secure(@chef_path, force = true) if File.exist?(@chef_path)
30
30
  end
31
31
  end
32
32
 
@@ -35,7 +35,7 @@ class TestGreenAndSecureModule < Test::Unit::TestCase
35
35
  end
36
36
 
37
37
  def test_002_it_locates_a_knife_config
38
- assert_match(/.*\/.chef\/knife\.rb/,@green.chef_config_base+"/knife.rb", "FAIL: knife.rb not found!")
38
+ assert_match(/.*\/.chef\/knife.rb/,@green.chef_config_base+"/.chef/knife.rb", "FAIL: knife.rb not found!")
39
39
  end
40
40
 
41
41
  def test_003_knife_rb_is_a_symlink
metadata CHANGED
@@ -1,58 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.2.1
6
5
  platform: ruby
7
6
  authors:
8
- - proffalken
7
+ - solarce
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-06-18 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Create and manage knife.rb files for OpsCodes' Chef
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-unit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
27
+ description: Create and manage knife.rb files for Chef
15
28
  email:
16
- - theprofessor@threedrunkensysadsonthe.net
29
+ - brandon@inatree.org
17
30
  executables: []
18
31
  extensions: []
19
32
  extra_rdoc_files: []
20
33
  files:
21
- - .gitignore
22
- - .travis.yml
34
+ - ".gitignore"
35
+ - ".travis.yml"
23
36
  - Gemfile
24
37
  - LICENSE
25
38
  - README.md
26
39
  - Rakefile
40
+ - assets/knife-block.png
27
41
  - knife-block.gemspec
28
42
  - lib/chef/knife/block.rb
29
43
  - lib/knife-block.rb
30
44
  - lib/knife-block/version.rb
45
+ - test/bin/chef_dk_install.sh
46
+ - test/bin/tests.sh
31
47
  - test/unit/knifeblock_test.rb
32
- homepage: https://github.com/greenandsecure/knife-block
48
+ homepage: https://github.com/knife-block/knife-block
33
49
  licenses:
34
50
  - MIT
51
+ metadata: {}
35
52
  post_install_message:
36
53
  rdoc_options: []
37
54
  require_paths:
38
55
  - lib
39
56
  required_ruby_version: !ruby/object:Gem::Requirement
40
- none: false
41
57
  requirements:
42
- - - ! '>='
58
+ - - ">="
43
59
  - !ruby/object:Gem::Version
44
60
  version: '0'
45
61
  required_rubygems_version: !ruby/object:Gem::Requirement
46
- none: false
47
62
  requirements:
48
- - - ! '>='
63
+ - - ">="
49
64
  - !ruby/object:Gem::Version
50
65
  version: '0'
51
66
  requirements: []
52
67
  rubyforge_project:
53
- rubygems_version: 1.8.26
68
+ rubygems_version: 2.4.6
54
69
  signing_key:
55
- specification_version: 3
56
- summary: Create and manage knife.rb files for OpsCodes' Chef
70
+ specification_version: 4
71
+ summary: Create and manage knife.rb files for Chef
57
72
  test_files:
73
+ - test/bin/chef_dk_install.sh
74
+ - test/bin/tests.sh
58
75
  - test/unit/knifeblock_test.rb