Skip to content

Commit dd58bc0

Browse files
committed
upgrade ci workflow
1 parent a719204 commit dd58bc0

27 files changed

+302
-99
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
jobs:
1313
main:
1414
name: Build, Validate and Deploy
15-
runs-on: ubuntu-20.04
15+
runs-on: ubuntu-24.04
1616
steps:
1717
- uses: actions/checkout@v2
1818
- uses: w3c/spec-prod@v2

cli/docker/Dockerfile-local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ COPY docker/local-gem/*.gem /tmp/
2828

2929
RUN addgroup -S user && \
3030
adduser -S user -G user && \
31-
apk add --no-cache vim libsodium-dev git make gcc musl-dev jq npm openjdk8 bash curl py3-pip && \
31+
apk add --no-cache vim libsodium-dev git make gcc musl-dev jq npm openjdk8 bash curl py3-pip openssl openssl-dev build-base ruby-dev && \
3232
gem install /tmp/*.gem && \
3333
gem install httparty ed25519 multibases multihashes multicodecs json-canonicalization optparse rbnacl dag uri && \
3434
gem install securerandom -v 0.1.1 && \

repo2/app/controllers/api/v1/resources_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def info
7070
end
7171

7272
def idaustria
73-
7473
STDOUT.sync = true
7574
logger = Logger.new(STDOUT)
7675
level ||= LOGLEVELS.index ENV.fetch("LOG_LEVEL","INFO")

repo2/app/controllers/api/v1/soya_controller.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ def read
1515
status: 404
1616
else
1717
if @store.soya_tag == "current"
18-
retval = {
19-
content: @store.item,
20-
"id": @store.id,
21-
"dri": @store.soya_name,
22-
"soya_name": @store.soya_name,
23-
}
18+
dri = @store.soya_name
2419
else
25-
retval = {
26-
content: @store.item,
27-
"id": @store.id,
28-
"dri": @store.soya_dri,
29-
"soya_name": @store.soya_name,
30-
}
31-
end
20+
dri = @store.soya_dri
21+
end
22+
retval = {
23+
data: @store.item,
24+
meta: @store.meta,
25+
"id": @store.id,
26+
"dri": dri,
27+
"soya_name": @store.soya_name,
28+
"soya_yaml": @store.soya_yaml
29+
}
3230
render json: retval.to_json,
3331
status: 200
3432
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class ApiController < ApplicationController
2+
def doorkeeper_unauthorized_render_options(error: nil)
3+
{ json: { error: "Not authorized" } }
4+
end
5+
6+
if !(ENV["AUTH"].to_s == "" || ENV["AUTH"].to_s.downcase == "false")
7+
# !!!fix-me ENV["AUTH"] == "optional" handling !!!
8+
if ENV["AUTH"].to_s.downcase != "optional"
9+
before_action -> { doorkeeper_authorize! :read, :write, :admin }, except: [:active, :idaustria]
10+
end
11+
end
12+
end

repo2/app/controllers/dri_controller.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ def read_yaml
6767
end
6868

6969
def delete
70+
# only logged-in users can delete
71+
@at = Doorkeeper::AccessToken.find_by_token(doorkeeper_token.token) rescue nil
72+
if @at.nil?
73+
render json: {"error": "not authorized"},
74+
status: 401
75+
return
76+
end
77+
case ENV['AUTH'].to_s.downcase
78+
when "optional", "delete"
79+
# only users of the same organisation can delete
80+
else
81+
# only admin users can delete
82+
end
7083
store_id, msg = get_soya(params[:dri])
7184
if store_id.nil?
7285
render json: {"error": "not found"},
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class FrontendController < ApplicationController
2+
include ActionController::Cookies
3+
4+
def register
5+
output = "<html><head><title>SOyA</title></head>"
6+
output +="<body><h1>SOyA - User Registration</h1></body>"
7+
output +="</html>"
8+
render html: output.html_safe,
9+
status: 200
10+
end
11+
12+
def user
13+
token = cookies[:Authorization].split(' ').last rescue nil
14+
puts "token: " + token.to_s
15+
if token.nil?
16+
redirect '/'
17+
return
18+
end
19+
@at = Doorkeeper::AccessToken.find_by_token(token) rescue nil
20+
puts "AccessToken: " + @at.to_s
21+
if @at.nil?
22+
redirect '/'
23+
return
24+
end
25+
@oauth = Doorkeeper::Application.find(@at.application_id) rescue nil
26+
puts "OauthApp: " + @oauth.to_s
27+
if @oauth.nil?
28+
redirect '/'
29+
return
30+
end
31+
@user = User.find_by_name(@oauth.name)
32+
puts "User: " + @user.to_s
33+
if @user.nil?
34+
redirect '/'
35+
return
36+
end
37+
38+
output = "<html><head><title>SOyA</title></head>"
39+
output +="<body><h1>User Profile - " + @user.full_name.to_s + "</h1>"
40+
# output +="<a href='/?APP_KEY=" + @oauth.uid + "&APP_SECRET=" + @oauth.secret + "'>back</a>"
41+
output +="<a href='/'>back</a>"
42+
output +="</body></html>"
43+
render html: output.html_safe,
44+
status: 200
45+
end
46+
end

repo2/app/helpers/soya_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def createDriVersion(input)
5656
base_url = input["@context"]["@base"] rescue ""
5757
input["@context"].delete("@base") rescue nil
5858
raw = input.to_json_c14n
59-
dri = Multibases.pack("base58btc", Multihashes.encode(Digest::SHA256.digest(raw), "sha2-256").unpack('C*')).to_s
59+
dri = Multibases.pack('base58btc', RbNaCl::Hash.sha256(raw).unpack('C*')).to_s
60+
# dri = Multibases.pack("base58btc", Multihashes.encode(Digest::SHA256.digest(raw), "sha2-256").unpack('C*')).to_s
6061
raw = JSON.parse(raw)
6162
raw["@context"]["@base"] = base_url.split('/')[0..-2].join("/") + "/" + dri + "/"
6263
rescue => error

repo2/app/helpers/stores_helper.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def write_item(item_data, meta_data, schema, did_document, did_log)
88

99
puts " - meta_data: " + meta_data.to_json
1010

11-
soya_json = item_data["content"]
12-
soya_yaml = item_data["soya_yaml"]
11+
soya_json = item_data
12+
soya_yaml = meta_data.delete("soya_yaml")
1313
soya_name = getSoyaName(soya_json.deep_dup)
1414
soya_dri_json, soya_dri, msg = createDriVersion(soya_json.deep_dup)
1515
soya_tag = ""
@@ -23,6 +23,7 @@ def write_item(item_data, meta_data, schema, did_document, did_log)
2323
meta_data["soya_dri"] = soya_dri
2424
if !meta_data["soya_tag"].nil?
2525
soya_tag = meta_data["soya_tag"].to_s
26+
puts " - soya_tag: " + soya_tag.to_s
2627
end
2728
if !meta_data["id"].nil?
2829
provided_id = meta_data["id"].to_i rescue nil
@@ -165,9 +166,18 @@ def write_item(item_data, meta_data, schema, did_document, did_log)
165166
@record.save
166167
return_id = @record.id
167168
puts "return_id: " + return_id.to_s
169+
# create DRI version
170+
new_dri = create_soya(soya_name, soya_dri_json, soya_yaml, meta_data, soya_tag, soya_dri, item_dri)
171+
puts "DRI version: " + new_dri.to_s
168172
else
169-
# copy record with new tag
173+
puts "soya_tag.to_s: " + soya_tag.to_s
174+
# record with new tag
170175
return_id = create_soya(soya_name, soya_json, soya_yaml, meta_data, soya_tag, soya_dri, dri)
176+
puts "return_id: " + return_id.to_s
177+
# create DRI version
178+
new_dri = create_soya(soya_name, soya_dri_json, soya_yaml, meta_data, '', soya_dri, item_dri)
179+
puts "DRI version: " + new_dri.to_s
180+
171181
end
172182
else
173183
# copy record with new tag

repo2/app/models/organization.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Organization < ApplicationRecord
2+
end

0 commit comments

Comments
 (0)