Class: Heroku::Kensa::Client
- Inherits:
-
Object
- Object
- Heroku::Kensa::Client
show all
- Defined in:
- lib/heroku/kensa/client.rb
Defined Under Namespace
Classes: CommandInvalid, OptParser, Screen
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args, options = {}) ⇒ Client
Returns a new instance of Client.
12
13
14
15
|
# File 'lib/heroku/kensa/client.rb', line 12
def initialize(args, options = {})
@args = args
@options = OptParser.parse(args).merge(options)
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10
11
12
|
# File 'lib/heroku/kensa/client.rb', line 10
def options
@options
end
|
Instance Method Details
#init ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/heroku/kensa/client.rb', line 25
def init
manifest = Manifest.new(@options)
protect_current_manifest!
manifest.write
screen.message "Initialized new addon manifest in #{filename}\n"
if @options[:foreman]
screen.message "Initialized new .env file\n"
end
end
|
#pull ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/heroku/kensa/client.rb', line 93
def pull
addon = @args.first || abort('usage: kensa pull <add-on name>')
protect_current_manifest!
user, password = ask_for_credentials
host = heroku_host
resource = RestClient::Resource.new(host, user, password)
manifest = resource["provider/addons/#{addon}"].get()
File.open(filename, 'w') { |f| f.puts manifest }
puts "-----> Manifest for \"#{addon}\" received successfully"
end
|
#push ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/heroku/kensa/client.rb', line 73
def push
user, password = ask_for_credentials
host = heroku_host
data = decoded_manifest
resource = RestClient::Resource.new(host, user, password)
manifest = resource['provider/addons'].post(resolve_manifest, )
puts "-----> Manifest for \"#{data['id']}\" was pushed successfully"
puts " Continue at #{(heroku_host)}/provider/addons/#{data['id']}"
File.open(filename, 'w') { |f| f.puts manifest } unless manifest.strip.empty?
rescue RestClient::UnprocessableEntity, RestClient::BadRequest => e
abort("FAILED: #{e.response}")
rescue RestClient::Unauthorized
abort("Authentication failure")
rescue RestClient::Forbidden
abort("Not authorized to push this manifest. Please make sure you have permissions to push it")
end
|
#run ⇒ Object
60
61
62
63
|
# File 'lib/heroku/kensa/client.rb', line 60
def run
abort "! missing command to run; see usage" if @args.empty?
run_check AllCheck, :args => @args
end
|
#run! ⇒ Object
19
20
21
22
23
|
# File 'lib/heroku/kensa/client.rb', line 19
def run!
command = @args.shift || @options[:command]
raise CommandInvalid unless command && respond_to?(command)
send(command)
end
|
#sso ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/heroku/kensa/client.rb', line 65
def sso
id = @args.shift || abort("! no id specified; see usage")
data = decoded_manifest
sso = Sso.new(data.merge(@options).merge(:id => id)).start
puts sso.message
Launchy.open sso.sso_url
end
|
#test ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/heroku/kensa/client.rb', line 35
def test
case check = @args.shift
when "manifest"
run_check ManifestCheck
when "provision"
run_check ManifestCheck, ProvisionCheck
when "deprovision"
id = @args.shift || abort("! no id specified; see usage")
run_check ManifestCheck, DeprovisionCheck, :id => id
when "planchange"
id = @args.shift || abort("! no id specified; see usage")
plan = @args.shift || abort("! no plan specified; see usage")
run_check ManifestCheck, PlanChangeCheck, :id => id, :plan => plan
when "sso"
id = @args.shift || abort("! no id specified; see usage")
run_check ManifestCheck, SsoCheck, :id => id
when "all"
run_check AllCheck
when nil
run_check AllCheck
else
abort "! Unknown test '#{check}'; see usage"
end
end
|
#version ⇒ Object
105
106
107
|
# File 'lib/heroku/kensa/client.rb', line 105
def version
puts "Kensa #{VERSION}"
end
|