access_schema 0.2.3 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/access_schema/builders/config_builder.rb +5 -0
- data/lib/access_schema/config.rb +8 -0
- data/lib/access_schema/loggers/proxy_logger.rb +22 -0
- data/lib/access_schema/loggers/stub_logger.rb +18 -0
- data/lib/access_schema/loggers/test_logger.rb +17 -0
- data/lib/access_schema/schema.rb +18 -0
- data/lib/access_schema/version.rb +1 -1
- data/lib/access_schema.rb +7 -0
- data/spec/access_schema/config_builder_spec.rb +13 -0
- data/spec/access_schema/loggers/proxy_logger_spec.rb +25 -0
- data/spec/access_schema/schema_spec.rb +25 -0
- data/spec/spec_helper.rb +2 -0
- metadata +13 -2
data/README.md
CHANGED
data/lib/access_schema/config.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module AccessSchema
|
2
|
+
|
3
|
+
class ProxyLogger
|
4
|
+
|
5
|
+
def initialize(logger)
|
6
|
+
@logger = logger
|
7
|
+
end
|
8
|
+
|
9
|
+
%w{debug info warn error fatal}.each do |level|
|
10
|
+
define_method(level) do |message = nil, &block|
|
11
|
+
if block
|
12
|
+
proxy_block = proc { "AccessSchema: #{block.call}" }
|
13
|
+
@logger.send(level, &proxy_block)
|
14
|
+
else
|
15
|
+
@logger.send(level, "AccessSchema: #{message}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AccessSchema
|
2
|
+
|
3
|
+
class TestLogger
|
4
|
+
|
5
|
+
attr_reader :output
|
6
|
+
attr_accessor :log_only_level
|
7
|
+
|
8
|
+
%w{debug info warn error fatal}.each do |level|
|
9
|
+
define_method(level) do |message = nil, &block|
|
10
|
+
return if log_only_level && level != log_only_level
|
11
|
+
@output = [@output, message || block.call].compact.join("\n")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/access_schema/schema.rb
CHANGED
@@ -55,6 +55,18 @@ module AccessSchema
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def check!(namespace_name, element_name, roles, options)
|
58
|
+
|
59
|
+
format_log_payload = lambda {
|
60
|
+
[
|
61
|
+
"namespace = '#{namespace_name}'",
|
62
|
+
"privilege = '#{element_name}'",
|
63
|
+
"roles = '#{roles.inspect}'",
|
64
|
+
"options = '#{options.inspect}'"
|
65
|
+
].join(', ')
|
66
|
+
}
|
67
|
+
|
68
|
+
logger.debug{ "check: #{format_log_payload.call}" }
|
69
|
+
|
58
70
|
allowed = for_element(namespace_name, element_name) do |element|
|
59
71
|
element.allow?(roles) do |expectation|
|
60
72
|
check_assert(expectation, options)
|
@@ -62,6 +74,7 @@ module AccessSchema
|
|
62
74
|
end
|
63
75
|
|
64
76
|
unless allowed
|
77
|
+
logger.info{ "check FAILED: #{format_log_payload.call}" }
|
65
78
|
raise NotAlowedError.new
|
66
79
|
else
|
67
80
|
true
|
@@ -87,5 +100,10 @@ module AccessSchema
|
|
87
100
|
@namespaces[namespace].elements
|
88
101
|
end
|
89
102
|
|
103
|
+
private
|
104
|
+
|
105
|
+
def logger
|
106
|
+
AccessSchema.config.logger
|
107
|
+
end
|
90
108
|
end
|
91
109
|
end
|
data/lib/access_schema.rb
CHANGED
@@ -8,6 +8,9 @@ require 'access_schema/namespace'
|
|
8
8
|
require 'access_schema/element'
|
9
9
|
require 'access_schema/expectation'
|
10
10
|
|
11
|
+
require 'access_schema/loggers/proxy_logger'
|
12
|
+
require 'access_schema/loggers/stub_logger'
|
13
|
+
|
11
14
|
require 'access_schema/builders/config_builder'
|
12
15
|
|
13
16
|
require 'access_schema/builders/basic_builder'
|
@@ -33,6 +36,10 @@ module AccessSchema
|
|
33
36
|
@config = ConfigBuilder.build(&block)
|
34
37
|
end
|
35
38
|
|
39
|
+
def self.config
|
40
|
+
@config ||= Config.new
|
41
|
+
end
|
42
|
+
|
36
43
|
def self.schema(name)
|
37
44
|
@config.schema(name)
|
38
45
|
end
|
@@ -12,4 +12,17 @@ describe AccessSchema::ConfigBuilder do
|
|
12
12
|
config.schema(:acl).plans.should_not be_nil
|
13
13
|
end
|
14
14
|
|
15
|
+
it "can specify logger" do
|
16
|
+
|
17
|
+
test_logger = AccessSchema::TestLogger.new
|
18
|
+
config = AccessSchema::ConfigBuilder.build do
|
19
|
+
logger test_logger
|
20
|
+
end
|
21
|
+
|
22
|
+
config.logger.debug("hello!")
|
23
|
+
|
24
|
+
test_logger.output.should == "AccessSchema: hello!"
|
25
|
+
|
26
|
+
end
|
27
|
+
|
15
28
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AccessSchema::ProxyLogger do
|
4
|
+
|
5
|
+
describe ".debug" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@logger = AccessSchema::TestLogger.new
|
9
|
+
@proxy = AccessSchema::ProxyLogger.new(@logger)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "adds 'AccessSchema: ' prefix to passed message" do
|
13
|
+
@proxy.debug("message test")
|
14
|
+
@logger.output.should == "AccessSchema: message test"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "adds the same prefix to message generated by passed block" do
|
18
|
+
@proxy.debug{ "block test" }
|
19
|
+
@logger.output.should == "AccessSchema: block test"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
@@ -2,6 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe AccessSchema::Schema, "errors rising" do
|
4
4
|
|
5
|
+
before do
|
6
|
+
@schema = AccessSchema::SchemaBuilder.build_file('spec/schema_example.rb')
|
7
|
+
end
|
8
|
+
|
5
9
|
describe "#add_plan" do
|
6
10
|
|
7
11
|
it "raises error if duplicate"
|
@@ -35,5 +39,26 @@ describe AccessSchema::Schema, "errors rising" do
|
|
35
39
|
|
36
40
|
end
|
37
41
|
|
42
|
+
describe "logging" do
|
43
|
+
|
44
|
+
before do
|
45
|
+
@logger = AccessSchema::TestLogger.new
|
46
|
+
AccessSchema.config.logger = @logger
|
47
|
+
end
|
48
|
+
|
49
|
+
it "logs check arguments with debug level" do
|
50
|
+
@logger.log_only_level = "debug"
|
51
|
+
@schema.allow? "Review", :mark_featured, :flower
|
52
|
+
@logger.output.should == "AccessSchema: check: namespace = 'Review', privilege = 'mark_featured', roles = '[:flower]', options = '{}'"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "logs check fail with info level" do
|
56
|
+
@logger.log_only_level = "info"
|
57
|
+
@schema.allow? "Review", :mark_featured, :none
|
58
|
+
@logger.output.should == "AccessSchema: check FAILED: namespace = 'Review', privilege = 'mark_featured', roles = '[:none]', options = '{}'"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
38
63
|
end
|
39
64
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: access_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: AccessSchema is a tool for ACL or tariff plans schema definition and
|
15
15
|
checks
|
@@ -40,11 +40,15 @@ files:
|
|
40
40
|
- lib/access_schema/element.rb
|
41
41
|
- lib/access_schema/exceptions.rb
|
42
42
|
- lib/access_schema/expectation.rb
|
43
|
+
- lib/access_schema/loggers/proxy_logger.rb
|
44
|
+
- lib/access_schema/loggers/stub_logger.rb
|
45
|
+
- lib/access_schema/loggers/test_logger.rb
|
43
46
|
- lib/access_schema/namespace.rb
|
44
47
|
- lib/access_schema/proxy.rb
|
45
48
|
- lib/access_schema/schema.rb
|
46
49
|
- lib/access_schema/version.rb
|
47
50
|
- spec/access_schema/config_builder_spec.rb
|
51
|
+
- spec/access_schema/loggers/proxy_logger_spec.rb
|
48
52
|
- spec/access_schema/proxy_spec.rb
|
49
53
|
- spec/access_schema/schema_builder_spec.rb
|
50
54
|
- spec/access_schema/schema_spec.rb
|
@@ -63,12 +67,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
67
|
- - ! '>='
|
64
68
|
- !ruby/object:Gem::Version
|
65
69
|
version: '0'
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
hash: -30797054816985066
|
66
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
74
|
none: false
|
68
75
|
requirements:
|
69
76
|
- - ! '>='
|
70
77
|
- !ruby/object:Gem::Version
|
71
78
|
version: '0'
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
hash: -30797054816985066
|
72
82
|
requirements: []
|
73
83
|
rubyforge_project: access_schema
|
74
84
|
rubygems_version: 1.8.16
|
@@ -77,6 +87,7 @@ specification_version: 3
|
|
77
87
|
summary: AccessSchema is an ACL tool
|
78
88
|
test_files:
|
79
89
|
- spec/access_schema/config_builder_spec.rb
|
90
|
+
- spec/access_schema/loggers/proxy_logger_spec.rb
|
80
91
|
- spec/access_schema/proxy_spec.rb
|
81
92
|
- spec/access_schema/schema_builder_spec.rb
|
82
93
|
- spec/access_schema/schema_spec.rb
|