cheffish 1.6.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/cheffish.gemspec +1 -0
  3. data/lib/chef/resource/chef_acl.rb +440 -20
  4. data/lib/chef/resource/chef_client.rb +50 -25
  5. data/lib/chef/resource/chef_container.rb +44 -11
  6. data/lib/chef/resource/chef_data_bag.rb +43 -10
  7. data/lib/chef/resource/chef_data_bag_item.rb +292 -82
  8. data/lib/chef/resource/chef_environment.rb +79 -27
  9. data/lib/chef/resource/chef_group.rb +77 -40
  10. data/lib/chef/resource/chef_mirror.rb +170 -21
  11. data/lib/chef/resource/chef_node.rb +77 -11
  12. data/lib/chef/resource/chef_organization.rb +153 -43
  13. data/lib/chef/resource/chef_resolved_cookbooks.rb +40 -9
  14. data/lib/chef/resource/chef_role.rb +81 -29
  15. data/lib/chef/resource/chef_user.rb +64 -33
  16. data/lib/chef/resource/private_key.rb +230 -17
  17. data/lib/chef/resource/public_key.rb +88 -9
  18. data/lib/cheffish/array_property.rb +29 -0
  19. data/lib/cheffish/base_resource.rb +254 -0
  20. data/lib/cheffish/chef_actor_base.rb +135 -0
  21. data/lib/cheffish/node_properties.rb +107 -0
  22. data/lib/cheffish/recipe_dsl.rb +0 -14
  23. data/lib/cheffish/version.rb +1 -1
  24. data/lib/cheffish.rb +4 -108
  25. data/spec/integration/chef_acl_spec.rb +0 -2
  26. data/spec/integration/chef_client_spec.rb +0 -1
  27. data/spec/integration/chef_container_spec.rb +0 -2
  28. data/spec/integration/chef_group_spec.rb +0 -2
  29. data/spec/integration/chef_mirror_spec.rb +0 -2
  30. data/spec/integration/chef_node_spec.rb +0 -2
  31. data/spec/integration/chef_organization_spec.rb +1 -3
  32. data/spec/integration/chef_role_spec.rb +0 -2
  33. data/spec/integration/chef_user_spec.rb +0 -2
  34. data/spec/integration/private_key_spec.rb +0 -4
  35. data/spec/integration/recipe_dsl_spec.rb +0 -2
  36. data/spec/support/spec_support.rb +0 -1
  37. data/spec/unit/get_private_key_spec.rb +13 -0
  38. metadata +22 -20
  39. data/lib/chef/provider/chef_acl.rb +0 -446
  40. data/lib/chef/provider/chef_client.rb +0 -53
  41. data/lib/chef/provider/chef_container.rb +0 -55
  42. data/lib/chef/provider/chef_data_bag.rb +0 -55
  43. data/lib/chef/provider/chef_data_bag_item.rb +0 -278
  44. data/lib/chef/provider/chef_environment.rb +0 -83
  45. data/lib/chef/provider/chef_group.rb +0 -83
  46. data/lib/chef/provider/chef_mirror.rb +0 -169
  47. data/lib/chef/provider/chef_node.rb +0 -87
  48. data/lib/chef/provider/chef_organization.rb +0 -155
  49. data/lib/chef/provider/chef_resolved_cookbooks.rb +0 -46
  50. data/lib/chef/provider/chef_role.rb +0 -84
  51. data/lib/chef/provider/chef_user.rb +0 -59
  52. data/lib/chef/provider/private_key.rb +0 -225
  53. data/lib/chef/provider/public_key.rb +0 -88
  54. data/lib/cheffish/actor_provider_base.rb +0 -131
  55. data/lib/cheffish/chef_provider_base.rb +0 -246
data/lib/cheffish.rb CHANGED
@@ -100,9 +100,9 @@ module Cheffish
100
100
  next unless File.exist?(private_key_path)
101
101
  Dir.entries(private_key_path).sort.each do |key|
102
102
  ext = File.extname(key)
103
- if ext == '' || ext == '.pem'
103
+ if key == name || ext == '' || ext == '.pem'
104
104
  key_name = key[0..-(ext.length+1)]
105
- if key_name == name
105
+ if key_name == name || key == name
106
106
  Chef::Log.info("Reading key #{name} from file #{private_key_path}/#{key}")
107
107
  return [ IO.read("#{private_key_path}/#{key}"), "#{private_key_path}/#{key}" ]
108
108
  end
@@ -113,113 +113,8 @@ module Cheffish
113
113
  nil
114
114
  end
115
115
 
116
- # `NOT_PASSED` is defined in chef-12.5.0, this guard will ensure we
117
- # don't redefine it if it's already there
118
- NOT_PASSED=Object.new unless defined?(NOT_PASSED)
119
-
120
116
  def self.node_attributes(klass)
121
- klass.class_eval do
122
- attribute :name, :kind_of => String, :regex => Cheffish::NAME_REGEX, :name_attribute => true
123
- attribute :chef_environment, :kind_of => String, :regex => Cheffish::NAME_REGEX
124
- attribute :run_list, :kind_of => Array # We should let them specify it as a series of parameters too
125
- attribute :attributes, :kind_of => Hash
126
-
127
- # Specifies that this is a complete specification for the environment (i.e. attributes you don't specify will be
128
- # reset to their defaults)
129
- attribute :complete, :kind_of => [TrueClass, FalseClass]
130
-
131
- attribute :raw_json, :kind_of => Hash
132
- attribute :chef_server, :kind_of => Hash
133
-
134
- # attribute 'ip_address', '127.0.0.1'
135
- # attribute [ 'pushy', 'port' ], '9000'
136
- # attribute 'ip_addresses' do |existing_value|
137
- # (existing_value || []) + [ '127.0.0.1' ]
138
- # end
139
- # attribute 'ip_address', :delete
140
- attr_accessor :attribute_modifiers
141
- def attribute(attribute_path, value=NOT_PASSED, &block)
142
- @attribute_modifiers ||= []
143
- if value != NOT_PASSED
144
- @attribute_modifiers << [ attribute_path, value ]
145
- elsif block
146
- @attribute_modifiers << [ attribute_path, block ]
147
- else
148
- raise "attribute requires either a value or a block"
149
- end
150
- end
151
-
152
- # Patchy tags
153
- # tag 'webserver', 'apache', 'myenvironment'
154
- def tag(*tags)
155
- attribute 'tags' do |existing_tags|
156
- existing_tags ||= []
157
- tags.each do |tag|
158
- if !existing_tags.include?(tag.to_s)
159
- existing_tags << tag.to_s
160
- end
161
- end
162
- existing_tags
163
- end
164
- end
165
- def remove_tag(*tags)
166
- attribute 'tags' do |existing_tags|
167
- if existing_tags
168
- tags.each do |tag|
169
- existing_tags.delete(tag.to_s)
170
- end
171
- end
172
- existing_tags
173
- end
174
- end
175
-
176
- # NON-patchy tags
177
- # tags :a, :b, :c # removes all other tags
178
- def tags(*tags)
179
- if tags.size == 0
180
- attribute('tags')
181
- else
182
- tags = tags[0] if tags.size == 1 && tags[0].kind_of?(Array)
183
- attribute 'tags', tags.map { |tag| tag.to_s }
184
- end
185
- end
186
-
187
- # Order matters--if two things here are in the wrong order, they will be flipped in the run list
188
- # recipe 'apache', 'mysql'
189
- # recipe 'recipe@version'
190
- # recipe 'recipe'
191
- # role ''
192
- attr_accessor :run_list_modifiers
193
- attr_accessor :run_list_removers
194
- def recipe(*recipes)
195
- if recipes.size == 0
196
- raise ArgumentError, "At least one recipe must be specified"
197
- end
198
- @run_list_modifiers ||= []
199
- @run_list_modifiers += recipes.map { |recipe| Chef::RunList::RunListItem.new("recipe[#{recipe}]") }
200
- end
201
- def role(*roles)
202
- if roles.size == 0
203
- raise ArgumentError, "At least one role must be specified"
204
- end
205
- @run_list_modifiers ||= []
206
- @run_list_modifiers += roles.map { |role| Chef::RunList::RunListItem.new("role[#{role}]") }
207
- end
208
- def remove_recipe(*recipes)
209
- if recipes.size == 0
210
- raise ArgumentError, "At least one recipe must be specified"
211
- end
212
- @run_list_removers ||= []
213
- @run_list_removers += recipes.map { |recipe| Chef::RunList::RunListItem.new("recipe[#{recipe}]") }
214
- end
215
- def remove_role(*roles)
216
- if roles.size == 0
217
- raise ArgumentError, "At least one role must be specified"
218
- end
219
- @run_list_removers ||= []
220
- @run_list_removers += roles.map { |role| Chef::RunList::RunListItem.new("role[#{role}]") }
221
- end
222
- end
117
+ klass.include Cheffish::NodeProperties
223
118
  end
224
119
  end
225
120
 
@@ -233,3 +128,4 @@ require 'chef/config_fetcher'
233
128
  require 'chef/log'
234
129
  require 'chef/application'
235
130
  require 'cheffish/recipe_dsl'
131
+ require 'cheffish/node_properties'
@@ -1,7 +1,5 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
- require 'chef/resource/chef_acl'
4
- require 'chef/provider/chef_acl'
5
3
  require 'chef_zero/version'
6
4
  require 'uri'
7
5
 
@@ -2,7 +2,6 @@ require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
3
  require 'support/key_support'
4
4
  require 'chef/resource/chef_client'
5
- require 'chef/provider/chef_client'
6
5
 
7
6
  repo_path = Dir.mktmpdir('chef_repo')
8
7
 
@@ -1,7 +1,5 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
- require 'chef/resource/chef_container'
4
- require 'chef/provider/chef_container'
5
3
 
6
4
  describe Chef::Resource::ChefContainer do
7
5
  extend Cheffish::RSpec::ChefRunSupport
@@ -1,7 +1,5 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
- require 'chef/resource/chef_group'
4
- require 'chef/provider/chef_group'
5
3
 
6
4
  describe Chef::Resource::ChefGroup do
7
5
  extend Cheffish::RSpec::ChefRunSupport
@@ -1,7 +1,5 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
- require 'chef/resource/chef_mirror'
4
- require 'chef/provider/chef_mirror'
5
3
 
6
4
  describe Chef::Resource::ChefMirror do
7
5
  extend Cheffish::RSpec::ChefRunSupport
@@ -1,7 +1,5 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
- require 'chef/resource/chef_node'
4
- require 'chef/provider/chef_node'
5
3
 
6
4
  describe Chef::Resource::ChefNode do
7
5
  extend Cheffish::RSpec::ChefRunSupport
@@ -1,7 +1,5 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
- require 'chef/resource/chef_organization'
4
- require 'chef/provider/chef_organization'
5
3
 
6
4
  describe Chef::Resource::ChefOrganization do
7
5
  extend Cheffish::RSpec::ChefRunSupport
@@ -195,7 +193,7 @@ describe Chef::Resource::ChefOrganization do
195
193
  expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq([])
196
194
  end
197
195
 
198
- it 'chef_organization "x" with members [] and "complete true" removes invites but not members' do
196
+ it 'chef_organization "x" with invites [] and "complete true" removes invites but not members' do
199
197
  expect_recipe {
200
198
  chef_organization 'x' do
201
199
  invites []
@@ -1,7 +1,5 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
- require 'chef/resource/chef_role'
4
- require 'chef/provider/chef_role'
5
3
 
6
4
  describe Chef::Resource::ChefRole do
7
5
  extend Cheffish::RSpec::ChefRunSupport
@@ -1,8 +1,6 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
3
  require 'support/key_support'
4
- require 'chef/resource/chef_user'
5
- require 'chef/provider/chef_user'
6
4
 
7
5
  repo_path = Dir.mktmpdir('chef_repo')
8
6
 
@@ -1,9 +1,5 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
- require 'chef/resource/private_key'
4
- require 'chef/provider/private_key'
5
- require 'chef/resource/public_key'
6
- require 'chef/provider/public_key'
7
3
  require 'support/key_support'
8
4
 
9
5
  repo_path = Dir.mktmpdir('chef_repo')
@@ -1,7 +1,5 @@
1
1
  require 'support/spec_support'
2
2
  require 'cheffish/rspec/chef_run_support'
3
- require 'chef/resource/chef_node'
4
- require 'chef/provider/chef_node'
5
3
  require 'tmpdir'
6
4
 
7
5
  describe 'Cheffish Recipe DSL' do
@@ -1,7 +1,6 @@
1
1
  require 'cheffish/rspec'
2
2
 
3
3
  require 'cheffish'
4
- require 'chef/provider/chef_acl'
5
4
 
6
5
  RSpec.configure do |config|
7
6
  config.filter_run :focus => true
@@ -26,6 +26,14 @@ describe Cheffish do
26
26
  key_file
27
27
  end
28
28
 
29
+ def setup_arbitrarily_named_key
30
+ key_file = File.expand_path("ned_stark.xxx", directory_that_exists)
31
+ File.open(key_file, "w+") do |f|
32
+ f.write private_key_contents
33
+ end
34
+ key_file
35
+ end
36
+
29
37
  def setup_pem_key
30
38
  key_file = File.expand_path("ned_stark.pem", directory_that_exists)
31
39
  File.open(key_file, "w+") do |f|
@@ -57,6 +65,11 @@ describe Cheffish do
57
65
  expect(Cheffish.get_private_key("ned_stark", config)).to eq(private_key_pem_contents)
58
66
  end
59
67
 
68
+ it "returns the contents of arbitrarily named keys" do
69
+ setup_arbitrarily_named_key
70
+ expect(Cheffish.get_private_key("ned_stark.xxx", config)).to eq(private_key_contents)
71
+ end
72
+
60
73
  # we arbitrarily prefer "ned_stark" over "ned_stark.pem" for deterministic behavior
61
74
  it "returns the contents of the key that does not have an extension if both exist" do
62
75
  setup_key
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cheffish
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-zero
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: compat_resource
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: chef
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -79,21 +93,6 @@ files:
79
93
  - README.md
80
94
  - Rakefile
81
95
  - cheffish.gemspec
82
- - lib/chef/provider/chef_acl.rb
83
- - lib/chef/provider/chef_client.rb
84
- - lib/chef/provider/chef_container.rb
85
- - lib/chef/provider/chef_data_bag.rb
86
- - lib/chef/provider/chef_data_bag_item.rb
87
- - lib/chef/provider/chef_environment.rb
88
- - lib/chef/provider/chef_group.rb
89
- - lib/chef/provider/chef_mirror.rb
90
- - lib/chef/provider/chef_node.rb
91
- - lib/chef/provider/chef_organization.rb
92
- - lib/chef/provider/chef_resolved_cookbooks.rb
93
- - lib/chef/provider/chef_role.rb
94
- - lib/chef/provider/chef_user.rb
95
- - lib/chef/provider/private_key.rb
96
- - lib/chef/provider/public_key.rb
97
96
  - lib/chef/resource/chef_acl.rb
98
97
  - lib/chef/resource/chef_client.rb
99
98
  - lib/chef/resource/chef_container.rb
@@ -110,14 +109,16 @@ files:
110
109
  - lib/chef/resource/private_key.rb
111
110
  - lib/chef/resource/public_key.rb
112
111
  - lib/cheffish.rb
113
- - lib/cheffish/actor_provider_base.rb
112
+ - lib/cheffish/array_property.rb
113
+ - lib/cheffish/base_resource.rb
114
114
  - lib/cheffish/basic_chef_client.rb
115
- - lib/cheffish/chef_provider_base.rb
115
+ - lib/cheffish/chef_actor_base.rb
116
116
  - lib/cheffish/chef_run.rb
117
117
  - lib/cheffish/chef_run_data.rb
118
118
  - lib/cheffish/chef_run_listener.rb
119
119
  - lib/cheffish/key_formatter.rb
120
120
  - lib/cheffish/merged_config.rb
121
+ - lib/cheffish/node_properties.rb
121
122
  - lib/cheffish/recipe_dsl.rb
122
123
  - lib/cheffish/rspec.rb
123
124
  - lib/cheffish/rspec/chef_run_support.rb
@@ -169,8 +170,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  version: '0'
170
171
  requirements: []
171
172
  rubyforge_project:
172
- rubygems_version: 2.4.7
173
+ rubygems_version: 2.4.8
173
174
  signing_key:
174
175
  specification_version: 4
175
176
  summary: A library to manipulate Chef in Chef.
176
177
  test_files: []
178
+ has_rdoc: