chef-dk 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/chef-dk/authenticated_http.rb +40 -0
  4. data/lib/chef-dk/chef_runner.rb +5 -0
  5. data/lib/chef-dk/command/exec.rb +4 -1
  6. data/lib/chef-dk/command/generate.rb +11 -0
  7. data/lib/chef-dk/command/generator_commands.rb +20 -365
  8. data/lib/chef-dk/command/generator_commands/app.rb +99 -0
  9. data/lib/chef-dk/command/generator_commands/attribute.rb +37 -0
  10. data/lib/chef-dk/command/generator_commands/base.rb +76 -0
  11. data/lib/chef-dk/command/generator_commands/cookbook.rb +100 -0
  12. data/lib/chef-dk/command/generator_commands/cookbook_code_file.rb +99 -0
  13. data/lib/chef-dk/command/generator_commands/cookbook_file.rb +45 -0
  14. data/lib/chef-dk/command/generator_commands/lwrp.rb +36 -0
  15. data/lib/chef-dk/command/generator_commands/recipe.rb +36 -0
  16. data/lib/chef-dk/command/generator_commands/repo.rb +96 -0
  17. data/lib/chef-dk/command/generator_commands/template.rb +45 -0
  18. data/lib/chef-dk/command/verify.rb +28 -0
  19. data/lib/chef-dk/component_test.rb +16 -3
  20. data/lib/chef-dk/cookbook_omnifetch.rb +2 -0
  21. data/lib/chef-dk/cookbook_profiler/identifiers.rb +3 -15
  22. data/lib/chef-dk/exceptions.rb +15 -0
  23. data/lib/chef-dk/generator.rb +102 -25
  24. data/lib/chef-dk/policyfile/community_cookbook_source.rb +0 -7
  25. data/lib/chef-dk/policyfile/{cookbook_spec.rb → cookbook_location_specification.rb} +35 -6
  26. data/lib/chef-dk/policyfile/cookbook_locks.rb +305 -0
  27. data/lib/chef-dk/policyfile/dsl.rb +26 -12
  28. data/lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb +70 -0
  29. data/lib/chef-dk/policyfile/solution_dependencies.rb +204 -0
  30. data/lib/chef-dk/policyfile/storage_config.rb +77 -0
  31. data/lib/chef-dk/policyfile/uploader.rb +110 -0
  32. data/lib/chef-dk/policyfile_compiler.rb +59 -29
  33. data/lib/chef-dk/policyfile_lock.rb +104 -160
  34. data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +1 -1
  35. data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +0 -1
  36. data/lib/chef-dk/skeletons/code_generator/files/default/repo/README.md +66 -0
  37. data/lib/chef-dk/skeletons/code_generator/files/default/repo/Rakefile +65 -0
  38. data/lib/chef-dk/skeletons/code_generator/files/default/repo/certificates/README.md +19 -0
  39. data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/README-policy.md +9 -0
  40. data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/README.md +54 -0
  41. data/lib/chef-dk/skeletons/code_generator/files/default/repo/data_bags/README.md +63 -0
  42. data/lib/chef-dk/skeletons/code_generator/files/default/repo/environments/README.md +5 -0
  43. data/lib/chef-dk/skeletons/code_generator/files/default/repo/roles/README.md +16 -0
  44. data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +7 -1
  45. data/lib/chef-dk/skeletons/code_generator/recipes/repo.rb +62 -0
  46. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
  47. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.apache2.erb +201 -0
  48. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv2.erb +339 -0
  49. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv3.erb +674 -0
  50. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.mit.erb +21 -0
  51. data/lib/chef-dk/skeletons/code_generator/templates/default/default_recipe.rb.erb +1 -4
  52. data/lib/chef-dk/skeletons/code_generator/templates/default/metadata.rb.erb +3 -3
  53. data/lib/chef-dk/skeletons/code_generator/templates/default/repo/config/rake.rb.erb +38 -0
  54. data/lib/chef-dk/skeletons/code_generator/templates/default/repo/gitignore.erb +11 -0
  55. data/lib/chef-dk/version.rb +1 -1
  56. data/spec/shared/a_file_generator.rb +121 -0
  57. data/spec/shared/a_generated_file.rb +12 -0
  58. data/spec/shared/fixture_cookbook_checksums.rb +47 -0
  59. data/spec/spec_helper.rb +4 -2
  60. data/spec/unit/chef_runner_spec.rb +12 -5
  61. data/spec/unit/cli_spec.rb +4 -4
  62. data/spec/unit/command/base_spec.rb +1 -1
  63. data/spec/unit/command/exec_spec.rb +37 -27
  64. data/spec/unit/command/generate_spec.rb +3 -3
  65. data/spec/unit/command/generator_commands/app_spec.rb +131 -0
  66. data/spec/unit/command/generator_commands/attribute_spec.rb +32 -0
  67. data/spec/unit/command/generator_commands/cookbook_file_spec.rb +32 -0
  68. data/spec/unit/command/generator_commands/cookbook_spec.rb +205 -0
  69. data/spec/unit/command/generator_commands/lwrp_spec.rb +32 -0
  70. data/spec/unit/command/generator_commands/recipe_spec.rb +32 -0
  71. data/spec/unit/command/generator_commands/repo_spec.rb +287 -0
  72. data/spec/unit/command/generator_commands/template_spec.rb +32 -0
  73. data/spec/unit/command/shell_init_spec.rb +4 -4
  74. data/spec/unit/command/verify_spec.rb +9 -9
  75. data/spec/unit/commands_map_spec.rb +1 -1
  76. data/spec/unit/component_test_spec.rb +3 -3
  77. data/spec/unit/cookbook_profiler/git_spec.rb +7 -7
  78. data/spec/unit/cookbook_profiler/identifiers_spec.rb +12 -8
  79. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +1 -1
  80. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +1 -1
  81. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +1 -1
  82. data/spec/unit/fixtures/example_cookbook/Berksfile +1 -1
  83. data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/README.md +4 -0
  84. data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/chefignore +96 -0
  85. data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/metadata.rb +8 -0
  86. data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/recipes/default.rb +8 -0
  87. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +1 -1
  88. data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
  89. data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
  90. data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
  91. data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
  92. data/spec/unit/generator_spec.rb +120 -0
  93. data/spec/unit/policyfile/{cookbook_spec_spec.rb → cookbook_location_specification_spec.rb} +83 -38
  94. data/spec/unit/policyfile/cookbook_locks_spec.rb +354 -0
  95. data/spec/unit/policyfile/read_cookbook_for_compat_mode_upload_spec.rb +85 -0
  96. data/spec/unit/policyfile/solution_dependencies_spec.rb +145 -0
  97. data/spec/unit/policyfile/storage_config_spec.rb +98 -0
  98. data/spec/unit/policyfile/uploader_spec.rb +292 -0
  99. data/spec/unit/policyfile_demands_spec.rb +177 -24
  100. data/spec/unit/policyfile_evaluation_spec.rb +40 -12
  101. data/spec/unit/{policyfile_builder_spec.rb → policyfile_lock_build_spec.rb} +179 -64
  102. data/spec/unit/policyfile_lock_install_spec.rb +138 -0
  103. data/spec/unit/policyfile_lock_validation_spec.rb +610 -0
  104. metadata +103 -59
  105. data/spec/unit/command/generator_commands_spec.rb +0 -504
@@ -0,0 +1,99 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 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/generator_commands/base'
19
+
20
+ module ChefDK
21
+ module Command
22
+ module GeneratorCommands
23
+
24
+ # ## App
25
+ # chef generate app path/to/basename --generator-cookbook=path/to/generator
26
+ #
27
+ # Generates a full "application" directory structure.
28
+ class App < Base
29
+
30
+ banner "Usage: chef generate app NAME [options]"
31
+
32
+ attr_reader :errors
33
+ attr_reader :app_name_or_path
34
+
35
+ options.merge!(SharedGeneratorOptions.options)
36
+
37
+ def initialize(params)
38
+ @params_valid = true
39
+ @app_name = nil
40
+ super
41
+ end
42
+
43
+ def run
44
+ read_and_validate_params
45
+ if params_valid?
46
+ setup_context
47
+ chef_runner.converge
48
+ else
49
+ msg(banner)
50
+ 1
51
+ end
52
+ end
53
+
54
+ def setup_context
55
+ super
56
+ Generator.add_attr_to_context(:app_root, app_root)
57
+ Generator.add_attr_to_context(:app_name, app_name)
58
+ Generator.add_attr_to_context(:cookbook_root, cookbook_root)
59
+ Generator.add_attr_to_context(:cookbook_name, cookbook_name)
60
+ end
61
+
62
+ def recipe
63
+ "app"
64
+ end
65
+
66
+ def app_name
67
+ File.basename(app_full_path)
68
+ end
69
+
70
+ def app_root
71
+ File.dirname(app_full_path)
72
+ end
73
+
74
+ def cookbook_root
75
+ File.join(app_full_path, 'cookbooks')
76
+ end
77
+
78
+ def cookbook_name
79
+ app_name
80
+ end
81
+
82
+ def app_full_path
83
+ File.expand_path(app_name_or_path, Dir.pwd)
84
+ end
85
+
86
+ def read_and_validate_params
87
+ arguments = parse_options(params)
88
+ @app_name_or_path = arguments[0]
89
+ @params_valid = false unless @app_name_or_path
90
+ end
91
+
92
+ def params_valid?
93
+ @params_valid
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+
@@ -0,0 +1,37 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 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/generator_commands/cookbook_code_file'
19
+
20
+ module ChefDK
21
+ module Command
22
+ module GeneratorCommands
23
+ # chef generate attribute [path/to/cookbook_root] NAME
24
+ class Attribute < CookbookCodeFile
25
+
26
+ banner "Usage: chef generate attribute [path/to/cookbook] NAME [options]"
27
+
28
+ options.merge!(SharedGeneratorOptions.options)
29
+
30
+ def recipe
31
+ 'attribute'
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,76 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 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/generator_commands'
19
+
20
+ module ChefDK
21
+ module Command
22
+ module GeneratorCommands
23
+ # ## Base
24
+ #
25
+ # Base class for `chef generate` subcommands. Contains basic behaviors
26
+ # for setting up the generator context, detecting git, and launching a
27
+ # chef converge.
28
+ #
29
+ # The behavior of the generators is largely delegated to a chef cookbook.
30
+ # The default implementation is the `code_generator` cookbook in
31
+ # chef-dk/skeletons/code_generator.
32
+ class Base < Command::Base
33
+
34
+ attr_reader :params
35
+
36
+ options.merge!(SharedGeneratorOptions.options)
37
+
38
+ def initialize(params)
39
+ super()
40
+ @params = params
41
+ end
42
+
43
+ # An instance of ChefRunner. Calling ChefRunner#converge will trigger
44
+ # convergence and generate the desired code.
45
+ def chef_runner
46
+ @chef_runner ||= ChefRunner.new(generator_cookbook_path, ["code_generator::#{recipe}"])
47
+ end
48
+
49
+ # Path to the directory where the code_generator cookbook is located.
50
+ # For now, this is hard coded to the 'skeletons' directory in this
51
+ # repo.
52
+ def generator_cookbook_path
53
+ config[:generator_cookbook]
54
+ end
55
+
56
+ # Sets git related generator_context values.
57
+ def setup_context
58
+ Generator.add_attr_to_context(:have_git, have_git?)
59
+ Generator.add_attr_to_context(:skip_git_init, false)
60
+ config.each do |k,v|
61
+ Generator.add_attr_to_context(k, v)
62
+ end
63
+ end
64
+
65
+ # Checks the `PATH` for the presence of a `git` (or `git.exe`, on
66
+ # windows) executable.
67
+ def have_git?
68
+ path = ENV["PATH"] || ""
69
+ paths = path.split(File::PATH_SEPARATOR)
70
+ paths.any? {|bin_path| File.exist?(File.join(bin_path, "git#{RbConfig::CONFIG['EXEEXT']}"))}
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
@@ -0,0 +1,100 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 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/generator_commands/base'
19
+
20
+ module ChefDK
21
+ module Command
22
+ module GeneratorCommands
23
+
24
+ # ## CookbookFile
25
+ # chef generate cookbook path/to/basename --generator-cookbook=path/to/generator
26
+ #
27
+ # Generates a basic cookbook directory structure. Most file types are
28
+ # omitted, the user is expected to add additional files as needed using
29
+ # the relevant generators.
30
+ class Cookbook < Base
31
+
32
+ banner "Usage: chef generate cookbook NAME [options]"
33
+
34
+ attr_reader :errors
35
+
36
+ attr_reader :cookbook_name_or_path
37
+
38
+ options.merge!(SharedGeneratorOptions.options)
39
+
40
+ def initialize(params)
41
+ @params_valid = true
42
+ @cookbook_name = nil
43
+ super
44
+ end
45
+
46
+ def run
47
+ read_and_validate_params
48
+ if params_valid?
49
+ setup_context
50
+ chef_runner.converge
51
+ else
52
+ msg(banner)
53
+ 1
54
+ end
55
+ end
56
+
57
+ def setup_context
58
+ super
59
+ Generator.add_attr_to_context(:skip_git_init, cookbook_path_in_git_repo?)
60
+ Generator.add_attr_to_context(:cookbook_root, cookbook_root)
61
+ Generator.add_attr_to_context(:cookbook_name, cookbook_name)
62
+ end
63
+
64
+ def recipe
65
+ "cookbook"
66
+ end
67
+
68
+ def cookbook_name
69
+ File.basename(cookbook_full_path)
70
+ end
71
+
72
+ def cookbook_root
73
+ File.dirname(cookbook_full_path)
74
+ end
75
+
76
+ def cookbook_full_path
77
+ File.expand_path(cookbook_name_or_path, Dir.pwd)
78
+ end
79
+
80
+ def read_and_validate_params
81
+ arguments = parse_options(params)
82
+ @cookbook_name_or_path = arguments[0]
83
+ @params_valid = false unless @cookbook_name_or_path
84
+ end
85
+
86
+ def params_valid?
87
+ @params_valid
88
+ end
89
+
90
+ def cookbook_path_in_git_repo?
91
+ Pathname.new(cookbook_full_path).ascend do |dir|
92
+ return true if File.directory?(File.join(dir.to_s, ".git"))
93
+ end
94
+ false
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+
@@ -0,0 +1,99 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 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/generator_commands/base'
19
+
20
+ module ChefDK
21
+ module Command
22
+ module GeneratorCommands
23
+ # ## CookbookCodeFile
24
+ # A base class for generators that add individual files to existing
25
+ # cookbooks.
26
+ class CookbookCodeFile < Base
27
+
28
+ attr_reader :errors
29
+ attr_reader :cookbook_path
30
+ attr_reader :new_file_basename
31
+
32
+ options.merge!(SharedGeneratorOptions.options)
33
+
34
+ def initialize(params)
35
+ @params_valid = true
36
+ @cookbook_full_path = nil
37
+ @new_file_basename = nil
38
+ @errors = []
39
+ @params = params
40
+ super
41
+ end
42
+
43
+ def run
44
+ read_and_validate_params
45
+ if params_valid?
46
+ setup_context
47
+ chef_runner.converge
48
+ else
49
+ errors.each {|error| err("Error: #{error}") }
50
+ parse_options(params)
51
+ msg(opt_parser)
52
+ 1
53
+ end
54
+ end
55
+
56
+ def setup_context
57
+ super
58
+ Generator.add_attr_to_context(:cookbook_root, cookbook_root)
59
+ Generator.add_attr_to_context(:cookbook_name, cookbook_name)
60
+ Generator.add_attr_to_context(:new_file_basename, new_file_basename)
61
+ end
62
+
63
+ def cookbook_root
64
+ File.dirname(cookbook_path)
65
+ end
66
+
67
+ def cookbook_name
68
+ File.basename(cookbook_path)
69
+ end
70
+
71
+ def read_and_validate_params
72
+ arguments = parse_options(params)
73
+ case arguments.size
74
+ when 1
75
+ @new_file_basename = arguments[0]
76
+ @cookbook_path = Dir.pwd
77
+ validate_cookbook_path
78
+ when 2
79
+ @cookbook_path = arguments[0]
80
+ @new_file_basename = arguments[1]
81
+ else
82
+ @params_valid = false
83
+ end
84
+ end
85
+
86
+ def validate_cookbook_path
87
+ unless File.directory?(File.join(cookbook_path, "recipes"))
88
+ @errors << "Directory #{cookbook_path} is not a cookbook"
89
+ @params_valid = false
90
+ end
91
+ end
92
+
93
+ def params_valid?
94
+ @params_valid
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 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/generator_commands/cookbook_code_file'
19
+
20
+ module ChefDK
21
+ module Command
22
+ module GeneratorCommands
23
+ # chef generate file [path/to/cookbook_root] name --source=source_file
24
+ class CookbookFile < CookbookCodeFile
25
+ option :source,
26
+ :short => "-s SOURCE_FILE",
27
+ :long => "--source SOURCE_FILE",
28
+ :description => "Copy content from SOURCE_FILE"
29
+
30
+ banner "Usage: chef generate file [path/to/cookbook] NAME [options]"
31
+
32
+ options.merge!(SharedGeneratorOptions.options)
33
+
34
+ def recipe
35
+ 'cookbook_file'
36
+ end
37
+
38
+ def setup_context
39
+ super
40
+ Generator.add_attr_to_context(:content_source, config[:source])
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end