Skip to content

Commit b3d7740

Browse files
committed
fix: remove highline colors and revert to net http
1 parent 281ef8f commit b3d7740

File tree

4 files changed

+33
-41
lines changed

4 files changed

+33
-41
lines changed

deployhq.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
1616
s.bindir = "bin"
1717
s.executables << "deployhq"
1818

19-
s.add_dependency('faraday', '~> 2.7')
2019
s.add_dependency('json', '~> 2.6')
2120
s.add_dependency('highline', '~> 2.1')
2221
s.add_dependency('websocket-eventmachine-client', '~> 1.2')

lib/deploy/cli.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
require 'deploy/cli/websocket_client'
66
require 'deploy/cli/deployment_progress_output'
77

8-
HighLine.colorize_strings
9-
108
module Deploy
119
class CLI
1210
## Constants for formatting output
@@ -69,12 +67,7 @@ def invoke(args)
6967
exit 1
7068
end
7169

72-
begin
73-
@project = Deploy::Project.find(project_permalink)
74-
rescue Deploy::Errors::TimeoutError => e
75-
STDERR.puts e
76-
exit 1
77-
end
70+
@project = Deploy::Project.find(project_permalink)
7871
end
7972

8073
case command
@@ -93,15 +86,15 @@ def server_list
9386
@server_groups ||= @project.server_groups
9487
if @server_groups.count > 0
9588
@server_groups.each do |group|
96-
puts "Group: #{group.name}".bold
89+
puts "Group: #{group.name}"
9790
puts group.servers.map {|server| format_server(server) }.join("\n\n")
9891
end
9992
end
10093

10194
@ungrouped_servers ||= @project.servers
10295
if @ungrouped_servers.count > 0
10396
puts "\n" if @server_groups.count > 0
104-
puts "Ungrouped Servers".bold
97+
puts "Ungrouped Servers"
10598
puts @ungrouped_servers.map {|server| format_server(server) }.join("\n\n")
10699
end
107100
end
@@ -186,7 +179,7 @@ def format_kv_pair(hash)
186179
longest_key = hash.keys.map(&:length).max + 2
187180
hash.each_with_index.map do |(k,v), i|
188181
str = sprintf("%#{longest_key}s : %s", k,v)
189-
i == 0 ? str.color(:bold) : str
182+
str
190183
end.join("\n")
191184
end
192185

lib/deploy/errors.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ class AccessDenied < Error; end
1616
## A communication error occurred while talking to the Deploy API
1717
class CommunicationError < Error; end
1818

19-
# A timeout error
20-
class TimeoutError < Error; end
21-
2219
# Raised from the websocket client when we receive an error event
2320
class WebsocketError < Error; end
2421
end

lib/deploy/request.rb

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
require 'faraday'
2-
require 'json'
3-
41
module Deploy
52
class Request
63

@@ -23,41 +20,47 @@ def output
2320
## Make a request to the Deploy API using net/http. Data passed can be a hash or a string
2421
## Hashes will be converted to JSON before being sent to the remote service.
2522
def make
26-
uri = URI.parse(Deploy.configuration.account)
27-
connection_url = "#{uri.scheme}://#{uri.host}:#{uri.port}"
23+
uri = URI.parse([Deploy.configuration.account, @path].join('/'))
24+
http_request = http_class.new(uri.request_uri)
25+
http_request.basic_auth(Deploy.configuration.username, Deploy.configuration.api_key)
26+
http_request["Accept"] = "application/json"
27+
http_request["Content-Type"] = "application/json"
2828

29-
connection = Faraday.new(url: connection_url, request: { timeout: 3 }) do |client|
30-
client.request :authorization, :basic, Deploy.configuration.username, Deploy.configuration.api_key
31-
client.headers['Accept'] = 'application/json'
32-
client.headers['Content-Type'] = 'application/json'
29+
http = Net::HTTP.new(uri.host, uri.port)
30+
if uri.scheme == 'https'
31+
http.use_ssl = true
3332
end
3433

3534
data = self.data.to_json if self.data.is_a?(Hash) && self.data.respond_to?(:to_json)
36-
37-
response = connection.send(@method) do |req|
38-
req.url @path
39-
req.body = data
40-
end
41-
42-
@output = response.body
43-
@success = case response.status
44-
when 200..299
35+
http_result = http.request(http_request, data)
36+
@output = http_result.body
37+
@success = case http_result
38+
when Net::HTTPSuccess
4539
true
46-
when 503
40+
when Net::HTTPServiceUnavailable
4741
raise Deploy::Errors::ServiceUnavailable
48-
when 401, 403
42+
when Net::HTTPForbidden, Net::HTTPUnauthorized
4943
raise Deploy::Errors::AccessDenied, "Access Denied for '#{Deploy.configuration.username}'"
50-
when 404
44+
when Net::HTTPNotFound
5145
raise Deploy::Errors::CommunicationError, "Not Found at #{uri.to_s}"
52-
when 400..499
46+
when Net::HTTPClientError
5347
false
5448
else
55-
raise Deploy::Errors::CommunicationError, response.body
49+
raise Deploy::Errors::CommunicationError, http_result.body
5650
end
57-
5851
self
59-
rescue Faraday::TimeoutError
60-
raise Deploy::Errors::TimeoutError, "Your request timed out, please try again in a few seconds"
52+
end
53+
54+
private
55+
56+
def http_class
57+
case @method
58+
when :post then Net::HTTP::Post
59+
when :put then Net::HTTP::Put
60+
when :delete then Net::HTTP::Delete
61+
else
62+
Net::HTTP::Get
63+
end
6164
end
6265

6366
end

0 commit comments

Comments
 (0)