hako-switch-hitter 0.1.2 → 0.1.3
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/README.md +4 -15
- data/hako-switch-hitter.gemspec +1 -1
- data/lib/hako/scripts/switch_hitter.rb +18 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37f7ab335173996bb8584be366b43d2c411ace4d
|
4
|
+
data.tar.gz: bb2b85f6635a6d62ac79d37dafb97aca5230d5b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f5184c9b4c3b44abc1314d651a6cac48cf7c69a0e15d6b3d1d7ead2bf9a592404dadd2ec0516ced997230b801aa46f2c33fceca8a5f34c62a309df1e50a3237
|
7
|
+
data.tar.gz: c107ccd15a09c97254672c12cf6e4092ef7b2112858fafedb5735cc30acb3dca78ac8c84c7edf089d62ab90a768af83e17d725b6f0a0a43984ad611e41c1bc09
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
# Hako::
|
1
|
+
# Hako::SwitchHitter
|
2
|
+
|
3
|
+
[](https://travis-ci.org/wata-gh/hako-switch-hitter)
|
2
4
|
|
3
5
|
Hit endpoint at [hako](https://github.com/eagletmt/hako) script deploy_finished.
|
4
6
|
|
@@ -23,22 +25,9 @@ Or install it yourself as:
|
|
23
25
|
```yaml
|
24
26
|
scripts:
|
25
27
|
- type: switch_hitter
|
26
|
-
endpoint:
|
27
|
-
proto: http
|
28
|
-
host: example.com
|
29
|
-
port: 10080
|
30
|
-
path: /switch_endpoint
|
28
|
+
endpoint: https://example.com/switch_endpoint
|
31
29
|
```
|
32
30
|
|
33
|
-
config | detail | required
|
34
|
-
--- | --- | ---
|
35
|
-
proto | http or https | true
|
36
|
-
host | example.com | true
|
37
|
-
port | 80 | false
|
38
|
-
path | /switch_endpoint | true
|
39
|
-
|
40
|
-
If `port` is not configured, hako-switch-hitter will 80 for http and 443 for https.
|
41
|
-
|
42
31
|
## Development
|
43
32
|
|
44
33
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/hako-switch-hitter.gemspec
CHANGED
@@ -2,6 +2,7 @@ require 'hako'
|
|
2
2
|
require 'hako/error'
|
3
3
|
require 'hako/script'
|
4
4
|
require 'net/http'
|
5
|
+
require 'uri'
|
5
6
|
|
6
7
|
module Hako
|
7
8
|
module Scripts
|
@@ -28,31 +29,30 @@ module Hako
|
|
28
29
|
@options['endpoint']
|
29
30
|
end
|
30
31
|
|
31
|
-
# @return [
|
32
|
-
def
|
33
|
-
|
34
|
-
raise Error.new("Switch hitter proto must be http or https") unless %w/http https/.include?(proto)
|
35
|
-
proto
|
32
|
+
# @return [URI]
|
33
|
+
def endpoint_uri
|
34
|
+
@uri ||= URI.parse(endpoint)
|
36
35
|
end
|
37
36
|
|
38
37
|
# @return [String]
|
39
|
-
def
|
40
|
-
|
38
|
+
def endpoint_scheme
|
39
|
+
raise Error.new("Switch hitter endpoint scheme must be http or https") unless %w/http https/.include?(endpoint_uri.scheme)
|
40
|
+
endpoint_uri.scheme
|
41
41
|
end
|
42
42
|
|
43
|
-
# @return [
|
44
|
-
def
|
45
|
-
|
43
|
+
# @return [String]
|
44
|
+
def endpoint_host
|
45
|
+
endpoint_uri.host
|
46
46
|
end
|
47
47
|
|
48
48
|
# @return [Fixnum]
|
49
49
|
def endpoint_port
|
50
|
-
|
50
|
+
endpoint_uri.port
|
51
51
|
end
|
52
52
|
|
53
53
|
# @return [String]
|
54
54
|
def endpoint_path
|
55
|
-
|
55
|
+
endpoint_uri.path
|
56
56
|
end
|
57
57
|
|
58
58
|
# @return [Net::HTTP]
|
@@ -60,32 +60,25 @@ module Hako
|
|
60
60
|
Net::HTTP.new(host, port)
|
61
61
|
end
|
62
62
|
|
63
|
-
# @return [String]
|
64
|
-
def url
|
65
|
-
"#{endpoint_proto}://#{endpoint_host}:#{endpoint_port}#{endpoint_path}"
|
66
|
-
end
|
67
|
-
|
68
63
|
# @return [nil]
|
69
64
|
def hit_switch
|
70
|
-
|
65
|
+
Hako.logger.info("Switch endpoint #{endpoint}")
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
net_http.use_ssl = true
|
75
|
-
end
|
67
|
+
net_http = http(endpoint_host, endpoint_port)
|
68
|
+
net_http.use_ssl = endpoint_scheme == 'https'
|
76
69
|
|
77
70
|
if @dry_run
|
78
|
-
Hako.logger.info("Switch hitter will request #{
|
71
|
+
Hako.logger.info("Switch hitter will request #{endpoint} [dry-run]")
|
79
72
|
return
|
80
73
|
end
|
81
74
|
|
82
75
|
net_http.start do
|
83
|
-
req = Net::HTTP::Get.new(
|
76
|
+
req = Net::HTTP::Get.new(endpoint_uri.request_uri)
|
84
77
|
res = net_http.request(req)
|
85
78
|
unless res.code == '200'
|
86
79
|
raise Error.new("Switch hitter HTTP Error: #{res.code}: #{res.body}")
|
87
80
|
end
|
88
|
-
Hako.logger.info("Enabled #{
|
81
|
+
Hako.logger.info("Enabled #{endpoint} at #{res.body}")
|
89
82
|
end
|
90
83
|
end
|
91
84
|
end
|