hako-switch-hitter 0.1.2 → 0.1.3

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: a493b68c2779e1afdf0e2fc80420bb2ae1dc3ca8
4
- data.tar.gz: 789bda97be8d7a8bfad32f31805ce38c74f85b13
3
+ metadata.gz: 37f7ab335173996bb8584be366b43d2c411ace4d
4
+ data.tar.gz: bb2b85f6635a6d62ac79d37dafb97aca5230d5b5
5
5
  SHA512:
6
- metadata.gz: 95e2b17ba7ab22146d3bfecf5d5148b61192702caeda8e64ca00e6a4c9230adaef45851373c3c8d5f040b8b7b01db1be927088fa6851163ff03f41946d9d2570
7
- data.tar.gz: d6121e4a3c8ef75972c19dc70636aab3b6b14aab0bfc8855a0018be397a4c22cd287506e04bc2c5c9a51afea8c8a835c9fc1dbc0e0dfb306daccf609c843c820
6
+ metadata.gz: 7f5184c9b4c3b44abc1314d651a6cac48cf7c69a0e15d6b3d1d7ead2bf9a592404dadd2ec0516ced997230b801aa46f2c33fceca8a5f34c62a309df1e50a3237
7
+ data.tar.gz: c107ccd15a09c97254672c12cf6e4092ef7b2112858fafedb5735cc30acb3dca78ac8c84c7edf089d62ab90a768af83e17d725b6f0a0a43984ad611e41c1bc09
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Hako::Switch::Hitter
1
+ # Hako::SwitchHitter
2
+
3
+ [![Build Status](https://travis-ci.org/wata-gh/hako-switch-hitter.svg)](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.
@@ -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.2'
7
+ spec.version = '0.1.3'
8
8
  spec.authors = ['wata']
9
9
  spec.email = ['wata.gm@gmail.com']
10
10
 
@@ -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 [String]
32
- def endpoint_proto
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
32
+ # @return [URI]
33
+ def endpoint_uri
34
+ @uri ||= URI.parse(endpoint)
36
35
  end
37
36
 
38
37
  # @return [String]
39
- def endpoint_host
40
- endpoint.fetch('host')
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 [Fixnum]
44
- def wellknown_port
45
- endpoint_proto == 'https' ? 443 : 80
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
- endpoint.fetch('port', wellknown_port)
50
+ endpoint_uri.port
51
51
  end
52
52
 
53
53
  # @return [String]
54
54
  def endpoint_path
55
- endpoint.fetch('path')
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
- net_http = http(endpoint_host, endpoint_port)
65
+ Hako.logger.info("Switch endpoint #{endpoint}")
71
66
 
72
- Hako.logger.info("Switch endpoint #{url}")
73
- if endpoint_proto == 'HTTPS'
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 #{url} [dry-run]")
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(endpoint_path)
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 #{endpoint_path} at #{res.body}")
81
+ Hako.logger.info("Enabled #{endpoint} at #{res.body}")
89
82
  end
90
83
  end
91
84
  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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - wata