File tree 2 files changed +57
-1
lines changed
ansible/files/home/deployer/webhook/lib/deployer
2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2024 Horimoto Yasuhiro <horimoto@clear-code.com>
1
2
# Copyright (C) 2024 Takuya Kodama <otegami@clear-code.com>
2
3
#
3
4
# This program is free software: you can redistribute it and/or modify
13
14
# You should have received a copy of the GNU General Public License
14
15
# along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16
17
+ require "openssl"
18
+ require_relative "response"
19
+
16
20
module Deployer
17
21
class App
18
22
def call ( env )
19
- [ 200 , { } , [ "Hello deployer" ] ]
23
+ request = Rack ::Request . new ( env )
24
+ response = Response . new
25
+ process ( request , response ) or response . finish
26
+ end
27
+
28
+ private
29
+
30
+ def process ( request , response )
31
+ unless request . post?
32
+ response . set ( :method_not_allowed , "must POST" )
33
+ return nil
34
+ end
35
+
36
+ unless verify_signature ( request )
37
+ response . set ( :unauthorized , "Authorization failed" )
38
+ return nil
39
+ end
40
+
41
+ response . finish
42
+ end
43
+
44
+ def verify_signature ( request )
45
+ signature = 'sha256=' + OpenSSL ::HMAC . hexdigest ( OpenSSL ::Digest . new ( 'sha256' ) ,
46
+ ENV [ 'SECRET_TOKEN' ] ,
47
+ request . body . read )
48
+ Rack ::Utils . secure_compare ( signature , request . env [ 'HTTP_X_HUB_SIGNATURE_256' ] )
20
49
end
21
50
end
22
51
end
Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2010-2019 Sutou Kouhei <kou@clear-code.com>
2
+ # Copyright (C) 2015 Kenji Okimoto <okimoto@clear-code.com>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+
17
+ require "rack/response"
18
+
19
+ module Deployer
20
+ class Response < Rack ::Response
21
+ def set ( status_keyword , message )
22
+ self . status = Rack ::Utils . status_code ( status_keyword )
23
+ self [ "Content-Type" ] = "text/plain"
24
+ write ( message )
25
+ end
26
+ end
27
+ end
You can’t perform that action at this time.
0 commit comments