8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/terraspace_bundler/mod/http/concern.rb', line 8
def http_request(url, auth_domain: nil)
uri = URI(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
http.max_retries = 1 http.read_timeout = 20 request = Net::HTTP::Get.new(uri)
if auth_domain
path = "#{ENV['HOME']}/.terraform.d/credentials.tfrc.json"
if File.exist?(path)
data = JSON.load(IO.read(path))
token = data['credentials'][auth_domain]['token']
request.add_field 'Authorization', "Bearer #{token}"
else
auth_error_exit!
end
end
begin
http.request(request) rescue Net::OpenTimeout => e http_request_error_message(e)
rescue Exception => e
http_request_error_message(e)
end
end
|