soar_auditor_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9879b49a5a82d14cc2fe47b7ebddaf5c63d482c0
4
+ data.tar.gz: 6b5131d74480cd7d7a4c5f15f11dfdcbe87b77e5
5
+ SHA512:
6
+ metadata.gz: a696ee6e0c1572c352e0990f3ee788a1d4929914287e5d59271863a66d82718c699168d411851af30b2be2232fda78822ee0ee76103f0ec4a52630ef2a579deb
7
+ data.tar.gz: 242caa4d8d79f6e521ceae3156885383b9227f5878be3f2c5028de8131f500fce233b3a26557553ef34186c8cc401a506666cce07281d39fab4ce41af3de5a63
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ .byebug_history
2
+ *tgz
3
+ left
4
+ test_tfa.sh
5
+ test_production.sh
6
+ iut-list
7
+ juddi-distro-*
8
+ *.swo
9
+ *.zip
10
+ *.tar.gz
11
+ *.swp
12
+ *.gem
13
+ *.rbc
14
+ /Gemfile.lock
15
+ /.config
16
+ /coverage/
17
+ /InstalledFiles
18
+ /pkg/
19
+ /spec/reports/
20
+ /spec/examples.txt
21
+ /test/tmp/
22
+ /test/version_tmp/
23
+ /tmp/
24
+ .DS_Store
25
+
26
+ ## Specific to RubyMotion:
27
+ .dat*
28
+ .repl_history
29
+ build/
30
+
31
+ ## Documentation cache and generated files:
32
+ /.yardoc/
33
+ /_yardoc/
34
+ /doc/
35
+ /rdoc/
36
+
37
+ ## Environment normalisation:
38
+ /.bundle/
39
+ /vendor/bundle
40
+ /lib/bundler/man/
41
+
42
+ # for a library or gem, you might want to ignore these files since the code is
43
+ # intended to run in multiple environments; otherwise, check them in:
44
+ # Gemfile.lock
45
+ # .ruby-version
46
+ # .ruby-gemset
47
+
48
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
49
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ soar_auditor_api
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soar_auditor_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Barney de Villiers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,155 @@
1
+ #TODO fix this file
2
+
3
+ # SoarAuditorApi
4
+
5
+ This gem provides the auditor api for the SOAR architecture.
6
+
7
+ ## State of the API
8
+
9
+
10
+
11
+ ## Installation
12
+
13
+ Add this line to your auditor Gemfile:
14
+
15
+ ```ruby
16
+ gem 'soar_auditor_api'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install soar_auditor_api
26
+
27
+ ## Testing
28
+
29
+ Behavioural driven testing can be performed:
30
+
31
+ $ bundle exec rspec -cfd spec/*
32
+
33
+ ## Usage
34
+
35
+
36
+
37
+ ### Auditing Providers that utilize the SoarAuditorAPI as clients
38
+
39
+
40
+ Note that the APIs (debug/info/warn/error/fatal) accept any object as a parameter. The object will be serialized using the .to_s method and therefore the object must implement the .to_s method (or already be a string that has the .to_s method).
41
+
42
+
43
+ ### Auditors that extend from the SoarAuditorAPI
44
+
45
+ Extend from the SoarAuditorAPI as follow
46
+
47
+ ``` ruby
48
+ class MyAuditor < SoarAuditorApi::SoarAuditorAPI
49
+ end
50
+ ```
51
+
52
+ The auditors that extend from this API must implement two methods: "audit" and "configuration_is_valid"
53
+
54
+ The configuration_is_valid method provides the API with a way of ensuring that a configuration is valid for the auditor.
55
+ ```ruby
56
+ def configuration_is_valid(configuration)
57
+ return configuration.include?("something_needed")
58
+ end
59
+ ```
60
+
61
+ The audit method will be called when the base API wants to publish an audit event after it has been formatted and filtered.
62
+ ```ruby
63
+ def audit(data)
64
+ puts data
65
+ end
66
+ ```
67
+
68
+ The configuration is made available to the auditor through the @configuration attribute in the API.
69
+
70
+
71
+
72
+
73
+ #TODO complete this section
74
+ #TODO Extend the SoarAuditorApi::AuditingProviderAPI to create an auditing provider:
75
+
76
+
77
+
78
+ Provide the required inversion of control method to configure (an) injected auditor(s):
79
+
80
+ ```
81
+ def configure_auditor(configuration = nil)
82
+ @auditor.configure(configuration)
83
+ end
84
+ ```
85
+
86
+ Initialize the provider so:
87
+
88
+ ```
89
+ auditor = MyAuditor.new
90
+ auditor_configuration = { 'some' => 'configuration' }
91
+ @iut = MyAuditingProvider.new(auditor, auditor_configuration)
92
+ ```
93
+
94
+ Audit using the API methods, e.g.:
95
+
96
+ ```
97
+ @iut.info("This is info")
98
+ @iut.debug(some_debug_object)
99
+ @iut.warn("Statistics show that dropped packets have increased to #{dropped}%")
100
+ @iut.error("Could not resend some dropped packets. They have been lost. All is still OK, I could compensate")
101
+ @iut.fatal("Unable to perform action, too many dropped packets. Functional degradation.")
102
+ @iut << 'Rack::CommonLogger requires this'
103
+ ```
104
+
105
+ The API also supports appending as below, enabling support, e.g. for Rack::CommonLogger, etc.:
106
+
107
+ ```
108
+ <<
109
+ ```
110
+
111
+ ## Detailed example
112
+
113
+ ```
114
+ require 'log4r'
115
+ require 'soar_auditor_api'
116
+
117
+ class Log4rAuditingProvider < SoarAuditorApi::AuditingProviderAPI
118
+ def configure_auditor(configuration = nil)
119
+ @auditor.outputters = configuration['outputter']
120
+ end
121
+ end
122
+
123
+ class Main
124
+ include Log4r
125
+
126
+ def test_sanity
127
+ auditor = Logger.new 'sanity'
128
+ auditor_configuration = { 'outputter' => Outputter.stdout }
129
+ @iut = Log4rAuditingProvider.new(auditor, auditor_configuration)
130
+
131
+ some_debug_object = 123
132
+ @iut.info("This is info")
133
+ @iut.debug(some_debug_object)
134
+ dropped = 95
135
+ @iut.warn("Statistics show that dropped packets have increased to #{dropped}%")
136
+ @iut.error("Could not resend some dropped packets. They have been lost. All is still OK, I could compensate")
137
+ @iut.fatal("Unable to perform action, too many dropped packets. Functional degradation.")
138
+ end
139
+ end
140
+
141
+ main = Main.new
142
+ main.test_sanity
143
+ ```
144
+
145
+ ## Contributing
146
+
147
+ Bug reports and feature requests are welcome by email to barney dot de dot villiers at hetzner dot co dot za. This gem is sponsored by Hetzner (Pty) Ltd (http://hetzner.co.za)
148
+
149
+ ## Notes
150
+
151
+ Though out of scope for the provider, auditors should take into account encoding, serialization, and other NFRs.
152
+
153
+ ## License
154
+
155
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "soar_auditor_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,65 @@
1
+ module SoarAuditorApi
2
+ class SoarAuditorAPI
3
+ DEBUG_PREFIX = "debug:" unless defined? DEBUG_PREFIX; DEBUG_PREFIX.freeze
4
+ INFO_PREFIX = "info:" unless defined? INFO_PREFIX; INFO_PREFIX.freeze
5
+ WARN_PREFIX = "warn:" unless defined? WARN_PREFIX; WARN_PREFIX.freeze
6
+ ERROR_PREFIX = "error:" unless defined? ERROR_PREFIX; ERROR_PREFIX.freeze
7
+ FATAL_PREFIX = "fatal:" unless defined? FATAL_PREFIX; FATAL_PREFIX.freeze
8
+
9
+ def initialize
10
+ @configuration = nil
11
+ @minimum_audit_level = :info
12
+ @audit_levels = [:debug, :info, :warn, :error, :fatal]
13
+ end
14
+
15
+ def configure(configuration = nil)
16
+ raise ArgumentError, "Invalid configuration provided" unless configuration_is_valid(configuration)
17
+ @configuration = configuration
18
+ end
19
+
20
+ def set_audit_level(minimum_audit_level)
21
+ raise ArgumentError, "Invalid audit level specified" unless @audit_levels.include?(minimum_audit_level)
22
+ @minimum_audit_level = minimum_audit_level
23
+ end
24
+
25
+ def debug(data)
26
+ audit(DEBUG_PREFIX + data.to_s) if audit_filtered(:debug)
27
+ end
28
+
29
+ def <<(data)
30
+ audit(INFO_PREFIX + data.to_s) if audit_filtered(:info)
31
+ end
32
+
33
+ def info(data)
34
+ audit(INFO_PREFIX + data.to_s) if audit_filtered(:info)
35
+ end
36
+
37
+ def warn(data)
38
+ audit(WARN_PREFIX + data.to_s) if audit_filtered(:warn)
39
+ end
40
+
41
+ def error(data)
42
+ audit(ERROR_PREFIX + data.to_s) if audit_filtered(:error)
43
+ end
44
+
45
+ def fatal(data)
46
+ audit(FATAL_PREFIX + data.to_s) if audit_filtered(:fatal)
47
+ end
48
+
49
+ #Safety to ensure that the Auditor that extends this API implements this IOC method
50
+ def configuration_is_valid(configuration)
51
+ raise NotImplementedError, "Method must implement configuration_is_valid method in Auditor extending the API"
52
+ end
53
+
54
+ #Safety to ensure that the Auditor that extends this API implements this IOC method
55
+ def audit(data)
56
+ raise NotImplementedError, "Method must implement audit method in Auditor extending the API"
57
+ end
58
+
59
+ private
60
+
61
+ def audit_filtered(audit_level)
62
+ return @audit_levels.index(@minimum_audit_level) <= @audit_levels.index(audit_level)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module SoarAuditorApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'soar_auditor_api/version'
2
+ require 'soar_auditor_api/auditor_api'
3
+
4
+ module SoarAuditorApi
5
+ end
@@ -0,0 +1 @@
1
+ sanity
@@ -0,0 +1 @@
1
+ ruby-2.2
data/sanity/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'log4r'
4
+ gem 'byebug'
5
+ gem 'soar_auditor_api', "~> 0.0.1"
data/sanity/sanity.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'soar_auditor_api'
2
+ require 'byebug'
3
+
4
+ class SanityAuditor < SoarAuditorAPI
5
+ def configuration_is_valid(configuration)
6
+ return true
7
+ end
8
+
9
+ def audit(data)
10
+ puts data
11
+ end
12
+ end
13
+
14
+ class Main
15
+ def test_sanity
16
+ @iut = SanityAuditor.new
17
+ @iut.configure(nil)
18
+
19
+ some_debug_object = 123
20
+ @iut.info("This is info")
21
+ @iut.debug(some_debug_object)
22
+ dropped = 95
23
+ @iut.warn("Statistics show that dropped packets have increased to #{dropped}%")
24
+ @iut.error("Could not resend some dropped packets. They have been lost. All is still OK, I could compensate")
25
+ @iut.fatal("Unable to perform action, too many dropped packets. Functional degradation.")
26
+ @iut << 'Rack::CommonLogger requires this'
27
+ end
28
+ end
29
+
30
+ main = Main.new
31
+ main.test_sanity
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soar_auditor_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soar_auditor_api"
8
+ spec.version = SoarAuditorApi::VERSION
9
+ spec.authors = ["Barney de Villiers"]
10
+ spec.email = ["barney.de.villiers@hetzner.co.za"]
11
+
12
+ spec.summary = %q{SOAR auditor api}
13
+ spec.description = %q{SOAR auditor api from which auditors will extend from}
14
+ spec.homepage = "https://github.hetzner.co.za/hetznerZA/soar_auditor_api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "byebug", "~> 9"
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soar_auditor_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Barney de Villiers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9'
69
+ description: SOAR auditor api from which auditors will extend from
70
+ email:
71
+ - barney.de.villiers@hetzner.co.za
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".ruby-gemset"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/soar_auditor_api.rb
88
+ - lib/soar_auditor_api/auditor_api.rb
89
+ - lib/soar_auditor_api/version.rb
90
+ - sanity/.ruby-gemset
91
+ - sanity/.ruby-version
92
+ - sanity/Gemfile
93
+ - sanity/sanity.rb
94
+ - soar_auditor_api.gemspec
95
+ homepage: https://github.hetzner.co.za/hetznerZA/soar_auditor_api
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.8
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: SOAR auditor api
119
+ test_files: []