27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/travis/deploy/secure_key.rb', line 27
def fetch_key
uri = URI.parse("https://#{host}/repos/#{slug}/key")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri, 'Accept' => 'application/vnd.travis-ci.2+json')
response = http.request(request)
if response.code.to_i == 200
body = MultiJson.decode(response.body)
public_key = body['key']
begin
OpenSSL::PKey::RSA.new(public_key)
rescue OpenSSL::PKey::RSAError
public_key.gsub!('RSA PUBLIC KEY', 'PUBLIC KEY')
OpenSSL::PKey::RSA.new(public_key)
end
else
raise FetchKeyError
end
end
|