Module: Dawn
- Defined in:
- lib/dawn/api/hosts.rb,
lib/dawn/api/version.rb,
lib/dawn/api/base_api.rb,
lib/dawn/api/models/app.rb,
lib/dawn/api/models/key.rb,
lib/dawn/api/models/gear.rb,
lib/dawn/api/authenticate.rb,
lib/dawn/api/health_check.rb,
lib/dawn/api/models/drain.rb,
lib/dawn/api/models/login.rb,
lib/dawn/api/models/domain.rb,
lib/dawn/api/safe/base_api.rb,
lib/dawn/api/models/account.rb,
lib/dawn/api/models/app/env.rb,
lib/dawn/api/models/release.rb,
lib/dawn/api/models/app/gears.rb,
lib/dawn/api/models/app/drains.rb,
lib/dawn/api/models/app/domains.rb,
lib/dawn/api/models/app/releases.rb,
lib/dawn/api/safe/safe_extension.rb
Overview
Defined Under Namespace
Modules: API, BaseApi, SafeExtension
Classes: Account, App, AuthenticationError, Domain, Drain, Gear, Key, Release, User
Constant Summary
collapse
{
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Accept-Encoding' => 'gzip',
'User-Agent' => "dawn/#{API::VERSION}",
'X-Ruby-Version' => RUBY_VERSION,
'X-Ruby-Platform' => RUBY_PLATFORM
}
- OPTIONS =
{
headers: {},
nonblock: false,
}
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.last_response_body ⇒ Object
Returns the value of attribute last_response_body.
28
29
30
|
# File 'lib/dawn/api/authenticate.rb', line 28
def last_response_body
@last_response_body
end
|
.log ⇒ Object
Returns the value of attribute log.
29
30
31
|
# File 'lib/dawn/api/authenticate.rb', line 29
def log
@log
end
|
Class Method Details
. ⇒ Object
. ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/dawn/api/authenticate.rb', line 67
def self.authenticate(options={})
options = OPTIONS.merge(host: dawn_api_host, scheme: dawn_scheme).merge(options)
options[:headers] = options[:headers].merge(HEADERS)
@api_key = options.delete(:api_key) || ENV['DAWN_API_KEY']
if !@api_key
hostname = options[:host]
url = "#{options[:scheme]}://#{hostname}"
if options.key?(:username) && options.key?(:password)
username = options.delete(:username)
password = options.delete(:password)
@connection = Excon.new url, headers: HEADERS
@api_key = User.login(username: username, password: password)['api_key']
netrc = Netrc.read
netrc[hostname] = username, @api_key
netrc.save
else
netrc = Netrc.read
username, api_key = netrc[hostname]
if api_key
@api_key = api_key
else
raise AuthenticationError, "api_key was not found, try dawn login to reset your .netrc"
end
end
end
@headers = HEADERS.merge(
'Authorization' => "Basic #{::Base64.strict_encode64("#{username}:#{@api_key}")}"
)
@connection = Excon.new "#{options[:scheme]}://#{options[:host]}", headers: @headers
end
|
.dawn_api_host ⇒ String
19
20
21
|
# File 'lib/dawn/api/hosts.rb', line 19
def self.dawn_api_host
ENV["DAWN_API_HOST"] || "api.#{dawn_host}"
end
|
.dawn_host ⇒ String
12
13
14
|
# File 'lib/dawn/api/hosts.rb', line 12
def self.dawn_host
ENV["DAWN_HOST"] || "dawn.dev"
end
|
.dawn_scheme ⇒ String
5
6
7
|
# File 'lib/dawn/api/hosts.rb', line 5
def self.dawn_scheme
ENV["DAWN_SCHEME"] || "http"
end
|
.debug(*args, &block) ⇒ Object
wrapper method for @log.puts This method will do nothing if log is nil or false
38
39
40
|
# File 'lib/dawn/api/authenticate.rb', line 38
def self.debug(*args, &block)
@log && @log.puts(*args, &block)
end
|
.git_host ⇒ String
26
27
28
|
# File 'lib/dawn/api/hosts.rb', line 26
def self.git_host
ENV["DAWN_GIT_HOST"] || "#{dawn_host}:2201"
end
|
.log_host ⇒ String
33
34
35
|
# File 'lib/dawn/api/hosts.rb', line 33
def self.log_host
ENV["DAWN_LOG_HOST"] || "#{dawn_host}:8001"
end
|
.request(options) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/dawn/api/authenticate.rb', line 45
def self.request(options)
Dawn.authenticate unless @connection
response = @connection.request(options)
self.last_response_body = response.body
response
rescue Excon::Errors::HTTPStatusError => ex
self.last_response_body = ex.response.body
debug Time.now.strftime("%D %T")
debug options.inspect
debug ex.response.body
debug "\n"
raise ex
end
|