site_hook 0.6.2 → 0.6.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
  SHA256:
3
- metadata.gz: 2111c48199b164cebd109b5501f5d5917bc8ed52dadb5399948ea7b9cc7edbcf
4
- data.tar.gz: 563f6850fbe028c6edbde43638b1094025d0f7e7acbc06825ce8505537ce4176
3
+ metadata.gz: 403f0b055ec58b6cf996dc94331b21b602f3ebc137721a7179f461f26db91a96
4
+ data.tar.gz: d01d26c3b0c0715f20f71212af872ebc27e817662a096a9974ad1daf15d5b457
5
5
  SHA512:
6
- metadata.gz: 6bed5baa92e5e6b4e29c190b5070c081e3d5b8a3ba921d2c912e9626c580b9b5ef99b788d5d0a3a7572ab0a33be223217bea0da5807940b080dad1430356a6f8
7
- data.tar.gz: 6ecb4076048ad00fcc76b98a4425e818aa6a851e902315e0a8ade024b98e104525ae4e88d16a935804f7086ea323730101133c2fb6e6a7da61bf4729b7b33c77
6
+ metadata.gz: 28b7820163b848829744517e4478ab1f700b54168d299f55ca484100bb97cff5d5d17b1e7542f61fbb1e50741b66ab1e93587fe0347e96adb5ce1fa04354dddb
7
+ data.tar.gz: 76efc64a030c3e189b59b7a6e4d97238855d72ba1be0a6f543c0c3e266baf94826ea2442e73c8de243be9d90bcd1a5311bac35790748d4ab1c04dd49b7457273
@@ -57,25 +57,28 @@ module SiteHook
57
57
  # @param [String] sig Signature or token from git service
58
58
  # @param [String] secret User-defined verification token
59
59
  # @param [Boolean] plaintext Whether the verification is plaintext
60
- def Webhook.verified?(body, sig, secret, plaintext:, service:) if plaintext
61
- if sig === secret
62
- true
63
- else false
64
- end
65
- else case service
66
- when 'gogs'
67
- if sig == OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, secret, body)
68
- APPLOG.debug "Secret verified: #{sig} === #{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, secret, body)}"
60
+ def Webhook.verified?(body, sig, secret, plaintext:, service:)
61
+ if plaintext
62
+ if sig === secret
69
63
  true
64
+ else
65
+ false
70
66
  end
71
- when 'github'
72
- if sig == OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, secret, body)
73
- APPLOG.debug "Secret verified: #{sig} === #{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, secret, body)}"
74
- true
67
+ else
68
+ case service
69
+ when 'gogs'
70
+ if sig == OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, secret, body)
71
+ APPLOG.debug "Secret verified: #{sig} === #{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, secret, body)}"
72
+ true
73
+ end
74
+ when 'github'
75
+ if sig == OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, secret, body)
76
+ APPLOG.debug "Secret verified: #{sig} === #{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, secret, body)}"
77
+ true
78
+ end
75
79
  end
76
- end
77
80
 
78
- end
81
+ end
79
82
  end
80
83
 
81
84
  get '/' do
@@ -105,7 +108,8 @@ module SiteHook
105
108
  get '/webhook/*' do
106
109
  if params[:splat]
107
110
  pass
108
- else halt 405, {'Content-Type' => 'application/json'}, {message: 'GET not allowed'}.to_json
111
+ else
112
+ halt 405, {'Content-Type' => 'application/json'}, {message: 'GET not allowed'}.to_json
109
113
  end
110
114
 
111
115
  end
@@ -147,14 +151,15 @@ module SiteHook
147
151
  }
148
152
  events_m_e = events.values.one?
149
153
  case events_m_e
150
- when true
151
- event = 'push'
152
- service = events.select { |key, value| value }.keys.first
153
- when false
154
- halt 400, {'Content-Type' => 'application/json'}, {message: 'events are mutually exclusive', status: 'failure'
155
- }.to_json
156
-
157
- else halt 400, {'Content-Type' => 'application/json'}, {'status': 'failure', 'message': 'something weird happened'
154
+ when true
155
+ event = 'push'
156
+ service = events.select { |key, value| value }.keys.first
157
+ when false
158
+ halt 400, {'Content-Type' => 'application/json'}, {message: 'events are mutually exclusive', status: 'failure'
159
+ }.to_json
160
+
161
+ else
162
+ halt 400, {'Content-Type' => 'application/json'}, {'status': 'failure', 'message': 'something weird happened'
158
163
  }
159
164
  end
160
165
  if event != 'push'
@@ -163,18 +168,18 @@ module SiteHook
163
168
  end
164
169
  end
165
170
  case service
166
- when 'gitlab'
167
- signature = request.env.fetch('HTTP_X_GITLAB_TOKEN', '')
168
- plaintext = true
169
- when 'github'
170
- signature = request.env.fetch('HTTP_X_HUB_SIGNATURE', ''
171
- ).sub!(/^sha1=/, ''
172
- )
173
- plaintext = false
171
+ when 'gitlab'
172
+ signature = request.env.fetch('HTTP_X_GITLAB_TOKEN', '')
173
+ plaintext = true
174
+ when 'github'
175
+ signature = request.env.fetch('HTTP_X_HUB_SIGNATURE', ''
176
+ ).sub!(/^sha1=/, ''
177
+ )
178
+ plaintext = false
174
179
 
175
- when 'gogs'
176
- signature = request.env.fetch('HTTP_X_GOGS_SIGNATURE', '')
177
- plaintext = false
180
+ when 'gogs'
181
+ signature = request.env.fetch('HTTP_X_GOGS_SIGNATURE', '')
182
+ plaintext = false
178
183
  end
179
184
  if Webhook.verified?(req_body.to_s, signature, project['hookpass'], plaintext: plaintext, service: service)
180
185
  BUILDLOG.info 'Building...'
@@ -183,19 +188,20 @@ module SiteHook
183
188
  jekyll_status = jekyllbuild.fetch(:status, 1)
184
189
  case jekyll_status
185
190
 
186
- when 0
187
- status 200
188
- headers 'Content-Type' => 'application/json'
189
- body { {'status': 'success'}.to_json
190
- }
191
- when -1, -2, -3
192
- status 400
193
- headers 'Content-Type' => 'application/json'
194
- body { {'status': 'exception', error: "#{jekyll_status.fetch(:message)}"}
195
- }
191
+ when 0
192
+ status 200
193
+ headers 'Content-Type' => 'application/json'
194
+ body { {'status': 'success'}.to_json
195
+ }
196
+ when -1, -2, -3
197
+ status 400
198
+ headers 'Content-Type' => 'application/json'
199
+ body { {'status': 'exception', error: "#{jekyll_status.fetch(:message)}"}
200
+ }
196
201
  end
197
202
 
198
- else halt 403, {'Content-Type' => 'application/json'}, {message: 'incorrect secret', 'status': 'failure'}.to_json
203
+ else
204
+ halt 403, {'Content-Type' => 'application/json'}, {message: 'incorrect secret', 'status': 'failure'}.to_json
199
205
  end
200
206
  end
201
207
  post '/webhook/?' do
@@ -1,3 +1,3 @@
1
1
  module SiteHook
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_hook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Spencer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-12 00:00:00.000000000 Z
11
+ date: 2018-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra