semcon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f3980361cb218919f5d7b87ffbbe03ee325c5d4e807f5da14ec474e65f120faf
4
+ data.tar.gz: 987a4b6112b196eb4409ea67c7589aef6d24efb12002ba8050105d3181bb62da
5
+ SHA512:
6
+ metadata.gz: dcf9ab7da19da4f1e7ca478f39c145b2cc95ca1ce9c84f3263c9b011da0e900df1c9852a5fd7fd7c977eddb4aefb04b65ac86488ac269618def615264ba5e949
7
+ data.tar.gz: 416a13437f6f51d3385bb15b9a2cad25c97845b55070b5239c408fe4dbccd8e5f3a73bf22fe741316aba1af7a5f59cddd6457bae98c995bbc8945743dd5aa3ef
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ * Christoph Fabianek <christoph@ownyourdata.eu>
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 OwnYourData
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # SemCon Gem
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/semcon.png)](http://badge.fury.io/rb/semcon)
4
+ [![Build Status](https://github.com/ownyourdata/semcon/workflows/CI/badge.svg)](https://github.com/ownyourdata/semcon/actions?query=workflow%3ACI)
5
+ [![Coverage Status](https://coveralls.io/repos/github/OwnYourData/semcon/badge.svg?branch=main)](https://coveralls.io/github/OwnYourData/semcon?branch=main)
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ class Semcon
5
+
6
+ # basic functions ---------------------------
7
+ def self.host_from_did(did, filter, options)
8
+ result, err_msg = Oydid.read(did, options)
9
+ if result.nil? || err_msg != ""
10
+ return [nil, err_msg]
11
+ end
12
+ result_url = ""
13
+ w3c_did = Oydid.w3c(result, options)
14
+ service_array = w3c_did["service"]
15
+ service_array.each do |service|
16
+ if service["type"] == filter
17
+ case filter
18
+ when "DecentralizedWebNode"
19
+ nodes = service["serviceEndpoint"]["nodes"] rescue nil
20
+ if nodes.nil?
21
+ next
22
+ end
23
+ result_url = service["serviceEndpoint"]["nodes"].first rescue nil
24
+ if nodes.nil?
25
+ next
26
+ end
27
+ break
28
+ else
29
+ result_url = service["serviceEndpoint"].to_s
30
+ break
31
+ end
32
+ end
33
+ end unless service_array.nil?
34
+ if result_url.to_s == ""
35
+ return [nil, "Service Endpoint URL not found in " + did.to_s]
36
+ else
37
+ return [result_url, ""]
38
+ end
39
+ end
40
+ end
data/lib/semcon.rb ADDED
@@ -0,0 +1,65 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ require 'httparty'
5
+ require 'oydid'
6
+ require 'semcon/basic'
7
+
8
+ class Semcon
9
+ def self.write(payload, target, options)
10
+ record_dri = Oydid.hash(Oydid.canonical({"content": payload, "meta": {}}))
11
+ # puts "Record DRI: " + record_dri.to_s
12
+ target_url, err_msg = host_from_did(target, "DecentralizedWebNode", options)
13
+ if target_url.nil? || err_msg != ""
14
+ return [nil, err_msg]
15
+ end
16
+ # puts "Target URL: " + target_url.to_s
17
+
18
+ content = [
19
+ {
20
+ "id": "#data",
21
+ "type": "data",
22
+ "serviceEndpoint": target + "?dri="+record_dri
23
+ }
24
+ ]
25
+ options[:location] = target_url
26
+ options[:doc_location] = target_url
27
+ options[:log_location] = target_url
28
+ did, didDocument, revoc_log, l1, l2, r1, privateKey, revocationKey, did_old, log_old, msg = Oydid.generate_base(content, "", "create", options)
29
+ semcon_object = {}
30
+ semcon_object["data"] = {"content": payload, "meta": {}}
31
+ semcon_object["did-document"] = didDocument
32
+ semcon_object["did-log"] = [l1, l2]
33
+ # puts "Write Object"
34
+ # puts JSON.pretty_generate(semcon_object)
35
+
36
+ retVal = HTTParty.post(target_url + "/api/data",
37
+ headers: { 'Content-Type' => 'application/json' },
38
+ body: semcon_object.to_json )
39
+
40
+ # puts "Response from dc-base:"
41
+ # puts JSON.pretty_generate(retVal.parsed_response)
42
+
43
+ err_msg = ""
44
+ did = retVal.parsed_response["did"].to_s rescue nil
45
+ if did.nil?
46
+ err_msg = retVal.parsed_response["error"] rescue nil
47
+ end
48
+ return [did, err_msg]
49
+ end
50
+
51
+ def self.read(target, options)
52
+ target_url, err_msg = host_from_did(target, "data", options)
53
+ if target_url.nil? || err_msg != ""
54
+ return [nil, err_msg]
55
+ end
56
+ dc_did = target_url.dup.split("?").first
57
+ host_url, err_msg = host_from_did(dc_did, "DecentralizedWebNode", options)
58
+ target_url = host_url.to_s + "/api/data?" + target_url.dup.split("?").last
59
+ retVal = HTTParty.get(target_url)
60
+ result = retVal.parsed_response
61
+
62
+ return [result, err_msg]
63
+ end
64
+ end
65
+
@@ -0,0 +1,14 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe "Semcon handling" do
4
+
5
+ # writing data
6
+ Dir.glob(File.expand_path("../input/*.doc", __FILE__)).each do |input|
7
+ it "writes #{input.split('/').last}" do
8
+ expected = File.read(input.sub('input', 'output'))
9
+ data = File.read(input)
10
+ expect(Semcon.write(data, {})).to eq expected
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,31 @@
1
+ $:.unshift(File.join("../lib", __FILE__))
2
+
3
+ require "bundler/setup"
4
+ require 'rspec'
5
+
6
+ begin
7
+ require 'simplecov'
8
+ require 'simplecov-lcov'
9
+
10
+ SimpleCov::Formatter::LcovFormatter.config do |config|
11
+ #Coveralls is coverage by default/lcov. Send info results
12
+ config.report_with_single_file = true
13
+ config.single_report_path = 'coverage/lcov.info'
14
+ end
15
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
16
+ SimpleCov::Formatter::HTMLFormatter,
17
+ SimpleCov::Formatter::LcovFormatter
18
+ ])
19
+
20
+ SimpleCov.start do
21
+ add_filter "/spec/"
22
+ end
23
+ rescue LoadError
24
+ end
25
+
26
+ require 'oydid'
27
+
28
+ ::RSpec.configure do |c|
29
+ c.filter_run focus: true
30
+ c.run_all_when_everything_filtered = true
31
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: semcon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Christoph Fabianek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.20.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.20.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: oydid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.2
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.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.10'
55
+ description: This gem provides the basic methods for managing Semantic Containers.
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - AUTHORS
62
+ - LICENSE
63
+ - README.md
64
+ - VERSION
65
+ - lib/semcon.rb
66
+ - lib/semcon/basic.rb
67
+ - spec/semcon_spec.rb
68
+ - spec/spec_helper.rb
69
+ homepage: http://github.com/ownyourdata/semcon
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ documentation_uri: https://ownyourdata.github.io/semcon
74
+ bug_tracker_uri: https://github.com/ownyourdata/semcon/issues
75
+ homepage_uri: http://github.com/ownyourdata/semcon
76
+ source_code_uri: http://github.com/ownyourdata/semcon/tree/main/ruby-gem
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.5.7
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.0.9
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Semantic Container handling in Ruby.
96
+ test_files:
97
+ - spec/spec_helper.rb
98
+ - spec/semcon_spec.rb