stream_auditor 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 894b6a9dbf40b4b66c3919484e8457c1e06c7235
4
+ data.tar.gz: dc994150516cdca9bd60b8efb77d8f7541c055dc
5
+ SHA512:
6
+ metadata.gz: 64f66715dd0021f18f8085daa98de1e8d2a68ff4cd7d81f8ad3ddde63d1dd40fdeafb6849e173bd6766c6767ef26c50e8bd1664766ff03226c247096ae0a1565
7
+ data.tar.gz: c82e5dc68d6091015d7319be2004d677f0832c3d843dc140a2dfb77e61229edbc156411d126c3cb6ae851797c1e5fcb722dd562fbe9748608268b1325a5565c4
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stream_auditor.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # StreamAuditor
2
+
3
+ This is an IO stream auditor for the [SOAR Auditing Provider](https://github.com/hetznerZA/soar_auditing_provider).
4
+
5
+ It supports auditing to the standard error and output streams, to a file path (in append mode) or to an already open IO object.
6
+ In all cases, the stream is flushed on every audit call.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'stream_auditor'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install stream_auditor
23
+
24
+ ## Usage
25
+
26
+ Configuration of the SOAR auditing provider is still chunky. The `queue_worker` config is not required for the stream auditor, but
27
+ the auditing provider insists on it. So for now:
28
+
29
+ ```ruby
30
+ # Log to stderr
31
+ config = {
32
+ "auditing" => {
33
+ "provider" => "SoarAuditingProvider::AuditingProvider",
34
+ "level" => "debug",
35
+ "install_exit_handler" => "true",
36
+ "direct_auditor_call" => "true",
37
+ "queue_worker" => {
38
+ "queue_size" => 1,
39
+ "back_off_attempts" => 1
40
+ },
41
+ "auditors" => {
42
+ "local" => {
43
+ "adaptor" => "StreamAuditor"
44
+ }
45
+ }
46
+ }
47
+ }
48
+ SoarAuditingProvider::AuditingProvider.new(config["auditing"])
49
+
50
+ # Log to stdout
51
+ config = {
52
+ "auditing" => {
53
+ "provider" => "SoarAuditingProvider::AuditingProvider",
54
+ "level" => "debug",
55
+ "install_exit_handler" => "true",
56
+ "direct_auditor_call" => "true",
57
+ "queue_worker" => {
58
+ "queue_size" => 1,
59
+ "back_off_attempts" => 1
60
+ },
61
+ "auditors" => {
62
+ "local" => {
63
+ "adaptor" => "StreamAuditor",
64
+ "standard_stream" => "stdout"
65
+ }
66
+ }
67
+ }
68
+ }
69
+ SoarAuditingProvider::AuditingProvider.new(config["auditing"])
70
+
71
+ # Log to file in append mode
72
+ config = {
73
+ "auditing" => {
74
+ "provider" => "SoarAuditingProvider::AuditingProvider",
75
+ "level" => "debug",
76
+ "install_exit_handler" => "true",
77
+ "direct_auditor_call" => "true",
78
+ "queue_worker" => {
79
+ "queue_size" => 1,
80
+ "back_off_attempts" => 1
81
+ },
82
+ "auditors" => {
83
+ "local" => {
84
+ "adaptor" => "StreamAuditor",
85
+ "path" => "/var/log/application.log"
86
+ }
87
+ }
88
+ }
89
+ }
90
+ SoarAuditingProvider::AuditingProvider.new(config["auditing"])
91
+
92
+ # Log to IO object
93
+ config = {
94
+ "auditing" => {
95
+ "provider" => "SoarAuditingProvider::AuditingProvider",
96
+ "level" => "debug",
97
+ "install_exit_handler" => "true",
98
+ "direct_auditor_call" => "true",
99
+ "queue_worker" => {
100
+ "queue_size" => 1,
101
+ "back_off_attempts" => 1
102
+ },
103
+ "auditors" => {
104
+ "local" => {
105
+ "adaptor" => "StreamAuditor",
106
+ "io" => File.open("/var/log/application.log", "a")
107
+ }
108
+ }
109
+ }
110
+ }
111
+ SoarAuditingProvider::AuditingProvider.new(config["auditing"])
112
+ ```
113
+
114
+ ## Development
115
+
116
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
117
+
118
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
119
+
120
+ ## Contributing
121
+
122
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/hetznerZA/stream_auditor).
123
+
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 "stream_auditor"
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,5 @@
1
+ require "soar_auditor_api/auditor_api"
2
+
3
+ class StreamAuditor < SoarAuditorApi::AuditorAPI
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,82 @@
1
+ require "stream_auditor/version"
2
+ require "soar_auditor_api/auditor_api"
3
+ require "fileutils"
4
+
5
+ class StreamAuditor < SoarAuditorApi::AuditorAPI
6
+
7
+ DEFAULT_CONFIGURATION = {
8
+ "standard_stream" => "stderr"
9
+ }
10
+
11
+ def initialize(configuration = nil)
12
+ configuration = cleanup_configuration(configuration)
13
+ super
14
+ end
15
+
16
+ def audit(data)
17
+ @stream << data.to_s.chomp + "\n"
18
+ @stream.flush
19
+ end
20
+
21
+ def configure(configuration = nil)
22
+ configuration = cleanup_configuration(configuration)
23
+ super
24
+ @stream = nil
25
+ @stream = configuration["io"] if configuration["io"]
26
+ @stream = standard_stream(configuration["standard_stream"]) if configuration["standard_stream"]
27
+ @stream = creative_open_file(configuration["path"]) if configuration["path"]
28
+ end
29
+
30
+ def configuration_is_valid?(configuration)
31
+ configuration = cleanup_configuration(configuration)
32
+ 1 == configuration.keys.inject(0) { |count, key| count += 1 if ["standard_stream", "path", "io"].include?(key) } and
33
+ configuration["io"].nil? || configuration["io"].respond_to?(:<<) and
34
+ configuration["path"].nil? || (File.expand_path(configuration["path"]) rescue false) and
35
+ configuration["standard_stream"].nil? || ["stderr", "stdout"].include?(configuration["standard_stream"])
36
+ end
37
+
38
+ private
39
+
40
+ # XXX Fight the auditor API
41
+ #
42
+ # The auditor API:
43
+ #
44
+ # * doesn't run the configure method for nil configuration,
45
+ # * insists on validation non-nil configuration, and
46
+ # * received the "adaptor" configuration key from the SOAR auditing provider.
47
+ #
48
+ def cleanup_configuration(configuration)
49
+ configuration = (configuration || {}).reject { |k, v| k == "adaptor" }
50
+
51
+ if configuration.nil? or configuration.empty?
52
+ DEFAULT_CONFIGURATION
53
+ else
54
+ configuration
55
+ end
56
+ end
57
+
58
+ # XXX Fight rspec
59
+ #
60
+ # From the rspec-expectations documentation:
61
+ #
62
+ # Note: to_stdout and to_stderr work by temporarily replacing $stdout or $stderr,
63
+ # so they're not able to intercept stream output that explicitly uses STDOUT/STDERR
64
+ # or that uses a reference to $stdout/$stderr that was stored before the matcher was used.
65
+ #
66
+ def standard_stream(stream_name)
67
+ case stream_name
68
+ when "stderr"
69
+ $stderr
70
+ when "stdout"
71
+ $stdout
72
+ else
73
+ raise ArgumentError, "unknown stream name #{stream_name.inspect}"
74
+ end
75
+ end
76
+
77
+ def creative_open_file(path)
78
+ FileUtils.mkdir_p(File.expand_path("..", path), mode: 0700)
79
+ File.open(path, "a")
80
+ end
81
+
82
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stream_auditor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stream_auditor"
8
+ spec.version = StreamAuditor::VERSION
9
+ spec.authors = ["Sheldon Hearn"]
10
+ spec.email = ["sheldonh@starjuice.net"]
11
+
12
+ spec.summary = %q{IO stream implementation of SOAR architecture auditing}
13
+ spec.description = %q{IO stream implementation of SOAR architecture auditing allowing easy publishing of events to a standard IO stream, (e.g. stderr)}
14
+ spec.homepage = "https://github.com/hetznerZA/stream_auditor"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+
25
+ spec.add_dependency "soar_auditor_api", "~> 0.0"
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stream_auditor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sheldon Hearn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-03 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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: soar_auditor_api
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.0'
69
+ description: IO stream implementation of SOAR architecture auditing allowing easy
70
+ publishing of events to a standard IO stream, (e.g. stderr)
71
+ email:
72
+ - sheldonh@starjuice.net
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/stream_auditor.rb
86
+ - lib/stream_auditor/version.rb
87
+ - stream_auditor.gemspec
88
+ homepage: https://github.com/hetznerZA/stream_auditor
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: IO stream implementation of SOAR architecture auditing
111
+ test_files: []
112
+ has_rdoc: