banacle 0.2.3 → 0.2.4

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: 45572c635e126a7ca610c10387909814e748ef1eebd99c825790bd873039dfb2
4
- data.tar.gz: 6092ccd18529bb92d30a931237429f39ea30cec076d93d0eb3b19f41ba8b9af0
3
+ metadata.gz: 1543019743d70530ef2330bceb9ea597fa75d87447a2cd6a094221fb8f82123f
4
+ data.tar.gz: ad9c0cb85d7599fc902c152a98157ebe8f4d80d40e09c13ab39bf81d9a54c6a9
5
5
  SHA512:
6
- metadata.gz: '09f7b8c15074e7885f94e00b4f8ba3cbee41aaa21b9ca170b10d15a164b1d1367a1b95fcacc17ea1031d3b0fd3f9278416dffa821cb9722566905ea7e016ff6d'
7
- data.tar.gz: 593b016ba1a5d3c560aa12e3f4543dc75639a5e4063f03da51052100d156d86f69f7db2d79253fd9ea18f89747ecd518a55d8e5cf10d693cd4a17bc2505bb455
6
+ metadata.gz: ba7fc79a90cedba53edf12f195d4dd3e5ebbde15e4f97b8db50ba6872da3a17f469deff93004b112f1895c90766319645145d0d0288c25635641c5e1d4353539
7
+ data.tar.gz: 87caa3ccf655e65159121c3a321a349811d15a31a9f15d0944de7cadcbee9e489d2bc5e87880151b23c5fbdd07fcd49822ca78ac9db53ef0c08ad9a4c0f8f959
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- banacle (0.2.3)
4
+ banacle (0.2.4)
5
5
  aws-sdk-ec2
6
6
  sinatra
7
7
  unicorn
@@ -9,17 +9,18 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- aws-eventstream (1.0.1)
13
- aws-partitions (1.131.0)
14
- aws-sdk-core (3.45.0)
15
- aws-eventstream (~> 1.0)
12
+ aws-eventstream (1.0.3)
13
+ aws-partitions (1.184.0)
14
+ aws-sdk-core (3.59.0)
15
+ aws-eventstream (~> 1.0, >= 1.0.2)
16
16
  aws-partitions (~> 1.0)
17
- aws-sigv4 (~> 1.0)
17
+ aws-sigv4 (~> 1.1)
18
18
  jmespath (~> 1.0)
19
- aws-sdk-ec2 (1.66.0)
20
- aws-sdk-core (~> 3, >= 3.39.0)
21
- aws-sigv4 (~> 1.0)
22
- aws-sigv4 (1.0.3)
19
+ aws-sdk-ec2 (1.99.0)
20
+ aws-sdk-core (~> 3, >= 3.58.0)
21
+ aws-sigv4 (~> 1.1)
22
+ aws-sigv4 (1.1.0)
23
+ aws-eventstream (~> 1.0, >= 1.0.2)
23
24
  backports (3.11.4)
24
25
  coderay (1.1.2)
25
26
  diff-lcs (1.3)
@@ -62,7 +63,7 @@ GEM
62
63
  sinatra (= 2.0.5)
63
64
  tilt (>= 1.3, < 3)
64
65
  tilt (2.0.9)
65
- unicorn (5.4.1)
66
+ unicorn (5.5.1)
66
67
  kgio (~> 2.6)
67
68
  raindrops (~> 0.7)
68
69
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Banacle: Create or delete DENY NACL entries on AWS VPC as ChatOps (Slack Slash Command)
1
+ # Banacle: Create or delete DENY NACL ingress entries on AWS VPC as ChatOps (Slack Slash Command)
2
2
 
3
3
  ## Installation
4
4
 
@@ -35,7 +35,9 @@ See example directory which implements a customized authentication feature for d
35
35
 
36
36
  ## Example: ban 1.2.3.4 from my VPC
37
37
 
38
- Execute a command that create a DENY NACL entry for 1.2.3.4 on a VPC named "test" in ap-northeast-1.
38
+ Note: Use documentation block for testing. https://tools.ietf.org/html/rfc5737
39
+
40
+ Execute a command that create a DENY NACL ingress entry for 1.2.3.4 on a VPC named "test" in ap-northeast-1.
39
41
 
40
42
  ![](./docs/demo1.png)
41
43
 
data/exe/cli ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'banacle/cli'
4
+
5
+ Banacle::Cli.start
@@ -34,7 +34,7 @@ module Banacle
34
34
  begin
35
35
  rule_number = create_network_acl_ingress_entry(cidr_block)
36
36
  Result.new(cidr_block: cidr_block, status: true, rule_number: rule_number)
37
- rescue AwsWrapper::Error => e
37
+ rescue AwsWrapper::Error, Aws::EC2::Errors::ServiceError => e
38
38
  Result.new(cidr_block: cidr_block, status: false, error: e)
39
39
  end
40
40
  end
@@ -45,7 +45,7 @@ module Banacle
45
45
  begin
46
46
  rule_number = delete_network_acl_entry(cidr_block)
47
47
  Result.new(cidr_block: cidr_block, status: true, rule_number: rule_number)
48
- rescue AwsWrapper::Error => e
48
+ rescue AwsWrapper::Error, Aws::EC2::Errors::ServiceError => e
49
49
  Result.new(cidr_block: cidr_block, status: false, error: e)
50
50
  end
51
51
  end
@@ -0,0 +1,114 @@
1
+ require 'banacle/slash_command/builder'
2
+ require 'banacle/slash_command/parser'
3
+
4
+ module Banacle
5
+ class Cli
6
+ SLASH_ACTION = 'slash'.freeze
7
+ INTERACTIVE_ACTION = 'interactive'.freeze
8
+ HELP_ACTION = 'help'.freeze
9
+ EXIT_ACTION = 'exit'.freeze
10
+
11
+ def self.start
12
+ new.start
13
+ end
14
+
15
+ def initialize
16
+ @store = MemoryStore.new
17
+ end
18
+
19
+ def start
20
+ main_loop
21
+ end
22
+
23
+ def main_loop
24
+ loop do
25
+ print '> '
26
+ input = STDIN.gets.chomp
27
+ args = input.split(" ")
28
+
29
+ case args.first
30
+ when SLASH_ACTION
31
+ handle_slash_action(args[1..-1].join(" "))
32
+ when INTERACTIVE_ACTION
33
+ handle_interactive_action(args[1..-1].join(" "))
34
+ when EXIT_ACTION
35
+ exit 0
36
+ when HELP_ACTION
37
+ print_help
38
+ else
39
+ print_help
40
+ end
41
+ end
42
+ end
43
+
44
+ def print_help
45
+ puts <<-EOS
46
+ #{SLASH_ACTION} #{SlashCommand::Parser.help}
47
+ execute slash command
48
+ #{INTERACTIVE_ACTION} key
49
+ approve slash command
50
+ #{HELP_ACTION}
51
+ print help
52
+ EOS
53
+ end
54
+
55
+ def handle_slash_action(input)
56
+ execute_slash_command(input)
57
+ end
58
+
59
+ def execute_slash_command(input)
60
+ begin
61
+ command = SlashCommand::Parser.parse(input)
62
+ i = @store.put(command)
63
+ puts "stored (key=#{i}, command=#{command.to_h})"
64
+ rescue SlashCommand::Error => e
65
+ puts e.message
66
+ end
67
+ end
68
+
69
+ def handle_interactive_action(input)
70
+ k = input.split(" ").first.to_i
71
+ command = @store.get(k)
72
+ unless command
73
+ puts "key=#{k} not found"
74
+ return
75
+ end
76
+ execute_interactive_message(command)
77
+ end
78
+
79
+ def execute_interactive_message(command)
80
+ puts command.execute
81
+ end
82
+
83
+ class MemoryStore
84
+ def initialize
85
+ @store = {}
86
+ @max_key = 0
87
+ end
88
+
89
+ def get(k)
90
+ @store[k]
91
+ end
92
+
93
+ def put(v)
94
+ put_with_key(k: nil, v: v)
95
+ end
96
+
97
+ def put_with_key(k:, v:)
98
+ if k
99
+ @store[k] = v
100
+ k
101
+ else
102
+ k = @max_key
103
+ @store[k] = v
104
+ @max_key += 1
105
+ k
106
+ end
107
+ end
108
+
109
+ def delete(k)
110
+ @store.delete(k)
111
+ end
112
+ end
113
+ end
114
+ end
@@ -8,16 +8,8 @@ module Banacle
8
8
  end
9
9
 
10
10
  def parse(payload)
11
- original_text = payload["original_message"]["text"]
12
- original_json = JSON.parse(
13
- original_text.match(command_json_regex)[1].strip, symbolize_names: true,
14
- )
15
- command = SlashCommand::Command.new(**original_json)
16
- end
17
-
18
- # TODO: sync slash_command/renderer
19
- def command_json_regex
20
- /```([^`]+)```/.freeze
11
+ original_message = payload["original_message"]["text"]
12
+ SlashCommand::Command.new_from_original_message(original_message)
21
13
  end
22
14
  end
23
15
  end
@@ -6,9 +6,17 @@ module Banacle
6
6
  class Command
7
7
  CREATE_ACTION = 'create'.freeze
8
8
  DELETE_ACTION = 'delete'.freeze
9
-
10
9
  PERMITTED_ACTIONS = [CREATE_ACTION, DELETE_ACTION].freeze
11
10
 
11
+ CODE_BLOCK_JSON_REGEX = /```([^`]+)```/.freeze
12
+
13
+ def self.new_from_original_message(message)
14
+ original_json = JSON.parse(
15
+ message.match(CODE_BLOCK_JSON_REGEX)[1].strip, symbolize_names: true,
16
+ )
17
+ new(**original_json)
18
+ end
19
+
12
20
  def initialize(action:, region:, vpc_id:, cidr_blocks:)
13
21
  @action = action
14
22
  @region = region
@@ -29,6 +37,14 @@ module Banacle
29
37
  end
30
38
  end
31
39
 
40
+ def to_code_block
41
+ <<-EOS
42
+ ```
43
+ #{JSON.pretty_generate(self.to_h)}
44
+ ```
45
+ EOS
46
+ end
47
+
32
48
  def to_h
33
49
  {
34
50
  action: action,
@@ -10,9 +10,10 @@ module Banacle
10
10
  new.parse(text)
11
11
  end
12
12
 
13
- #
14
- # /banacle (create|delete) [region] [vpc_id or vpc_name] [cidr_block1,cidr_block2,...]
15
- #
13
+ def self.help
14
+ '(create|delete) [region] [vpc_id or vpc_name] [cidr_block1,cidr_block2,...]'
15
+ end
16
+
16
17
  def parse(text)
17
18
  elems = text.split(" ")
18
19
 
@@ -21,9 +21,7 @@ module Banacle
21
21
  def render_approval_request
22
22
  text = <<-EOS
23
23
  <@#{user_id}> wants to *#{command.action} NACL DENY entry* under the following conditions:
24
- ```
25
- #{JSON.pretty_generate(command.to_h)}
26
- ```
24
+ #{command.to_code_block}
27
25
  EOS
28
26
 
29
27
  Slack::Response.new(
@@ -1,3 +1,3 @@
1
1
  module Banacle
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banacle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuya Kosugiyama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-12 00:00:00.000000000 Z
11
+ date: 2019-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,7 +126,8 @@ description: Create or delete DENY NACL entries on AWS VPC as ChatOps (Slack Sla
126
126
  Command)
127
127
  email:
128
128
  - re@itkq.jp
129
- executables: []
129
+ executables:
130
+ - cli
130
131
  extensions: []
131
132
  extra_rdoc_files: []
132
133
  files:
@@ -149,11 +150,13 @@ files:
149
150
  - example/Gemfile.lock
150
151
  - example/README.md
151
152
  - example/config.ru
153
+ - exe/cli
152
154
  - lib/banacle.rb
153
155
  - lib/banacle/app.rb
154
156
  - lib/banacle/aws_wrapper/error.rb
155
157
  - lib/banacle/aws_wrapper/nacl.rb
156
158
  - lib/banacle/aws_wrapper/vpc.rb
159
+ - lib/banacle/cli.rb
157
160
  - lib/banacle/config.rb
158
161
  - lib/banacle/interactive_message/authenticator.rb
159
162
  - lib/banacle/interactive_message/handler.rb
@@ -189,8 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
192
  - !ruby/object:Gem::Version
190
193
  version: '0'
191
194
  requirements: []
192
- rubyforge_project:
193
- rubygems_version: 2.7.6
195
+ rubygems_version: 3.0.4
194
196
  signing_key:
195
197
  specification_version: 4
196
198
  summary: Create or delete DENY NACL entries on AWS VPC as ChatOps (Slack Slash Command)