bard 0.64.0 → 0.65.0

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: 846754c2ad0d14dc0df687db107e05ecad69a9122540fba07b2362b83ff7b4a0
4
+ data.tar.gz: 04da3c9f2faa9d2d698d6d08442360a69bbe114e0333b6730257bc9b3ff18e35
5
5
  SHA512:
6
- metadata.gz: f4e42669d831bdf57dc6749ca7443690a307d9abf048f1a1e0eecbfd33a7f53e0a94a4aa1bf78f3724054407f7e679f49fcac029cc1fa00199c7584e68c5301b
7
- data.tar.gz: 7193a3c7324ee1da26262f18516f3a672299ccc29b1f1737eee7ad121c7cb992e7609fd271cc963b5f673285f9ec31f5c44074ae869f738264ba6ecd8b6749c8
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 default_ping
84
- uri = URI.parse("ssh://#{ssh}")
85
- "https://#{uri.host}"
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 normalized_ping
89
- normalized = ping || default_ping
90
- normalized = "https://#{normalized}" unless normalized =~ /^http/
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.normalized_ping
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
- return true if server.ping == false
9
-
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
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
- command = "curl -sfL #{url} 2>&1 1>/dev/null"
18
- system command
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
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "0.64.0"
2
+ VERSION = "0.65.0"
3
3
  end
4
4
 
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.default_ping}"
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
- unless Bard::Ping.call(server)
212
- puts "#{server.key.to_s.capitalize} is down!"
213
- exit 1
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"
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.65.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel