chef-stove 7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +202 -0
  3. data/bin/stove +5 -0
  4. data/lib/stove.rb +87 -0
  5. data/lib/stove/artifactory.rb +83 -0
  6. data/lib/stove/cli.rb +199 -0
  7. data/lib/stove/config.rb +76 -0
  8. data/lib/stove/cookbook.rb +120 -0
  9. data/lib/stove/cookbook/metadata.rb +245 -0
  10. data/lib/stove/error.rb +56 -0
  11. data/lib/stove/filter.rb +60 -0
  12. data/lib/stove/mash.rb +25 -0
  13. data/lib/stove/mixins/insideable.rb +13 -0
  14. data/lib/stove/mixins/instanceable.rb +24 -0
  15. data/lib/stove/mixins/optionable.rb +41 -0
  16. data/lib/stove/mixins/validatable.rb +11 -0
  17. data/lib/stove/packager.rb +156 -0
  18. data/lib/stove/plugins/artifactory.rb +14 -0
  19. data/lib/stove/plugins/base.rb +48 -0
  20. data/lib/stove/plugins/git.rb +70 -0
  21. data/lib/stove/plugins/supermarket.rb +18 -0
  22. data/lib/stove/rake_task.rb +22 -0
  23. data/lib/stove/runner.rb +39 -0
  24. data/lib/stove/supermarket.rb +79 -0
  25. data/lib/stove/util.rb +56 -0
  26. data/lib/stove/validator.rb +68 -0
  27. data/lib/stove/version.rb +3 -0
  28. data/templates/errors/abstract_method.erb +5 -0
  29. data/templates/errors/artifactory_key_validation_failed.erb +11 -0
  30. data/templates/errors/git_clean_validation_failed.erb +1 -0
  31. data/templates/errors/git_failed.erb +5 -0
  32. data/templates/errors/git_repository_validation_failed.erb +3 -0
  33. data/templates/errors/git_tagging_failed.erb +5 -0
  34. data/templates/errors/git_up_to_date_validation_failed.erb +7 -0
  35. data/templates/errors/metadata_not_found.erb +1 -0
  36. data/templates/errors/server_unavailable.erb +1 -0
  37. data/templates/errors/stove_error.erb +1 -0
  38. data/templates/errors/supermarket_already_exists.erb +5 -0
  39. data/templates/errors/supermarket_key_validation_failed.erb +3 -0
  40. data/templates/errors/supermarket_username_validation_failed.erb +3 -0
  41. metadata +212 -0
@@ -0,0 +1,18 @@
1
+ module Stove
2
+ class Plugin::Supermarket < Plugin::Base
3
+ id 'supermarket'
4
+ description 'Publish the release to the Chef Supermarket'
5
+
6
+ validate(:username) do
7
+ Config.username
8
+ end
9
+
10
+ validate(:key) do
11
+ Config.key
12
+ end
13
+
14
+ run('Publishing the release to the Chef Supermarket') do
15
+ Supermarket.upload(cookbook, options[:extended_metadata])
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'stove'
4
+
5
+ module Stove
6
+ class RakeTask < Rake::TaskLib
7
+ attr_accessor :stove_opts
8
+
9
+ def initialize(name = nil)
10
+ yield self if block_given?
11
+
12
+ desc 'Publish this cookbook' unless ::Rake.application.last_description
13
+ task(name || :publish) do |t, args|
14
+ Cli.new(stove_opts || []).execute!
15
+ end
16
+ end
17
+
18
+ def log_level=(level)
19
+ Stove.log_level = level
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ module Stove
2
+ class Runner
3
+ include Logify
4
+
5
+ attr_reader :cookbook
6
+ attr_reader :options
7
+
8
+ def initialize(cookbook, options = {})
9
+ @cookbook = cookbook
10
+ @options = options
11
+ end
12
+
13
+ def run
14
+ run_plugin :git
15
+ if Config.artifactory
16
+ run_plugin :artifactory
17
+ else
18
+ run_plugin :supermarket
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def run_plugin(name)
25
+ if skip?(name)
26
+ log.info { "Skipping plugin `:#{name}'" }
27
+ else
28
+ log.info { "Running plugin `:#{name}'" }
29
+ klass = Plugin.const_get(Util.camelize(name))
30
+ klass.new(cookbook, options).run
31
+ end
32
+ end
33
+
34
+ def skip?(thing)
35
+ key = "no_#{thing}".to_sym
36
+ !!options[key]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,79 @@
1
+ require 'chef-api'
2
+
3
+ module Stove
4
+ class Supermarket
5
+ include Mixin::Instanceable
6
+ include Mixin::Optionable
7
+
8
+ #
9
+ # The default endpoint where the Supermarket lives.
10
+ #
11
+ # @return [String]
12
+ #
13
+ DEFAULT_ENDPOINT = 'https://supermarket.chef.io/api/v1'
14
+
15
+ #
16
+ # Get and cache a community cookbook's JSON response from the given name
17
+ # and version.
18
+ #
19
+ # @example Find a cookbook by name
20
+ # Supermarket.cookbook('apache2') #=> {...}
21
+ #
22
+ # @example Find a cookbook by name and version
23
+ # Supermarket.cookbook('apache2', '1.0.0') #=> {...}
24
+ #
25
+ # @example Find a non-existent cookbook
26
+ # Supermarket.cookbook('not-real') #=> Community::BadResponse
27
+ #
28
+ # @raise [Supermarket::BadResponse]
29
+ # if the given cookbook (or cookbook version) does not exist on the Supermarket
30
+ #
31
+ # @param [String] name
32
+ # the name of the cookbook on the Supermarket
33
+ # @param [String] version (optional)
34
+ # the version of the cookbook to find
35
+ #
36
+ # @return [Hash]
37
+ # the hash of the cookbook
38
+ #
39
+ def cookbook(name, version = nil)
40
+ if version.nil?
41
+ connection.get("cookbooks/#{name}")
42
+ else
43
+ connection.get("cookbooks/#{name}/versions/#{Util.version_for_url(version)}")
44
+ end
45
+ end
46
+
47
+ #
48
+ # Upload a cookbook to the community site.
49
+ #
50
+ # @param [Cookbook] cookbook
51
+ # the cookbook to upload
52
+ #
53
+ def upload(cookbook, extended_metadata = false)
54
+ connection.post('cookbooks', {
55
+ 'tarball' => cookbook.tarball(extended_metadata),
56
+
57
+ # This is for legacy, backwards-compatability reasons. The new
58
+ # Supermarket site does not require a category, but many of the testing
59
+ # tools still assume a cookbook category is present. We just hardcode
60
+ # "Other" here.
61
+ 'cookbook' => JSON.fast_generate(category: 'Other'),
62
+ })
63
+ end
64
+
65
+ private
66
+
67
+ #
68
+ # The ChefAPI connection object with lots of pretty middleware.
69
+ #
70
+ def connection
71
+ @connection ||= ChefAPI::Connection.new do |conn|
72
+ conn.endpoint = ENV['STOVE_ENDPOINT'] || Config.endpoint || DEFAULT_ENDPOINT
73
+ conn.client = ENV['STOVE_USERNAME'] || Config.username
74
+ conn.key = ENV['STOVE_KEY'] || Config.key
75
+ conn.ssl_verify = ENV['STOVE_NO_SSL_VERIFY'] || Config.ssl_verify
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,56 @@
1
+ module Stove
2
+ module Util
3
+ extend self
4
+
5
+ # Convert a version string (x.y.z) to a community-site friendly format
6
+ # (x_y_z).
7
+ #
8
+ # @example Convert a version to a version string
9
+ # format_version('1.2.3') #=> 1_2_3
10
+ #
11
+ # @param [#to_s] version
12
+ # the version string to convert
13
+ #
14
+ # @return [String]
15
+ def version_for_url(version)
16
+ version
17
+ .to_s
18
+ .gsub('.', '_')
19
+ end
20
+
21
+ #
22
+ # Covert the given CaMelCaSeD string to under_score. Graciously borrowed
23
+ # from http://stackoverflow.com/questions/1509915.
24
+ #
25
+ # @param [String] string
26
+ # the string to use for transformation
27
+ #
28
+ # @return [String]
29
+ #
30
+ def underscore(string)
31
+ string
32
+ .to_s
33
+ .gsub(/::/, '/')
34
+ .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
35
+ .gsub(/([a-z\d])([A-Z])/,'\1_\2')
36
+ .tr('-', '_')
37
+ .downcase
38
+ end
39
+
40
+ #
41
+ # Convert an underscored string to it's camelcase equivalent constant.
42
+ #
43
+ # @param [String]
44
+ # the string to convert
45
+ #
46
+ # @return [String]
47
+ #
48
+ def camelize(string)
49
+ string
50
+ .to_s
51
+ .split('_')
52
+ .map { |e| e.capitalize }
53
+ .join
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ module Stove
2
+ class Validator
3
+ include Logify
4
+
5
+ include Mixin::Insideable
6
+
7
+ #
8
+ # The class that created this validator.
9
+ #
10
+ # @return [~Class]
11
+ #
12
+ attr_reader :klass
13
+
14
+ #
15
+ # The identifier or field this validator runs against.
16
+ #
17
+ # @return [Symbol]
18
+ #
19
+ attr_reader :id
20
+
21
+ #
22
+ # The block to execute to see if the validation passes.
23
+ #
24
+ # @return [Proc]
25
+ #
26
+ attr_reader :block
27
+
28
+ #
29
+ # Create a new validator object.
30
+ #
31
+ # @param [~Class] klass
32
+ # the class that created this validator
33
+ # @param [Symbol] id
34
+ # the identifier or field this validator runs against
35
+ # @param [Proc] block
36
+ # the block to execute to see if the validation passes
37
+ #
38
+ def initialize(klass, id, &block)
39
+ @klass = klass
40
+ @id = id
41
+ @block = block
42
+ end
43
+
44
+ #
45
+ # Execute this validation in the context of the creating class, inside the
46
+ # given cookbook's path.
47
+ #
48
+ # @param [Cookbook]
49
+ # the cookbook to run this validation against
50
+ #
51
+ def run(cookbook, options = {})
52
+ log.info("Running validations for `#{klass.id}.#{id}'")
53
+
54
+ inside(cookbook) do
55
+ instance = klass.new(cookbook, options)
56
+ unless result = instance.instance_eval(&block)
57
+ log.debug("Validation failed, result: #{result.inspect}")
58
+
59
+ # Convert the class and id to their magical equivalents
60
+ error = Error.const_get("#{Util.camelize(klass.id)}#{Util.camelize(id)}ValidationFailed")
61
+ raise error.new(path: Dir.pwd, result: result)
62
+ end
63
+ end
64
+
65
+ log.debug("Validation #{id} passed!")
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module Stove
2
+ VERSION = '7.1.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ '<%= @method %>' is an abstract method. You must override this method in your subclass with the proper implementation and logic. For more information, please see the inline documentation for <%= @method %>. If you are not a developer, this is most likely a bug in the ChefAPI gem. Please file a bug report at:
2
+
3
+ https://github.com/sethvargo/stove/issues/new
4
+
5
+ and include the command(s) or code you ran to arrive at this error.
@@ -0,0 +1,11 @@
1
+ You did not specify an Artifactory API key! You can pass the key either via a command line argument:
2
+
3
+ stove --artifactory-key sUeEpLXJvfhw3UZHbVPrGCgdou8VI6fXpD5sUHd0pKAxCmuGWNHLgerpFPkCJ2EjBBPYcM4My
4
+
5
+ Or via a file path:
6
+
7
+ stove --artifactory-key @~/.artifactory/api.key
8
+
9
+ Or via an environment variable:
10
+
11
+ export ARTIFACTORY_API_KEY=sUeEpLXJvfhw3UZHbVPrGCgdou8VI6fXpD5sUHd0pKAxCmuGWNHLgerpFPkCJ2EjBBPYcM4My
@@ -0,0 +1 @@
1
+ The cookbook at `<%= @path %>' has untracked files! In order to use the git plugin, you must have a clean working directory. Please commit or stash your changes before running Stove again.
@@ -0,0 +1,5 @@
1
+ An error occurred while running:
2
+
3
+ git <%= @command %>
4
+
5
+ There is likely an informative message from git that explains what happened right above this message.
@@ -0,0 +1,3 @@
1
+ The cookbook at `<%= @path %>' does not appear to be a valid git repository. In order to use the git plugin, your cookbook must be initialized as a git repository. To create a git repository, run:
2
+
3
+ git init <%= @path %>
@@ -0,0 +1,5 @@
1
+ An error occurred while attempting to tag the release in git by running:
2
+
3
+ git <%= @command %>
4
+
5
+ This often occurs when you've already attempted to release a cookbook with stove. If you would like to try to release again without git tagging use the '--no-git' option
@@ -0,0 +1,7 @@
1
+ The cookbook at `<%= @path %>' is out of sync with the remote repository. Please update your local cache with the remote repository before continuing:
2
+
3
+ git pull
4
+
5
+ And then push your local changes to the remote repository:
6
+
7
+ git push
@@ -0,0 +1 @@
1
+ The file at `<%= @path %>' does not exist or does not contain valid metadata. Please make sure you have specified the correct path and that the metdata file exists.
@@ -0,0 +1 @@
1
+ The server at `<%= @url %>' is unavailable or is not currently accepting client connections. Please ensure the server is accessible via ping (or telnet) on your local network. If this error persists, please contact your network administrator.
@@ -0,0 +1 @@
1
+ Oh no! Something really bad happened. I am not sure what actually happened because this is the catch-all error, but you should most definitely report an issue on GitHub at https://github.com/sethvargo/stove.
@@ -0,0 +1,5 @@
1
+ Cookbook <%= @cookbook.name %> already has a version <%= @cookbook.version %> uploaded.
2
+
3
+ Please change the version number before uploading again.
4
+
5
+ If you need to change an existing version, please remove it first.
@@ -0,0 +1,3 @@
1
+ You did not specify the path to a private key! The Chef Supermarket requires a private key for authentication:
2
+
3
+ stove --key ~/.chef/sethvargo.pem
@@ -0,0 +1,3 @@
1
+ You did not specify the username to authenticate with! The Chef Supermarket requires a username for authentication:
2
+
3
+ stove --username sethvargo
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-stove
3
+ version: !ruby/object:Gem::Version
4
+ version: 7.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Seth Vargo
8
+ - Tim Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-09-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chef-infra-api
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.5'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: logify
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.2'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.2'
42
+ - !ruby/object:Gem::Dependency
43
+ name: aruba
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.6.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.6.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: chef-community-zero
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '2.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '2.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '3.0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '3.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rspec-command
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: webmock
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '3.0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '3.0'
140
+ description: A utility for releasing Chef community cookbooks
141
+ email:
142
+ - sethvargo@gmail.com
143
+ - tsmith84@gmail.com
144
+ executables:
145
+ - stove
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - LICENSE
150
+ - bin/stove
151
+ - lib/stove.rb
152
+ - lib/stove/artifactory.rb
153
+ - lib/stove/cli.rb
154
+ - lib/stove/config.rb
155
+ - lib/stove/cookbook.rb
156
+ - lib/stove/cookbook/metadata.rb
157
+ - lib/stove/error.rb
158
+ - lib/stove/filter.rb
159
+ - lib/stove/mash.rb
160
+ - lib/stove/mixins/insideable.rb
161
+ - lib/stove/mixins/instanceable.rb
162
+ - lib/stove/mixins/optionable.rb
163
+ - lib/stove/mixins/validatable.rb
164
+ - lib/stove/packager.rb
165
+ - lib/stove/plugins/artifactory.rb
166
+ - lib/stove/plugins/base.rb
167
+ - lib/stove/plugins/git.rb
168
+ - lib/stove/plugins/supermarket.rb
169
+ - lib/stove/rake_task.rb
170
+ - lib/stove/runner.rb
171
+ - lib/stove/supermarket.rb
172
+ - lib/stove/util.rb
173
+ - lib/stove/validator.rb
174
+ - lib/stove/version.rb
175
+ - templates/errors/abstract_method.erb
176
+ - templates/errors/artifactory_key_validation_failed.erb
177
+ - templates/errors/git_clean_validation_failed.erb
178
+ - templates/errors/git_failed.erb
179
+ - templates/errors/git_repository_validation_failed.erb
180
+ - templates/errors/git_tagging_failed.erb
181
+ - templates/errors/git_up_to_date_validation_failed.erb
182
+ - templates/errors/metadata_not_found.erb
183
+ - templates/errors/server_unavailable.erb
184
+ - templates/errors/stove_error.erb
185
+ - templates/errors/supermarket_already_exists.erb
186
+ - templates/errors/supermarket_key_validation_failed.erb
187
+ - templates/errors/supermarket_username_validation_failed.erb
188
+ homepage: https://github.com/chef/stove
189
+ licenses:
190
+ - Apache-2.0
191
+ metadata: {}
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '2.3'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubyforge_project:
208
+ rubygems_version: 2.7.9
209
+ signing_key:
210
+ specification_version: 4
211
+ summary: A command-line utility for releasing Chef community cookbooks
212
+ test_files: []