audit 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -0
- data/Rakefile +3 -17
- data/audit.gemspec +3 -3
- data/lib/audit.rb +1 -1
- data/lib/audit/log.rb +3 -2
- data/lib/audit/tracking.rb +1 -1
- data/test/log_test.rb +9 -3
- data/test/storage-conf.xml +1 -1
- data/test/test_helper.rb +9 -4
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -45,14 +45,6 @@ task :compat do
|
|
45
45
|
sh "rvm 1.9.2@audit,ree-1.8.7-2010.01@audit rake test"
|
46
46
|
end
|
47
47
|
|
48
|
-
desc "Generate RCov test coverage and open in your browser"
|
49
|
-
task :coverage do
|
50
|
-
require 'rcov'
|
51
|
-
sh "rm -fr coverage"
|
52
|
-
sh "rcov test/test_*.rb"
|
53
|
-
sh "open coverage/index.html"
|
54
|
-
end
|
55
|
-
|
56
48
|
require 'rake/rdoctask'
|
57
49
|
Rake::RDocTask.new do |rdoc|
|
58
50
|
rdoc.rdoc_dir = 'rdoc'
|
@@ -61,15 +53,7 @@ Rake::RDocTask.new do |rdoc|
|
|
61
53
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
54
|
end
|
63
55
|
|
64
|
-
desc "
|
65
|
-
task :console do
|
66
|
-
sh "irb -rubygems -r ./lib/#{name}.rb"
|
67
|
-
end
|
68
|
-
|
69
|
-
# =============
|
70
|
-
# = Packaging =
|
71
|
-
# =============
|
72
|
-
|
56
|
+
desc "Build, tag, push and publish a new release."
|
73
57
|
task :release => :build do
|
74
58
|
unless `git branch` =~ /^\* master$/
|
75
59
|
puts "You must be on the master branch to release!"
|
@@ -82,12 +66,14 @@ task :release => :build do
|
|
82
66
|
sh "gem push pkg/#{name}-#{version}.gem"
|
83
67
|
end
|
84
68
|
|
69
|
+
desc "Build a new gem"
|
85
70
|
task :build => :gemspec do
|
86
71
|
sh "mkdir -p pkg"
|
87
72
|
sh "gem build #{gemspec_file}"
|
88
73
|
sh "mv #{gem_file} pkg"
|
89
74
|
end
|
90
75
|
|
76
|
+
desc "Update the generated gemspec"
|
91
77
|
task :gemspec => :validate do
|
92
78
|
# read spec file and split out manifest section
|
93
79
|
spec = File.read(gemspec_file)
|
data/audit.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'audit'
|
16
|
-
s.version = '0.
|
17
|
-
s.date = '2010-
|
16
|
+
s.version = '0.4.0'
|
17
|
+
s.date = '2010-11-16'
|
18
18
|
s.rubyforge_project = 'audit'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
## a custom homepage, consider using your GitHub URL or the like.
|
28
28
|
s.authors = ["Adam Keys"]
|
29
29
|
s.email = 'adam@therealadam.com'
|
30
|
-
s.homepage = 'http://github.com/therealadam/
|
30
|
+
s.homepage = 'http://github.com/therealadam/audit'
|
31
31
|
|
32
32
|
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
33
33
|
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
data/lib/audit.rb
CHANGED
data/lib/audit/log.rb
CHANGED
@@ -14,12 +14,13 @@ module Audit::Log
|
|
14
14
|
# bucket - the String name for the logical bucket this audit record belongs
|
15
15
|
# to (i.e. table)
|
16
16
|
# key - the String key into the logical bucket
|
17
|
+
# timestamp - timestamp to use for this record's UUID
|
17
18
|
# changes - the changes hash (as generated by ActiveRecord) to store
|
18
19
|
#
|
19
20
|
# Returns nothing.
|
20
|
-
def self.record(bucket, key, changes)
|
21
|
+
def self.record(bucket, key, timestamp, changes)
|
21
22
|
json = Yajl::Encoder.encode(changes)
|
22
|
-
payload = {SimpleUUID::UUID.new => json}
|
23
|
+
payload = {SimpleUUID::UUID.new(timestamp) => json}
|
23
24
|
connection.insert(:Audits, "#{bucket}:#{key}", payload)
|
24
25
|
end
|
25
26
|
|
data/lib/audit/tracking.rb
CHANGED
@@ -34,7 +34,7 @@ module Audit::Tracking
|
|
34
34
|
end
|
35
35
|
|
36
36
|
data = {"changes" => changes, "metadata" => audit_metadata}
|
37
|
-
Audit::Tracking.log.record(audit_bucket, self.id, data)
|
37
|
+
Audit::Tracking.log.record(audit_bucket, self.id, Time.now.utc, data)
|
38
38
|
@audit_metadata = {}
|
39
39
|
end
|
40
40
|
|
data/test/log_test.rb
CHANGED
@@ -3,16 +3,18 @@ require 'test_helper'
|
|
3
3
|
class LogTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
should "save audit record" do
|
6
|
-
|
6
|
+
assert_nothing_raised do
|
7
|
+
Audit::Log.record(:Users, 1, timestamp, simple_change)
|
8
|
+
end
|
7
9
|
end
|
8
10
|
|
9
11
|
should "load audit records" do
|
10
|
-
Audit::Log.record(:Users, 1, simple_change)
|
12
|
+
Audit::Log.record(:Users, 1, timestamp, simple_change)
|
11
13
|
assert_kind_of Audit::Changeset, Audit::Log.audits(:Users, 1).first
|
12
14
|
end
|
13
15
|
|
14
16
|
should "load audits with multiple changed attributes" do
|
15
|
-
Audit::Log.record(:Users, 1, multiple_changes)
|
17
|
+
Audit::Log.record(:Users, 1, timestamp, multiple_changes)
|
16
18
|
changes = Audit::Log.audits(:Users, 1).first.changes
|
17
19
|
changes.each do |change|
|
18
20
|
assert %w{username age}.include?(change.attribute)
|
@@ -20,6 +22,10 @@ class LogTest < Test::Unit::TestCase
|
|
20
22
|
assert ["adam", 31].include?(change.new_value)
|
21
23
|
end
|
22
24
|
end
|
25
|
+
|
26
|
+
def timestamp
|
27
|
+
Time.now.utc
|
28
|
+
end
|
23
29
|
|
24
30
|
def simple_change
|
25
31
|
{"changes" => {"username" => ["akk", "adam"]}, "metadata" => {}}
|
data/test/storage-conf.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
<Keyspaces>
|
3
3
|
<Keyspace Name="Audit">
|
4
4
|
<KeysCachedFraction>0.01</KeysCachedFraction>
|
5
|
-
<ColumnFamily CompareWith="
|
5
|
+
<ColumnFamily CompareWith="TimeUUIDType" Name="Audits" />
|
6
6
|
<ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
|
7
7
|
<ReplicationFactor>1</ReplicationFactor>
|
8
8
|
<EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch>
|
data/test/test_helper.rb
CHANGED
@@ -14,10 +14,15 @@ class Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
alias_method :original_setup, :setup
|
16
16
|
def setup
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
if ENV["CASSANDRA"] == "Y"
|
18
|
+
Audit::Log.connection = Cassandra.new("Audit")
|
19
|
+
Audit::Log.connection.clear_keyspace!
|
20
|
+
else
|
21
|
+
Audit::Log.connection = Cassandra::Mock.new(
|
22
|
+
'Audit',
|
23
|
+
File.join(File.dirname(__FILE__), 'storage-conf.xml')
|
24
|
+
)
|
25
|
+
end
|
21
26
|
original_setup
|
22
27
|
end
|
23
28
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 4
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Adam Keys
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-16 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -90,7 +90,7 @@ files:
|
|
90
90
|
- test/test_helper.rb
|
91
91
|
- test/tracking_test.rb
|
92
92
|
has_rdoc: true
|
93
|
-
homepage: http://github.com/therealadam/
|
93
|
+
homepage: http://github.com/therealadam/audit
|
94
94
|
licenses: []
|
95
95
|
|
96
96
|
post_install_message:
|