soar_auditing_format 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +8 -91
- data/lib/soar_auditing_format/version.rb +1 -1
- data/sanity/Gemfile +1 -1
- data/sanity/sanity.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63b94935c99264de5ac0f5a9fb0b88ce2f1718b4
|
4
|
+
data.tar.gz: 7397a4fff409fa113cfd28b2e7a3a5288921bf58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20f98f028dc46a3dcc30d774810a06cd4c4c46776b764b1bd940fe79c992e3575b96046578e3639e5f494bc74e669f360ea15b1fa55052898dd2a802519c8223
|
7
|
+
data.tar.gz: 7b596173ba504e477b029af241326eab01920e5489b3499e3ae82f1cc67b6547f01751a22c49fdc0689911393ca76ea86d384310b94f69aa33b9a173c40851e8
|
data/README.md
CHANGED
@@ -1,15 +1,6 @@
|
|
1
1
|
# SoarAuditingFormatter
|
2
2
|
|
3
|
-
This gem provides the formatting for auditing
|
4
|
-
|
5
|
-
#TODO complete file
|
6
|
-
|
7
|
-
## State of the API
|
8
|
-
|
9
|
-
This API is still a work in progress but should be sufficient for most auditors
|
10
|
-
|
11
|
-
Future work:
|
12
|
-
* The API should support the reformating of timestamps to a standardized ISO8601 format.
|
3
|
+
This gem provides the formatting of audit entries for auditing purposes.
|
13
4
|
|
14
5
|
## Installation
|
15
6
|
|
@@ -35,70 +26,16 @@ Behavioural driven testing can be performed:
|
|
35
26
|
|
36
27
|
## Usage
|
37
28
|
|
38
|
-
|
39
|
-
|
40
|
-
Extend from the AuditorAPI as follow
|
41
|
-
|
42
|
-
``` ruby
|
43
|
-
class MyAuditor < SoarAuditingFormatter::AuditorAPI
|
44
|
-
end
|
45
|
-
```
|
46
|
-
|
47
|
-
It is required that the auditors that extend from this API implement two methods: "audit" and "configuration_is_valid". The API will call these methods using inversion of control as follow:
|
48
|
-
|
49
|
-
The configuration_is_valid method provides the API with a way of ensuring that a configuration is valid for the auditor.
|
50
|
-
```ruby
|
51
|
-
def configuration_is_valid(configuration)
|
52
|
-
return configuration.include?("something_needed")
|
53
|
-
end
|
54
|
-
```
|
55
|
-
|
56
|
-
The audit method will be called when the base API wants to publish an audit event after it has been formatted and filtered.
|
57
|
-
```ruby
|
58
|
-
def audit(data)
|
59
|
-
puts data
|
60
|
-
end
|
61
|
-
```
|
62
|
-
|
63
|
-
The configuration is made available to the auditor through the @configuration attribute in the API class.
|
64
|
-
```ruby
|
65
|
-
def audit(data)
|
66
|
-
puts @configuration["preprefix"] + data
|
67
|
-
end
|
68
|
-
```
|
69
|
-
|
70
|
-
|
71
|
-
### Auditing Providers that utilize the AuditorAPI as clients
|
72
|
-
|
73
|
-
Instantiate an auditor that extends the AuditorAPI:
|
74
|
-
```ruby
|
75
|
-
@iut = SanityAuditor.new
|
76
|
-
```
|
77
|
-
|
78
|
-
Configure the auditor with required parameters:
|
79
|
-
```ruby
|
80
|
-
configuration = { "preprefix" => "very important:" }
|
81
|
-
@iut.configure(configuration)
|
82
|
-
```
|
29
|
+
When formatting an auditing entry call the formatter as follow:
|
83
30
|
|
84
|
-
Set the desired audit level. Allowed levels (in increasing level of priority) are :debug, :info, :warn, :error and :fatal. As an example only :warn, :error and :fatal audit events will be logged if you set the level to :warn.
|
85
31
|
```ruby
|
86
|
-
|
32
|
+
SoarAuditingFormatter::Formatter.format(:error,SecureRandom.hex(32),Time.now,"message")
|
87
33
|
```
|
88
34
|
|
89
|
-
|
90
|
-
```ruby
|
91
|
-
@iut.info("This is info")
|
92
|
-
@iut.warn("Statistics show that dropped packets have increased to #{dropped}%")
|
93
|
-
@iut.error("Could not resend some dropped packets. They have been lost. All is still OK, I could compensate")
|
94
|
-
@iut.fatal("Unable to perform action, too many dropped packets. Functional degradation.")
|
95
|
-
@iut << 'Rack::CommonLogger requires this'
|
96
|
-
```
|
35
|
+
When formatting an optional field call the formatter as follow:
|
97
36
|
|
98
|
-
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 of a basic object type that has the .to_s method).
|
99
37
|
```ruby
|
100
|
-
|
101
|
-
@iut.debug(some_debug_object)
|
38
|
+
SoarAuditingFormatter::Formatter.optional_field_format("somekey", "somevalue")
|
102
39
|
```
|
103
40
|
|
104
41
|
## Detailed example
|
@@ -106,32 +43,12 @@ some_debug_object = 123
|
|
106
43
|
```ruby
|
107
44
|
require 'soar_auditing_format'
|
108
45
|
require 'byebug'
|
109
|
-
|
110
|
-
class SanityAuditor < SoarAuditingFormatter::AuditorAPI
|
111
|
-
def configuration_is_valid(configuration)
|
112
|
-
return configuration.include?("preprefix")
|
113
|
-
end
|
114
|
-
|
115
|
-
def audit(data)
|
116
|
-
puts @configuration["preprefix"] + data
|
117
|
-
end
|
118
|
-
end
|
46
|
+
require 'securerandom'
|
119
47
|
|
120
48
|
class Main
|
121
49
|
def test_sanity
|
122
|
-
|
123
|
-
|
124
|
-
@iut.configure(configuration)
|
125
|
-
@iut.set_audit_level(:debug)
|
126
|
-
|
127
|
-
some_debug_object = 123
|
128
|
-
@iut.info("This is info")
|
129
|
-
@iut.debug(some_debug_object)
|
130
|
-
dropped = 95
|
131
|
-
@iut.warn("Statistics show that dropped packets have increased to #{dropped}%")
|
132
|
-
@iut.error("Could not resend some dropped packets. They have been lost. All is still OK, I could compensate")
|
133
|
-
@iut.fatal("Unable to perform action, too many dropped packets. Functional degradation.")
|
134
|
-
@iut << 'Rack::CommonLogger requires this'
|
50
|
+
my_optional_field = SoarAuditingFormatter::Formatter.optional_field_format("somekey", "somevalue")
|
51
|
+
puts SoarAuditingFormatter::Formatter.format(:error,SecureRandom.hex(32),Time.now,"#{my_optional_field} message")
|
135
52
|
end
|
136
53
|
end
|
137
54
|
|
data/sanity/Gemfile
CHANGED
data/sanity/sanity.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'soar_auditing_format'
|
2
2
|
require 'byebug'
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
class Main
|
5
6
|
def test_sanity
|
6
|
-
SoarAuditingFormatter::Formatter.
|
7
|
+
my_optional_field = SoarAuditingFormatter::Formatter.optional_field_format("somekey", "somevalue")
|
8
|
+
puts SoarAuditingFormatter::Formatter.format(:error,SecureRandom.hex(32),Time.now,"#{my_optional_field} message")
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|