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 +4 -4
- data/README.md +3 -3
- data/lib/stream_auditor/version.rb +1 -1
- data/lib/stream_auditor.rb +36 -56
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50250b66a46864c7c059e9b0b55983f25086a662
|
4
|
+
data.tar.gz: d0b0f3f9d49fea41c7a24001d0035c022862f4c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
"
|
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
|
-
"
|
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
|
-
"
|
106
|
+
"stream" => File.open("/var/log/application.log", "a")
|
107
107
|
}
|
108
108
|
}
|
109
109
|
}
|
data/lib/stream_auditor.rb
CHANGED
@@ -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
|
-
|
18
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
52
|
-
|
53
|
-
else
|
54
|
-
configuration
|
55
|
-
end
|
38
|
+
def stream
|
39
|
+
@stream || $stderr
|
56
40
|
end
|
57
41
|
|
58
|
-
|
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
|
78
|
-
|
79
|
-
|
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:
|
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-
|
11
|
+
date: 2017-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|