bard 0.64.0 → 0.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bard/config.rb +18 -6
- data/lib/bard/data.rb +1 -1
- data/lib/bard/ping.rb +24 -9
- data/lib/bard/version.rb +1 -1
- data/lib/bard.rb +4 -5
- 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: 846754c2ad0d14dc0df687db107e05ecad69a9122540fba07b2362b83ff7b4a0
|
4
|
+
data.tar.gz: 04da3c9f2faa9d2d698d6d08442360a69bbe114e0333b6730257bc9b3ff18e35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e742ede7bf2afc73dd8e68e60991ef1b13a819df55b0adea253b58ba70e5102a0139bdb26fcd10e2fe51574cd7a69262224484f6b6855794d930e57bd6739ab1
|
7
|
+
data.tar.gz: 17de7f6f053b646ccdf948197846f0890c2d765e86098a8b41b23d9063bfb376e16dd42bb912b7ad7ce65fc0fcfb84514b43fcac67dd187750f49d280f5c992e
|
data/lib/bard/config.rb
CHANGED
@@ -80,14 +80,26 @@ 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 == 0
|
85
|
+
(super() || [nil]).map(&method(:normalize_ping))
|
86
|
+
else
|
87
|
+
self.ping = args
|
88
|
+
end
|
86
89
|
end
|
87
90
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
+
private def normalize_ping value
|
92
|
+
return value if value == false
|
93
|
+
uri = URI.parse("ssh://#{ssh}")
|
94
|
+
normalized = "https://#{uri.host}" # default if none specified
|
95
|
+
if value =~ %r{^/}
|
96
|
+
normalized += value
|
97
|
+
elsif value.to_s.length > 0
|
98
|
+
normalized = value
|
99
|
+
end
|
100
|
+
if normalized !~ /^http/
|
101
|
+
normalized = "https://#{normalized}"
|
102
|
+
end
|
91
103
|
normalized
|
92
104
|
end
|
93
105
|
|
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.first
|
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
|
@@ -5,17 +8,29 @@ module Bard
|
|
5
8
|
end
|
6
9
|
|
7
10
|
def call
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
url += server.ping
|
13
|
-
elsif server.ping.to_s.length > 0
|
14
|
-
url = server.ping
|
11
|
+
server.ping.reject do |url|
|
12
|
+
next true if url == false
|
13
|
+
response = get_response_with_redirect(url) rescue nil
|
14
|
+
response.is_a?(Net::HTTPSuccess)
|
15
15
|
end
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
private
|
19
|
+
|
20
|
+
def get_response_with_redirect uri_str, limit=5
|
21
|
+
response = Net::HTTP.get_response(URI(uri_str))
|
22
|
+
|
23
|
+
case response
|
24
|
+
when Net::HTTPRedirection
|
25
|
+
if limit == 0
|
26
|
+
puts "too many HTTP redirects"
|
27
|
+
response
|
28
|
+
else
|
29
|
+
get_response_with_redirect(response["location"], limit - 1)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
response
|
33
|
+
end
|
19
34
|
end
|
20
35
|
end
|
21
36
|
end
|
data/lib/bard/version.rb
CHANGED
data/lib/bard.rb
CHANGED
@@ -138,7 +138,7 @@ class Bard::CLI < Thor
|
|
138
138
|
def open server=nil
|
139
139
|
server ||= @config.servers.key?(:production) ? :production : :staging
|
140
140
|
server = @config.servers[server.to_sym]
|
141
|
-
exec "xdg-open #{server.
|
141
|
+
exec "xdg-open #{server.ping.first}"
|
142
142
|
end
|
143
143
|
|
144
144
|
desc "hurt", "reruns a command until it fails"
|
@@ -208,10 +208,9 @@ class Bard::CLI < Thor
|
|
208
208
|
desc "ping [SERVER=production]", "hits the server over http to verify that its up."
|
209
209
|
def ping server=:production
|
210
210
|
server = @config.servers[server.to_sym]
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
end
|
211
|
+
down_urls = Bard::Ping.call(server)
|
212
|
+
down_urls.each { |url| puts "#{url} is down!" }
|
213
|
+
exit 1 if down_urls.any?
|
215
214
|
end
|
216
215
|
|
217
216
|
desc "master_key --from=production --to=local", "copy master key from from to to"
|