banacle 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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/banacle/app.rb +14 -3
- data/lib/banacle/authenticator.rb +17 -0
- data/lib/banacle/handler.rb +17 -37
- data/lib/banacle/interactive_message/handler.rb +20 -0
- data/lib/banacle/slash_command/handler.rb +26 -0
- data/lib/banacle/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ed9aa2704808715b44bd16ddd6c0a8c1a6d36cf4f2de385e75d2ca0b52e4a70
|
4
|
+
data.tar.gz: 0456565ccd292ebdee407e23fe69ea6ff152a4ac485d08c12c91951a6ee5bc16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17728a74b44f940c19544a43262a7dd79a9ce0941045723aeffa9497d8b4fc6ddea34af861e2b0499c3135d233882cc3a9ed36d67300e28af266ee07d82d678c
|
7
|
+
data.tar.gz: 2019918492687104f2767c3c0d0b74d764a7e53c02e043d2c4fa8b79d86d61c5ccc606e9393ffbdcb626c48b8fbd8a8523b638d93e923e31c051462ac8b1d433
|
data/Gemfile.lock
CHANGED
data/lib/banacle/app.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'sinatra/reloader'
|
3
|
-
require 'banacle/handler'
|
3
|
+
require 'banacle/slash_command/handler'
|
4
|
+
require 'banacle/interactive_message/handler'
|
4
5
|
|
5
6
|
module Banacle
|
6
7
|
class App < Sinatra::Base
|
@@ -8,14 +9,24 @@ module Banacle
|
|
8
9
|
register Sinatra::Reloader
|
9
10
|
end
|
10
11
|
|
12
|
+
helpers do
|
13
|
+
def command_handler
|
14
|
+
@command_handler ||= SlashCommand::Handler.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def message_handler
|
18
|
+
@message_handler ||= InteractiveMessage::Handler.new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
11
22
|
post '/slack/command' do
|
12
23
|
content_type :json
|
13
|
-
|
24
|
+
command_handler.handle(request)
|
14
25
|
end
|
15
26
|
|
16
27
|
post '/slack/message' do
|
17
28
|
content_type :json
|
18
|
-
|
29
|
+
message_handler.handle(request)
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
data/lib/banacle/handler.rb
CHANGED
@@ -1,61 +1,41 @@
|
|
1
|
-
require 'banacle/slash_command/error'
|
2
|
-
require 'banacle/slash_command/parser'
|
3
|
-
require 'banacle/slash_command/renderer'
|
4
|
-
|
5
|
-
require 'banacle/interactive_message/parser'
|
6
|
-
require 'banacle/interactive_message/renderer'
|
7
|
-
|
8
1
|
require 'banacle/slack_validator'
|
9
2
|
|
10
3
|
module Banacle
|
11
4
|
class Handler
|
12
|
-
|
13
|
-
new(request).handle_slash_command
|
14
|
-
end
|
5
|
+
class InvalidAuthenticatorError < StandardError; end
|
15
6
|
|
16
|
-
|
17
|
-
new(request).handle_interactive_message
|
18
|
-
end
|
7
|
+
attr_reader :request, :auth
|
19
8
|
|
20
|
-
def
|
9
|
+
def handle(request)
|
21
10
|
@request = request
|
22
|
-
end
|
23
11
|
|
24
|
-
attr_reader :request
|
25
|
-
|
26
|
-
def handle_slash_command
|
27
12
|
unless skip_validation? || SlackValidator.valid_signature?(request)
|
28
13
|
return [401, {}, "invalid request"]
|
29
14
|
end
|
30
15
|
|
31
|
-
|
32
|
-
|
33
|
-
rescue SlashCommand::Error => e
|
34
|
-
return SlashCommand::Renderer.render_error(e)
|
16
|
+
if auth && !auth.authenticate(request)
|
17
|
+
return [402, {}, "unauthenticated"]
|
35
18
|
end
|
36
19
|
|
37
|
-
|
20
|
+
handle_request
|
38
21
|
end
|
39
22
|
|
40
|
-
|
41
|
-
|
42
|
-
return [401, {}, "invalid request"]
|
43
|
-
end
|
44
|
-
|
45
|
-
command = InteractiveMessage::Parser.parse(JSON.parse(request_payload))
|
46
|
-
InteractiveMessage::Renderer.render(request.params, command)
|
47
|
-
end
|
48
|
-
|
49
|
-
def request_text
|
50
|
-
request.params["text"]
|
23
|
+
# override
|
24
|
+
def handle_request
|
51
25
|
end
|
52
26
|
|
53
|
-
|
54
|
-
request.params["payload"]
|
55
|
-
end
|
27
|
+
private
|
56
28
|
|
57
29
|
def skip_validation?
|
58
30
|
request.params["skip_validation"] || ENV["BANACLE_SKIP_VALIDATION"]
|
59
31
|
end
|
32
|
+
|
33
|
+
def set_authenticator!
|
34
|
+
unless auth.is_a?(Banacle::Authentication)
|
35
|
+
raise InvalidAuthenticatorError.new(auth.inspect)
|
36
|
+
end
|
37
|
+
|
38
|
+
@auth = auth
|
39
|
+
end
|
60
40
|
end
|
61
41
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'banacle/handler'
|
2
|
+
require 'banacle/interactive_message/parser'
|
3
|
+
require 'banacle/interactive_message/renderer'
|
4
|
+
|
5
|
+
module Banacle
|
6
|
+
module InteractiveMessage
|
7
|
+
class Handler < Banacle::Handler
|
8
|
+
def handle_request
|
9
|
+
command = InteractiveMessage::Parser.parse(JSON.parse(request_payload))
|
10
|
+
InteractiveMessage::Renderer.render(request.params, command)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def request_payload
|
16
|
+
request.params["payload"]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'banacle/handler'
|
2
|
+
require 'banacle/slash_command/error'
|
3
|
+
require 'banacle/slash_command/parser'
|
4
|
+
require 'banacle/slash_command/renderer'
|
5
|
+
|
6
|
+
module Banacle
|
7
|
+
module SlashCommand
|
8
|
+
class Handler < Banacle::Handler
|
9
|
+
def handle_request
|
10
|
+
begin
|
11
|
+
command = SlashCommand::Parser.parse(request_text)
|
12
|
+
rescue SlashCommand::Error => e
|
13
|
+
return SlashCommand::Renderer.render_error(e)
|
14
|
+
end
|
15
|
+
|
16
|
+
SlashCommand::Renderer.render(request.params, command)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def request_text
|
22
|
+
request.params["text"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/banacle/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banacle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takuya Kosugiyama
|
@@ -147,11 +147,13 @@ files:
|
|
147
147
|
- docs/nacl.png
|
148
148
|
- lib/banacle.rb
|
149
149
|
- lib/banacle/app.rb
|
150
|
+
- lib/banacle/authenticator.rb
|
150
151
|
- lib/banacle/aws_wrapper/error.rb
|
151
152
|
- lib/banacle/aws_wrapper/nacl.rb
|
152
153
|
- lib/banacle/aws_wrapper/result.rb
|
153
154
|
- lib/banacle/aws_wrapper/vpc.rb
|
154
155
|
- lib/banacle/handler.rb
|
156
|
+
- lib/banacle/interactive_message/handler.rb
|
155
157
|
- lib/banacle/interactive_message/parser.rb
|
156
158
|
- lib/banacle/interactive_message/renderer.rb
|
157
159
|
- lib/banacle/slack.rb
|
@@ -159,6 +161,7 @@ files:
|
|
159
161
|
- lib/banacle/slash_command/builder.rb
|
160
162
|
- lib/banacle/slash_command/command.rb
|
161
163
|
- lib/banacle/slash_command/error.rb
|
164
|
+
- lib/banacle/slash_command/handler.rb
|
162
165
|
- lib/banacle/slash_command/parser.rb
|
163
166
|
- lib/banacle/slash_command/renderer.rb
|
164
167
|
- lib/banacle/version.rb
|