banacle 0.2.2 → 0.2.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: b3fc2e3711e8ef218a8015c9946bb866dae0e6719ddd3ea0364ed2151bb492d2
4
- data.tar.gz: 030b0b31f9fc0ccc1b2ef5027b495115210284dcb41417e6823e86c4fd3cffd6
3
+ metadata.gz: 45572c635e126a7ca610c10387909814e748ef1eebd99c825790bd873039dfb2
4
+ data.tar.gz: 6092ccd18529bb92d30a931237429f39ea30cec076d93d0eb3b19f41ba8b9af0
5
5
  SHA512:
6
- metadata.gz: c7d7a9067e6ab5782a46ff10c2dbe216ef58c96a1f004c58fa90f32e80455c837578750e47eda7e552a5a51ad7d1fb6b6b15c67dc9d630ce859dfcb40af9c3f4
7
- data.tar.gz: de1b1f7199d4ec2b138128848eb17bba4bffdfeddefcc9979ae1df2401f2a62259fc99a1e05f54b6ed104fa9f82816b0a01cb1207f5a24924776b011776ccb95
6
+ metadata.gz: '09f7b8c15074e7885f94e00b4f8ba3cbee41aaa21b9ca170b10d15a164b1d1367a1b95fcacc17ea1031d3b0fd3f9278416dffa821cb9722566905ea7e016ff6d'
7
+ data.tar.gz: 593b016ba1a5d3c560aa12e3f4543dc75639a5e4063f03da51052100d156d86f69f7db2d79253fd9ea18f89747ecd518a55d8e5cf10d693cd4a17bc2505bb455
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- banacle (0.2.2)
4
+ banacle (0.2.3)
5
5
  aws-sdk-ec2
6
6
  sinatra
7
7
  unicorn
@@ -10,13 +10,13 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  aws-eventstream (1.0.1)
13
- aws-partitions (1.127.0)
14
- aws-sdk-core (3.44.1)
13
+ aws-partitions (1.131.0)
14
+ aws-sdk-core (3.45.0)
15
15
  aws-eventstream (~> 1.0)
16
16
  aws-partitions (~> 1.0)
17
17
  aws-sigv4 (~> 1.0)
18
18
  jmespath (~> 1.0)
19
- aws-sdk-ec2 (1.65.0)
19
+ aws-sdk-ec2 (1.66.0)
20
20
  aws-sdk-core (~> 3, >= 3.39.0)
21
21
  aws-sigv4 (~> 1.0)
22
22
  aws-sigv4 (1.0.3)
data/README.md CHANGED
@@ -27,13 +27,15 @@ Banacle is supposed to be run as a Sinatra server. You can run it simply by `rac
27
27
  - `/slack/command`: handle Slash Command
28
28
  - `/slack/message`: handle Interactive Message
29
29
 
30
+ By default, the format of Slack Slash Command is: `/[cmd] [create or delete] [region] [vpc_id or vpc_name] [cidr_blocks]`
31
+
30
32
  ### Customize authentication
31
33
  You can customize Banacle by using request handler modules.
32
34
  See example directory which implements a customized authentication feature for details.
33
35
 
34
36
  ## Example: ban 1.2.3.4 from my VPC
35
37
 
36
- Execute an command that create a DENY NACL entry for 1.2.3.4 on a VPC named "test" in ap-northeast-1.
38
+ Execute a command that create a DENY NACL entry for 1.2.3.4 on a VPC named "test" in ap-northeast-1.
37
39
 
38
40
  ![](./docs/demo1.png)
39
41
 
data/example/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- banacle (0.2.2)
4
+ banacle (0.2.3)
5
5
  aws-sdk-ec2
6
6
  sinatra
7
7
  unicorn
@@ -10,13 +10,13 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  aws-eventstream (1.0.1)
13
- aws-partitions (1.127.0)
14
- aws-sdk-core (3.44.1)
13
+ aws-partitions (1.131.0)
14
+ aws-sdk-core (3.45.0)
15
15
  aws-eventstream (~> 1.0)
16
16
  aws-partitions (~> 1.0)
17
17
  aws-sigv4 (~> 1.0)
18
18
  jmespath (~> 1.0)
19
- aws-sdk-ec2 (1.65.0)
19
+ aws-sdk-ec2 (1.66.0)
20
20
  aws-sdk-core (~> 3, >= 3.39.0)
21
21
  aws-sigv4 (~> 1.0)
22
22
  aws-sigv4 (1.0.3)
@@ -1,6 +1,5 @@
1
1
  require 'aws-sdk-ec2'
2
2
  require 'banacle/aws_wrapper/error'
3
- require 'banacle/aws_wrapper/result'
4
3
 
5
4
  module Banacle
6
5
  module AwsWrapper
@@ -8,6 +7,8 @@ module Banacle
8
7
  class EntryDuplicatedError < AwsWrapper::Error; end
9
8
  class EntryNotFoundError < AwsWrapper::Error; end
10
9
 
10
+ Result = Struct.new(:cidr_block, :status, :error, :rule_number, keyword_init: true) do; end
11
+
11
12
  DEFAULT_RULE_NUMBER = 100
12
13
 
13
14
  def self.create_network_acl_ingress_entries(region:, vpc_id:, cidr_blocks:)
@@ -30,26 +31,24 @@ module Banacle
30
31
 
31
32
  def create_network_acl_ingress_entries
32
33
  cidr_blocks.map do |cidr_block|
33
- result = begin
34
- create_network_acl_ingress_entry(cidr_block)
35
- AwsWrapper::Result.new(status: true)
36
- rescue AwsWrapper::Error => e
37
- AwsWrapper::Result.new(status: false, error: e)
38
- end
39
- [cidr_block, result]
40
- end.to_h
34
+ begin
35
+ rule_number = create_network_acl_ingress_entry(cidr_block)
36
+ Result.new(cidr_block: cidr_block, status: true, rule_number: rule_number)
37
+ rescue AwsWrapper::Error => e
38
+ Result.new(cidr_block: cidr_block, status: false, error: e)
39
+ end
40
+ end
41
41
  end
42
42
 
43
43
  def delete_network_acl_entries
44
44
  cidr_blocks.map do |cidr_block|
45
- result = begin
46
- delete_network_acl_entry(cidr_block)
47
- AwsWrapper::Result.new(status: true)
48
- rescue AwsWrapper::Error => e
49
- AwsWrapper::Result.new(status: false, error: e)
50
- end
51
- [cidr_block, result]
52
- end.to_h
45
+ begin
46
+ rule_number = delete_network_acl_entry(cidr_block)
47
+ Result.new(cidr_block: cidr_block, status: true, rule_number: rule_number)
48
+ rescue AwsWrapper::Error => e
49
+ Result.new(cidr_block: cidr_block, status: false, error: e)
50
+ end
51
+ end
53
52
  end
54
53
 
55
54
  private
@@ -95,6 +94,8 @@ module Banacle
95
94
  else
96
95
  raise EntryNotFoundError.new("not found")
97
96
  end
97
+
98
+ target.rule_number
98
99
  end
99
100
 
100
101
  def add_rule_number(num)
@@ -1,6 +1,5 @@
1
1
  require 'aws-sdk-ec2'
2
2
  require 'banacle/aws_wrapper/error'
3
- require 'banacle/aws_wrapper/result'
4
3
 
5
4
  module Banacle
6
5
  module AwsWrapper
@@ -22,13 +22,16 @@ module Banacle
22
22
 
23
23
  self.request = Request.new(raw_request)
24
24
 
25
- if request.action.approved?
26
- handle_approval
27
- elsif request.action.rejected?
28
- handle_reject
29
- elsif request.action.cancelled?
30
- handle_cancellation
31
- end
25
+ json = if request.action.approved?
26
+ handle_approval
27
+ elsif request.action.rejected?
28
+ handle_reject
29
+ elsif request.action.cancelled?
30
+ handle_cancellation
31
+ end
32
+ puts json
33
+
34
+ json
32
35
  end
33
36
 
34
37
  private
@@ -61,10 +61,10 @@ module Banacle
61
61
  end
62
62
 
63
63
  def format_results(results)
64
- results.map do |cidr_block, result|
65
- t = "#{action} DENY #{cidr_block} => "
64
+ results.map do |result|
65
+ t = "#{action} DENY #{result.cidr_block} => "
66
66
  if result.status
67
- t += "succeeded"
67
+ t += "succeeded (rule number: #{result.rule_number})"
68
68
  else
69
69
  t += "error: #{result.error}"
70
70
  end
@@ -28,7 +28,10 @@ module Banacle
28
28
  return Renderer.render_error(e)
29
29
  end
30
30
 
31
- Renderer.new(request, command, config).render_approval_request
31
+ json = Renderer.new(request, command, config).render_approval_request
32
+ puts json
33
+
34
+ json
32
35
  end
33
36
 
34
37
  private
@@ -15,6 +15,11 @@ module Banacle
15
15
  #
16
16
  def parse(text)
17
17
  elems = text.split(" ")
18
+
19
+ if elems.size > 4
20
+ raise ParseError.new("too many arguments")
21
+ end
22
+
18
23
  action, region, vpc_id_or_name, cidr_blocks_str = elems
19
24
 
20
25
  unless action
@@ -1,3 +1,3 @@
1
1
  module Banacle
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuya Kosugiyama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-30 00:00:00.000000000 Z
11
+ date: 2019-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -153,7 +153,6 @@ files:
153
153
  - lib/banacle/app.rb
154
154
  - lib/banacle/aws_wrapper/error.rb
155
155
  - lib/banacle/aws_wrapper/nacl.rb
156
- - lib/banacle/aws_wrapper/result.rb
157
156
  - lib/banacle/aws_wrapper/vpc.rb
158
157
  - lib/banacle/config.rb
159
158
  - lib/banacle/interactive_message/authenticator.rb
@@ -1,6 +0,0 @@
1
- module Banacle
2
- module AwsWrapper
3
- Result = Struct.new(:status, :error, keyword_init: true) do
4
- end
5
- end
6
- end