hako-switch-hitter 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/hako-switch-hitter.gemspec +1 -1
- data/lib/hako/scripts/switch_hitter.rb +18 -49
- 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: a493b68c2779e1afdf0e2fc80420bb2ae1dc3ca8
|
4
|
+
data.tar.gz: 789bda97be8d7a8bfad32f31805ce38c74f85b13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e2b17ba7ab22146d3bfecf5d5148b61192702caeda8e64ca00e6a4c9230adaef45851373c3c8d5f040b8b7b01db1be927088fa6851163ff03f41946d9d2570
|
7
|
+
data.tar.gz: d6121e4a3c8ef75972c19dc70636aab3b6b14aab0bfc8855a0018be397a4c22cd287506e04bc2c5c9a51afea8c8a835c9fc1dbc0e0dfb306daccf609c843c820
|
data/README.md
CHANGED
@@ -32,12 +32,12 @@ scripts:
|
|
32
32
|
|
33
33
|
config | detail | required
|
34
34
|
--- | --- | ---
|
35
|
-
proto | http or https |
|
36
|
-
host | example.com |
|
35
|
+
proto | http or https | true
|
36
|
+
host | example.com | true
|
37
37
|
port | 80 | false
|
38
38
|
path | /switch_endpoint | true
|
39
39
|
|
40
|
-
If `
|
40
|
+
If `port` is not configured, hako-switch-hitter will 80 for http and 443 for https.
|
41
41
|
|
42
42
|
## Development
|
43
43
|
|
data/hako-switch-hitter.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'aws-sdk'
|
2
1
|
require 'hako'
|
3
2
|
require 'hako/error'
|
4
3
|
require 'hako/script'
|
@@ -31,26 +30,29 @@ module Hako
|
|
31
30
|
|
32
31
|
# @return [String]
|
33
32
|
def endpoint_proto
|
34
|
-
endpoint
|
33
|
+
proto = endpoint.fetch('proto')
|
34
|
+
raise Error.new("Switch hitter proto must be http or https") unless %w/http https/.include?(proto)
|
35
|
+
proto
|
35
36
|
end
|
36
37
|
|
37
38
|
# @return [String]
|
38
39
|
def endpoint_host
|
39
|
-
|
40
|
+
endpoint.fetch('host')
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
+
# @return [Fixnum]
|
44
|
+
def wellknown_port
|
45
|
+
endpoint_proto == 'https' ? 443 : 80
|
43
46
|
end
|
44
47
|
|
45
48
|
# @return [Fixnum]
|
46
49
|
def endpoint_port
|
47
|
-
endpoint
|
50
|
+
endpoint.fetch('port', wellknown_port)
|
48
51
|
end
|
49
52
|
|
50
53
|
# @return [String]
|
51
54
|
def endpoint_path
|
52
|
-
|
53
|
-
endpoint['path']
|
55
|
+
endpoint.fetch('path')
|
54
56
|
end
|
55
57
|
|
56
58
|
# @return [Net::HTTP]
|
@@ -58,18 +60,22 @@ module Hako
|
|
58
60
|
Net::HTTP.new(host, port)
|
59
61
|
end
|
60
62
|
|
63
|
+
# @return [String]
|
64
|
+
def url
|
65
|
+
"#{endpoint_proto}://#{endpoint_host}:#{endpoint_port}#{endpoint_path}"
|
66
|
+
end
|
67
|
+
|
61
68
|
# @return [nil]
|
62
69
|
def hit_switch
|
63
70
|
net_http = http(endpoint_host, endpoint_port)
|
64
71
|
|
65
|
-
Hako.logger.info("Switch endpoint #{
|
66
|
-
if endpoint_proto
|
72
|
+
Hako.logger.info("Switch endpoint #{url}")
|
73
|
+
if endpoint_proto == 'HTTPS'
|
67
74
|
net_http.use_ssl = true
|
68
|
-
net_http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
69
75
|
end
|
70
76
|
|
71
77
|
if @dry_run
|
72
|
-
Hako.logger.info("Switch hitter will request #{
|
78
|
+
Hako.logger.info("Switch hitter will request #{url} [dry-run]")
|
73
79
|
return
|
74
80
|
end
|
75
81
|
|
@@ -82,43 +88,6 @@ module Hako
|
|
82
88
|
Hako.logger.info("Enabled #{endpoint_path} at #{res.body}")
|
83
89
|
end
|
84
90
|
end
|
85
|
-
|
86
|
-
# @return [String]
|
87
|
-
def region
|
88
|
-
@app.yaml.fetch('scheduler').fetch('region')
|
89
|
-
end
|
90
|
-
|
91
|
-
# @return [Fixnum]
|
92
|
-
def port
|
93
|
-
@app.yaml.fetch('scheduler').fetch('elb_v2').fetch('listeners')[0].fetch('port')
|
94
|
-
end
|
95
|
-
|
96
|
-
# @return [String]
|
97
|
-
def protocol
|
98
|
-
@app.yaml.fetch('scheduler').fetch('elb_v2').fetch('listeners')[0].fetch('protocol')
|
99
|
-
end
|
100
|
-
|
101
|
-
# @return [Aws::ElasticLoadBalancingV2::Client]
|
102
|
-
def elb_v2
|
103
|
-
@elb_v2 ||= Aws::ElasticLoadBalancingV2::Client.new(region: region)
|
104
|
-
end
|
105
|
-
|
106
|
-
# @return [Aws::ElasticLoadBalancingV2::Types::Listener]
|
107
|
-
def describe_listener(load_balancer_arn)
|
108
|
-
elb_v2.describe_listeners(load_balancer_arn: load_balancer_arn).listeners[0]
|
109
|
-
end
|
110
|
-
|
111
|
-
# @return [Aws::ElasticLoadBalancingV2::Types::LoadBalancer]
|
112
|
-
def describe_load_balancer
|
113
|
-
elb_v2.describe_load_balancers(names: [name]).load_balancers[0]
|
114
|
-
rescue Aws::ElasticLoadBalancingV2::Errors::LoadBalancerNotFound
|
115
|
-
nil
|
116
|
-
end
|
117
|
-
|
118
|
-
# @return [String]
|
119
|
-
def name
|
120
|
-
"hako-#{@app.id}"
|
121
|
-
end
|
122
91
|
end
|
123
92
|
end
|
124
93
|
end
|