chef-dk 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/chef-dk/builtin_commands.rb +10 -0
  4. data/lib/chef-dk/command/base.rb +2 -2
  5. data/lib/chef-dk/command/clean_policy_cookbooks.rb +116 -0
  6. data/lib/chef-dk/command/clean_policy_revisions.rb +113 -0
  7. data/lib/chef-dk/command/delete_policy.rb +122 -0
  8. data/lib/chef-dk/command/delete_policy_group.rb +122 -0
  9. data/lib/chef-dk/command/export.rb +3 -3
  10. data/lib/chef-dk/command/generate.rb +8 -0
  11. data/lib/chef-dk/command/generator_commands/app.rb +1 -1
  12. data/lib/chef-dk/command/generator_commands/cookbook.rb +1 -1
  13. data/lib/chef-dk/command/generator_commands/policyfile.rb +1 -1
  14. data/lib/chef-dk/command/generator_commands/repo.rb +1 -1
  15. data/lib/chef-dk/command/install.rb +22 -5
  16. data/lib/chef-dk/command/provision.rb +0 -4
  17. data/lib/chef-dk/command/push.rb +1 -2
  18. data/lib/chef-dk/command/shell_init.rb +65 -6
  19. data/lib/chef-dk/command/show_policy.rb +1 -2
  20. data/lib/chef-dk/command/undelete.rb +155 -0
  21. data/lib/chef-dk/command/update.rb +5 -5
  22. data/lib/chef-dk/command/verify.rb +61 -17
  23. data/lib/chef-dk/completions/bash.sh.erb +5 -0
  24. data/lib/chef-dk/completions/chef.fish.erb +10 -0
  25. data/lib/chef-dk/completions/zsh.zsh.erb +21 -0
  26. data/lib/chef-dk/exceptions.rb +12 -0
  27. data/lib/chef-dk/helpers.rb +17 -0
  28. data/lib/chef-dk/policyfile/community_cookbook_source.rb +0 -3
  29. data/lib/chef-dk/policyfile/lister.rb +3 -1
  30. data/lib/chef-dk/policyfile/undo_record.rb +142 -0
  31. data/lib/chef-dk/policyfile/undo_stack.rb +130 -0
  32. data/lib/chef-dk/policyfile_lock.rb +30 -0
  33. data/lib/chef-dk/policyfile_services/clean_policies.rb +5 -4
  34. data/lib/chef-dk/policyfile_services/clean_policy_cookbooks.rb +125 -0
  35. data/lib/chef-dk/policyfile_services/rm_policy.rb +142 -0
  36. data/lib/chef-dk/policyfile_services/rm_policy_group.rb +86 -0
  37. data/lib/chef-dk/policyfile_services/show_policy.rb +1 -1
  38. data/lib/chef-dk/policyfile_services/undelete.rb +108 -0
  39. data/lib/chef-dk/service_exceptions.rb +11 -0
  40. data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +6 -2
  41. data/lib/chef-dk/skeletons/code_generator/files/default/repo/README.md +1 -1
  42. data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/attributes/default.rb +1 -1
  43. data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +1 -1
  44. data/lib/chef-dk/version.rb +1 -1
  45. data/lib/kitchen/provisioner/policyfile_zero.rb +4 -1
  46. data/spec/unit/command/base_spec.rb +26 -1
  47. data/spec/unit/command/clean_policy_cookbooks_spec.rb +181 -0
  48. data/spec/unit/command/clean_policy_revisions_spec.rb +181 -0
  49. data/spec/unit/command/delete_policy_group_spec.rb +207 -0
  50. data/spec/unit/command/delete_policy_spec.rb +207 -0
  51. data/spec/unit/command/generate_spec.rb +41 -1
  52. data/spec/unit/command/generator_commands/cookbook_spec.rb +1 -1
  53. data/spec/unit/command/generator_commands/policyfile_spec.rb +1 -1
  54. data/spec/unit/command/install_spec.rb +24 -0
  55. data/spec/unit/command/shell_init_spec.rb +176 -5
  56. data/spec/unit/command/undelete_spec.rb +246 -0
  57. data/spec/unit/helpers_spec.rb +24 -0
  58. data/spec/unit/policyfile/lister_spec.rb +16 -0
  59. data/spec/unit/policyfile/undo_record_spec.rb +260 -0
  60. data/spec/unit/policyfile/undo_stack_spec.rb +266 -0
  61. data/spec/unit/policyfile_lock_serialization_spec.rb +41 -0
  62. data/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb +275 -0
  63. data/spec/unit/policyfile_services/rm_policy_group_spec.rb +241 -0
  64. data/spec/unit/policyfile_services/rm_policy_spec.rb +266 -0
  65. data/spec/unit/policyfile_services/show_policy_spec.rb +52 -2
  66. data/spec/unit/policyfile_services/undelete_spec.rb +304 -0
  67. metadata +43 -91
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee32c7f8bf0ecdab62b80de5ea8a4464b51c6838
4
- data.tar.gz: 2e111a49b664088c4111f0b66fd07b17ed0c5eaa
3
+ metadata.gz: 860e0ce1331356dc81adf225d0c041d3917eee74
4
+ data.tar.gz: 9356d799cc078070b9671c2f189032bc95f3d3ac
5
5
  SHA512:
6
- metadata.gz: ebe65296faf1e24202b4f577422a0956feb1feb722d623b9c74b9894f64d43afc55aac6fdd87ea3e659c2be85fa97a80af44b05a5e7866d1d5deaed2f2ead062
7
- data.tar.gz: 713d6cca6c4fc3cc510e6f402bee5a8c81e7df06cf8be0423e911267b8419df6c6568f6e7b348f54959ff27f997acd44b0b824700653f3335c99c2ba5c86390e
6
+ metadata.gz: ef5d1c817016b7d92dd47d0eca0090cc78da9dab98320099093807ff802bbbb87f5bc99c55aae143d6bc0da16e381549b503a6ef0d79144989f67764771afb75
7
+ data.tar.gz: 1dfcfbcc52339443436eb7a9653d2ba161bb7ee3c8bca649b82d17a681083cf251964c1c883874e64aa84f229f9823ab733ff772c2b7548ee4314b1503bb4934
data/README.md CHANGED
@@ -269,8 +269,8 @@ dpkg -P chefdk
269
269
  [Berkshelf]: http://berkshelf.com "Berkshelf"
270
270
  [Chef]: https://www.chef.io "Chef"
271
271
  [ChefDK]: https://downloads.chef.io/chef-dk "Chef Development Kit"
272
- [Chef Documentation]: http://docs.chef.io "Chef Documentation"
272
+ [Chef Documentation]: https://docs.chef.io "Chef Documentation"
273
273
  [ChefSpec]: http://chefspec.org "ChefSpec"
274
274
  [Foodcritic]: http://foodcritic.io "Foodcritic"
275
- [Learn Chef]: http://learn.chef.io "Learn Chef"
275
+ [Learn Chef]: https://learn.chef.io "Learn Chef"
276
276
  [Test Kitchen]: http://kitchen.ci "Test Kitchen"
@@ -46,5 +46,15 @@ ChefDK.commands do |c|
46
46
 
47
47
  c.builtin "export", :Export, desc: "Export a policy lock as a Chef Zero code repo"
48
48
 
49
+ c.builtin "clean-policy-revisions", :CleanPolicyRevisions, desc: "Delete unused policy revisions on the server"
50
+
51
+ c.builtin "clean-policy-cookbooks", :CleanPolicyCookbooks, desc: "Delete unused policyfile cookbooks on the server"
52
+
53
+ c.builtin "delete-policy-group", :DeletePolicyGroup, desc: "Delete a policy group on the server"
54
+
55
+ c.builtin "delete-policy", :DeletePolicy, desc: "Delete all revisions of a policy on the server"
56
+
57
+ c.builtin "undelete", :Undelete, desc: "Undo a delete command"
58
+
49
59
  c.builtin "verify", :Verify, desc: "Test the embedded ChefDK applications"
50
60
  end
@@ -56,8 +56,8 @@ module ChefDK
56
56
  else
57
57
  run(params)
58
58
  end
59
- rescue OptionParser::InvalidOption => e
60
- err(e.message)
59
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
60
+ err("ERROR: #{e.message}\n")
61
61
  msg(opt_parser)
62
62
  1
63
63
  end
@@ -0,0 +1,116 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2015 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef-dk/command/base'
19
+ require 'chef-dk/ui'
20
+ require 'chef-dk/configurable'
21
+ require 'chef-dk/policyfile_services/clean_policy_cookbooks'
22
+
23
+ module ChefDK
24
+ module Command
25
+
26
+
27
+ class CleanPolicyCookbooks < Base
28
+
29
+ banner(<<-BANNER)
30
+ Usage: chef clean-policy-cookbooks [options]
31
+
32
+ `chef clean-policy-cookbooks` deletes unused policyfile cookbooks. Cookbooks
33
+ are considered unused when they are not referenced by any policyfile revision
34
+ on the server. Note that cookbooks which are referenced by "orphaned" policy
35
+ revisions are not removed, so you may wish to run `chef clean-policy-revisions`
36
+ to remove orphaned policies before running this command.
37
+
38
+ See our detailed README for more information:
39
+
40
+ https://github.com/opscode/chef-dk/blob/master/POLICYFILE_README.md
41
+
42
+ Options:
43
+
44
+ BANNER
45
+
46
+ option :config_file,
47
+ short: "-c CONFIG_FILE",
48
+ long: "--config CONFIG_FILE",
49
+ description: "Path to configuration file"
50
+
51
+ option :debug,
52
+ short: "-D",
53
+ long: "--debug",
54
+ description: "Enable stacktraces and other debug output",
55
+ default: false
56
+
57
+ include Configurable
58
+
59
+ attr_accessor :ui
60
+
61
+ attr_reader :policy_name
62
+
63
+ attr_reader :policy_group
64
+
65
+ def initialize(*args)
66
+ super
67
+ @ui = UI.new
68
+
69
+ @clean_policy_cookbooks_service = nil
70
+ end
71
+
72
+ def run(params)
73
+ return 1 unless apply_params!(params)
74
+ clean_policy_cookbooks_service.run
75
+ 0
76
+ rescue PolicyfileServiceError => e
77
+ handle_error(e)
78
+ 1
79
+ end
80
+
81
+ def clean_policy_cookbooks_service
82
+ @clean_policy_cookbooks_service ||=
83
+ PolicyfileServices::CleanPolicyCookbooks.new(config: chef_config, ui: ui)
84
+ end
85
+
86
+ def debug?
87
+ !!config[:debug]
88
+ end
89
+
90
+ def handle_error(error)
91
+ ui.err("Error: #{error.message}")
92
+ if error.respond_to?(:reason)
93
+ ui.err("Reason: #{error.reason}")
94
+ ui.err("")
95
+ ui.err(error.extended_error_info) if debug?
96
+ ui.err(error.cause.backtrace.join("\n")) if debug?
97
+ end
98
+ end
99
+
100
+ def apply_params!(params)
101
+ remaining_args = parse_options(params)
102
+
103
+ if !remaining_args.empty?
104
+ ui.err("Too many arguments")
105
+ ui.err("")
106
+ ui.err(opt_parser)
107
+ false
108
+ else
109
+ true
110
+ end
111
+ end
112
+
113
+ end
114
+ end
115
+ end
116
+
@@ -0,0 +1,113 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2015 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef-dk/command/base'
19
+ require 'chef-dk/ui'
20
+ require 'chef-dk/configurable'
21
+ require 'chef-dk/policyfile_services/clean_policies'
22
+
23
+ module ChefDK
24
+ module Command
25
+
26
+
27
+ class CleanPolicyRevisions < Base
28
+
29
+ banner(<<-BANNER)
30
+ Usage: chef clean-policy-revisions [options]
31
+
32
+ `chef clean-policy-revisions` deletes orphaned policyfile revisions from the Chef
33
+ Server. Orphaned policyfile revisions are not associated to any group, and
34
+ therefore not in active use by any nodes. To list orphaned policyfile revisions
35
+ before deleting them, use `chef show-policy --orphans`.
36
+
37
+ See our detailed README for more information:
38
+
39
+ https://github.com/opscode/chef-dk/blob/master/POLICYFILE_README.md
40
+
41
+ Options:
42
+
43
+ BANNER
44
+
45
+ option :config_file,
46
+ short: "-c CONFIG_FILE",
47
+ long: "--config CONFIG_FILE",
48
+ description: "Path to configuration file"
49
+
50
+ option :debug,
51
+ short: "-D",
52
+ long: "--debug",
53
+ description: "Enable stacktraces and other debug output",
54
+ default: false
55
+
56
+ include Configurable
57
+
58
+ attr_accessor :ui
59
+
60
+ attr_reader :policy_name
61
+
62
+ attr_reader :policy_group
63
+
64
+ def initialize(*args)
65
+ super
66
+ @ui = UI.new
67
+ end
68
+
69
+ def run(params)
70
+ return 1 unless apply_params!(params)
71
+ clean_policies_service.run
72
+ 0
73
+ rescue PolicyfileServiceError => e
74
+ handle_error(e)
75
+ 1
76
+ end
77
+
78
+ def clean_policies_service
79
+ @policy_list_service ||=
80
+ PolicyfileServices::CleanPolicies.new(config: chef_config, ui: ui)
81
+ end
82
+
83
+ def debug?
84
+ !!config[:debug]
85
+ end
86
+
87
+ def handle_error(error)
88
+ ui.err("Error: #{error.message}")
89
+ if error.respond_to?(:reason)
90
+ ui.err("Reason: #{error.reason}")
91
+ ui.err("")
92
+ ui.err(error.extended_error_info) if debug?
93
+ ui.err(error.cause.backtrace.join("\n")) if debug?
94
+ end
95
+ end
96
+
97
+ def apply_params!(params)
98
+ remaining_args = parse_options(params)
99
+
100
+ if !remaining_args.empty?
101
+ ui.err("Too many arguments")
102
+ ui.err("")
103
+ ui.err(opt_parser)
104
+ false
105
+ else
106
+ true
107
+ end
108
+ end
109
+
110
+ end
111
+ end
112
+ end
113
+
@@ -0,0 +1,122 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2015 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef-dk/command/base'
19
+ require 'chef-dk/ui'
20
+ require 'chef-dk/configurable'
21
+ require 'chef-dk/policyfile_services/rm_policy'
22
+
23
+ module ChefDK
24
+ module Command
25
+
26
+
27
+ class DeletePolicy < Base
28
+
29
+ banner(<<-BANNER)
30
+ Usage: chef delete-policy POLICY_NAME [options]
31
+
32
+ `chef delete-policy POLICY_NAME` deletes all revisions of the policy
33
+ `POLICY_NAME` on the configured Chef Server. All policy revisions will be
34
+ backed up locally, allowing you to undo this operation via the `chef undelete`
35
+ command.
36
+
37
+ See our detailed README for more information:
38
+
39
+ https://github.com/opscode/chef-dk/blob/master/POLICYFILE_README.md
40
+
41
+ Options:
42
+
43
+ BANNER
44
+
45
+ option :config_file,
46
+ short: "-c CONFIG_FILE",
47
+ long: "--config CONFIG_FILE",
48
+ description: "Path to configuration file"
49
+
50
+ option :debug,
51
+ short: "-D",
52
+ long: "--debug",
53
+ description: "Enable stacktraces and other debug output",
54
+ default: false
55
+
56
+ include Configurable
57
+
58
+ attr_accessor :ui
59
+
60
+ attr_reader :policy_name
61
+
62
+ def initialize(*args)
63
+ super
64
+ @policy_name = nil
65
+ @rm_policy_service = nil
66
+ @ui = UI.new
67
+ end
68
+
69
+ def run(params)
70
+ return 1 unless apply_params!(params)
71
+ rm_policy_service.run
72
+ ui.msg("This operation can be reversed by running `chef undelete --last`.")
73
+ 0
74
+ rescue PolicyfileServiceError => e
75
+ handle_error(e)
76
+ 1
77
+ end
78
+
79
+ def rm_policy_service
80
+ @rm_policy_service ||=
81
+ PolicyfileServices::RmPolicy.new(config: chef_config,
82
+ ui: ui,
83
+ policy_name: policy_name)
84
+ end
85
+
86
+ def debug?
87
+ !!config[:debug]
88
+ end
89
+
90
+ def handle_error(error)
91
+ ui.err("Error: #{error.message}")
92
+ if error.respond_to?(:reason)
93
+ ui.err("Reason: #{error.reason}")
94
+ ui.err("")
95
+ ui.err(error.extended_error_info) if debug?
96
+ ui.err(error.cause.backtrace.join("\n")) if debug?
97
+ end
98
+ end
99
+
100
+ def apply_params!(params)
101
+ remaining_args = parse_options(params)
102
+
103
+ if remaining_args.size == 1
104
+ @policy_name = remaining_args.first
105
+ true
106
+ elsif remaining_args.empty?
107
+ ui.err("You must specify the POLICY_NAME to delete.")
108
+ ui.err("")
109
+ ui.err(opt_parser)
110
+ false
111
+ else
112
+ ui.err("Too many arguments")
113
+ ui.err("")
114
+ ui.err(opt_parser)
115
+ false
116
+ end
117
+ end
118
+
119
+ end
120
+ end
121
+ end
122
+
@@ -0,0 +1,122 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2015 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef-dk/command/base'
19
+ require 'chef-dk/ui'
20
+ require 'chef-dk/configurable'
21
+ require 'chef-dk/policyfile_services/rm_policy_group'
22
+
23
+ module ChefDK
24
+ module Command
25
+
26
+
27
+ class DeletePolicyGroup < Base
28
+
29
+ banner(<<-BANNER)
30
+ Usage: chef delete-policy-group POLICY_GROUP [options]
31
+
32
+ `chef delete-policy-group POLICY_GROUP` deletes the policy group POLICY_GROUP on
33
+ the configured Chef Server. Policy Revisions associated to the policy group are
34
+ not deleted. The state of the policy group will be backed up locally, allowing
35
+ you to undo this operation via the `chef undelete` command.
36
+
37
+ See our detailed README for more information:
38
+
39
+ https://github.com/opscode/chef-dk/blob/master/POLICYFILE_README.md
40
+
41
+ Options:
42
+
43
+ BANNER
44
+
45
+ option :config_file,
46
+ short: "-c CONFIG_FILE",
47
+ long: "--config CONFIG_FILE",
48
+ description: "Path to configuration file"
49
+
50
+ option :debug,
51
+ short: "-D",
52
+ long: "--debug",
53
+ description: "Enable stacktraces and other debug output",
54
+ default: false
55
+
56
+ include Configurable
57
+
58
+ attr_accessor :ui
59
+
60
+ attr_reader :policy_group
61
+
62
+ def initialize(*args)
63
+ super
64
+ @policy_group = nil
65
+ @rm_policy_group_service = nil
66
+ @ui = UI.new
67
+ end
68
+
69
+ def run(params)
70
+ return 1 unless apply_params!(params)
71
+ rm_policy_group_service.run
72
+ ui.msg("This operation can be reversed by running `chef undelete --last`.")
73
+ 0
74
+ rescue PolicyfileServiceError => e
75
+ handle_error(e)
76
+ 1
77
+ end
78
+
79
+ def rm_policy_group_service
80
+ @rm_policy_group_service ||=
81
+ PolicyfileServices::RmPolicyGroup.new(config: chef_config,
82
+ ui: ui,
83
+ policy_group: policy_group)
84
+ end
85
+
86
+ def debug?
87
+ !!config[:debug]
88
+ end
89
+
90
+ def handle_error(error)
91
+ ui.err("Error: #{error.message}")
92
+ if error.respond_to?(:reason)
93
+ ui.err("Reason: #{error.reason}")
94
+ ui.err("")
95
+ ui.err(error.extended_error_info) if debug?
96
+ ui.err(error.cause.backtrace.join("\n")) if debug?
97
+ end
98
+ end
99
+
100
+ def apply_params!(params)
101
+ remaining_args = parse_options(params)
102
+
103
+ if remaining_args.size == 1
104
+ @policy_group = remaining_args.first
105
+ true
106
+ elsif remaining_args.empty?
107
+ ui.err("You must specify the POLICY_GROUP to delete.")
108
+ ui.err("")
109
+ ui.err(opt_parser)
110
+ false
111
+ else
112
+ ui.err("Too many arguments")
113
+ ui.err("")
114
+ ui.err(opt_parser)
115
+ false
116
+ end
117
+ end
118
+
119
+ end
120
+ end
121
+ end
122
+