Class: DPL::Provider::ExoScale

Inherits:
DPL::Provider show all
Defined in:
lib/dpl/provider/exoscale.rb

Instance Attribute Summary collapse

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from DPL::Provider

apt_get, #cleanup, #commit_msg, context, #create_key, #default_text_charset, #default_text_charset?, #deploy, #detect_encoding?, #encoding_for, #error, experimental, #log, #needs_key?, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup, #user_agent, #warn

Constructor Details

#initialize(context, options) ⇒ ExoScale

Returns a new instance of ExoScale.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dpl/provider/exoscale.rb', line 11

def initialize(context, options)
  super
  option(:email) && option(:password) && option(:deployment)
  @app_name, @dep_name = options[:deployment].split('/')

  @http = Net::HTTP.new('api.app.exo.io', 443)
  @http.use_ssl = true

  @tokenHttp = Net::HTTP.new('portal.exoscale.ch', 443)
  @tokenHttp.use_ssl = true
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



8
9
10
# File 'lib/dpl/provider/exoscale.rb', line 8

def app_name
  @app_name
end

#dep_nameObject

Returns the value of attribute dep_name.



9
10
11
# File 'lib/dpl/provider/exoscale.rb', line 9

def dep_name
  @dep_name
end

Instance Method Details

#check_appObject



27
28
29
30
31
# File 'lib/dpl/provider/exoscale.rb', line 27

def check_app
  response = api_call('GET', "/app/#{ app_name }/deployment/#{ dep_name }")
  error('application check failed') if response.code != '200'
  @repository = JSON.parse(response.body)["branch"]
end

#check_authObject



23
24
25
# File 'lib/dpl/provider/exoscale.rb', line 23

def check_auth
  headers_with_token
end

#push_appObject



46
47
48
49
50
# File 'lib/dpl/provider/exoscale.rb', line 46

def push_app
  branch = (dep_name == 'default') ? 'master' : dep_name
  context.shell "git push #{ @repository } HEAD:#{ branch } -f"
  deploy_app
end

#remove_keyObject



41
42
43
44
# File 'lib/dpl/provider/exoscale.rb', line 41

def remove_key
  response = api_call('DELETE', "/user/#{ user['username']}/key/#{ @ssh_key_id }")
  error('key removal failed') if response.code != '204'
end

#setup_key(file) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/dpl/provider/exoscale.rb', line 33

def setup_key(file)
  data = { 'key' => File.read(file).chomp }
  response = api_call('POST', "/user/#{ user['username'] }/key", JSON.dump(data))
  error('adding key failed') if response.code != '200'
  key = JSON.parse response.body
  @ssh_key_id = key['key_id']
end