stream_auditor 0.1.0 → 1.0.0

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
  SHA1:
3
- metadata.gz: 894b6a9dbf40b4b66c3919484e8457c1e06c7235
4
- data.tar.gz: dc994150516cdca9bd60b8efb77d8f7541c055dc
3
+ metadata.gz: 50250b66a46864c7c059e9b0b55983f25086a662
4
+ data.tar.gz: d0b0f3f9d49fea41c7a24001d0035c022862f4c1
5
5
  SHA512:
6
- metadata.gz: 64f66715dd0021f18f8085daa98de1e8d2a68ff4cd7d81f8ad3ddde63d1dd40fdeafb6849e173bd6766c6767ef26c50e8bd1664766ff03226c247096ae0a1565
7
- data.tar.gz: c82e5dc68d6091015d7319be2004d677f0832c3d843dc140a2dfb77e61229edbc156411d126c3cb6ae851797c1e5fcb722dd562fbe9748608268b1325a5565c4
6
+ metadata.gz: 4fed046c80026fedecd44e6932339fdef25c67802197bb506697a889810a1456a6ff41917ebb1db12a43b8df51f80685f01ec250deceebd821f91e7f623464f0
7
+ data.tar.gz: 55f98b27fdc3ce7f24d26da9761005120a42b8a4f899285a613f21b772e4b659d119f45ed368975eef12a41c92177f5f59f98ec488e3ba91fb348f081d218592
data/README.md CHANGED
@@ -61,7 +61,7 @@ config = {
61
61
  "auditors" => {
62
62
  "local" => {
63
63
  "adaptor" => "StreamAuditor",
64
- "standard_stream" => "stdout"
64
+ "stream" => "$stdout"
65
65
  }
66
66
  }
67
67
  }
@@ -82,7 +82,7 @@ config = {
82
82
  "auditors" => {
83
83
  "local" => {
84
84
  "adaptor" => "StreamAuditor",
85
- "path" => "/var/log/application.log"
85
+ "stream" => "/var/log/application.log"
86
86
  }
87
87
  }
88
88
  }
@@ -103,7 +103,7 @@ config = {
103
103
  "auditors" => {
104
104
  "local" => {
105
105
  "adaptor" => "StreamAuditor",
106
- "io" => File.open("/var/log/application.log", "a")
106
+ "stream" => File.open("/var/log/application.log", "a")
107
107
  }
108
108
  }
109
109
  }
@@ -1,5 +1,5 @@
1
1
  require "soar_auditor_api/auditor_api"
2
2
 
3
3
  class StreamAuditor < SoarAuditorApi::AuditorAPI
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -4,79 +4,59 @@ require "fileutils"
4
4
 
5
5
  class StreamAuditor < SoarAuditorApi::AuditorAPI
6
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
7
  def audit(data)
17
- @stream << data.to_s.chomp + "\n"
18
- @stream.flush
8
+ stream << data.to_s.chomp + "\n"
9
+ stream.flush
19
10
  end
20
11
 
21
12
  def configure(configuration = nil)
22
- configuration = cleanup_configuration(configuration)
23
13
  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"]
14
+ if configuration
15
+ s = configuration["stream"]
16
+ @stream = if want_stdout_stream?(s) then $stdout
17
+ elsif want_stderr_stream?(s) then $stderr
18
+ elsif want_io_stream?(s) then s
19
+ elsif want_path_stream?(s) then creative_open_file(s)
20
+ end
21
+ end
28
22
  end
29
23
 
30
24
  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"])
25
+ return false unless (configuration.keys - ["adaptor", "stream"]).empty?
26
+
27
+ s = configuration["stream"]
28
+ want_default_stream?(s) or want_stderr_stream?(s) or want_stdout_stream?(s) or want_io_stream?(s) or want_path_stream?(s)
36
29
  end
37
30
 
38
31
  private
39
32
 
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" }
33
+ def creative_open_file(path)
34
+ FileUtils.mkdir_p(File.expand_path("..", path), mode: 0700)
35
+ File.open(path, "a")
36
+ end
50
37
 
51
- if configuration.nil? or configuration.empty?
52
- DEFAULT_CONFIGURATION
53
- else
54
- configuration
55
- end
38
+ def stream
39
+ @stream || $stderr
56
40
  end
57
41
 
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
42
+ def want_default_stream?(s)
43
+ s.nil?
75
44
  end
76
45
 
77
- def creative_open_file(path)
78
- FileUtils.mkdir_p(File.expand_path("..", path), mode: 0700)
79
- File.open(path, "a")
46
+ def want_io_stream?(s)
47
+ s.respond_to?(:<<) and s.respond_to?(:flush)
48
+ end
49
+
50
+ def want_path_stream?(s)
51
+ s.respond_to?(:start_with?) and (!s.start_with?("$")) and !!(File.expand_path(s) rescue false)
52
+ end
53
+
54
+ def want_stderr_stream?(s)
55
+ s == "$stderr"
56
+ end
57
+
58
+ def want_stdout_stream?(s)
59
+ s == "$stdout"
80
60
  end
81
61
 
82
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stream_auditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Hearn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-03 00:00:00.000000000 Z
11
+ date: 2017-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler