cewebs-aman 2.0.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 +7 -0
- data/AUTHORS +1 -0
- data/LICENSE.GPL +674 -0
- data/README.md +17 -0
- data/Rakefile +25 -0
- data/cewebs-aman.gemspec +24 -0
- data/lib/cewebs-aman/delivery.rb +261 -0
- data/lib/cewebs-aman/helpers/place.rb +185 -0
- data/lib/cewebs-aman/helpers/relaxngui_1_2.rb +1042 -0
- data/lib/cewebs-aman/implementation.rb +21 -0
- data/lib/cewebs-aman/implementation.xml +18 -0
- data/lib/cewebs-aman/notification.rb +35 -0
- data/lib/cewebs-aman/repository.rb +163 -0
- data/server/aman +15 -0
- data/server/data/Default/Services.xml +1 -0
- data/server/data/partnerkeys.xml +3 -0
- data/server/data/services.xml +6 -0
- data/server/data/strings.xml +66 -0
- data/test/tc_aman.rb +129 -0
- data/tools/cewebs-aman +64 -0
- metadata +81 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
2
|
+
require 'cewebs-servicesbase/service'
|
|
3
|
+
require_relative 'helpers/relaxngui_1_2'
|
|
4
|
+
require_relative 'helpers/place'
|
|
5
|
+
require_relative 'delivery'
|
|
6
|
+
require_relative 'repository'
|
|
7
|
+
require_relative 'notification'
|
|
8
|
+
|
|
9
|
+
module AMan
|
|
10
|
+
SERVER = CEWebS::declaration(File.join(__dir__,'implementation.xml'))
|
|
11
|
+
|
|
12
|
+
def self::implementation(opts) #{{{
|
|
13
|
+
CEWebS::data_dir = File.expand_path(opts[:data_dir] || 'data',opts[:basepath])
|
|
14
|
+
|
|
15
|
+
Proc.new do
|
|
16
|
+
interface 'delivery', &CEWebS::delivery(AMan::Delivery.new)
|
|
17
|
+
interface 'repository', &AMan::repository
|
|
18
|
+
interface 'notification', &AMan::notification
|
|
19
|
+
end
|
|
20
|
+
end #}}}
|
|
21
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<declaration xmlns="http://riddl.org/ns/declaration/1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
|
|
2
|
+
<interface name="delivery">
|
|
3
|
+
<xi:include href="contracts/delivery.xml"/>
|
|
4
|
+
</interface>
|
|
5
|
+
<interface name="repository">
|
|
6
|
+
<xi:include href="contracts/repository.xml"/>
|
|
7
|
+
</interface>
|
|
8
|
+
<interface name="notification">
|
|
9
|
+
<xi:include href="contracts/notification.xml"/>
|
|
10
|
+
</interface>
|
|
11
|
+
<facade>
|
|
12
|
+
<tile>
|
|
13
|
+
<layer name="delivery"><apply-to>/delivery</apply-to></layer>
|
|
14
|
+
<layer name="repository"><apply-to>/repository</apply-to></layer>
|
|
15
|
+
<layer name="notification"><apply-to>/notification</apply-to></layer>
|
|
16
|
+
</tile>
|
|
17
|
+
</facade>
|
|
18
|
+
</declaration>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
2
|
+
module AMan
|
|
3
|
+
# somebody changed its own configuration
|
|
4
|
+
class DoNotification < Riddl::Implementation
|
|
5
|
+
include CEWebS::Respond
|
|
6
|
+
|
|
7
|
+
def response #{{{
|
|
8
|
+
respond do
|
|
9
|
+
key = @h['CEWEBS_KEY'].to_s
|
|
10
|
+
raise CEWebS::Error.new('not allowed',403) unless CEWebS::key?(key)
|
|
11
|
+
operation, path, xml = @p.map { |e| e.value.to_s.dup.force_encoding('UTF-8') }
|
|
12
|
+
operation = 'treeAdd' if operation == 'treeAddDynamic'
|
|
13
|
+
if AMan::engine?(key)
|
|
14
|
+
engine, target = key, 'Engine'
|
|
15
|
+
else
|
|
16
|
+
engine = Dir.glob(CEWebS::data('*','Services',"#{key}.xml")).map { |f| File.basename(File.dirname(f,2)) }.first
|
|
17
|
+
target = key
|
|
18
|
+
end
|
|
19
|
+
raise CEWebS::Error.new('not allowed',403) if engine.nil?
|
|
20
|
+
place = [target,'Shared'].lazy.filter_map { |t| p = (Place.new(engine,t) rescue nil); p if p && p.part(@r[0]) }.first
|
|
21
|
+
raise CEWebS::Error.new('part not known',404) if place.nil?
|
|
22
|
+
place.change(@r[0],operation,path,xml,key)
|
|
23
|
+
[]
|
|
24
|
+
end
|
|
25
|
+
end #}}}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self::notification #{{{
|
|
29
|
+
Proc.new do
|
|
30
|
+
on resource do
|
|
31
|
+
run DoNotification if put 'change'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end #}}}
|
|
35
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
2
|
+
module AMan
|
|
3
|
+
class DoRepository < Riddl::Implementation
|
|
4
|
+
include CEWebS::Respond
|
|
5
|
+
|
|
6
|
+
def response #{{{
|
|
7
|
+
respond do
|
|
8
|
+
key = @h['CEWEBS_KEY'].to_s
|
|
9
|
+
operation = @a[0]
|
|
10
|
+
raise CEWebS::Error.new('not allowed',403) unless operation == :register || AMan::engine?(key)
|
|
11
|
+
language = @h['CEWEBS_LANGUAGE'].to_s.split(',')
|
|
12
|
+
Place::catch_up
|
|
13
|
+
ret = case operation
|
|
14
|
+
when :register; register(@p[0].value.to_s.strip,@p[1].value.to_s)
|
|
15
|
+
when :location; location(key,@p[0].value.to_s)
|
|
16
|
+
when :available; available(language)
|
|
17
|
+
when :service; service(key,@p[0].value.to_i,@p[1].value.to_s.dup.force_encoding('UTF-8'))
|
|
18
|
+
when :rename; rename(key,known(key,@r[1]),@p[0].value.to_s.dup.force_encoding('UTF-8'))
|
|
19
|
+
when :unregister; unregister(key,known(key,@r[1]))
|
|
20
|
+
when :entrypoints; entrypoints(key,known(key,@r[1]),language)
|
|
21
|
+
when :reports; reports(key,known(key,@r[1]))
|
|
22
|
+
when :shared; shared(key,language)
|
|
23
|
+
end
|
|
24
|
+
ret.nil? ? [] : xml(:list,ret)
|
|
25
|
+
end
|
|
26
|
+
end #}}}
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def known(key,service) #{{{
|
|
31
|
+
ret = CEWebS::key?(service) && XML::Smart.open(CEWebS::data(key,'Services.xml')).find("/services/service[@key='#{service}']").first
|
|
32
|
+
ret || raise(CEWebS::Error.new('service not known',404))
|
|
33
|
+
end #}}}
|
|
34
|
+
def details(id) #{{{
|
|
35
|
+
XML::Smart.open(CEWebS::data('services.xml')).find("/services/service[@id='#{id.to_i}']").first || raise(CEWebS::Error.new('service not known',404))
|
|
36
|
+
end #}}}
|
|
37
|
+
def url(link) #{{{
|
|
38
|
+
raise CEWebS::Error.new('invalid link',400) unless link =~ /\Ahttps?:\/\//
|
|
39
|
+
link
|
|
40
|
+
end #}}}
|
|
41
|
+
|
|
42
|
+
def register(key,link) #{{{
|
|
43
|
+
partner = XML::Smart.open(CEWebS::data('partnerkeys.xml')).find('/keys/key').any? { |k| k.to_s == key }
|
|
44
|
+
raise CEWebS::Error.new('not allowed',403) unless partner && key != ''
|
|
45
|
+
url(link)
|
|
46
|
+
name = CEWebS::key
|
|
47
|
+
FileUtils.cp_r(CEWebS::data('Default'),CEWebS::data(name))
|
|
48
|
+
XML::Smart.modify(CEWebS::data(name,'Services.xml')) do |doc|
|
|
49
|
+
doc.root.attributes['engine'] = link
|
|
50
|
+
end
|
|
51
|
+
# the engine does not know its key yet, so it is asked when it calls back with location
|
|
52
|
+
[{ :key => name }]
|
|
53
|
+
end #}}}
|
|
54
|
+
|
|
55
|
+
def location(key,link) #{{{
|
|
56
|
+
url(link)
|
|
57
|
+
XML::Smart.modify(CEWebS::data(key,'Services.xml')) do |doc|
|
|
58
|
+
doc.root.attributes['engine'] = link
|
|
59
|
+
end
|
|
60
|
+
Place::sync(key,'Engine') unless File.exist?(CEWebS::data(key,'Engine.xml'))
|
|
61
|
+
nil
|
|
62
|
+
end #}}}
|
|
63
|
+
|
|
64
|
+
def available(language) #{{{
|
|
65
|
+
XML::Smart.open(CEWebS::data('services.xml')).find("/services/service[@visible='true']").map do |s|
|
|
66
|
+
d = s.lfind('description',language)
|
|
67
|
+
{ :id => s.attributes['id'], :name => d.sfind('name'), :details => d.sfind('details') }
|
|
68
|
+
end
|
|
69
|
+
end #}}}
|
|
70
|
+
|
|
71
|
+
def service(key,id,comment) #{{{
|
|
72
|
+
node = details(id)
|
|
73
|
+
ukey = CEWebS::key
|
|
74
|
+
engine = XML::Smart.open(CEWebS::data(key,'Services.xml')).find('string(/services/@engine)')
|
|
75
|
+
created = CEWebS::Remote.new(node.sfind('administration'),ukey).call(:post,'',[
|
|
76
|
+
['authentication',node.sfind('authentication')],
|
|
77
|
+
['key',ukey],
|
|
78
|
+
['description',"#{engine}: #{comment}"]
|
|
79
|
+
])[1]
|
|
80
|
+
instance = CEWebS::Messages::parse_list(created)[0][:instance]
|
|
81
|
+
XML::Smart.modify(CEWebS::data(key,'Services.xml')) do |doc|
|
|
82
|
+
doc.root.add('service',comment,{ 'id' => id, 'key' => ukey, 'instance' => instance })
|
|
83
|
+
end
|
|
84
|
+
Place::sync(key,ukey)
|
|
85
|
+
[{ :delivery => node.sfind('delivery'), :instance => instance, :key => ukey, :identifier => node.sfind('identifier') }]
|
|
86
|
+
end #}}}
|
|
87
|
+
|
|
88
|
+
def rename(key,ser,comment) #{{{
|
|
89
|
+
XML::Smart.modify(CEWebS::data(key,'Services.xml')) do |doc|
|
|
90
|
+
doc.find("/services/service[@key='#{ser.attributes['key']}']").first.text = comment
|
|
91
|
+
end
|
|
92
|
+
nil
|
|
93
|
+
end #}}}
|
|
94
|
+
|
|
95
|
+
def unregister(key,ser) #{{{
|
|
96
|
+
service = ser.attributes['key']
|
|
97
|
+
remote = Place::remote(key,service)
|
|
98
|
+
XML::Smart.modify(CEWebS::data(key,'Services.xml')) do |doc|
|
|
99
|
+
doc.find("/services/service[@key='#{service}']").delete_all!
|
|
100
|
+
end
|
|
101
|
+
XML::Smart.modify(CEWebS::data(key,'Shared.xml'),'<parts/>') do |doc|
|
|
102
|
+
doc.find("/parts/part/who[.='#{service}']").delete_all!
|
|
103
|
+
obsolete = doc.find('/parts/part[not(who)]')
|
|
104
|
+
obsolete.each do |ele|
|
|
105
|
+
FileUtils.rm_f(Dir.glob(CEWebS::data(key,'Shared',"#{ele.attributes['id']}.*")))
|
|
106
|
+
end
|
|
107
|
+
obsolete.delete_all!
|
|
108
|
+
end
|
|
109
|
+
FileUtils.rm_rf(CEWebS::data(key,'Services',service))
|
|
110
|
+
FileUtils.rm_f(CEWebS::data(key,'Services',service + '.xml'))
|
|
111
|
+
begin
|
|
112
|
+
CEWebS::Remote.new(*remote).call(:delete)
|
|
113
|
+
rescue CEWebS::Error => e
|
|
114
|
+
# the engine also has to forget the service, otherwise nobody can remove it
|
|
115
|
+
File.write(CEWebS::data('notdeleted.log'),"#{Time.now.iso8601} #{remote[0]}: #{e.message}\n",:mode => 'a')
|
|
116
|
+
end
|
|
117
|
+
nil
|
|
118
|
+
end #}}}
|
|
119
|
+
|
|
120
|
+
def entrypoints(key,ser,language) #{{{
|
|
121
|
+
url, ukey = Place::remote(key,ser.attributes['key'])
|
|
122
|
+
CEWebS::Remote.new(url,ukey,:language => language).list('entrypoints')
|
|
123
|
+
end #}}}
|
|
124
|
+
|
|
125
|
+
def reports(key,ser) #{{{
|
|
126
|
+
[{ :available => details(ser.attributes['id']).sfind('report') != '' }]
|
|
127
|
+
end #}}}
|
|
128
|
+
|
|
129
|
+
def shared(key,language) #{{{
|
|
130
|
+
return [] unless File.exist?(CEWebS::data(key,'Shared.xml'))
|
|
131
|
+
Place.new(key,'Shared').parts.map do |e|
|
|
132
|
+
s = e.lfind('description',language)
|
|
133
|
+
{ :id => e.attributes['id'], :short => s.sfind('short'), :long => s.sfind('long') }
|
|
134
|
+
end
|
|
135
|
+
end #}}}
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def self::repository #{{{
|
|
139
|
+
Proc.new do
|
|
140
|
+
run DoRepository, :register if post 'register'
|
|
141
|
+
run DoRepository, :location if put 'location'
|
|
142
|
+
on resource 'available' do
|
|
143
|
+
run DoRepository, :available if get 'key'
|
|
144
|
+
end
|
|
145
|
+
on resource 'services' do
|
|
146
|
+
run DoRepository, :service if post 'service'
|
|
147
|
+
on resource do
|
|
148
|
+
run DoRepository, :rename if put 'rename'
|
|
149
|
+
run DoRepository, :unregister if delete 'key'
|
|
150
|
+
on resource 'entrypoints' do
|
|
151
|
+
run DoRepository, :entrypoints if get 'key'
|
|
152
|
+
end
|
|
153
|
+
on resource 'reports' do
|
|
154
|
+
run DoRepository, :reports if get 'key'
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
on resource 'shared' do
|
|
159
|
+
run DoRepository, :shared if get 'key'
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end #}}}
|
|
163
|
+
end
|
data/server/aman
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/ruby -W0
|
|
2
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
3
|
+
require 'cewebs-aman/implementation'
|
|
4
|
+
|
|
5
|
+
options = {
|
|
6
|
+
:bind => '127.0.0.1',
|
|
7
|
+
:host => 'localhost',
|
|
8
|
+
:port => 9021
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
Riddl::Server.new(AMan::SERVER, options) do
|
|
12
|
+
accessible_description true
|
|
13
|
+
|
|
14
|
+
use AMan::implementation(@riddl_opts)
|
|
15
|
+
end.loop!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<services engine=""/>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<strings>
|
|
2
|
+
<strings xml:lang="en">
|
|
3
|
+
<back>Back</back>
|
|
4
|
+
<newentry>New entry</newentry>
|
|
5
|
+
<source>Source</source>
|
|
6
|
+
<source_edit>Edit the XML source of this part of the configuration.</source_edit>
|
|
7
|
+
<source_error_meanwhile>The configuration has been changed in the meantime. Nothing has been saved.</source_error_meanwhile>
|
|
8
|
+
<source_error_wellformed>The source is not well-formed. Nothing has been saved.</source_error_wellformed>
|
|
9
|
+
<source_error_schema>The source does not match the schema. Nothing has been saved.</source_error_schema>
|
|
10
|
+
<set>Set</set>
|
|
11
|
+
<reset>Reset</reset>
|
|
12
|
+
<search>Search</search>
|
|
13
|
+
<addsearch>Add criterion</addsearch>
|
|
14
|
+
<delsearch>Remove criterion</delsearch>
|
|
15
|
+
<element>Element</element>
|
|
16
|
+
<order>Order</order>
|
|
17
|
+
<order_save>Save order</order_save>
|
|
18
|
+
<more>More ...</more>
|
|
19
|
+
<optional>Optional</optional>
|
|
20
|
+
<readonly>Read only</readonly>
|
|
21
|
+
<new>New</new>
|
|
22
|
+
<edit>Edit</edit>
|
|
23
|
+
<delete>Delete</delete>
|
|
24
|
+
<suredelete>Really delete?</suredelete>
|
|
25
|
+
<dateformat>%Y-%m-%d</dateformat>
|
|
26
|
+
<timeformat>%H:%M</timeformat>
|
|
27
|
+
<datetimeformat>%Y-%m-%d %H:%M</datetimeformat>
|
|
28
|
+
<nomatch>The value does not match the expected format!</nomatch>
|
|
29
|
+
<noint>The value is not a valid integer!</noint>
|
|
30
|
+
<nofloat>The value is not a valid number!</nofloat>
|
|
31
|
+
<error>Error</error>
|
|
32
|
+
<waiting>Waiting ...</waiting>
|
|
33
|
+
</strings>
|
|
34
|
+
<strings xml:lang="de">
|
|
35
|
+
<back>Zurück</back>
|
|
36
|
+
<newentry>Neuer Eintrag</newentry>
|
|
37
|
+
<source>Quelltext</source>
|
|
38
|
+
<source_edit>XML Quelltext dieses Teils der Konfiguration bearbeiten.</source_edit>
|
|
39
|
+
<source_error_meanwhile>Die Konfiguration wurde in der Zwischenzeit geändert. Es wurde nichts gespeichert.</source_error_meanwhile>
|
|
40
|
+
<source_error_wellformed>Der Quelltext ist nicht wohlgeformt. Es wurde nichts gespeichert.</source_error_wellformed>
|
|
41
|
+
<source_error_schema>Der Quelltext entspricht nicht dem Schema. Es wurde nichts gespeichert.</source_error_schema>
|
|
42
|
+
<set>Setzen</set>
|
|
43
|
+
<reset>Zurücksetzen</reset>
|
|
44
|
+
<search>Suchen</search>
|
|
45
|
+
<addsearch>Kriterium hinzufügen</addsearch>
|
|
46
|
+
<delsearch>Kriterium entfernen</delsearch>
|
|
47
|
+
<element>Element</element>
|
|
48
|
+
<order>Reihenfolge</order>
|
|
49
|
+
<order_save>Reihenfolge speichern</order_save>
|
|
50
|
+
<more>Mehr ...</more>
|
|
51
|
+
<optional>Optional</optional>
|
|
52
|
+
<readonly>Nur lesbar</readonly>
|
|
53
|
+
<new>Neu</new>
|
|
54
|
+
<edit>Bearbeiten</edit>
|
|
55
|
+
<delete>Löschen</delete>
|
|
56
|
+
<suredelete>Wirklich löschen?</suredelete>
|
|
57
|
+
<dateformat>%d.%m.%Y</dateformat>
|
|
58
|
+
<timeformat>%H:%M</timeformat>
|
|
59
|
+
<datetimeformat>%d.%m.%Y %H:%M</datetimeformat>
|
|
60
|
+
<nomatch>Der Wert hat nicht das erwartete Format!</nomatch>
|
|
61
|
+
<noint>Der Wert ist keine gültige ganze Zahl!</noint>
|
|
62
|
+
<nofloat>Der Wert ist keine gültige Zahl!</nofloat>
|
|
63
|
+
<error>Fehler</error>
|
|
64
|
+
<waiting>Warten ...</waiting>
|
|
65
|
+
</strings>
|
|
66
|
+
</strings>
|
data/test/tc_aman.rb
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'tmpdir'
|
|
3
|
+
require_relative '../lib/cewebs-aman/implementation'
|
|
4
|
+
|
|
5
|
+
# answers instead of the engine and the services
|
|
6
|
+
module FakeRemote
|
|
7
|
+
DOWN = []
|
|
8
|
+
CALLS = []
|
|
9
|
+
def call(method,path='',parameters=[],headers={})
|
|
10
|
+
key = @headers['CEWEBS-KEY']
|
|
11
|
+
raise CEWebS::Remote::Unavailable.new('not reachable',502) if DOWN.include?(key)
|
|
12
|
+
CALLS << [key,method,path,parameters.to_h]
|
|
13
|
+
[200,'',{}]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
CEWebS::Remote.prepend FakeRemote
|
|
17
|
+
|
|
18
|
+
class TestAMan < Minitest::Test
|
|
19
|
+
ENGINE = 'a' * 32
|
|
20
|
+
SERVICE = 'b' * 32
|
|
21
|
+
SCHEMA = <<~END
|
|
22
|
+
<element name="names" cewebs:uiversion="1.2" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" xmlns="http://relaxng.org/ns/structure/1.0" xmlns:cewebs="http://www.cewebs.org">
|
|
23
|
+
<cewebs:ui><cewebs:heading>Names</cewebs:heading></cewebs:ui>
|
|
24
|
+
<zeroOrMore>
|
|
25
|
+
<cewebs:ui><cewebs:list><cewebs:column label="Name">@id</cewebs:column></cewebs:list></cewebs:ui>
|
|
26
|
+
<element name="name">
|
|
27
|
+
<cewebs:ui><cewebs:heading>Name</cewebs:heading></cewebs:ui>
|
|
28
|
+
<attribute name="id"><cewebs:ui><cewebs:label>Value:</cewebs:label><cewebs:unique/></cewebs:ui><data type="string"/></attribute>
|
|
29
|
+
</element>
|
|
30
|
+
</zeroOrMore>
|
|
31
|
+
</element>
|
|
32
|
+
END
|
|
33
|
+
|
|
34
|
+
def setup
|
|
35
|
+
@dir = Dir.mktmpdir
|
|
36
|
+
CEWebS::data_dir = @dir
|
|
37
|
+
FakeRemote::DOWN.clear
|
|
38
|
+
FakeRemote::CALLS.clear
|
|
39
|
+
FileUtils.cp(File.join(__dir__,'..','server','data','strings.xml'),@dir)
|
|
40
|
+
write 'services.xml', '<services><service id="1"><administration>http://s/administration</administration></service></services>'
|
|
41
|
+
write "#{ENGINE}/Services.xml", %(<services engine="http://e"><service id="1" key="#{SERVICE}" instance="7">Wiki</service></services>)
|
|
42
|
+
write "#{ENGINE}/Services/#{SERVICE}.xml", '<parts/>'
|
|
43
|
+
write "#{ENGINE}/Shared.xml", %(<parts><part id="names" share="x"><description><short>Names</short></description><who>Engine</who><who>#{SERVICE}</who></part></parts>)
|
|
44
|
+
write "#{ENGINE}/Shared/names.xml", '<names><name id="old"/></names>'
|
|
45
|
+
write "#{ENGINE}/Shared/names.rng", SCHEMA
|
|
46
|
+
@place = AMan::Place.new(ENGINE,'Shared')
|
|
47
|
+
end
|
|
48
|
+
# nothing may run in the background when the directory is removed
|
|
49
|
+
def teardown
|
|
50
|
+
AMan::Place.instance_variable_get(:@catch_up)&.kill&.join
|
|
51
|
+
FileUtils.rm_rf(@dir)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def write(name,text)
|
|
55
|
+
FileUtils.mkdir_p(File.dirname(File.join(@dir,name)))
|
|
56
|
+
File.write(File.join(@dir,name),text)
|
|
57
|
+
end
|
|
58
|
+
def id; XML::Smart.open(@place.file('names')).find('string(/names/name/@id)'); end
|
|
59
|
+
def change(except=nil) @place.change('names','valueReplace','/names/name/@id','new',except); end
|
|
60
|
+
|
|
61
|
+
def test_service_down
|
|
62
|
+
FakeRemote::DOWN << SERVICE
|
|
63
|
+
change
|
|
64
|
+
assert_equal 'new', id
|
|
65
|
+
assert_equal [SERVICE], @place.pending('names')
|
|
66
|
+
FakeRemote::DOWN.clear
|
|
67
|
+
AMan::Place.resend
|
|
68
|
+
assert_empty @place.pending('names')
|
|
69
|
+
key, _, path, parameters = FakeRemote::CALLS.last
|
|
70
|
+
assert_equal [SERVICE,'parts/names','treeReplace'], [key,path,parameters['operation']]
|
|
71
|
+
assert_includes parameters['xml'], 'id="new"'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_resent_in_background
|
|
75
|
+
FakeRemote::DOWN << SERVICE
|
|
76
|
+
change
|
|
77
|
+
AMan::Place.instance_variable_get(:@catch_up).kill.join
|
|
78
|
+
FakeRemote::DOWN.clear
|
|
79
|
+
AMan::Place.catch_up(0.01)
|
|
80
|
+
AMan::Place.instance_variable_get(:@catch_up).join(5)
|
|
81
|
+
assert_empty @place.pending('names')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_engine_already_changed
|
|
85
|
+
FakeRemote::DOWN << SERVICE
|
|
86
|
+
change(ENGINE)
|
|
87
|
+
assert_equal 'new', id
|
|
88
|
+
assert_equal [SERVICE], @place.pending('names')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_everybody_down
|
|
92
|
+
FakeRemote::DOWN.push(ENGINE,SERVICE)
|
|
93
|
+
assert_raises(CEWebS::Error) { change }
|
|
94
|
+
assert_equal 'old', id
|
|
95
|
+
assert_empty @place.pending('names')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_unregister
|
|
99
|
+
FakeRemote::DOWN << SERVICE
|
|
100
|
+
service = XML::Smart.open(CEWebS::data(ENGINE,'Services.xml')).find('/services/service').first
|
|
101
|
+
AMan::DoRepository.allocate.send(:unregister,ENGINE,service)
|
|
102
|
+
assert_empty XML::Smart.open(CEWebS::data(ENGINE,'Services.xml')).find('/services/service')
|
|
103
|
+
assert_includes File.read(CEWebS::data('notdeleted.log')), 'http://s/administration/7'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def request(command,parameters)
|
|
107
|
+
paras = { 't' => 'Shared', 'part' => 'names' }.merge(parameters).map { |k,v| Riddl::Parameter::Simple.new(k,v) }
|
|
108
|
+
CEWebS::Request.new({ 'CEWEBS_KEY' => ENGINE, 'CEWEBS_LANGUAGE' => 'en' },paras,'0',command)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_names
|
|
112
|
+
["O'Neill",'Say "hi"','a [b','a ] b',%q{both " and '}].each do |name|
|
|
113
|
+
XML::Smart.modify(@place.file('names')) { |doc| doc.find('/names/name').first.attributes['id'] = name }
|
|
114
|
+
assert_includes AMan::Delivery.new.document(request('gui',{})).content, 'edit_child', name
|
|
115
|
+
id = "[@id=#{CEWebS::Configuration::literal(name)}]"
|
|
116
|
+
page = AMan::Delivery.new.document(request('gui','path' => ['names/name'].pack('m0'),'id' => [id].pack('m0')))
|
|
117
|
+
assert_includes page.content, 'Value:', name
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_source_error
|
|
122
|
+
original = XML::Smart.open(@place.file('names')).root.dump
|
|
123
|
+
page = AMan::Delivery.new.document(request('sourcesave','source' => '<names><mine</names>','original' => [original].pack('m0')))
|
|
124
|
+
assert_includes page.content, 'not well-formed'
|
|
125
|
+
assert_includes page.content, '<mine'
|
|
126
|
+
assert_includes page.content, [original].pack('m0')
|
|
127
|
+
assert_equal 'old', id
|
|
128
|
+
end
|
|
129
|
+
end
|
data/tools/cewebs-aman
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/ruby -W0
|
|
2
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'securerandom'
|
|
5
|
+
require 'xml/smart'
|
|
6
|
+
require 'cewebs-servicesbase/scaffold'
|
|
7
|
+
|
|
8
|
+
ARGV.options { |opt|
|
|
9
|
+
opt.summary_indent = ' ' * 2
|
|
10
|
+
opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} new DIR | addkey DIR | service DIR SERVICE [URL]\n"
|
|
11
|
+
opt.on('Options:')
|
|
12
|
+
opt.on('--help', '-h', 'This text') { puts opt; exit }
|
|
13
|
+
opt.separator <<~END
|
|
14
|
+
|
|
15
|
+
new DIR scaffolds an AMan. If DIR exists everything except its data is updated.
|
|
16
|
+
|
|
17
|
+
addkey DIR allows one more engine to use the AMan in DIR, and prints the partner key for it.
|
|
18
|
+
|
|
19
|
+
service DIR SERVICE [URL] adds the service scaffolded in the directory SERVICE to the AMan in DIR. URL is
|
|
20
|
+
where engines on other servers reach the services. If the AMan already knows
|
|
21
|
+
the service only the URL is changed.
|
|
22
|
+
END
|
|
23
|
+
opt.parse!
|
|
24
|
+
}
|
|
25
|
+
command, dir, service, url = ARGV
|
|
26
|
+
unless (%w(new addkey).include?(command) && ARGV.length == 2) ||
|
|
27
|
+
(command == 'service' && (ARGV.length == 3 || (ARGV.length == 4 && url =~ /\Ahttps?:\/\//)))
|
|
28
|
+
puts ARGV.options
|
|
29
|
+
exit 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
case command
|
|
33
|
+
when 'new'
|
|
34
|
+
CEWebS::Scaffold::create(File.join(__dir__,'..','server'),dir)
|
|
35
|
+
when 'addkey'
|
|
36
|
+
key = SecureRandom.hex(16)
|
|
37
|
+
XML::Smart.modify(CEWebS::Scaffold::data(dir,'partnerkeys.xml')) do |doc|
|
|
38
|
+
doc.find("/keys/key[.='change-me']").delete_all!
|
|
39
|
+
doc.root.add('key',key)
|
|
40
|
+
end
|
|
41
|
+
puts key
|
|
42
|
+
when 'service'
|
|
43
|
+
services = CEWebS::Scaffold::data(dir,'services.xml')
|
|
44
|
+
repositories = CEWebS::Scaffold::data(service,'repositories.xml')
|
|
45
|
+
new = XML::Smart.open(File.join(service,'service.xml')).root
|
|
46
|
+
identifier = new.find('string(identifier)')
|
|
47
|
+
XML::Smart.modify(services) do |doc|
|
|
48
|
+
node = doc.find('/services/service').find { |s| s.find('string(identifier)') == identifier }
|
|
49
|
+
if node.nil?
|
|
50
|
+
id = doc.find('/services/service/@id').map { |i| i.value.to_i }.max.to_i + 1
|
|
51
|
+
auth = SecureRandom.hex(16)
|
|
52
|
+
XML::Smart.modify(repositories) do |rep|
|
|
53
|
+
rep.root.add('repository',{ 'id' => "aman#{rep.find('/repositories/repository').length + 1}" }).add('key',auth)
|
|
54
|
+
end
|
|
55
|
+
node = doc.root.add('service',{ 'id' => id, 'visible' => 'true' })
|
|
56
|
+
new.find('*').each do |e|
|
|
57
|
+
node.add('authentication',auth) if e.qname.name == 'description' && node.find('authentication').empty?
|
|
58
|
+
node.add(e)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
# engines get this url from the AMan
|
|
62
|
+
node.find('delivery').first.text = "#{url.sub(/\/+\z/,'')}/#{identifier}/delivery" if url
|
|
63
|
+
end
|
|
64
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cewebs-aman
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Juergen eTM Mangler
|
|
8
|
+
bindir: tools
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: cewebs-servicesbase
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '3.0'
|
|
19
|
+
- - ">="
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 3.0.1
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - "~>"
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '3.0'
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: 3.0.1
|
|
32
|
+
description: Subscribing to services, and configuration of services and the engine.
|
|
33
|
+
email: juergen.mangler@gmail.com
|
|
34
|
+
executables:
|
|
35
|
+
- cewebs-aman
|
|
36
|
+
extensions: []
|
|
37
|
+
extra_rdoc_files:
|
|
38
|
+
- README.md
|
|
39
|
+
files:
|
|
40
|
+
- AUTHORS
|
|
41
|
+
- LICENSE.GPL
|
|
42
|
+
- README.md
|
|
43
|
+
- Rakefile
|
|
44
|
+
- cewebs-aman.gemspec
|
|
45
|
+
- lib/cewebs-aman/delivery.rb
|
|
46
|
+
- lib/cewebs-aman/helpers/place.rb
|
|
47
|
+
- lib/cewebs-aman/helpers/relaxngui_1_2.rb
|
|
48
|
+
- lib/cewebs-aman/implementation.rb
|
|
49
|
+
- lib/cewebs-aman/implementation.xml
|
|
50
|
+
- lib/cewebs-aman/notification.rb
|
|
51
|
+
- lib/cewebs-aman/repository.rb
|
|
52
|
+
- server/aman
|
|
53
|
+
- server/data/Default/Services.xml
|
|
54
|
+
- server/data/partnerkeys.xml
|
|
55
|
+
- server/data/services.xml
|
|
56
|
+
- server/data/strings.xml
|
|
57
|
+
- test/tc_aman.rb
|
|
58
|
+
- tools/cewebs-aman
|
|
59
|
+
homepage: http://www.cewebs.org
|
|
60
|
+
licenses:
|
|
61
|
+
- GPL-3.0-or-later
|
|
62
|
+
metadata: {}
|
|
63
|
+
rdoc_options: []
|
|
64
|
+
require_paths:
|
|
65
|
+
- lib
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '3.2'
|
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
requirements: []
|
|
77
|
+
rubygems_version: 3.6.9
|
|
78
|
+
specification_version: 4
|
|
79
|
+
summary: Administration manager of CEWebS
|
|
80
|
+
test_files:
|
|
81
|
+
- test/tc_aman.rb
|