semcon 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/semcon/basic.rb +27 -0
  4. data/lib/semcon.rb +45 -16
  5. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3980361cb218919f5d7b87ffbbe03ee325c5d4e807f5da14ec474e65f120faf
4
- data.tar.gz: 987a4b6112b196eb4409ea67c7589aef6d24efb12002ba8050105d3181bb62da
3
+ metadata.gz: 7ee16deb2a5ad8f6853d3cb8408f56d9b9c5d69e8043f8a6721a4b93ce79e8a3
4
+ data.tar.gz: 1c1b57506dd53622cd4e583a9bf27ea13d727a39c6557323de8bb32908b40759
5
5
  SHA512:
6
- metadata.gz: dcf9ab7da19da4f1e7ca478f39c145b2cc95ca1ce9c84f3263c9b011da0e900df1c9852a5fd7fd7c977eddb4aefb04b65ac86488ac269618def615264ba5e949
7
- data.tar.gz: 416a13437f6f51d3385bb15b9a2cad25c97845b55070b5239c408fe4dbccd8e5f3a73bf22fe741316aba1af7a5f59cddd6457bae98c995bbc8945743dd5aa3ef
6
+ metadata.gz: 8394a8fbe28fee22c8b54bab20782156f2b08c3a5d831ccad1c56f0ca9ece15e11a9e5dc90600e8be896799bfe71098cb93752ff71442c4e597879024df369ec
7
+ data.tar.gz: 577b2c31c534fdef35b1746b3df51df1f532e364d45d79dfab9f9eeb41bb94ddec12832c16fa08f146da0012a1c08fc24e4186d22851a7e6b6a3afea778c622f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/semcon/basic.rb CHANGED
@@ -37,4 +37,31 @@ class Semcon
37
37
  return [result_url, ""]
38
38
  end
39
39
  end
40
+
41
+ # OAuth functions ---------------------------
42
+ def self.oauth_headers(token)
43
+ { 'Accept' => '*/*',
44
+ 'Content-Type' => 'application/json',
45
+ 'Authorization' => 'Bearer ' + token.to_s
46
+ }
47
+ end
48
+
49
+ def self.oauth_token(url, key, secret)
50
+ auth_url = url.to_s + "/oauth/token"
51
+ response_nil = false
52
+ begin
53
+ response = HTTParty.post(auth_url,
54
+ headers: { 'Content-Type' => 'application/json' },
55
+ body: { client_id: key,
56
+ client_secret: secret,
57
+ grant_type: "client_credentials" }.to_json )
58
+ rescue => e
59
+ return [nil, e.message.to_s]
60
+ end
61
+ if !response_nil && !response.body.nil? && response.code == 200
62
+ return [response.parsed_response["access_token"].to_s, ""]
63
+ else
64
+ return ["", response.code.to_s]
65
+ end
66
+ end
40
67
  end
data/lib/semcon.rb CHANGED
@@ -7,14 +7,16 @@ require 'semcon/basic'
7
7
 
8
8
  class Semcon
9
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
10
+ write_payload = {"content": payload, "meta": {}}
11
+ if !options[:meta].nil?
12
+ write_payload[:meta] = options[:meta]
13
+ end
14
+ record_dri = Oydid.hash(Oydid.canonical(write_payload))
12
15
  target_url, err_msg = host_from_did(target, "DecentralizedWebNode", options)
13
16
  if target_url.nil? || err_msg != ""
17
+ puts "Error: " + err_msg.to_s
14
18
  return [nil, err_msg]
15
19
  end
16
- # puts "Target URL: " + target_url.to_s
17
-
18
20
  content = [
19
21
  {
20
22
  "id": "#data",
@@ -25,17 +27,34 @@ class Semcon
25
27
  options[:location] = target_url
26
28
  options[:doc_location] = target_url
27
29
  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)
30
+ # did, didDocument, revoc_log, l1, l2, r1, privateKey, revocationKey, did_old, log_old, msg = Oydid.generate_base(content, "", "create", options)
31
+ did_doc, did_key, did_log, msg = Oydid.generate_base(content, "", "create", options)
32
+ did = did_doc[:did]
33
+ didDocument = did_doc[:didDocument]
34
+ did_old = did_doc[:did_old]
35
+ revoc_log = did_log[:revoc_log]
36
+ l1 = did_log[:l1]
37
+ l2 = did_log[:l2]
38
+ r1 = did_log[:r1]
39
+ log_old = did_log[:log_old]
40
+
29
41
  semcon_object = {}
30
- semcon_object["data"] = {"content": payload, "meta": {}}
42
+ semcon_object["data"] = write_payload
31
43
  semcon_object["did-document"] = didDocument
32
44
  semcon_object["did-log"] = [l1, l2]
33
45
  # puts "Write Object"
34
46
  # puts JSON.pretty_generate(semcon_object)
35
47
 
36
- retVal = HTTParty.post(target_url + "/api/data",
37
- headers: { 'Content-Type' => 'application/json' },
38
- body: semcon_object.to_json )
48
+ if options[:token].to_s == ""
49
+ retVal = HTTParty.post(target_url + "/api/data",
50
+ headers: { 'Content-Type' => 'application/json' },
51
+ body: semcon_object.to_json )
52
+ else
53
+ retVal = HTTParty.post(target_url + "/api/data",
54
+ headers: { 'Content-Type' => 'application/json',
55
+ 'Authorization' => 'Bearer ' + options[:token].to_s },
56
+ body: semcon_object.to_json )
57
+ end
39
58
 
40
59
  # puts "Response from dc-base:"
41
60
  # puts JSON.pretty_generate(retVal.parsed_response)
@@ -48,16 +67,26 @@ class Semcon
48
67
  return [did, err_msg]
49
68
  end
50
69
 
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
70
+ def self.read(target_url, options)
56
71
  dc_did = target_url.dup.split("?").first
57
72
  host_url, err_msg = host_from_did(dc_did, "DecentralizedWebNode", options)
58
73
  target_url = host_url.to_s + "/api/data?" + target_url.dup.split("?").last
59
- retVal = HTTParty.get(target_url)
60
- result = retVal.parsed_response
74
+ if options[:key_pwd].to_s != ""
75
+ options[:token] = Oydid.token_from_challenge(host_url, options[:key_pwd]) rescue ""
76
+ end
77
+ if options[:token].to_s == ""
78
+ retVal = HTTParty.get(target_url)
79
+ else
80
+ retVal = HTTParty.get(target_url,
81
+ headers: { 'Authorization' => 'Bearer ' + options[:token].to_s })
82
+ end
83
+ err_msg = ""
84
+ if retVal.code == 200
85
+ result = retVal.parsed_response
86
+ else
87
+ result = nil
88
+ err_msg = retVal.response.message
89
+ end
61
90
 
62
91
  return [result, err_msg]
63
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semcon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Fabianek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-24 00:00:00.000000000 Z
11
+ date: 2023-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.2
33
+ version: 0.5.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.4.2
40
+ version: 0.5.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: 2.5.7
85
+ version: 2.6.9
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="