ruby_yappl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/parser.rb +22 -0
- data/lib/policy.rb +84 -0
- data/lib/ruby_yappl.rb +8 -0
- data/lib/rule.rb +46 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7ddcce6585d16853a0e8dad53cb65842f94423b3
|
4
|
+
data.tar.gz: faaa209a92c611bd1932af1aa828d80261d92aaf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81ad6072e4b766128d1c8b14ebb8a8c6650044ad0febbdd85a234cc05d9df46a4be0eaf141f1327406537e42ac20ae0b96961d51b9eafc38835449c1e4fdad26
|
7
|
+
data.tar.gz: 2316925d189a73c984f503572ce30f6d277a967141be524297333dca395fe57cd77e21994878c285b7074ab5cc52a01c5c68a5687739ac65b8a3d1ae61e2c232
|
data/lib/parser.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module YaPPL
|
2
|
+
class Parser
|
3
|
+
def self.parse(json)
|
4
|
+
raise SchemaError unless JsonValidator.validate('yappl', json)
|
5
|
+
|
6
|
+
data = JSON.parse(json)
|
7
|
+
rules = data['preference'].collect do |preference|
|
8
|
+
rule = preference['rule']
|
9
|
+
Rule.new(
|
10
|
+
permitted_purposes: rule['purpose']['permitted'],
|
11
|
+
excluded_purposes: rule['purpose']['excluded'],
|
12
|
+
permitted_utilizers: rule['utilizer']['permitted'],
|
13
|
+
excluded_utilizers: rule['utilizer']['excluded'],
|
14
|
+
transformations: rule['transformation'],
|
15
|
+
valid_from: Time.parse(rule['valid_from']),
|
16
|
+
expiration_date: Time.parse(rule['exp_date'])
|
17
|
+
)
|
18
|
+
end
|
19
|
+
return Policy.new(data['id'], rules)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/policy.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module YaPPL
|
2
|
+
class Policy
|
3
|
+
attr_reader :id, :rules
|
4
|
+
|
5
|
+
def initialize(id, rules)
|
6
|
+
@id = id
|
7
|
+
@rules = rules
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.from_policy_file(json)
|
11
|
+
Parser.parse(json)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_policy
|
15
|
+
to_json
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_excluded_purpose
|
19
|
+
rules.map(&:excluded_purposes).flatten.uniq
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_excluded_utilizer
|
23
|
+
rules.map(&:excluded_utilizers).flatten.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
def new_rule(args)
|
27
|
+
add_rule Rule.new(args)
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_rule(rule)
|
31
|
+
max_id = rules.map(&:id).max
|
32
|
+
rule.id = max_id + 1
|
33
|
+
rules << rule
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_tr_rules # rename?
|
37
|
+
active_rules.map do |rule|
|
38
|
+
{
|
39
|
+
permitted_purposes: rule.permitted_purposes,
|
40
|
+
permitted_utilizers: rule.permitted_utilizers,
|
41
|
+
transformations: rule.transformations
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def archive_rule(rule_id)
|
47
|
+
rule = rule_by_id(rule_id)
|
48
|
+
rule.archive!
|
49
|
+
end
|
50
|
+
|
51
|
+
def update_rule(id, args)
|
52
|
+
archive_rule(id)
|
53
|
+
rule = Rule.new(args)
|
54
|
+
rule.id = id
|
55
|
+
rules << rule
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_json
|
59
|
+
preferences = @rules.map { |rule| { rule: rule.to_h } }
|
60
|
+
|
61
|
+
{
|
62
|
+
id: @id,
|
63
|
+
preference: preferences
|
64
|
+
}.to_json
|
65
|
+
end
|
66
|
+
|
67
|
+
def rule_by_id(id)
|
68
|
+
matching_rules = rules.select { |rule| rule.id == id }
|
69
|
+
if matching_rules.count == 1
|
70
|
+
matching_rules.first
|
71
|
+
else
|
72
|
+
matching_rules
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def archived_rules
|
77
|
+
rules.select { |rule| rule.id == -1 }
|
78
|
+
end
|
79
|
+
|
80
|
+
def active_rules
|
81
|
+
rules.select { |rule| rule.id != -1 && !rule.expired? }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/ruby_yappl.rb
ADDED
data/lib/rule.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module YaPPL
|
2
|
+
class Rule
|
3
|
+
attr_accessor :id
|
4
|
+
attr_reader :permitted_purposes, :excluded_purposes, :permitted_utilizers,
|
5
|
+
:excluded_utilizers, :transformations, :valid_from, :expiration_date
|
6
|
+
|
7
|
+
def initialize(args = {})
|
8
|
+
args.each do |key, value|
|
9
|
+
self.instance_variable_set("@#{key}".to_sym, value)
|
10
|
+
end
|
11
|
+
@valid_from = Time.now unless valid_from
|
12
|
+
@expiration_date = default_time unless expiration_date
|
13
|
+
end
|
14
|
+
|
15
|
+
def archive!
|
16
|
+
@id = -1
|
17
|
+
@expiration_date = Time.now
|
18
|
+
end
|
19
|
+
|
20
|
+
def expired?
|
21
|
+
expiration_date != default_time && Time.now > expiration_date
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_h
|
25
|
+
{
|
26
|
+
purpose: {
|
27
|
+
permitted: permitted_purposes,
|
28
|
+
excluded: excluded_purposes
|
29
|
+
},
|
30
|
+
utilizer: {
|
31
|
+
permitted: permitted_utilizers,
|
32
|
+
excluded: excluded_utilizers
|
33
|
+
},
|
34
|
+
transformation: transformations,
|
35
|
+
valid_from: valid_from.strftime('%FT%T.%LZ'),
|
36
|
+
exp_date: expiration_date.strftime('%FT%T.%LZ')
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def default_time
|
43
|
+
Time.new(0, 1, 1)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_yappl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Peikert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: t.s.peikert+yappl@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/parser.rb
|
20
|
+
- lib/policy.rb
|
21
|
+
- lib/ruby_yappl.rb
|
22
|
+
- lib/rule.rb
|
23
|
+
homepage: http://rubygems.org/gems/ruby_yappl
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.5.2
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: ruby gem for the yappl privacy preference language
|
47
|
+
test_files: []
|