Class: Deis::Client
- Inherits:
-
Object
- Object
- Deis::Client
- Defined in:
- lib/deis_client.rb
Constant Summary collapse
- @@methods =
{ # method => HTTP-verb, path login: [:post, '/auth/login/'], change_password: [:post, '/auth/passwd/'], apps: [:get, '/apps'], create_app: [:post, '/apps/'], delete_app: [:delete, '/apps/:app/'], app: [:get, '/apps/:app/'], app_logs: [:get, '/apps/:app/logs/'], app_run: [:post, '/apps/:app/run/'], containers: [:get, '/apps/:app/containers/'], containers_by_type: [:get, '/apps/:app/containers/:type/'], restart_containers: [:post, '/apps/:app/containers/restart/'], restart_containers_by_type: [:post, '/apps/:app/containers/:type/restart/'], restart_container: [:post, '/apps/:app/containers/:type/:number/restart'], scale: [:post, '/apps/:app/scale/'], config: [:get, '/apps/:app/config/'], set_config: [:post, '/apps/:app/config/'], domains: [:get, '/apps/:app/domains/'], add_domain: [:post, '/apps/:app/domains/'], remove_domain: [:delete, '/apps/:app/domains/:domain'], builds: [:get, '/apps/:app/builds/'], create_build: [:post, '/apps/:app/builds/'], releases: [:get, '/apps/:app/releases/'], release: [:get, '/apps/:app/releases/:release/'], rollback_release: [:post, '/apps/:app/releases/rollback/'], create_cert: [:post, '/certs/'], delete_cert: [:delete, '/certs/:domain'], certs: [:get, '/certs'], cert: [:get, '/certs/:domain'] }
Instance Method Summary collapse
- #add_domain(app_id, domain) ⇒ Object
- #app(id) ⇒ Object
- #app_logs(id) ⇒ Object
- #app_run(id, command) ⇒ Object
- #apps ⇒ Object
- #builds(app_id) ⇒ Object
- #cert(domain) ⇒ Object
- #certs ⇒ Object
- #change_password(old, new, opts = {}) ⇒ Object
- #config(app_id) ⇒ Object
- #containers(app_id, opts = {}) ⇒ Object
- #create_app(id = nil) ⇒ Object
- #create_build(app_id, image) ⇒ Object
- #create_cert(certificate, key, name = nil) ⇒ Object
- #delete_app(id) ⇒ Object
- #delete_cert(domain) ⇒ Object
- #domains(app_id) ⇒ Object
-
#initialize(deis_url, username, password) ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
- #release(app_id, release) ⇒ Object
- #releases(app_id) ⇒ Object
- #remove_domain(app_id, domain) ⇒ Object
- #restart_containers(app_id, opts = {}) ⇒ Object
- #rollback_release(app_id, release) ⇒ Object
- #scale(app_id, type_number_hash) ⇒ Object
- #set_config(app_id, values) ⇒ Object
Constructor Details
#initialize(deis_url, username, password) ⇒ Client
Returns a new instance of Client.
90 91 92 93 94 |
# File 'lib/deis_client.rb', line 90 def initialize(deis_url, username, password) @http = Deis::ApiWrapper.new deis_url @headers = {'Content-Type' => 'application/json'} @auth = { username: username, password: password } end |
Instance Method Details
#add_domain(app_id, domain) ⇒ Object
182 183 184 |
# File 'lib/deis_client.rb', line 182 def add_domain(app_id, domain) perform :add_domain, { app: app_id }, domain: domain end |
#app(id) ⇒ Object
134 135 136 |
# File 'lib/deis_client.rb', line 134 def app(id) perform :app, app: id end |
#app_logs(id) ⇒ Object
138 139 140 |
# File 'lib/deis_client.rb', line 138 def app_logs(id) perform :app_logs, app: id end |
#app_run(id, command) ⇒ Object
142 143 144 |
# File 'lib/deis_client.rb', line 142 def app_run(id, command) perform :app_run, { app: id }, command: command end |
#apps ⇒ Object
118 119 120 |
# File 'lib/deis_client.rb', line 118 def apps perform :apps end |
#builds(app_id) ⇒ Object
190 191 192 |
# File 'lib/deis_client.rb', line 190 def builds(app_id) perform :builds, app: app_id end |
#cert(domain) ⇒ Object
226 227 228 |
# File 'lib/deis_client.rb', line 226 def cert(domain) perform :cert, { domain: domain } end |
#certs ⇒ Object
222 223 224 |
# File 'lib/deis_client.rb', line 222 def certs perform :certs end |
#change_password(old, new, opts = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/deis_client.rb', line 107 def change_password(old, new, opts = {}) body = { password: old, new_password: new } body[:username] = opts[:username] if opts[:username] perform :change_password, {}, body end |
#config(app_id) ⇒ Object
170 171 172 |
# File 'lib/deis_client.rb', line 170 def config(app_id) perform :config, app: app_id end |
#containers(app_id, opts = {}) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/deis_client.rb', line 146 def containers(app_id, opts = {}) if opts[:type] perform :containers_by_type, app: app_id, type: opts[:type] else perform :containers, app: app_id end end |
#create_app(id = nil) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/deis_client.rb', line 122 def create_app(id = nil) if id perform :create_app, {}, id: id else perform :create_app end end |
#create_build(app_id, image) ⇒ Object
194 195 196 |
# File 'lib/deis_client.rb', line 194 def create_build(app_id, image) perform :create_build, { app: app_id }, image: image end |
#create_cert(certificate, key, name = nil) ⇒ Object
210 211 212 213 214 215 216 |
# File 'lib/deis_client.rb', line 210 def create_cert(certificate, key, name = nil) if name.nil? perform :create_cert, { }, { certificate: certificate, key: key } else perform :create_cert, { }, { certificate: certificate, key: key, common_name: name } end end |
#delete_app(id) ⇒ Object
130 131 132 |
# File 'lib/deis_client.rb', line 130 def delete_app(id) perform :delete_app, app: id end |
#delete_cert(domain) ⇒ Object
218 219 220 |
# File 'lib/deis_client.rb', line 218 def delete_cert(domain) perform :delete_cert, { domain: domain } end |
#domains(app_id) ⇒ Object
178 179 180 |
# File 'lib/deis_client.rb', line 178 def domains(app_id) perform :domains, app: app_id end |
#login ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/deis_client.rb', line 96 def login verb, path = @@methods[:login] response = @http.public_send(verb, path, body: @auth) raise AuthorizationError.new unless response.code == 200 @token = response['token'] @headers['Authorization'] = "token #{@token}" response end |
#release(app_id, release) ⇒ Object
202 203 204 |
# File 'lib/deis_client.rb', line 202 def release(app_id, release) perform :releases, app: app_id, release: release end |
#releases(app_id) ⇒ Object
198 199 200 |
# File 'lib/deis_client.rb', line 198 def releases(app_id) perform :releases, app: app_id end |
#remove_domain(app_id, domain) ⇒ Object
186 187 188 |
# File 'lib/deis_client.rb', line 186 def remove_domain(app_id, domain) perform :remove_domain, { app: app_id, domain: domain } end |
#restart_containers(app_id, opts = {}) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/deis_client.rb', line 154 def restart_containers(app_id, opts = {}) if opts[:type] if opts[:number] perform :restart_container, opts.merge(app: app_id) else perform :restart_containers_by_type, app: app_id, type: opts[:type] end else perform :restart_containers, app: app_id end end |
#rollback_release(app_id, release) ⇒ Object
206 207 208 |
# File 'lib/deis_client.rb', line 206 def rollback_release(app_id, release) perform :rollback_release, { app: app_id }, release: release end |
#scale(app_id, type_number_hash) ⇒ Object
166 167 168 |
# File 'lib/deis_client.rb', line 166 def scale(app_id, type_number_hash) perform :scale, { app: app_id }, type_number_hash end |
#set_config(app_id, values) ⇒ Object
174 175 176 |
# File 'lib/deis_client.rb', line 174 def set_config(app_id, values) perform :set_config, { app: app_id }, values: values end |