camtool 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f150b39a20695aa69a3bde1a84e1f22f78e1fc007920b10a8a49c332c3d0512
4
- data.tar.gz: 94f865410c2a203d77e4ca8fcbc3db3422b12e79412a9caf8cbed2ce06c86f2e
3
+ metadata.gz: ae93580f3dcb26411ab426f91bc103138b6669311a93cfbfa5b27bbf9bc02f59
4
+ data.tar.gz: fbf7af3643fdb725e6c14097cb75125417e8231d010e46ebe96e4d8fd4036827
5
5
  SHA512:
6
- metadata.gz: 2c7c82e135f38b92b6fb70468c9fe42c4647e0fc3af17fd2208d38e4326e6f2e43d6d03965abc769341697181fbe6ebf498e1442a0013a7a33de9c809614a9ba
7
- data.tar.gz: 187a61ec87799ac4c7e9546b624263a252948396d2a96fabd967313028fc6bd01629dd62893f0c126a13bb73acccf5e84d889754a1e71b7432cf46ce9e53f693
6
+ metadata.gz: 210081179a8b11f5a0900851d92e139b097599ac01bf4c1cf4ba2a809659c218e980447df8a37f8fc18ceaa89433ec6c6ff09bd9f4487dcb2eba8e1ce0c584ae
7
+ data.tar.gz: a1b78e33126a9c38a14bf8e40ceb1fa7db92189b0e3e97e2254b65c1cb525a8a3321b0ae4dea4e31e607b8b7e4e8c8e3ba7ff3c1408102d207a4f1f8f0875c4b
@@ -20,9 +20,11 @@ elsif instruction == '--break'
20
20
  CamTool::LogBreaker.new.break_log_file target
21
21
  elsif instruction == '--validate'
22
22
  CamTool::ProvJSONtoRGL.new.read_log_file(target).validate
23
- puts 'Graph structure verified...'
23
+ puts 'Graph structure verified.'
24
24
  CamTool::EdgeValidator.new.read_log_file(target)
25
- puts 'Relations verified...'
25
+ puts 'Relations verified.'
26
+ CamTool::NodePresenceValidator.new.read_log_file(target).validate
27
+ puts 'Verticies presence verified.'
26
28
  elsif instruction == '--packet'
27
29
  CamTool::CheckPacket.new.read_log_file(target)
28
30
  elsif instruction == '--png'
@@ -30,13 +32,17 @@ elsif instruction == '--png'
30
32
  elsif instruction == '--list'
31
33
  types = ARGV[2]
32
34
  CamTool::ProvJSONtoRGL.new.read_log_file(target).list(types)
35
+ elsif instruction == '--search'
36
+ id = ARGV[2]
37
+ CamTool::Search.new.read_log_file(target).search(id)
33
38
  else
34
39
  puts '--version'
35
40
  puts '--info <path to log file>'
41
+ puts '--validate <path to log file>'
42
+ puts '--search <path to log file> <vertex/edge ID>'
36
43
  puts '--publish <path to log file>'
37
44
  puts '--break <path to log file>'
38
45
  puts '--png <path to log file>'
39
46
  puts '--packet <path to log file>'
40
- puts '--validate <path to log file>'
41
47
  puts '--list <path to log file> [optional comma-separated list of element type e.g. "path,argv"]'
42
48
  end
@@ -1,7 +1,10 @@
1
1
  require 'camtool/provjson_parser'
2
2
  require 'camtool/provjson_to_rgl'
3
3
  require 'camtool/edge_counter'
4
+ require 'camtool/validator_utils'
4
5
  require 'camtool/edge_validator'
6
+ require 'camtool/node_presence_validator'
7
+ require 'camtool/search'
5
8
  require 'camtool/vertex_counter'
6
9
  require 'camtool/log_breaker'
7
10
  require 'camtool/check_packet.rb'
@@ -1,45 +1,8 @@
1
1
  module CamTool
2
- class EdgeValidator < ProvJSONParser
2
+ class EdgeValidator < ValidatorUtils
3
3
  def initialize
4
4
  end
5
5
 
6
- def print_relation_bytes id
7
- id = id.gsub 'cf:', ''
8
- bytes = Base64.decode64(id).bytes.to_a
9
- type = bytes[7] & 0xF0
10
- puts type.to_s(16)
11
- type = bytes[8]
12
- puts type.to_s(16)
13
- end
14
-
15
- def is_relation? id
16
- id = id.gsub 'cf:', ''
17
- bytes = Base64.decode64(id).bytes.to_a
18
- type = bytes[7] & 0xF0
19
- return type == 0x80
20
- end
21
-
22
- def is_activity? id
23
- id = id.gsub 'cf:', ''
24
- bytes = Base64.decode64(id).bytes.to_a
25
- type = bytes[7] & 0xF0
26
- return type == 0x40
27
- end
28
-
29
- def is_entity? id
30
- id = id.gsub 'cf:', ''
31
- bytes = Base64.decode64(id).bytes.to_a
32
- type = bytes[7] & 0xF0
33
- return type == 0x20
34
- end
35
-
36
- def is_agent? id
37
- id = id.gsub 'cf:', ''
38
- bytes = Base64.decode64(id).bytes.to_a
39
- type = bytes[7] & 0xF0
40
- return type == 0x10
41
- end
42
-
43
6
  def used k, v
44
7
  abort "used prov:entity is of wrong type: #{v}." unless is_entity? v['prov:entity']
45
8
  abort "used prov:activity is of wrong type: #{v}." unless is_activity? v['prov:activity']
@@ -66,7 +29,6 @@ module CamTool
66
29
  end
67
30
 
68
31
  def relation k, v
69
- print_relation_bytes k
70
32
  puts v
71
33
  abort "relation should not be used"
72
34
  end
@@ -0,0 +1,90 @@
1
+ module CamTool
2
+ class NodePresenceValidator < ValidatorUtils
3
+ attr_reader :edges
4
+ attr_reader :nodes
5
+ attr_reader :sources
6
+ attr_reader :destinations
7
+
8
+ def initialize
9
+ @edges = Hash.new
10
+ @nodes = Hash.new
11
+ @sources = Hash.new
12
+ @destinations = Hash.new
13
+ end
14
+
15
+ def used k, v
16
+ @edges[k] = v
17
+ @destinations[k] = v['prov:entity']
18
+ @sources[k] = v['prov:activity']
19
+ end
20
+
21
+ def wasGeneratedBy k, v
22
+ @edges[k] = v
23
+ @destinations[k] = v['prov:activity']
24
+ @sources[k] = v['prov:entity']
25
+ end
26
+
27
+ def wasDerivedFrom k, v
28
+ @edges[k] = v
29
+ @destinations[k] = v['prov:generatedEntity']
30
+ @sources[k] = v['prov:usedEntity']
31
+ end
32
+
33
+ def wasInformedBy k, v
34
+ @edges[k] = v
35
+ @destinations[k] = v['prov:informant']
36
+ @sources[k] = v['prov:informed']
37
+ end
38
+
39
+ def wasAssociatedWith k, v
40
+ @edges[k] = v
41
+ @destinations[k] = v['prov:agent']
42
+ @sources[k] = v['prov:activity']
43
+ end
44
+
45
+ def entity k, v
46
+ abort "entity is of wrong type: #{v}." unless is_entity? k
47
+ @nodes[k]=v
48
+ end
49
+
50
+ def activity k, v
51
+ abort "activity is of wrong type: #{v}." unless is_activity? k
52
+ @nodes[k]=v
53
+ end
54
+
55
+ def agent k, v
56
+ abort "agent is of wrong type: #{v}." unless is_agent?(k) || v['prov:type']=='machine'
57
+ @nodes[k]=v
58
+ end
59
+
60
+ def validate
61
+ a = []
62
+ @sources = @sources.sort_by { |k, v| @edges[k]['cf:id'].to_i }.to_h
63
+ @sources.each do |k, v|
64
+ puts "Could not find source #{v}\nin\n#{@edges[k]}" unless @nodes.has_key? v
65
+ puts "destination:\n#{@destinations[k]}:#{@nodes[@destinations[k]]}\n\n" unless @nodes.has_key? v
66
+ a << v unless @nodes.has_key? v
67
+ end
68
+
69
+ @destinations = @destinations.sort_by { |k, v| @edges[k]['cf:id'].to_i }.to_h
70
+ @destinations.each do |k, v|
71
+ puts "Could not find destination #{v}\nin\n#{@edges[k]}" unless @nodes.has_key? v
72
+ puts "source:\n#{@sources[k]}:#{@nodes[@sources[k]]}\n\n" unless @nodes.has_key? v
73
+ a << v unless @nodes.has_key? v
74
+ end
75
+ if !a.empty?
76
+ puts "#{a.length} edge(s) with missing element."
77
+ a = a.uniq
78
+ puts "#{a.length} missing element(s).\n\n"
79
+ a.each do |v|
80
+ puts "Entity: " unless !is_entity? v
81
+ puts "Activity: " unless !is_activity? v
82
+ puts "Agent: " unless !is_agent? v
83
+ puts v
84
+ puts "\n"
85
+ end
86
+ abort 'Verification failed. Missing verticies.'
87
+ end
88
+ end
89
+ end
90
+ end
@@ -73,7 +73,7 @@ module CamTool
73
73
  end unless !json.key? 'activity'
74
74
 
75
75
  json['agent'].each do |k, v|
76
- self.activity k, v
76
+ self.agent k, v
77
77
  end unless !json.key? 'agent'
78
78
 
79
79
  json['used'].each do |k, v|
@@ -93,6 +93,7 @@ module CamTool
93
93
  a = @dg.topsort_iterator.to_a
94
94
  a_type = types.split(',')
95
95
  a.each do |v|
96
+ next unless !@map[v].nil?
96
97
  if a_type.include?(@map[v]['prov:type']) || types.nil?
97
98
  puts v + ' ' + @map[v]['prov:label'] unless @map[v]['prov:label'].nil?
98
99
  puts v + ' no label' unless !@map[v]['prov:label'].nil?
@@ -0,0 +1,45 @@
1
+ module CamTool
2
+ class Search < ProvJSONParser
3
+ attr_reader :map
4
+
5
+ def initialize
6
+ @map = Hash.new(0)
7
+ end
8
+
9
+ def used k, v
10
+ @map[k] = v
11
+ end
12
+
13
+ def wasGeneratedBy k, v
14
+ @map[k] = v
15
+ end
16
+
17
+ def wasDerivedFrom k, v
18
+ @map[k] = v
19
+ end
20
+
21
+ def wasInformedBy k, v
22
+ @map[k] = v
23
+ end
24
+
25
+ def wasAssociatedWith k, v
26
+ @map[k] = v
27
+ end
28
+
29
+ def entity k, v
30
+ @map[k] = v
31
+ end
32
+
33
+ def activity k, v
34
+ @map[k] = v
35
+ end
36
+
37
+ def agent k, v
38
+ @map[k] = v
39
+ end
40
+
41
+ def search id
42
+ puts @map[id]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,34 @@
1
+ module CamTool
2
+ class ValidatorUtils < ProvJSONParser
3
+ def initialize
4
+ end
5
+
6
+ def is_relation? id
7
+ id = id.gsub 'cf:', ''
8
+ bytes = Base64.decode64(id).bytes.to_a
9
+ type = bytes[7] & 0xF0
10
+ return type == 0x80
11
+ end
12
+
13
+ def is_activity? id
14
+ id = id.gsub 'cf:', ''
15
+ bytes = Base64.decode64(id).bytes.to_a
16
+ type = bytes[7] & 0xF0
17
+ return type == 0x40
18
+ end
19
+
20
+ def is_entity? id
21
+ id = id.gsub 'cf:', ''
22
+ bytes = Base64.decode64(id).bytes.to_a
23
+ type = bytes[7] & 0xF0
24
+ return type == 0x20
25
+ end
26
+
27
+ def is_agent? id
28
+ id = id.gsub 'cf:', ''
29
+ bytes = Base64.decode64(id).bytes.to_a
30
+ type = bytes[7] & 0xF0
31
+ return type == 0x10
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  module CamTool
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
 
4
4
  def self.version
5
5
  puts VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camtool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Pasquier
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-01-21 00:00:00.000000000 Z
12
+ date: 2019-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rgl
@@ -112,8 +112,11 @@ files:
112
112
  - lib/camtool/edge_counter.rb
113
113
  - lib/camtool/edge_validator.rb
114
114
  - lib/camtool/log_breaker.rb
115
+ - lib/camtool/node_presence_validator.rb
115
116
  - lib/camtool/provjson_parser.rb
116
117
  - lib/camtool/provjson_to_rgl.rb
118
+ - lib/camtool/search.rb
119
+ - lib/camtool/validator_utils.rb
117
120
  - lib/camtool/version.rb
118
121
  - lib/camtool/vertex_counter.rb
119
122
  homepage: https://github.com/tfjmp/camtool