stove 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ require 'logger'
2
+
3
+ module Stove
4
+ module Logger
5
+ class << self
6
+ def set_level(level)
7
+ logger.level = level
8
+ logger
9
+ end
10
+
11
+ def set_output(output)
12
+ old_level = @logger.sev_threshold
13
+
14
+ @logger = ::Logger.new(output)
15
+ @logger.level = old_level
16
+ @logger
17
+ end
18
+
19
+ [:fatal, :error, :warn, :info, :debug, :sev_threshold].each do |name|
20
+ define_method(name) do |*args|
21
+ logger.send(name, *args)
22
+ end
23
+ end
24
+
25
+ private
26
+ def logger
27
+ @logger ||= begin
28
+ logger = ::Logger.new($stdout)
29
+ logger.level = ::Logger::WARN
30
+ logger
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
data/lib/stove/mash.rb ADDED
@@ -0,0 +1,25 @@
1
+ module Stove
2
+ class Mash < ::Hash
3
+ def method_missing(m, *args, &block)
4
+ if has_key?(m.to_sym)
5
+ self[m.to_sym]
6
+ elsif has_key?(m.to_s)
7
+ self[m.to_s]
8
+ else
9
+ super
10
+ end
11
+ end
12
+
13
+ def methods(include_private = false)
14
+ super + self.keys.map(&:to_sym)
15
+ end
16
+
17
+ def respond_to?(m, include_private = false)
18
+ if has_key?(m.to_sym) || has_key?(m.to_s)
19
+ true
20
+ else
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,82 @@
1
+ require 'archive/tar/minitar'
2
+ require 'fileutils'
3
+ require 'tmpdir'
4
+ require 'tempfile'
5
+ require 'zlib'
6
+
7
+ module Stove
8
+ class Packager
9
+ ACCEPTABLE_FILES = [
10
+ 'README.*',
11
+ 'CHANGELOG.*',
12
+ 'metadata.{json,rb}',
13
+ 'attributes',
14
+ 'definitions',
15
+ 'files',
16
+ 'libraries',
17
+ 'providers',
18
+ 'recipes',
19
+ 'resources',
20
+ 'templates',
21
+ ]
22
+
23
+ # The cookbook to package.
24
+ #
25
+ # @erturn [Stove::Cookbook]
26
+ attr_reader :cookbook
27
+
28
+ # Create a new packager instance.
29
+ #
30
+ # @param [Stove::Cookbook]
31
+ # the cookbook to package
32
+ def initialize(cookbook)
33
+ @cookbook = cookbook
34
+ end
35
+
36
+ # The list of files that should actually be uploaded.
37
+ #
38
+ # @return [Array]
39
+ # the array of file paths
40
+ def cookbook_files
41
+ Dir.glob("#{File.expand_path(cookbook.path)}/{#{ACCEPTABLE_FILES.join(',')}}")
42
+ end
43
+
44
+ # The path to the tar.gz package in the temporary directory.
45
+ #
46
+ # @return [String]
47
+ def package_path
48
+ pack!
49
+ end
50
+
51
+ private
52
+ def pack!
53
+ destination = Tempfile.new(cookbook.name).path
54
+
55
+ # Sandbox
56
+ sandbox = Dir.mktmpdir
57
+ FileUtils.mkdir_p(sandbox)
58
+
59
+ # Containing folder
60
+ container = File.join(sandbox, cookbook.name)
61
+ FileUtils.mkdir_p(container)
62
+
63
+ # Copy filles
64
+ FileUtils.cp_r(cookbook_files, container)
65
+
66
+ # Generate metadata
67
+ File.open(File.join(container, 'metadata.json'), 'w') do |f|
68
+ f.write(cookbook.metadata.to_json)
69
+ end
70
+
71
+ Dir.chdir(sandbox) do |dir|
72
+ # This is super fucking annoying. The community site should really
73
+ # be better at reading tarballs
74
+ relative_path = container.gsub(sandbox + '/', '') + '/'
75
+ tgz = Zlib::GzipWriter.new(File.open(destination, 'wb'))
76
+ Archive::Tar::Minitar.pack(relative_path, tgz)
77
+ end
78
+
79
+ return destination
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,73 @@
1
+ require 'httparty'
2
+ require 'httmultiparty'
3
+ require 'mixlib/authentication/signedheaderauth'
4
+ require 'openssl'
5
+
6
+ module Stove
7
+ class Uploader
8
+ include HTTMultiParty
9
+
10
+ # The cookbook associated with this uploader
11
+ #
12
+ # @return [Stove::Cookbook]
13
+ attr_reader :cookbook
14
+
15
+ # Create a new uploader instance for the given cookbook.
16
+ #
17
+ # @param [Stove::Cookbook] cookbook
18
+ # the cookbook for this uploader
19
+ def initialize(cookbook)
20
+ @cookbook = cookbook
21
+ end
22
+
23
+ def upload!
24
+ response = self.class.post(upload_url, {
25
+ :headers => headers,
26
+ :query => {
27
+ :tarball => File.new(tarball),
28
+ :cookbook => { category: cookbook.category }.to_json,
29
+ },
30
+ })
31
+
32
+ if response.success?
33
+ Stove.formatter.upload(cookbook)
34
+ else
35
+ raise Stove::UploadError.new(response)
36
+ end
37
+ end
38
+
39
+ private
40
+ def headers
41
+ {
42
+ 'Accept' => 'application/json',
43
+ }.merge(Mixlib::Authentication::SignedHeaderAuth.signing_object({
44
+ :http_method => 'post',
45
+ :timestamp => Time.now.utc.iso8601,
46
+ :user_id => username,
47
+ :path => URI.parse(upload_url).path,
48
+ :file => File.new(tarball),
49
+ }).sign(pem_file))
50
+ end
51
+
52
+ # So there's this really really crazy bug that the tmp directory could
53
+ # be deleted mid-request...
54
+ def tarball
55
+ begin
56
+ tgz = Stove::Packager.new(cookbook).package_path
57
+ end until File.exists?(tgz)
58
+ tgz
59
+ end
60
+
61
+ def pem_file
62
+ OpenSSL::PKey::RSA.new(File.read(File.expand_path(Stove::Config['opscode_pem_file'])))
63
+ end
64
+
65
+ def username
66
+ Stove::Config['opscode_username']
67
+ end
68
+
69
+ def upload_url
70
+ "#{Stove::CommunitySite.base_uri}/cookbooks"
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Stove
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,33 @@
1
+ require 'community_zero/server'
2
+
3
+ module Stove
4
+ module RSpec
5
+ module CommunitySite
6
+ class << self
7
+ def start(options = {})
8
+ return @server if @server
9
+
10
+ @server = CommunityZero::Server.new(options)
11
+ @server.start_background
12
+ @server
13
+ end
14
+
15
+ def stop
16
+ @server.stop if running?
17
+ end
18
+
19
+ def running?
20
+ !!(@server && @server.running?)
21
+ end
22
+
23
+ def reset!
24
+ @server && @server.reset!
25
+ end
26
+
27
+ def server_url
28
+ @server && @server.url
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,51 @@
1
+ require 'fileutils'
2
+
3
+ module Stove
4
+ module RSpec
5
+ module Git
6
+ include Stove::Git
7
+
8
+ def git_init(path = Dir.pwd)
9
+ Dir.chdir(path) do
10
+ git 'init .'
11
+ git 'add --all'
12
+ git 'commit --message "Initial commit"'
13
+ git 'remote add origin file://' + fake_git_remote
14
+ end
15
+ end
16
+
17
+ def fake_git_remote
18
+ path = File.expand_path(File.join(tmp_path, 'remote.git'))
19
+ return path if File.exists?(path)
20
+
21
+ FileUtils.mkdir_p(path)
22
+ Dir.chdir(path) do
23
+ git 'init .'
24
+ git 'config receive.denyCurrentBranch ignore'
25
+ git 'config receive.denyNonFastforwards true'
26
+ git 'config core.sharedrepository 1'
27
+ end
28
+
29
+ path
30
+ end
31
+
32
+ def git_shas(path)
33
+ Dir.chdir(path) do
34
+ git('log --oneline').split("\n").map { |line| line.split(/\s+/, 2).first.strip } rescue []
35
+ end
36
+ end
37
+
38
+ def git_commits(path)
39
+ Dir.chdir(path) do
40
+ git('log --oneline').split("\n").map { |line| line.split(/\s+/, 2).last.strip } rescue []
41
+ end
42
+ end
43
+
44
+ def git_tags(path)
45
+ Dir.chdir(path) do
46
+ git('tag --list').split("\n").map(&:strip) rescue []
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
data/stove.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stove/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'stove'
8
+ spec.version = Stove::VERSION
9
+ spec.authors = ['Seth Vargo']
10
+ spec.email = ['sethvargo@gmail.com']
11
+ spec.description = %q{A simple gem for packaging, releasing, and sanity-checking a community cookbook}
12
+ spec.summary = %q{A simple gem for packaging, releasing, and sanity-checking an Opscode community cookbook. This gem automatically packages the appropiate files, syncs with JIRA issues (if applicable), and automatically generates CHANGELOGs.}
13
+ spec.homepage = 'https://github.com/sethvargo/stove'
14
+ spec.license = 'Apache 2.0'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'httparty', '~> 0.11'
22
+ spec.add_dependency 'httmultiparty', '~> 0.3'
23
+ spec.add_dependency 'jiralicious', '~> 0.3'
24
+ spec.add_dependency 'minitar', '~> 0.5'
25
+ spec.add_dependency 'mixlib-authentication', '~> 1.3'
26
+ spec.add_dependency 'solve', '~> 0.8'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.3'
29
+ spec.add_development_dependency 'rake'
30
+
31
+ spec.add_development_dependency 'aruba', '~> 0.5'
32
+ spec.add_development_dependency 'community-zero', '~> 1.1'
33
+ spec.add_development_dependency 'rspec', '~> 2.14'
34
+ end
metadata ADDED
@@ -0,0 +1,251 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stove
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Seth Vargo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httmultiparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jiralicious
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mixlib-authentication
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: solve
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: aruba
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '0.5'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '0.5'
139
+ - !ruby/object:Gem::Dependency
140
+ name: community-zero
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '1.1'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: '1.1'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: '2.14'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: '2.14'
167
+ description: A simple gem for packaging, releasing, and sanity-checking a community
168
+ cookbook
169
+ email:
170
+ - sethvargo@gmail.com
171
+ executables:
172
+ - bake
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - .gitignore
177
+ - .travis.yml
178
+ - Gemfile
179
+ - LICENSE
180
+ - README.md
181
+ - Rakefile
182
+ - bin/bake
183
+ - features/changelog.feature
184
+ - features/cli.feature
185
+ - features/git.feature
186
+ - features/step_definitions/cli_steps.rb
187
+ - features/step_definitions/community_site_steps.rb
188
+ - features/step_definitions/cookbook_steps.rb
189
+ - features/step_definitions/git_steps.rb
190
+ - features/support/env.rb
191
+ - features/upload.feature
192
+ - lib/stove.rb
193
+ - lib/stove/cli.rb
194
+ - lib/stove/community_site.rb
195
+ - lib/stove/config.rb
196
+ - lib/stove/cookbook.rb
197
+ - lib/stove/cookbook/metadata.rb
198
+ - lib/stove/error.rb
199
+ - lib/stove/formatter.rb
200
+ - lib/stove/formatter/base.rb
201
+ - lib/stove/formatter/human.rb
202
+ - lib/stove/formatter/silent.rb
203
+ - lib/stove/git.rb
204
+ - lib/stove/jira.rb
205
+ - lib/stove/logger.rb
206
+ - lib/stove/mash.rb
207
+ - lib/stove/packager.rb
208
+ - lib/stove/uploader.rb
209
+ - lib/stove/version.rb
210
+ - spec/support/community_site.rb
211
+ - spec/support/git.rb
212
+ - stove.gemspec
213
+ homepage: https://github.com/sethvargo/stove
214
+ licenses:
215
+ - Apache 2.0
216
+ metadata: {}
217
+ post_install_message:
218
+ rdoc_options: []
219
+ require_paths:
220
+ - lib
221
+ required_ruby_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - '>='
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ required_rubygems_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - '>='
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ requirements: []
232
+ rubyforge_project:
233
+ rubygems_version: 2.0.3
234
+ signing_key:
235
+ specification_version: 4
236
+ summary: A simple gem for packaging, releasing, and sanity-checking an Opscode community
237
+ cookbook. This gem automatically packages the appropiate files, syncs with JIRA
238
+ issues (if applicable), and automatically generates CHANGELOGs.
239
+ test_files:
240
+ - features/changelog.feature
241
+ - features/cli.feature
242
+ - features/git.feature
243
+ - features/step_definitions/cli_steps.rb
244
+ - features/step_definitions/community_site_steps.rb
245
+ - features/step_definitions/cookbook_steps.rb
246
+ - features/step_definitions/git_steps.rb
247
+ - features/support/env.rb
248
+ - features/upload.feature
249
+ - spec/support/community_site.rb
250
+ - spec/support/git.rb
251
+ has_rdoc: