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 +4 -4
- data/lib/bard/config.rb +20 -6
- data/lib/bard/data.rb +1 -1
- data/lib/bard/ping.rb +21 -8
- data/lib/bard/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9d061d17e01a9c194b56cbc5c86ed626e390048c939453f6af87a7b9a136f24
|
4
|
+
data.tar.gz: 89cbc27d550599e4a8c2eb5287969d19dafdb2176f37d0f65c606966d77542a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
84
|
-
|
85
|
-
|
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
|
89
|
-
|
90
|
-
|
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.
|
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
|
-
|
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
|
-
|
18
|
-
|
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