firewall_generator 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c21b3fe27863c8bbf411f177920b93b613654e7
4
+ data.tar.gz: 79bfd5dacde923cff09bff88c1cca9ac79176e41
5
+ SHA512:
6
+ metadata.gz: 5b4349744f2bdda06a7f866236253d3cffea15f8911aac0fa2abcd546bc6f4c4b687c51aeaf5d2364b7d09e7aa9a2a20946bd106a8513bcd41213f89dd7371db
7
+ data.tar.gz: 17482bd4013cc7358062ae0629f4a14df7f11620ae49d6d34e8ba97d883a9da097d8faebaa55765f970f9b508f28bb0edc0b4a726f17060be3cda88ba91dcb93
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in firewall_generator.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # Firewall Generator
2
+
3
+ Simple plugin based firewall generation
4
+
5
+ ## Installation
6
+
7
+ Install using:
8
+
9
+ $ gem install firewall_generator
10
+
11
+ ## Config
12
+
13
+ myconfig.yml
14
+
15
+ ---
16
+ :input:
17
+ - :type: aws
18
+ :options:
19
+ :access_key_id: AKIAFOOBARFOOBAR
20
+ :secret_access_key: aTasgWEGA/gwEGwageawseAGaGawegasEGAewgas
21
+ - :type: aws
22
+ :options:
23
+ :access_key_id: AKIAFOOBARFOOBAR
24
+ :secret_access_key: hWEgherhERHedrhdesrhAERG/.argaeagagswawe
25
+ :output:
26
+ - :type: template
27
+ :options:
28
+ :template: mytemplate.erb
29
+ :output: output.rules
30
+
31
+ mytemplate.erb
32
+
33
+ <% list.each do |item| %>
34
+ -A INPUT -p tcp --dport 1234 -s <%= item %>/32 -j ACCEPT
35
+ <% end %>
36
+
37
+ ## Usage
38
+
39
+ $ firewall_generator myconfig.yml
40
+ $ cat output.rules
41
+ -A INPUT -p tcp --dport 1234 -s 1.2.3.4/32 -j ACCEPT
42
+ -A INPUT -p tcp --dport 1234 -s 2.3.4.5/32 -j ACCEPT
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'firewall_generator'
3
+
4
+ command = FirewallGenerator::Command.new(ARGV)
5
+ command.run
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'firewall_generator/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "firewall_generator"
8
+ gem.version = FirewallGenerator::VERSION
9
+ gem.authors = ["Joshua B. Bussdieker"]
10
+ gem.email = ["jbussdieker@gmail.com"]
11
+ gem.summary = %q{Simple firewall generation tool}
12
+ gem.homepage = ""
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ gem.add_runtime_dependency 'aws-sdk'
19
+ end
@@ -0,0 +1,7 @@
1
+ require "firewall_generator/version"
2
+ require "firewall_generator/command"
3
+ require "firewall_generator/input"
4
+ require "firewall_generator/output"
5
+
6
+ module FirewallGenerator
7
+ end
@@ -0,0 +1,47 @@
1
+ require 'yaml'
2
+
3
+ module FirewallGenerator
4
+ class Command
5
+ def initialize(args)
6
+ @args = args
7
+ end
8
+
9
+ def config_file
10
+ @args[0] || "config/application.yml"
11
+ end
12
+
13
+ def config
14
+ YAML.load(config_data)
15
+ end
16
+
17
+ def inputs
18
+ config[:input].collect do |input|
19
+ Input.new(input)
20
+ end
21
+ end
22
+
23
+ def outputs
24
+ config[:output].collect do |output|
25
+ Output.new(output)
26
+ end
27
+ end
28
+
29
+ def run
30
+ list = []
31
+ inputs.each do |input|
32
+ list += input.result
33
+ end
34
+
35
+ outputs.each do |output|
36
+ output.list = list
37
+ output.result
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def config_data
44
+ File.read(config_file)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,10 @@
1
+ require 'firewall_generator/input/aws'
2
+
3
+ module FirewallGenerator
4
+ module Input
5
+ def self.new(input)
6
+ klass = const_get(input[:type].capitalize)
7
+ klass.new(input[:options])
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,38 @@
1
+ require 'aws-sdk'
2
+
3
+ module FirewallGenerator
4
+ module Input
5
+ class Aws
6
+ attr_accessor :options
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def ec2
13
+ AWS::EC2.new(options)
14
+ end
15
+
16
+ def result
17
+ all_public_ips.tap do |list|
18
+ list.compact!
19
+ list.uniq!
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def all_public_ips
26
+ [].tap do |list|
27
+ AWS.memoize do
28
+ ec2.regions.each do |region|
29
+ region.instances.each do |instance|
30
+ list << instance.public_ip_address
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ require 'firewall_generator/output/template'
2
+
3
+ module FirewallGenerator
4
+ module Output
5
+ def self.new(output)
6
+ klass = const_get(output[:type].capitalize)
7
+ klass.new(output[:options])
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ require 'erb'
2
+
3
+ module FirewallGenerator
4
+ module Output
5
+ class Template
6
+ attr_accessor :options, :list
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def template
13
+ ERB.new(template_data, nil, "<>")
14
+ end
15
+
16
+ def result
17
+ template.result(binding).tap do |result|
18
+ File.open(options[:output], "w") do |f|
19
+ f.write(result)
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def template_data
27
+ File.read(options[:template])
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module FirewallGenerator
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firewall_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joshua B. Bussdieker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - jbussdieker@gmail.com
30
+ executables:
31
+ - firewall_generator
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/firewall_generator
41
+ - firewall_generator.gemspec
42
+ - lib/firewall_generator.rb
43
+ - lib/firewall_generator/command.rb
44
+ - lib/firewall_generator/input.rb
45
+ - lib/firewall_generator/input/aws.rb
46
+ - lib/firewall_generator/output.rb
47
+ - lib/firewall_generator/output/template.rb
48
+ - lib/firewall_generator/version.rb
49
+ homepage: ''
50
+ licenses: []
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.2.2
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Simple firewall generation tool
72
+ test_files: []
73
+ has_rdoc: