soar_json_auditing_format 0.0.1

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: fbc77dd43c8bf34e66e772fe89c857e93f52cf02
4
+ data.tar.gz: a95fff53840670f27c0e9fb6eb4e33fe2b8904f0
5
+ SHA512:
6
+ metadata.gz: 49d04478b8f0fba152886dad58e2e481f25644994ad3d210806057a345bbc4f088bbd80ed4552becbbb616050af01e61e9e7f8029aeafb04a9ab688b71f0d227
7
+ data.tar.gz: 7ab143427537d1c246d4f590c93ef046483c75160683ff4bad95a14492e1276b557cdc90afbddcf7ef386f3febca226c13d63f32b83776cf5ae4ed89a0ce5fbd
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ .byebug_history
2
+ *tgz
3
+ left
4
+ test_tfa.sh
5
+ test_production.sh
6
+ iut-list
7
+ juddi-distro-*
8
+ *.swo
9
+ *.zip
10
+ *.tar.gz
11
+ *.swp
12
+ *.gem
13
+ *.rbc
14
+ Gemfile.lock
15
+ /.config
16
+ /coverage/
17
+ /InstalledFiles
18
+ /pkg/
19
+ /spec/reports/
20
+ /spec/examples.txt
21
+ /test/tmp/
22
+ /test/version_tmp/
23
+ /tmp/
24
+ .DS_Store
25
+
26
+ ## Specific to RubyMotion:
27
+ .dat*
28
+ .repl_history
29
+ build/
30
+
31
+ ## Documentation cache and generated files:
32
+ /.yardoc/
33
+ /_yardoc/
34
+ /doc/
35
+ /rdoc/
36
+
37
+ ## Environment normalisation:
38
+ /.bundle/
39
+ /vendor/bundle
40
+ /lib/bundler/man/
41
+
42
+ # for a library or gem, you might want to ignore these files since the code is
43
+ # intended to run in multiple environments; otherwise, check them in:
44
+ # Gemfile.lock
45
+ # .ruby-version
46
+ # .ruby-gemset
47
+
48
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
49
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ soar_json_auditing_format
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
data/Dockerfile ADDED
@@ -0,0 +1,10 @@
1
+ FROM ruby:2.3.0
2
+
3
+ WORKDIR /usr/local/src/
4
+
5
+ ADD . /usr/local/src/
6
+ RUN cd /usr/local/src/
7
+ RUN gem install bundler
8
+ RUN bundle install
9
+
10
+ CMD bundle exec rspec -cfd spec/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soar_json_auditing_format.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Barney de Villiers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # SoarJsonAuditingFormatter
2
+
3
+ This gem provides the formatting of audit entries for auditing purposes.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your auditor Gemfile:
8
+
9
+ ```ruby
10
+ gem 'soar_json_auditing_format'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install soar_json_auditing_format
20
+
21
+ ## Testing
22
+
23
+ Run the rspec test tests using docker compose:
24
+
25
+ ```bash
26
+ export UID
27
+ docker-compose build --force-rm --no-cache
28
+ docker-compose down
29
+ docker-compose run --rm soar-json-auditing-format
30
+ docker-compose down
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ When formatting an auditing entry call the formatter as follow:
36
+
37
+ ```ruby
38
+ SoarJsonAuditingFormatter::Formatter.format(:error,SecureRandom.hex(32),Time.now,"message")
39
+ ```
40
+
41
+ When formatting an optional field call the formatter as follow:
42
+
43
+ ```ruby
44
+ SoarJsonAuditingFormatter::Formatter.optional_field_format("somekey", "somevalue")
45
+ ```
46
+
47
+ ## Detailed example
48
+
49
+ ```ruby
50
+ require 'soar_json_auditing_format'
51
+ require 'byebug'
52
+ require 'securerandom'
53
+
54
+ class Main
55
+ def test_sanity
56
+ my_optional_field = SoarJsonAuditingFormatter::Formatter.optional_field_format("somekey", "somevalue")
57
+ puts SoarJsonAuditingFormatter::Formatter.format(:error,SecureRandom.hex(32),Time.now.utc.iso8601(3),"#{my_optional_field} message")
58
+ end
59
+ end
60
+
61
+ main = Main.new
62
+ main.test_sanity
63
+ ```
64
+
65
+ The formatted output of the example above will be something like this:
66
+
67
+ ``` bash
68
+ error,9241cee6f0368942202d4d0e22ac09cde6c88446137c8c48e4eb053a703855f8,2016-05-27T08:40:27.087Z,[somekey:somevalue] message
69
+ ```
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and feature requests are welcome by email to barney dot de dot villiers at hetzner dot co dot za. This gem is sponsored by Hetzner (Pty) Ltd (http://hetzner.co.za)
74
+
75
+ ## Notes
76
+
77
+ Though out of scope for the provider, auditors should take into account encoding, serialization, and other NFRs.
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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 "soar_json_auditing_format"
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,8 @@
1
+ version: '2.0'
2
+ services:
3
+ soar-json-auditing-format:
4
+ user: $UID:$UID
5
+ build: .
6
+ image: soar-json-auditing-format
7
+ volumes:
8
+ - .:/usr/local/src/
@@ -0,0 +1,5 @@
1
+ require 'soar_json_auditing_format/version'
2
+ require 'soar_json_auditing_format/formatter'
3
+
4
+ module SoarJsonAuditingFormatter
5
+ end
@@ -0,0 +1,25 @@
1
+ require 'time'
2
+ require 'json'
3
+
4
+ module SoarJsonAuditingFormatter
5
+ class Formatter
6
+ def self.format(level, service_id, flow_id, timestamp, message)
7
+ audit = message
8
+ if audit.is_a? Hash
9
+ audit['timestamp'] = Time.parse(timestamp.to_s).utc.iso8601(3)
10
+ audit['level'] = level
11
+ audit['service_id'] = service_id
12
+ audit['flow_id'] = flow_id unless audit['flow_id']
13
+ else
14
+ audit = {
15
+ 'timestamp' => Time.parse(timestamp.to_s).utc.iso8601(3),
16
+ 'level' => level,
17
+ 'service_id' => service_id,
18
+ 'flow_id' => flow_id,
19
+ 'message' => message
20
+ }
21
+ end
22
+ audit.to_json
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module SoarJsonAuditingFormatter
2
+ VERSION = "0.0.1"
3
+ end
data/retry.sh ADDED
@@ -0,0 +1,23 @@
1
+ #!/bin/bash
2
+
3
+ # Retries a command on failure.
4
+ # $1 - the max number of attempts
5
+ # $2... - the command to run
6
+ retry() {
7
+ local -r -i max_attempts="$1"; shift
8
+ local -r cmd="$@"
9
+ local -i attempt_num=1
10
+ local -i cmd_exit_code=0
11
+ until $cmd
12
+ do
13
+ cmd_exit_code=$?
14
+ if (( attempt_num == max_attempts ))
15
+ then
16
+ echo "Attempt $attempt_num failed with code $cmd_exit_code and there are no more attempts left!"
17
+ exit $cmd_exit_code
18
+ else
19
+ echo "Attempt $attempt_num failed with code $cmd_exit_code! Trying again in $attempt_num seconds..."
20
+ sleep $(( attempt_num++ ))
21
+ fi
22
+ done
23
+ }
@@ -0,0 +1 @@
1
+ sanity
@@ -0,0 +1 @@
1
+ ruby-2.2
data/sanity/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'byebug'
4
+ gem 'soar_json_auditing_format', "~> 0.0.5"
data/sanity/sanity.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'soar_json_auditing_format'
2
+ require 'byebug'
3
+ require 'securerandom'
4
+
5
+ class Main
6
+ def test_sanity
7
+ my_optional_field = SoarJsonAuditingFormatter::Formatter.optional_field_format("somekey", "somevalue")
8
+ puts SoarJsonAuditingFormatter::Formatter.format(:error,'my-service-identifier',SecureRandom.hex(32),Time.now.utc.iso8601(3),"#{my_optional_field} message")
9
+ end
10
+ end
11
+
12
+ main = Main.new
13
+ main.test_sanity
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soar_json_auditing_format/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soar_json_auditing_format"
8
+ spec.version = SoarJsonAuditingFormatter::VERSION
9
+ spec.authors = ["Barney de Villiers"]
10
+ spec.email = ["barney.de.villiers@hetzner.co.za"]
11
+
12
+ spec.summary = %q{SOAR JSON auditing format}
13
+ spec.description = %q{SOAR JSON auditing format that will define auditing event entries}
14
+ spec.homepage = "https://github.com/hetznerZA/soar_json_auditing_format"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "byebug", "~> 9"
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soar_json_auditing_format
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Barney de Villiers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-10 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9'
69
+ description: SOAR JSON auditing format that will define auditing event entries
70
+ email:
71
+ - barney.de.villiers@hetzner.co.za
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".ruby-gemset"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Dockerfile
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - docker-compose.yml
89
+ - lib/soar_json_auditing_format.rb
90
+ - lib/soar_json_auditing_format/formatter.rb
91
+ - lib/soar_json_auditing_format/version.rb
92
+ - retry.sh
93
+ - sanity/.ruby-gemset
94
+ - sanity/.ruby-version
95
+ - sanity/Gemfile
96
+ - sanity/sanity.rb
97
+ - soar_json_auditing_format.gemspec
98
+ homepage: https://github.com/hetznerZA/soar_json_auditing_format
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.8
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: SOAR JSON auditing format
122
+ test_files: []