cheffish 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -201
  3. data/README.md +120 -117
  4. data/Rakefile +23 -23
  5. data/lib/chef/provider/chef_acl.rb +439 -434
  6. data/lib/chef/provider/chef_client.rb +53 -48
  7. data/lib/chef/provider/chef_container.rb +55 -50
  8. data/lib/chef/provider/chef_data_bag.rb +55 -50
  9. data/lib/chef/provider/chef_data_bag_item.rb +278 -273
  10. data/lib/chef/provider/chef_environment.rb +83 -78
  11. data/lib/chef/provider/chef_group.rb +83 -78
  12. data/lib/chef/provider/chef_mirror.rb +169 -164
  13. data/lib/chef/provider/chef_node.rb +87 -82
  14. data/lib/chef/provider/chef_organization.rb +155 -150
  15. data/lib/chef/provider/chef_resolved_cookbooks.rb +46 -41
  16. data/lib/chef/provider/chef_role.rb +84 -79
  17. data/lib/chef/provider/chef_user.rb +59 -54
  18. data/lib/chef/provider/private_key.rb +225 -220
  19. data/lib/chef/provider/public_key.rb +88 -82
  20. data/lib/chef/resource/chef_acl.rb +69 -65
  21. data/lib/chef/resource/chef_client.rb +48 -44
  22. data/lib/chef/resource/chef_container.rb +22 -18
  23. data/lib/chef/resource/chef_data_bag.rb +22 -18
  24. data/lib/chef/resource/chef_data_bag_item.rb +121 -114
  25. data/lib/chef/resource/chef_environment.rb +77 -71
  26. data/lib/chef/resource/chef_group.rb +53 -49
  27. data/lib/chef/resource/chef_mirror.rb +52 -48
  28. data/lib/chef/resource/chef_node.rb +22 -18
  29. data/lib/chef/resource/chef_organization.rb +69 -64
  30. data/lib/chef/resource/chef_resolved_cookbooks.rb +35 -31
  31. data/lib/chef/resource/chef_role.rb +110 -104
  32. data/lib/chef/resource/chef_user.rb +56 -52
  33. data/lib/chef/resource/private_key.rb +48 -44
  34. data/lib/chef/resource/public_key.rb +25 -21
  35. data/lib/cheffish.rb +235 -233
  36. data/lib/cheffish/actor_provider_base.rb +131 -131
  37. data/lib/cheffish/basic_chef_client.rb +184 -184
  38. data/lib/cheffish/chef_provider_base.rb +246 -246
  39. data/lib/cheffish/chef_run.rb +162 -155
  40. data/lib/cheffish/chef_run_data.rb +19 -19
  41. data/lib/cheffish/chef_run_listener.rb +30 -30
  42. data/lib/cheffish/key_formatter.rb +113 -113
  43. data/lib/cheffish/merged_config.rb +94 -94
  44. data/lib/cheffish/recipe_dsl.rb +157 -157
  45. data/lib/cheffish/rspec.rb +8 -8
  46. data/lib/cheffish/rspec/chef_run_support.rb +83 -83
  47. data/lib/cheffish/rspec/matchers.rb +4 -4
  48. data/lib/cheffish/rspec/matchers/be_idempotent.rb +16 -16
  49. data/lib/cheffish/rspec/matchers/emit_no_warnings_or_errors.rb +15 -15
  50. data/lib/cheffish/rspec/matchers/have_updated.rb +37 -37
  51. data/lib/cheffish/rspec/matchers/partially_match.rb +63 -63
  52. data/lib/cheffish/rspec/recipe_run_wrapper.rb +59 -47
  53. data/lib/cheffish/rspec/repository_support.rb +108 -108
  54. data/lib/cheffish/server_api.rb +52 -52
  55. data/lib/cheffish/version.rb +3 -3
  56. data/lib/cheffish/with_pattern.rb +21 -21
  57. data/spec/functional/fingerprint_spec.rb +64 -64
  58. data/spec/functional/merged_config_spec.rb +19 -19
  59. data/spec/functional/server_api_spec.rb +13 -13
  60. data/spec/integration/chef_acl_spec.rb +879 -879
  61. data/spec/integration/chef_client_spec.rb +105 -105
  62. data/spec/integration/chef_container_spec.rb +33 -33
  63. data/spec/integration/chef_group_spec.rb +309 -309
  64. data/spec/integration/chef_mirror_spec.rb +491 -491
  65. data/spec/integration/chef_node_spec.rb +786 -786
  66. data/spec/integration/chef_organization_spec.rb +226 -226
  67. data/spec/integration/chef_role_spec.rb +78 -0
  68. data/spec/integration/chef_user_spec.rb +85 -85
  69. data/spec/integration/private_key_spec.rb +399 -399
  70. data/spec/integration/recipe_dsl_spec.rb +28 -28
  71. data/spec/integration/rspec/converge_spec.rb +183 -183
  72. data/spec/support/key_support.rb +29 -29
  73. data/spec/support/spec_support.rb +15 -15
  74. data/spec/unit/get_private_key_spec.rb +131 -131
  75. data/spec/unit/recipe_run_wrapper_spec.rb +37 -0
  76. metadata +8 -5
@@ -1,82 +1,88 @@
1
- require 'chef/provider/lwrp_base'
2
- require 'openssl'
3
- require 'cheffish/key_formatter'
4
-
5
- class Chef::Provider::PublicKey < Chef::Provider::LWRPBase
6
- action :create do
7
- if !new_source_key
8
- raise "No source key specified"
9
- end
10
- desired_output = encode_public_key(new_source_key)
11
- if Array(current_resource.action) == [ :delete ] || desired_output != IO.read(new_resource.path)
12
- converge_by "write #{new_resource.format} public key #{new_resource.path} from #{new_source_key_publicity} key #{new_resource.source_key_path}" do
13
- IO.write(new_resource.path, desired_output)
14
- # TODO permissions on file?
15
- end
16
- end
17
- end
18
-
19
- action :delete do
20
- if Array(current_resource.action) == [ :create ]
21
- converge_by "delete public key #{new_resource.path}" do
22
- ::File.unlink(new_resource.path)
23
- end
24
- end
25
- end
26
-
27
- def whyrun_supported?
28
- true
29
- end
30
-
31
- def encode_public_key(key)
32
- key_format = {}
33
- key_format[:format] = new_resource.format if new_resource.format
34
- Cheffish::KeyFormatter.encode(key, key_format)
35
- end
36
-
37
- attr_reader :current_public_key
38
- attr_reader :new_source_key_publicity
39
-
40
- def new_source_key
41
- @new_source_key ||= begin
42
- if new_resource.source_key.is_a?(String)
43
- source_key, source_key_format = Cheffish::KeyFormatter.decode(new_resource.source_key, new_resource.source_key_pass_phrase)
44
- elsif new_resource.source_key
45
- source_key = new_resource.source_key
46
- elsif new_resource.source_key_path
47
- source_key, source_key_format = Cheffish::KeyFormatter.decode(IO.read(new_resource.source_key_path), new_resource.source_key_pass_phrase, new_resource.source_key_path)
48
- else
49
- return nil
50
- end
51
-
52
- if source_key.private?
53
- @new_source_key_publicity = 'private'
54
- source_key.public_key
55
- else
56
- @new_source_key_publicity = 'public'
57
- source_key
58
- end
59
- end
60
- end
61
-
62
- def load_current_resource
63
- if ::File.exist?(new_resource.path)
64
- resource = Chef::Resource::PublicKey.new(new_resource.path, run_context)
65
- begin
66
- key, key_format = Cheffish::KeyFormatter.decode(IO.read(new_resource.path), nil, new_resource.path)
67
- if key
68
- @current_public_key = key
69
- resource.format key_format[:format]
70
- end
71
- rescue
72
- # If there is an error reading we assume format and such is broken
73
- end
74
-
75
- @current_resource = resource
76
- else
77
- not_found_resource = Chef::Resource::PublicKey.new(new_resource.path, run_context)
78
- not_found_resource.action :delete
79
- @current_resource = not_found_resource
80
- end
81
- end
82
- end
1
+ require 'chef/provider/lwrp_base'
2
+ require 'openssl'
3
+ require 'cheffish/key_formatter'
4
+
5
+ class Chef
6
+ class Provider
7
+ class PublicKey < Chef::Provider::LWRPBase
8
+ provides :public_key
9
+
10
+ action :create do
11
+ if !new_source_key
12
+ raise "No source key specified"
13
+ end
14
+ desired_output = encode_public_key(new_source_key)
15
+ if Array(current_resource.action) == [ :delete ] || desired_output != IO.read(new_resource.path)
16
+ converge_by "write #{new_resource.format} public key #{new_resource.path} from #{new_source_key_publicity} key #{new_resource.source_key_path}" do
17
+ IO.write(new_resource.path, desired_output)
18
+ # TODO permissions on file?
19
+ end
20
+ end
21
+ end
22
+
23
+ action :delete do
24
+ if Array(current_resource.action) == [ :create ]
25
+ converge_by "delete public key #{new_resource.path}" do
26
+ ::File.unlink(new_resource.path)
27
+ end
28
+ end
29
+ end
30
+
31
+ def whyrun_supported?
32
+ true
33
+ end
34
+
35
+ def encode_public_key(key)
36
+ key_format = {}
37
+ key_format[:format] = new_resource.format if new_resource.format
38
+ Cheffish::KeyFormatter.encode(key, key_format)
39
+ end
40
+
41
+ attr_reader :current_public_key
42
+ attr_reader :new_source_key_publicity
43
+
44
+ def new_source_key
45
+ @new_source_key ||= begin
46
+ if new_resource.source_key.is_a?(String)
47
+ source_key, source_key_format = Cheffish::KeyFormatter.decode(new_resource.source_key, new_resource.source_key_pass_phrase)
48
+ elsif new_resource.source_key
49
+ source_key = new_resource.source_key
50
+ elsif new_resource.source_key_path
51
+ source_key, source_key_format = Cheffish::KeyFormatter.decode(IO.read(new_resource.source_key_path), new_resource.source_key_pass_phrase, new_resource.source_key_path)
52
+ else
53
+ return nil
54
+ end
55
+
56
+ if source_key.private?
57
+ @new_source_key_publicity = 'private'
58
+ source_key.public_key
59
+ else
60
+ @new_source_key_publicity = 'public'
61
+ source_key
62
+ end
63
+ end
64
+ end
65
+
66
+ def load_current_resource
67
+ if ::File.exist?(new_resource.path)
68
+ resource = Chef::Resource::PublicKey.new(new_resource.path, run_context)
69
+ begin
70
+ key, key_format = Cheffish::KeyFormatter.decode(IO.read(new_resource.path), nil, new_resource.path)
71
+ if key
72
+ @current_public_key = key
73
+ resource.format key_format[:format]
74
+ end
75
+ rescue
76
+ # If there is an error reading we assume format and such is broken
77
+ end
78
+
79
+ @current_resource = resource
80
+ else
81
+ not_found_resource = Chef::Resource::PublicKey.new(new_resource.path, run_context)
82
+ not_found_resource.action :delete
83
+ @current_resource = not_found_resource
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -1,65 +1,69 @@
1
- require 'cheffish'
2
- require 'chef/resource/lwrp_base'
3
-
4
- class Chef::Resource::ChefAcl < Chef::Resource::LWRPBase
5
- self.resource_name = 'chef_acl'
6
-
7
- actions :create, :nothing
8
- default_action :create
9
-
10
- def initialize(*args)
11
- super
12
- chef_server run_context.cheffish.current_chef_server
13
- end
14
-
15
- # Path of the thing being secured, e.g. nodes, nodes/*, nodes/mynode,
16
- # */*, **, roles/base, data/secrets, cookbooks/apache2, /users/*,
17
- # /organizations/foo/nodes/x
18
- attribute :path, :kind_of => String, :name_attribute => true
19
-
20
- # Whether to change things recursively. true means it will descend all children
21
- # and make the same modifications to them. :on_change will only descend if
22
- # the parent has changed. :on_change is the default.
23
- attribute :recursive, :equal_to => [ true, false, :on_change ], :default => :on_change
24
-
25
- # Specifies that this is a complete specification for the acl (i.e. rights
26
- # you don't specify will be reset to their defaults)
27
- attribute :complete, :kind_of => [TrueClass, FalseClass]
28
-
29
- attribute :raw_json, :kind_of => Hash
30
- attribute :chef_server, :kind_of => Hash
31
-
32
- # rights :read, :users => 'jkeiser', :groups => [ 'admins', 'users' ]
33
- # rights [ :create, :read ], :users => [ 'jkeiser', 'adam' ]
34
- # rights :all, :users => 'jkeiser'
35
- def rights(*values)
36
- if values.size == 0
37
- @rights
38
- else
39
- args = values.pop
40
- args[:permissions] ||= []
41
- values.each do |value|
42
- args[:permissions] |= Array(value)
43
- end
44
- @rights ||= []
45
- @rights << args
46
- end
47
- end
48
-
49
- # remove_rights :read, :users => 'jkeiser', :groups => [ 'admins', 'users' ]
50
- # remove_rights [ :create, :read ], :users => [ 'jkeiser', 'adam' ]
51
- # remove_rights :all, :users => [ 'jkeiser', 'adam' ]
52
- def remove_rights(*values)
53
- if values.size == 0
54
- @remove_rights
55
- else
56
- args = values.pop
57
- args[:permissions] ||= []
58
- values.each do |value|
59
- args[:permissions] |= Array(value)
60
- end
61
- @remove_rights ||= []
62
- @remove_rights << args
63
- end
64
- end
65
- end
1
+ require 'cheffish'
2
+ require 'chef/resource/lwrp_base'
3
+
4
+ class Chef
5
+ class Resource
6
+ class ChefAcl < Chef::Resource::LWRPBase
7
+ self.resource_name = 'chef_acl'
8
+
9
+ actions :create, :nothing
10
+ default_action :create
11
+
12
+ def initialize(*args)
13
+ super
14
+ chef_server run_context.cheffish.current_chef_server
15
+ end
16
+
17
+ # Path of the thing being secured, e.g. nodes, nodes/*, nodes/mynode,
18
+ # */*, **, roles/base, data/secrets, cookbooks/apache2, /users/*,
19
+ # /organizations/foo/nodes/x
20
+ attribute :path, :kind_of => String, :name_attribute => true
21
+
22
+ # Whether to change things recursively. true means it will descend all children
23
+ # and make the same modifications to them. :on_change will only descend if
24
+ # the parent has changed. :on_change is the default.
25
+ attribute :recursive, :equal_to => [ true, false, :on_change ], :default => :on_change
26
+
27
+ # Specifies that this is a complete specification for the acl (i.e. rights
28
+ # you don't specify will be reset to their defaults)
29
+ attribute :complete, :kind_of => [TrueClass, FalseClass]
30
+
31
+ attribute :raw_json, :kind_of => Hash
32
+ attribute :chef_server, :kind_of => Hash
33
+
34
+ # rights :read, :users => 'jkeiser', :groups => [ 'admins', 'users' ]
35
+ # rights [ :create, :read ], :users => [ 'jkeiser', 'adam' ]
36
+ # rights :all, :users => 'jkeiser'
37
+ def rights(*values)
38
+ if values.size == 0
39
+ @rights
40
+ else
41
+ args = values.pop
42
+ args[:permissions] ||= []
43
+ values.each do |value|
44
+ args[:permissions] |= Array(value)
45
+ end
46
+ @rights ||= []
47
+ @rights << args
48
+ end
49
+ end
50
+
51
+ # remove_rights :read, :users => 'jkeiser', :groups => [ 'admins', 'users' ]
52
+ # remove_rights [ :create, :read ], :users => [ 'jkeiser', 'adam' ]
53
+ # remove_rights :all, :users => [ 'jkeiser', 'adam' ]
54
+ def remove_rights(*values)
55
+ if values.size == 0
56
+ @remove_rights
57
+ else
58
+ args = values.pop
59
+ args[:permissions] ||= []
60
+ values.each do |value|
61
+ args[:permissions] |= Array(value)
62
+ end
63
+ @remove_rights ||= []
64
+ @remove_rights << args
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,44 +1,48 @@
1
- require 'cheffish'
2
- require 'chef/resource/lwrp_base'
3
-
4
- class Chef::Resource::ChefClient < Chef::Resource::LWRPBase
5
- self.resource_name = 'chef_client'
6
-
7
- actions :create, :delete, :regenerate_keys, :nothing
8
- default_action :create
9
-
10
- def initialize(*args)
11
- super
12
- chef_server run_context.cheffish.current_chef_server
13
- end
14
-
15
- # Client attributes
16
- attribute :name, :kind_of => String, :regex => Cheffish::NAME_REGEX, :name_attribute => true
17
- attribute :admin, :kind_of => [TrueClass, FalseClass]
18
- attribute :validator, :kind_of => [TrueClass, FalseClass]
19
-
20
- # Input key
21
- attribute :source_key # String or OpenSSL::PKey::*
22
- attribute :source_key_path, :kind_of => String
23
- attribute :source_key_pass_phrase
24
-
25
- # Output public key (if so desired)
26
- attribute :output_key_path, :kind_of => String
27
- attribute :output_key_format, :kind_of => Symbol, :default => :openssh, :equal_to => [ :pem, :der, :openssh ]
28
-
29
- # If this is set, client is not patchy
30
- attribute :complete, :kind_of => [TrueClass, FalseClass]
31
-
32
- attribute :raw_json, :kind_of => Hash
33
- attribute :chef_server, :kind_of => Hash
34
-
35
- # Proc that runs just before the resource executes. Called with (resource)
36
- def before(&block)
37
- block ? @before = block : @before
38
- end
39
-
40
- # Proc that runs after the resource completes. Called with (resource, json, private_key, public_key)
41
- def after(&block)
42
- block ? @after = block : @after
43
- end
44
- end
1
+ require 'cheffish'
2
+ require 'chef/resource/lwrp_base'
3
+
4
+ class Chef
5
+ class Resource
6
+ class ChefClient < Chef::Resource::LWRPBase
7
+ self.resource_name = 'chef_client'
8
+
9
+ actions :create, :delete, :regenerate_keys, :nothing
10
+ default_action :create
11
+
12
+ def initialize(*args)
13
+ super
14
+ chef_server run_context.cheffish.current_chef_server
15
+ end
16
+
17
+ # Client attributes
18
+ attribute :name, :kind_of => String, :regex => Cheffish::NAME_REGEX, :name_attribute => true
19
+ attribute :admin, :kind_of => [TrueClass, FalseClass]
20
+ attribute :validator, :kind_of => [TrueClass, FalseClass]
21
+
22
+ # Input key
23
+ attribute :source_key # String or OpenSSL::PKey::*
24
+ attribute :source_key_path, :kind_of => String
25
+ attribute :source_key_pass_phrase
26
+
27
+ # Output public key (if so desired)
28
+ attribute :output_key_path, :kind_of => String
29
+ attribute :output_key_format, :kind_of => Symbol, :default => :openssh, :equal_to => [ :pem, :der, :openssh ]
30
+
31
+ # If this is set, client is not patchy
32
+ attribute :complete, :kind_of => [TrueClass, FalseClass]
33
+
34
+ attribute :raw_json, :kind_of => Hash
35
+ attribute :chef_server, :kind_of => Hash
36
+
37
+ # Proc that runs just before the resource executes. Called with (resource)
38
+ def before(&block)
39
+ block ? @before = block : @before
40
+ end
41
+
42
+ # Proc that runs after the resource completes. Called with (resource, json, private_key, public_key)
43
+ def after(&block)
44
+ block ? @after = block : @after
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,18 +1,22 @@
1
- require 'cheffish'
2
- require 'chef/resource/lwrp_base'
3
-
4
- class Chef::Resource::ChefContainer < Chef::Resource::LWRPBase
5
- self.resource_name = 'chef_container'
6
-
7
- actions :create, :delete, :nothing
8
- default_action :create
9
-
10
- # Grab environment from with_environment
11
- def initialize(*args)
12
- super
13
- chef_server run_context.cheffish.current_chef_server
14
- end
15
-
16
- attribute :name, :kind_of => String, :regex => Cheffish::NAME_REGEX, :name_attribute => true
17
- attribute :chef_server, :kind_of => Hash
18
- end
1
+ require 'cheffish'
2
+ require 'chef/resource/lwrp_base'
3
+
4
+ class Chef
5
+ class Resource
6
+ class ChefContainer < Chef::Resource::LWRPBase
7
+ self.resource_name = 'chef_container'
8
+
9
+ actions :create, :delete, :nothing
10
+ default_action :create
11
+
12
+ # Grab environment from with_environment
13
+ def initialize(*args)
14
+ super
15
+ chef_server run_context.cheffish.current_chef_server
16
+ end
17
+
18
+ attribute :name, :kind_of => String, :regex => Cheffish::NAME_REGEX, :name_attribute => true
19
+ attribute :chef_server, :kind_of => Hash
20
+ end
21
+ end
22
+ end
@@ -1,18 +1,22 @@
1
- require 'cheffish'
2
- require 'chef/resource/lwrp_base'
3
-
4
- class Chef::Resource::ChefDataBag < Chef::Resource::LWRPBase
5
- self.resource_name = 'chef_data_bag'
6
-
7
- actions :create, :delete, :nothing
8
- default_action :create
9
-
10
- def initialize(*args)
11
- super
12
- chef_server run_context.cheffish.current_chef_server
13
- end
14
-
15
- attribute :name, :kind_of => String, :regex => Cheffish::NAME_REGEX, :name_attribute => true
16
-
17
- attribute :chef_server, :kind_of => Hash
18
- end
1
+ require 'cheffish'
2
+ require 'chef/resource/lwrp_base'
3
+
4
+ class Chef
5
+ class Resource
6
+ class ChefDataBag < Chef::Resource::LWRPBase
7
+ self.resource_name = 'chef_data_bag'
8
+
9
+ actions :create, :delete, :nothing
10
+ default_action :create
11
+
12
+ def initialize(*args)
13
+ super
14
+ chef_server run_context.cheffish.current_chef_server
15
+ end
16
+
17
+ attribute :name, :kind_of => String, :regex => Cheffish::NAME_REGEX, :name_attribute => true
18
+
19
+ attribute :chef_server, :kind_of => Hash
20
+ end
21
+ end
22
+ end