knife-helper 0.0.2 → 0.0.3

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: ef2d92029961512c387c27d225dfc085fab4a9c2
4
- data.tar.gz: 5e621d5bf2dc2a150e6312edd33c37ab23064ec8
3
+ metadata.gz: 3d8d47d7494a1ece95286151574f566669c80616
4
+ data.tar.gz: aae10db6ef15f2f3a842655b52f01a031953e98d
5
5
  SHA512:
6
- metadata.gz: 40654093cb4dc049b74294a484dd9ca83d6b8341aa2e4421b48df8260179d132e33c0a4c2c12d42290f28a995324b84f299c8884cfad4c5973aac496204da267
7
- data.tar.gz: 463e3b0ab0150b9d7ac0b8d22db0a6231ac68d4966684cba2d09127eb748cddbf4a320b85dc5b343bd656a782a1a75bb9544162ed8005920ef0ced50213cf965
6
+ metadata.gz: 0e2a7d473d14b0ffe723cf08f639e7c4a77b61701b0eed5760d5a60cf472a9d11149d61fea52446581fec6ee69f28057a5790d7fb16881ba1ec25834176aae90
7
+ data.tar.gz: 0c032eada7bef7e7da1e4e60ee783dbf725636cd7c49cb5b70dc8c07b099a69e0c510c4d22c3e959bd46d3b3f622e55f3ca552cec8a3e814f2ed796ab1e479cb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.0.3
2
+
3
+ * Support some external configuration files [#2]
4
+
1
5
  ## 0.0.2
2
6
 
3
7
  * Add `user_bundle` option
@@ -6,3 +10,6 @@
6
10
  ## 0.0.1
7
11
 
8
12
  * Initial release
13
+
14
+ <!--- The following link definition list is generated by PimpMyChangelog --->
15
+ [#2]: https://github.com/marcy-terui/knife-helper/issues/2
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/knife-helper.svg)](http://badge.fury.io/rb/knife-helper) [![Build Status](https://travis-ci.org/marcy-terui/knife-helper.svg?branch=master)](https://travis-ci.org/marcy-terui/knife-helper)
4
4
 
5
- Helper and Command builder for `knife` (`chef-server`, `knife-zero`, etc)
5
+ Helper and Command builder for knife (chef-server, knife-zero, etc)
6
6
 
7
7
  ## Installation
8
8
 
@@ -48,6 +48,9 @@ $ knife helper exec NAME (option)
48
48
 
49
49
  ```yaml
50
50
  ---
51
+ includes:
52
+ - example.yml
53
+
51
54
  settings:
52
55
  command_base: /home/marcy/.rbenv/versions/2.1.5/bin/knife
53
56
 
@@ -58,6 +61,9 @@ commands:
58
61
  options:
59
62
  ```
60
63
 
64
+ ### includes
65
+ Include some external configuration files.
66
+
61
67
  ### settings:command_base
62
68
  Path to `knife` execution script.
63
69
 
@@ -71,7 +77,7 @@ Condition for search and execute command.
71
77
  Command options.
72
78
 
73
79
  ## ChangeLog
74
- see [CHANGELOG](https://github.com/marcy-terui/knife-helper/blob/master/CHANGELOG.md)
80
+ see [CHANGELOG][changelog]
75
81
 
76
82
  ## Contributing
77
83
 
@@ -99,4 +105,5 @@ Apache 2.0 (see [LICENSE][license])
99
105
  [author]: https://github.com/marcy-terui
100
106
  [issues]: https://github.com/marcy-terui/knife-helper/issues
101
107
  [license]: https://github.com/marcy-terui/knife-helper/blob/master/LICENSE.txt
108
+ [changelog]: https://github.com/marcy-terui/knife-helper/blob/master/CHANGELOG.md
102
109
  [repo]: https://github.com/marcy-terui/knife-helper
@@ -1,7 +1,6 @@
1
1
  require 'chef'
2
- require 'safe_yaml'
3
- require 'erb'
4
2
  require 'knife/helper/commands'
3
+ require 'knife/helper/config'
5
4
 
6
5
  class Chef
7
6
  class Knife
@@ -25,7 +24,7 @@ class Chef
25
24
  def run
26
25
  file = config[:file] == "" ? default_config_file : config[:file]
27
26
  commands = ::Knife::Helper::Commands.new(
28
- load_yml(get_content(read_file(file)))
27
+ ::Knife::Helper::Config.new(file).data
29
28
  )
30
29
  @name_args.each do |cmd|
31
30
  if config[:print_command]
@@ -38,22 +37,10 @@ class Chef
38
37
 
39
38
  private
40
39
 
41
- def read_file(file)
42
- ::File.exist?(file.to_s) ? IO.read(file) : ""
43
- end
44
-
45
40
  def default_config_file
46
41
  ::File.join(Dir.pwd, ".knife.helper.yml")
47
42
  end
48
43
 
49
- def get_content(str)
50
- ::ERB.new(str).result
51
- end
52
-
53
- def load_yml(str)
54
- ::SafeYAML.load(str) || Hash.new
55
- end
56
-
57
44
  end
58
45
  end
59
46
  end
@@ -65,9 +65,9 @@ class Chef
65
65
 
66
66
  def create_knife_rb
67
67
  ::Knife::Helper::Template.new("knife.rb.erb", ".chef/knife.rb",
68
- :local_mode => config[:use_local_mode].to_s,
69
- :cookbook_path => config[:cookbook_path].split(',').to_s,
70
- :repo_path => "\"#{config[:repo_path]}\""
68
+ :local_mode => config[:use_local_mode].to_s,
69
+ :cookbook_path => config[:cookbook_path].split(',').to_s,
70
+ :repo_path => "\"#{config[:repo_path]}\""
71
71
  ).flush
72
72
  end
73
73
 
@@ -0,0 +1,43 @@
1
+ require 'safe_yaml'
2
+ require 'erb'
3
+ require 'chef/mixin/deep_merge'
4
+
5
+ module Knife
6
+ module Helper
7
+ class Config
8
+
9
+ attr_reader :data
10
+
11
+ def initialize(file)
12
+ @data = load_config(file)
13
+ end
14
+
15
+ def load_config(file)
16
+ conf = load_yml(get_content(read_file(file)))
17
+ Array(conf['includes']).each do |inc|
18
+ inc_path = nil
19
+ rel_path = File.expand_path("../#{inc}", file)
20
+ [inc, rel_path].each {|f| inc_path = f if File.exists?(f) }
21
+ raise "'#{inc}' is not exists." if inc_path.nil?
22
+ conf = Chef::Mixin::DeepMerge.deep_merge(
23
+ load_yml(get_content(read_file(inc_path))),
24
+ conf
25
+ )
26
+ end
27
+ conf
28
+ end
29
+
30
+ def read_file(file)
31
+ ::File.exist?(file.to_s) ? IO.read(file) : ""
32
+ end
33
+
34
+ def get_content(str)
35
+ ::ERB.new(str).result
36
+ end
37
+
38
+ def load_yml(str)
39
+ ::SafeYAML.load(str) || Hash.new
40
+ end
41
+ end
42
+ end
43
+ end
@@ -10,7 +10,9 @@ module Knife
10
10
  def initialize(source, target, params={})
11
11
  super()
12
12
  self.class.source_root(
13
- Pathname.new(File.expand_path("../../../../", __FILE__)).join("templates")
13
+ Pathname.new(
14
+ File.expand_path("../../../../", __FILE__)
15
+ ).join("templates")
14
16
  )
15
17
  @source = source
16
18
  @target = target
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Helper
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'knife/helper/config'
3
+
4
+ describe Knife::Helper::Config do
5
+
6
+ describe 'normal' do
7
+ conf = Knife::Helper::Config.new(test_file_path('normal.yml')).data
8
+ example { expect(conf['settings']).to include('command_base' => 'bundle exec knife') }
9
+ example { expect(conf['commands'].first).to include('name' => 'test') }
10
+ example { expect(conf['commands'].first).to include('condition' => 'chef_environment:test') }
11
+ example { expect(conf['commands'].first['options']).to include('ssh-user' => 'ec2-user') }
12
+ example { expect(conf['commands'].first['options']).to include('sudo' => nil) }
13
+ end
14
+
15
+ describe 'merge' do
16
+ conf = Knife::Helper::Config.new(test_file_path('merge.yml')).data
17
+ example { expect(conf['settings']).to include('command_base' => 'bundle exec knife') }
18
+ example { expect(conf['option_sets'].first).to include('name' => 'test_set') }
19
+ example { expect(conf['settings']).to include('test01' => 'value01') }
20
+ example { expect(conf['settings']).to include('test02' => 'overwrited') }
21
+ example { expect(conf['settings']).to include('test03' => 'value03') }
22
+ example { expect(conf['commands'].first).to include('name' => 'test') }
23
+ example { expect(conf['commands'].first).to include('condition' => 'chef_environment:test') }
24
+ example { expect(conf['commands'].first['options']).to include('ssh-user' => 'ec2-user') }
25
+ example { expect(conf['commands'].first['options']).to include('sudo' => nil) }
26
+ end
27
+ end
data/spec/spec_helper.rb CHANGED
@@ -89,3 +89,7 @@ RSpec.configure do |config|
89
89
  Kernel.srand config.seed
90
90
  =end
91
91
  end
92
+
93
+ def test_file_path(file)
94
+ File.expand_path("../test_files/#{file}", __FILE__)
95
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ option_sets:
3
+ - name: test_set
@@ -0,0 +1,4 @@
1
+ ---
2
+ settings:
3
+ test02: overwrited
4
+ test03: value03
@@ -0,0 +1,17 @@
1
+ ---
2
+ settings:
3
+ command_base: bundle exec knife
4
+ test01: value01
5
+ test02: value02
6
+
7
+ includes:
8
+ - include01.yml
9
+ - include02.yml
10
+
11
+ commands:
12
+ - name: test
13
+ command: zero chef_client
14
+ condition: chef_environment:test
15
+ options:
16
+ ssh-user: ec2-user
17
+ sudo:
@@ -0,0 +1,11 @@
1
+ ---
2
+ settings:
3
+ command_base: bundle exec knife
4
+
5
+ commands:
6
+ - name: test
7
+ command: zero chef_client
8
+ condition: chef_environment:test
9
+ options:
10
+ ssh-user: ec2-user
11
+ sudo:
@@ -1,4 +1,6 @@
1
1
  ---
2
+ includes:
3
+
2
4
  settings:
3
5
  command_base: <%= config[:command_base] %>
4
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masashi Terui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-09 00:00:00.000000000 Z
11
+ date: 2015-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -114,10 +114,16 @@ files:
114
114
  - lib/chef/knife/helper_init.rb
115
115
  - lib/knife/helper.rb
116
116
  - lib/knife/helper/commands.rb
117
+ - lib/knife/helper/config.rb
117
118
  - lib/knife/helper/template.rb
118
119
  - lib/knife/helper/version.rb
119
120
  - spec/knife/helper/commands_spec.rb
121
+ - spec/knife/helper/config_spec.rb
120
122
  - spec/spec_helper.rb
123
+ - spec/test_files/include01.yml
124
+ - spec/test_files/include02.yml
125
+ - spec/test_files/merge.yml
126
+ - spec/test_files/normal.yml
121
127
  - templates/Berksfile.erb
122
128
  - templates/Cheffile.erb
123
129
  - templates/helper.yml.erb
@@ -148,4 +154,9 @@ specification_version: 4
148
154
  summary: Helper and Command builder for knife
149
155
  test_files:
150
156
  - spec/knife/helper/commands_spec.rb
157
+ - spec/knife/helper/config_spec.rb
151
158
  - spec/spec_helper.rb
159
+ - spec/test_files/include01.yml
160
+ - spec/test_files/include02.yml
161
+ - spec/test_files/merge.yml
162
+ - spec/test_files/normal.yml