-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
32 lines (25 loc) · 734 Bytes
/
app.rb
File metadata and controls
32 lines (25 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require './mail_sync'
require 'openssl'
class MailSyncApp < Sinatra::Base
def self.secret
@secret ||= ENV['APPLICATION_SECRET']
end
get '/' do
'Info https://github.com/docrystal/mail_sync'
end
post '/payload' do
request.body.rewind
payload_body = request.body.read
verify_signature(payload_body)
sync = MailSync.new
sync.sync_info
sync.sync_teams
sync.sync_members
'Sync'
end
private
def verify_signature(payload_body)
signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), self.class.secret, payload_body)
return halt 500, "Signatures didn't match!" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE'])
end
end