stream_auditor 1.0.0 → 1.0.1

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: 50250b66a46864c7c059e9b0b55983f25086a662
4
- data.tar.gz: d0b0f3f9d49fea41c7a24001d0035c022862f4c1
3
+ metadata.gz: 7d895a8c1753ca74e5ae3c007c4e8330db73138d
4
+ data.tar.gz: 70ea4dc5e3193f09e51b7b5d61af2194c27ac883
5
5
  SHA512:
6
- metadata.gz: 4fed046c80026fedecd44e6932339fdef25c67802197bb506697a889810a1456a6ff41917ebb1db12a43b8df51f80685f01ec250deceebd821f91e7f623464f0
7
- data.tar.gz: 55f98b27fdc3ce7f24d26da9761005120a42b8a4f899285a613f21b772e4b659d119f45ed368975eef12a41c92177f5f59f98ec488e3ba91fb348f081d218592
6
+ metadata.gz: bae9104d6cd01600b625e86da2aeb9a17ecf656f6a2e45ec5527eebbd8a37ebac7ed84d693fc9853fec0c6a66ff331b6b4876168aa05592ba97fec283b050023
7
+ data.tar.gz: d6cc276f4291bbf79431d09dd9a757106170290c1e58e707e60acf39253e8f83bd4f3b58b23a0f808ee9846b6e6721a38cdc6b065ab9002e739fd95b198685c0
@@ -1,5 +1,5 @@
1
1
  require "soar_auditor_api/auditor_api"
2
2
 
3
3
  class StreamAuditor < SoarAuditorApi::AuditorAPI
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
@@ -2,13 +2,86 @@ require "stream_auditor/version"
2
2
  require "soar_auditor_api/auditor_api"
3
3
  require "fileutils"
4
4
 
5
+ ##
6
+ # An IO stream (or file) implementation of {http://www.rubydoc.info/gems/soar_auditor_api/SoarAuditorApi/AuditorAPI SoarAuditorApi::AuditorAPI}
7
+ #
8
+ # This implementation supports auditing to:
9
+ #
10
+ # * an already open {IO} object (or anything that implements {IO#<<} and {IO#flush},
11
+ # * the standard error stream (+$stderr+),
12
+ # * the standard output stream (+$stdout+), or
13
+ # * a file.
14
+ #
15
+ # Developers should not need to work directly with this class. Instead, they should configure it through the
16
+ # {http://www.rubydoc.info/gems/soar_auditing_provider/SoarAuditingProvider/AuditingProvider SOAR auditing provider}.
17
+ #
18
+ # @example Log to file
19
+ #
20
+ # require "soar_auditing_provider"
21
+ # require "stream_auditor"
22
+ #
23
+ # config = {
24
+ # "auditing" => {
25
+ # "provider" => "SoarAuditingProvider::AuditingProvider",
26
+ # "level" => "debug",
27
+ # "install_exit_handler" => "true",
28
+ # "direct_auditor_call" => "true",
29
+ # "queue_worker" => {
30
+ # "queue_size" => 1,
31
+ # "back_off_attempts" => 1
32
+ # },
33
+ # "auditors" => {
34
+ # "local" => {
35
+ # "adaptor" => "StreamAuditor",
36
+ # "stream" => "/var/log/application.log"
37
+ # }
38
+ # }
39
+ # }
40
+ # }
41
+ #
42
+ # auditor = SoarAuditingProvider::AuditingProvider.new(config["auditing"])
43
+ # auditor.info("Auditor initialized")
44
+ #
5
45
  class StreamAuditor < SoarAuditorApi::AuditorAPI
6
46
 
47
+ ##
48
+ # Write data to the configured stream
49
+ #
50
+ # The stream is immediately flushed after the data is written.
51
+ #
52
+ # @param [Object] data
53
+ # the {String} (or {Object} with +to_s+ method) to write.
54
+ # If the string is not newline-terminated, a newline is added.
55
+ #
7
56
  def audit(data)
8
57
  stream << data.to_s.chomp + "\n"
9
58
  stream.flush
10
59
  end
11
60
 
61
+ ##
62
+ # Apply the configuration supplied to {#initialize}
63
+ #
64
+ # @param [Hash] configuration
65
+ # This method accepts +nil+ or a {Hash}, but the auditor API only calls
66
+ # this method when the configuration is not +nil+.
67
+ #
68
+ # The configuration may contain the following {String} keys:
69
+ #
70
+ # * +adaptor+ - ignored (for compatibility with the SOAR auditing provider
71
+ # * +stream+ - the stream to audit to, one of:
72
+ # * an {IO} object (or anything that implements {IO#<<} and {IO#flush}
73
+ # * the string +$stderr+ for the standard error stream
74
+ # * the string +$stdout+ for the standard output stream
75
+ # * the string path to a file
76
+ #
77
+ # If the +stream+ key is ommitted, the default is +$stderr+.
78
+ #
79
+ # When the stream is the path to a file:
80
+ #
81
+ # * any missing intermediate directories will be created (mode 0700),
82
+ # * the file will be created if missing (mode 0600),
83
+ # * the file is opened in append mode.
84
+ #
12
85
  def configure(configuration = nil)
13
86
  super
14
87
  if configuration
@@ -21,6 +94,15 @@ class StreamAuditor < SoarAuditorApi::AuditorAPI
21
94
  end
22
95
  end
23
96
 
97
+ ##
98
+ # Validates the configuration
99
+ #
100
+ # @param [Hash] configuration
101
+ # the configuration to validate
102
+ #
103
+ # @return [true] if the configuration is valid
104
+ # @return [false] if the configuration is invalid
105
+ #
24
106
  def configuration_is_valid?(configuration)
25
107
  return false unless (configuration.keys - ["adaptor", "stream"]).empty?
26
108
 
@@ -32,7 +114,7 @@ class StreamAuditor < SoarAuditorApi::AuditorAPI
32
114
 
33
115
  def creative_open_file(path)
34
116
  FileUtils.mkdir_p(File.expand_path("..", path), mode: 0700)
35
- File.open(path, "a")
117
+ File.open(path, "a", 0600)
36
118
  end
37
119
 
38
120
  def stream
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stream_auditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Hearn