bard 0.64.0 → 0.64.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f618df3bbb634f25fcb5f03f81a68b733e2fd70d5a654b8e8f9e0733ce180849
4
- data.tar.gz: 155060b90c13a3365bf3cd768642966bbc4926643b92d9f18378f69a9516df01
3
+ metadata.gz: c9d061d17e01a9c194b56cbc5c86ed626e390048c939453f6af87a7b9a136f24
4
+ data.tar.gz: 89cbc27d550599e4a8c2eb5287969d19dafdb2176f37d0f65c606966d77542a8
5
5
  SHA512:
6
- metadata.gz: f4e42669d831bdf57dc6749ca7443690a307d9abf048f1a1e0eecbfd33a7f53e0a94a4aa1bf78f3724054407f7e679f49fcac029cc1fa00199c7584e68c5301b
7
- data.tar.gz: 7193a3c7324ee1da26262f18516f3a672299ccc29b1f1737eee7ad121c7cb992e7609fd271cc963b5f673285f9ec31f5c44074ae869f738264ba6ecd8b6749c8
6
+ metadata.gz: 468913ca2b377d72a317fa44c73a7602445f4a9479d260326be1044598feb727aa13a2d35bebd65d06120eb50ade5960e767ff292f664e602ad394f96a996130
7
+ data.tar.gz: d322765c29287237823708b6cb71887d8662445826e61d726c0acfd819526062ffec20a5e79a33f404f959969d8b45ecc9d70f21506f2f9312027c16eab85111
data/lib/bard/config.rb CHANGED
@@ -80,14 +80,28 @@ module Bard
80
80
 
81
81
  setting :ssh, :path, :ping, :gateway, :ssh_key, :env
82
82
 
83
- def default_ping
84
- uri = URI.parse("ssh://#{ssh}")
85
- "https://#{uri.host}"
83
+ def ping(*args)
84
+ if args.length == 1
85
+ self.ping = args.first
86
+ elsif args.length == 0
87
+ normalize_ping(super())
88
+ else
89
+ raise ArgumentError
90
+ end
86
91
  end
87
92
 
88
- def normalized_ping
89
- normalized = ping || default_ping
90
- normalized = "https://#{normalized}" unless normalized =~ /^http/
93
+ private def normalize_ping value
94
+ return value if value == false
95
+ uri = URI.parse("ssh://#{ssh}")
96
+ normalized = "https://#{uri.host}" # default if none specified
97
+ if value =~ %r{^/}
98
+ normalized += value
99
+ elsif value.to_s.length > 0
100
+ normalized = value
101
+ end
102
+ if normalized !~ /^http/
103
+ normalized = "https://#{normalized}"
104
+ end
91
105
  normalized
92
106
  end
93
107
 
data/lib/bard/data.rb CHANGED
@@ -3,7 +3,7 @@ class Bard::CLI < Thor
3
3
  def call
4
4
  if to == "production"
5
5
  server = bard.instance_variable_get(:@config).servers[to.to_sym]
6
- url = server.normalized_ping
6
+ url = server.ping
7
7
  puts bard.yellow("WARNING: You are about to push data to production, overwriting everything that is there!")
8
8
  answer = bard.ask("If you really want to do this, please type in the full HTTPS url of the production server:")
9
9
  if answer != url
data/lib/bard/ping.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require "net/http"
2
+ require "uri"
3
+
1
4
  module Bard
2
5
  class Ping < Struct.new(:server)
3
6
  def self.call server
@@ -6,16 +9,26 @@ module Bard
6
9
 
7
10
  def call
8
11
  return true if server.ping == false
12
+ response = get_response_with_redirect(server.ping)
13
+ response.is_a?(Net::HTTPSuccess)
14
+ end
9
15
 
10
- url = server.default_ping
11
- if server.ping =~ %r{^/}
12
- url += server.ping
13
- elsif server.ping.to_s.length > 0
14
- url = server.ping
15
- end
16
+ private
16
17
 
17
- command = "curl -sfL #{url} 2>&1 1>/dev/null"
18
- system command
18
+ def get_response_with_redirect uri_str, limit=5
19
+ response = Net::HTTP.get_response(URI(uri_str))
20
+
21
+ case response
22
+ when Net::HTTPRedirection
23
+ if limit == 0
24
+ puts "too many HTTP redirects"
25
+ response
26
+ else
27
+ get_response_with_redirect(response["location"], limit - 1)
28
+ end
29
+ else
30
+ response
31
+ end
19
32
  end
20
33
  end
21
34
  end
data/lib/bard/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "0.64.0"
2
+ VERSION = "0.64.1"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.64.0
4
+ version: 0.64.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel