kensa 1.0.0 → 1.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -15,10 +15,10 @@ begin
15
15
  require 'heroku/kensa'
16
16
  Jeweler::Tasks.new do |gemspec|
17
17
  gemspec.name = "kensa"
18
- gemspec.summary = ""
19
- gemspec.description = ""
18
+ gemspec.summary = "Tool to help Heroku add-on providers integrating their services"
19
+ gemspec.description = "Kensa is a command-line tool to help add-on providers integrating their services with Heroku. It manages manifest files, and provides a TDD-like approach for programmers to test and develop their APIs."
20
20
  gemspec.email = "pedro@heroku.com"
21
- gemspec.homepage = "http://heroku.com"
21
+ gemspec.homepage = "http://provider.heroku.com/resources"
22
22
  gemspec.authors = ["Blake Mizerany", "Pedro Belo", "Adam Wiggins"]
23
23
 
24
24
  gemspec.add_development_dependency(%q<turn>, [">= 0"])
data/bin/kensa CHANGED
@@ -18,6 +18,7 @@ ARGV.options do |o|
18
18
  o.on("--production") { options[:env] = "production" }
19
19
  o.on("--without-sso") { options[:sso] = false }
20
20
  o.on("-h", "--help") { command = "help" }
21
+ o.on("-p plan", "--plan") { |plan| options[:plan] = plan }
21
22
  o.on("-v", "--version") { options[:command] = "version" }
22
23
  o.parse!
23
24
  end
@@ -44,6 +45,9 @@ OPTIONS
44
45
  -h, --help
45
46
  Show this message
46
47
 
48
+ -p, --plan
49
+ Provision the specified plan instead of "test"
50
+
47
51
  --async
48
52
  Check provision call with async response.
49
53
 
@@ -70,6 +74,9 @@ TEST TYPES
70
74
  deprovision <id>
71
75
  Simulate a deprovision call from Heroku.
72
76
 
77
+ planchange <id> <new_plan>
78
+ Simulate a plan change call from Heroku.
79
+
73
80
  sso <id>
74
81
  Simulate a single sign-on call from Heroku.
75
82
 
data/kensa.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kensa}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1.pre"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Blake Mizerany", "Pedro Belo", "Adam Wiggins"]
12
- s.date = %q{2010-09-14}
12
+ s.date = %q{2010-09-27}
13
13
  s.default_executable = %q{kensa}
14
- s.description = %q{}
14
+ s.description = %q{Kensa is a command-line tool to help add-on providers integrating their services with Heroku. It manages manifest files, and provides a TDD-like approach for programmers to test and develop their APIs.}
15
15
  s.email = %q{pedro@heroku.com}
16
16
  s.executables = ["kensa"]
17
17
  s.extra_rdoc_files = [
@@ -31,10 +31,11 @@ Gem::Specification.new do |s|
31
31
  "lib/heroku/kensa/sso.rb",
32
32
  "set-env.sh",
33
33
  "test/all_check_test.rb",
34
- "test/deprovision_check.rb",
34
+ "test/deprovision_check_test.rb",
35
35
  "test/helper.rb",
36
36
  "test/manifest_check_test.rb",
37
37
  "test/manifest_test.rb",
38
+ "test/plan_change_check_test.rb",
38
39
  "test/provision_check_test.rb",
39
40
  "test/provision_response_check_test.rb",
40
41
  "test/resources/runner.rb",
@@ -42,17 +43,18 @@ Gem::Specification.new do |s|
42
43
  "test/sso_check_test.rb",
43
44
  "test/sso_test.rb"
44
45
  ]
45
- s.homepage = %q{http://heroku.com}
46
+ s.homepage = %q{http://provider.heroku.com/resources}
46
47
  s.rdoc_options = ["--charset=UTF-8"]
47
48
  s.require_paths = ["lib"]
48
49
  s.rubygems_version = %q{1.3.6}
49
- s.summary = %q{}
50
+ s.summary = %q{Tool to help Heroku add-on providers integrating their services}
50
51
  s.test_files = [
51
52
  "test/all_check_test.rb",
52
- "test/deprovision_check.rb",
53
+ "test/deprovision_check_test.rb",
53
54
  "test/helper.rb",
54
55
  "test/manifest_check_test.rb",
55
56
  "test/manifest_test.rb",
57
+ "test/plan_change_check_test.rb",
56
58
  "test/provision_check_test.rb",
57
59
  "test/provision_response_check_test.rb",
58
60
  "test/resources/runner.rb",
data/lib/heroku/kensa.rb CHANGED
@@ -5,6 +5,6 @@ require 'heroku/kensa/sso'
5
5
 
6
6
  module Heroku
7
7
  module Kensa
8
- VERSION = "1.0.0"
8
+ VERSION = "1.0.1.pre"
9
9
  end
10
10
  end
@@ -148,10 +148,13 @@ module Heroku
148
148
  def call!
149
149
  response = data[:provision_response]
150
150
  test "response"
151
+
151
152
  check "contains an id" do
152
153
  response.is_a?(Hash) && response.has_key?("id")
153
154
  end
154
155
 
156
+ screen.message " (id #{response['id']})"
157
+
155
158
  if response.has_key?("config")
156
159
  test "config data"
157
160
  check "is a hash" do
@@ -225,7 +228,7 @@ module Heroku
225
228
 
226
229
  payload = {
227
230
  :heroku_id => APPID,
228
- :plan => 'test',
231
+ :plan => data[:plan] || 'test',
229
232
  :callback_url => callback
230
233
  }
231
234
 
@@ -328,6 +331,40 @@ module Heroku
328
331
  end
329
332
 
330
333
 
334
+ class PlanChangeCheck < ApiCheck
335
+ include HTTP
336
+
337
+ def call!
338
+ id = data[:id]
339
+ raise ArgumentError, "No id specified" if id.nil?
340
+
341
+ new_plan = data[:plan]
342
+ raise ArgumentError, "No plan specified" if new_plan.nil?
343
+
344
+ path = "/heroku/resources/#{CGI::escape(id.to_s)}"
345
+
346
+ test "PUT #{path}"
347
+ check "response" do
348
+ code, _ = put(credentials, path, { :plan => new_plan})
349
+ if code == 200
350
+ true
351
+ elsif code == -1
352
+ error("unable to connect to #{url}")
353
+ else
354
+ error("expected 200, got #{code}")
355
+ end
356
+ end
357
+
358
+ check "authentication" do
359
+ wrong_credentials = ['wrong', 'secret']
360
+ code, _ = delete(wrong_credentials, path, nil)
361
+ error("expected 401, got #{code}") if code != 401
362
+ true
363
+ end
364
+ end
365
+ end
366
+
367
+
331
368
  class SsoCheck < ApiCheck
332
369
  include HTTP
333
370
 
@@ -406,13 +443,13 @@ module Heroku
406
443
  if args
407
444
  screen.message "\n\n"
408
445
  screen.message "Starting #{args.first}..."
409
- screen.message ""
446
+ screen.message "\n\n"
410
447
 
411
448
  run_in_env(config) { system(*args) }
412
449
  error("run exited abnormally, expected 0, got #{$?.to_i}") unless $?.to_i == 0
413
450
 
414
- screen.message ""
415
- screen.message "End of #{args.first}"
451
+ screen.message "\n"
452
+ screen.message "End of #{args.first}\n"
416
453
  end
417
454
 
418
455
  run DeprovisionCheck, data
@@ -39,6 +39,11 @@ module Heroku
39
39
  id = ARGV.shift || abort("! no id specified; see usage")
40
40
  run_check ManifestCheck
41
41
  run_check DeprovisionCheck, :id => id
42
+ when "planchange"
43
+ id = ARGV.shift || abort("! no id specified; see usage")
44
+ plan = ARGV.shift || abort("! no plan specified; see usage")
45
+ run_check ManifestCheck
46
+ run_check PlanChangeCheck, :id => id, :plan => plan
42
47
  when "sso"
43
48
  id = ARGV.shift || abort("! no id specified; see usage")
44
49
  run_check ManifestCheck
@@ -63,11 +68,10 @@ module Heroku
63
68
  end
64
69
 
65
70
  def push
66
- require_heroku
67
- client = Heroku::Command.run "auth:client", ['--ignore-keys']
71
+ user, password = ask_for_credentials
68
72
  host = ENV['ADDONS_HOST'] || 'https://addons.heroku.com'
69
73
  data = Yajl::Parser.parse(resolve_manifest)
70
- resource = RestClient::Resource.new(host, client.user, client.password)
74
+ resource = RestClient::Resource.new(host, user, password)
71
75
  resource['provider/addons'].post(resolve_manifest)
72
76
  puts "-----> Manifest for \"#{data['id']}\" was pushed successfully"
73
77
  puts " Continue at https://provider.heroku.com/addons/#{data['id']}"
@@ -99,12 +103,53 @@ module Heroku
99
103
  screen.finish
100
104
  end
101
105
 
102
- def require_heroku
103
- require 'heroku'
104
- require 'heroku/command'
105
- require 'heroku/commands/auth'
106
- rescue LoadError
107
- abort("fatal: Could not load the Heroku gem. Plase make sure the Heroku gem is available and up to date")
106
+ def running_on_windows?
107
+ RUBY_PLATFORM =~ /mswin32|mingw32/
108
+ end
109
+
110
+ def echo_off
111
+ system "stty -echo"
112
+ end
113
+
114
+ def echo_on
115
+ system "stty echo"
116
+ end
117
+
118
+ def ask_for_credentials
119
+ puts "Enter your Heroku Provider credentials."
120
+
121
+ print "Email: "
122
+ user = gets.strip
123
+
124
+ print "Password: "
125
+ password = running_on_windows? ? ask_for_password_on_windows : ask_for_password
126
+
127
+ [ user, password ]
128
+ end
129
+
130
+ def ask_for_password_on_windows
131
+ require "Win32API"
132
+ char = nil
133
+ password = ''
134
+
135
+ while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do
136
+ break if char == 10 || char == 13 # received carriage return or newline
137
+ if char == 127 || char == 8 # backspace and delete
138
+ password.slice!(-1, 1)
139
+ else
140
+ password << char.chr
141
+ end
142
+ end
143
+ puts
144
+ return password
145
+ end
146
+
147
+ def ask_for_password
148
+ echo_off
149
+ password = gets.strip
150
+ puts
151
+ echo_on
152
+ return password
108
153
  end
109
154
 
110
155
 
@@ -132,7 +177,7 @@ module Heroku
132
177
  end
133
178
 
134
179
  def message(msg)
135
- $stdout.puts msg
180
+ $stdout.print msg
136
181
  end
137
182
 
138
183
  def finish
@@ -13,6 +13,10 @@ module Heroku
13
13
  request(:post, credentials, path, payload)
14
14
  end
15
15
 
16
+ def put(credentials, path, payload=nil)
17
+ request(:put, credentials, path, payload)
18
+ end
19
+
16
20
  def delete(credentials, path, payload=nil)
17
21
  request(:delete, credentials, path, payload)
18
22
  end
@@ -0,0 +1,28 @@
1
+ require 'test/helper'
2
+
3
+ class PlanChangeCheckTest < Test::Unit::TestCase
4
+ include Heroku::Kensa
5
+
6
+ setup do
7
+ @data = Manifest.new.skeleton.merge :id => 123, :plan => 'premium'
8
+ @data['api']['username'] = 'test'
9
+ @data['api']['password'] = 'secret'
10
+ end
11
+
12
+ def check ; PlanChangeCheck ; end
13
+
14
+ test "working plan change call" do
15
+ @data['api']['test'] += "working"
16
+ assert_valid
17
+ end
18
+
19
+ test "detects invalid status" do
20
+ @data['api']['test'] += "invalid-status"
21
+ assert_invalid
22
+ end
23
+
24
+ test "detects missing auth" do
25
+ @data['api']['test'] += "invalid-missing-auth"
26
+ assert_invalid
27
+ end
28
+ end
@@ -64,6 +64,22 @@ post '/invalid-missing-auth/heroku/resources' do
64
64
  end
65
65
 
66
66
 
67
+ put '/working/heroku/resources/:id' do
68
+ heroku_only!
69
+ {}.to_json
70
+ end
71
+
72
+ put '/invalid-missing-auth/heroku/resources/:id' do
73
+ { :id => 123 }.to_json
74
+ end
75
+
76
+ put '/invalid-status/heroku/resources/:id' do
77
+ heroku_only!
78
+ status 422
79
+ {}.to_json
80
+ end
81
+
82
+
67
83
  delete '/working/heroku/resources/:id' do
68
84
  heroku_only!
69
85
  "Ok"
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kensa
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 0
9
- version: 1.0.0
8
+ - 1
9
+ - pre
10
+ version: 1.0.1.pre
10
11
  platform: ruby
11
12
  authors:
12
13
  - Blake Mizerany
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-09-14 00:00:00 -07:00
20
+ date: 2010-09-27 00:00:00 -07:00
20
21
  default_executable: kensa
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -138,7 +139,7 @@ dependencies:
138
139
  version: 1.0.0
139
140
  type: :runtime
140
141
  version_requirements: *id009
141
- description: ""
142
+ description: Kensa is a command-line tool to help add-on providers integrating their services with Heroku. It manages manifest files, and provides a TDD-like approach for programmers to test and develop their APIs.
142
143
  email: pedro@heroku.com
143
144
  executables:
144
145
  - kensa
@@ -160,10 +161,11 @@ files:
160
161
  - lib/heroku/kensa/sso.rb
161
162
  - set-env.sh
162
163
  - test/all_check_test.rb
163
- - test/deprovision_check.rb
164
+ - test/deprovision_check_test.rb
164
165
  - test/helper.rb
165
166
  - test/manifest_check_test.rb
166
167
  - test/manifest_test.rb
168
+ - test/plan_change_check_test.rb
167
169
  - test/provision_check_test.rb
168
170
  - test/provision_response_check_test.rb
169
171
  - test/resources/runner.rb
@@ -171,7 +173,7 @@ files:
171
173
  - test/sso_check_test.rb
172
174
  - test/sso_test.rb
173
175
  has_rdoc: true
174
- homepage: http://heroku.com
176
+ homepage: http://provider.heroku.com/resources
175
177
  licenses: []
176
178
 
177
179
  post_install_message:
@@ -188,24 +190,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
190
  version: "0"
189
191
  required_rubygems_version: !ruby/object:Gem::Requirement
190
192
  requirements:
191
- - - ">="
193
+ - - ">"
192
194
  - !ruby/object:Gem::Version
193
195
  segments:
194
- - 0
195
- version: "0"
196
+ - 1
197
+ - 3
198
+ - 1
199
+ version: 1.3.1
196
200
  requirements: []
197
201
 
198
202
  rubyforge_project:
199
203
  rubygems_version: 1.3.6
200
204
  signing_key:
201
205
  specification_version: 3
202
- summary: ""
206
+ summary: Tool to help Heroku add-on providers integrating their services
203
207
  test_files:
204
208
  - test/all_check_test.rb
205
- - test/deprovision_check.rb
209
+ - test/deprovision_check_test.rb
206
210
  - test/helper.rb
207
211
  - test/manifest_check_test.rb
208
212
  - test/manifest_test.rb
213
+ - test/plan_change_check_test.rb
209
214
  - test/provision_check_test.rb
210
215
  - test/provision_response_check_test.rb
211
216
  - test/resources/runner.rb