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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 602c22b719d9246b52f80bb2c3085d230273bb60
4
- data.tar.gz: 73a4924dabb8158750b99cc1f21431365a147429
3
+ metadata.gz: a493b68c2779e1afdf0e2fc80420bb2ae1dc3ca8
4
+ data.tar.gz: 789bda97be8d7a8bfad32f31805ce38c74f85b13
5
5
  SHA512:
6
- metadata.gz: 10476b28b50af8918bad76b9068d67fb65381ad2dd13fd4f4b2556ac7c2094bb0e8c4b784b5d23a9440d74b0acf5d14789f6b3b730ade87fcae2312787c40b6f
7
- data.tar.gz: ef80d8398d4288f6d3560b1275cc2c454cf5656676235293e7aedcb53e41a50167751711ebb4999cbe1cef3c6bd41aba8810f24f1c41d750e253d7093f97fb15
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 | false
36
- host | example.com | false
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 `proto`, `host`, `port` is not configured, hako-switch-hitter will use ELB v2 address.
40
+ If `port` is not configured, hako-switch-hitter will 80 for http and 443 for https.
41
41
 
42
42
  ## Development
43
43
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'hako-switch-hitter'
7
- spec.version = '0.1.1'
7
+ spec.version = '0.1.2'
8
8
  spec.authors = ['wata']
9
9
  spec.email = ['wata.gm@gmail.com']
10
10
 
@@ -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['proto'] || protocol
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
- return endpoint['host'] if endpoint['host']
40
+ endpoint.fetch('host')
41
+ end
40
42
 
41
- load_balancer = describe_load_balancer
42
- load_balancer.dns_name
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['port'] || port
50
+ endpoint.fetch('port', wellknown_port)
48
51
  end
49
52
 
50
53
  # @return [String]
51
54
  def endpoint_path
52
- raise Error.new("Switch hitter path is not configured") unless endpoint['path']
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 #{endpoint_proto.downcase}://#{endpoint_host}:#{endpoint_port}#{endpoint_path}")
66
- if endpoint_proto.upcase == 'HTTPS'
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 #{endpoint_proto.downcase}://#{endpoint_host}:#{endpoint_port}#{endpoint_path} [dry-run]")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hako-switch-hitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - wata