Skip to content

Commit f4298a6

Browse files
domnik23dominik kuehne
andauthored
Xml configuration (#3)
* switch to install xar from db * add xml config * config.xql changes * switch to config:sm() * switch to config:apikeys() * switch to config:prefix() * switch to config variables to functions * fixing things * add * some changes * some changes Co-authored-by: dominik kuehne <[email protected]>
1 parent 39f8d75 commit f4298a6

File tree

13 files changed

+206
-136
lines changed

13 files changed

+206
-136
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ node_modules
55
.vscode
66
.DS_Store
77
*.xar
8+
src/data/test.xml

README.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Synchronizes your data collection with GitHub and GitLab.
2222

2323
## Current restrictions
2424

25-
In version 1.1.0 not implemented:
25+
In version 1.1.1 not implemented:
2626
- webhooks are not fully implemented.
2727

2828
## Building and Installation
@@ -48,35 +48,39 @@ Run tests with ```npm test```
4848

4949
## Configuration
5050

51-
Tuttle is configured in `modules/config.xqm`.
51+
Tuttle is configured in `data/tuttle.xml`.
5252

5353
### Gitservice configuration
54-
The name of the configuration is always the destination collection. It will be configured in `modules/config.xqm`
54+
@name is always the name of the destination collection. It will be configured in `data/tuttle.xml`
5555

5656
An example:
57-
```xquery
58-
"sample-collection-github" : map {
59-
"vcs" : "github",
60-
"baseurl" : "https://api.github.com/",
61-
"repo" : "tuttle-demo",
62-
"owner" : "Jinntec",
63-
"ref" : "master",
64-
"token" : "146152be6a97a9efe9dd4647e71da8f3e4faf263",
65-
"hookuser" : "admin",
66-
"hookpasswd" : ""
67-
},
68-
"sample-collection-gitlab" : map {
69-
"vcs" : "gitlab",
70-
"baseurl" : "https://gitlab.com/api/v4/",
71-
"project-id" : "25852323",
72-
"ref" : "master",
73-
"token" : "9vq6jmzbxCMtNkobUfoM",
74-
"hookuser" : "admin",
75-
"hookpasswd" : ""
76-
}
57+
```xml
58+
<repos>
59+
<collection name="tuttle-sample-data">
60+
<default>true</default>
61+
<type>github</type>
62+
<baseurl>https://api.github.com/</baseurl>
63+
<repo>tuttle-sample-data</repo>
64+
<owner>tuttle-sample-data</owner>
65+
<token>XXX</token>
66+
<ref>master</ref>
67+
<hookuser>admin</hookuser>
68+
<hookpasswd></hookpasswd>
69+
</collection>
70+
71+
<collection name="tuttle-sample-gitlab">
72+
<type>gitlab</type>
73+
<baseurl>https://gitlab.com/api/v4/</baseurl>
74+
<project-id>tuttle-sample-data</project-id>
75+
<token>XXX</token>
76+
<ref>master</ref>
77+
<hookuser>admin</hookuser>
78+
<hookpasswd></hookpasswd>
79+
</collection>
80+
</repos>
7781
```
7882

79-
#### vcs
83+
#### type
8084
Gitserver type: 'github' or 'gitlab'
8185

8286
#### baseurl
@@ -117,7 +121,7 @@ The page below is reachable via [api.html](api.html) in your installed tuttle ap
117121

118122
### API endpoint description
119123

120-
Calling the API without {collection} ``$config:default-collection`` is chosen.
124+
Calling the API without {collection} ``config:default-collection()`` is chosen.
121125

122126
#### Fetch to staging collection
123127

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tuttle",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "tuttle - a Git-integration for eXist-db",
55
"scripts": {
66
"test": "gulp install && mocha --exit",

src/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"openapi": "3.0.0",
33
"info": {
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"title": "Tuttle API",
66
"description": "API for Tuttle Git integration"
77
},

src/data/tuttle.xml

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
11
<tuttle>
2-
<default>sample-collection-github</default>
32
<repos>
4-
<repo type="github" url="https://github.com/Jinntec/tuttle-demo" ref="master" collection="sample-collection-github"/>
5-
<repo type="gitlab" url="https://gitlab.com/tuttle-test/tuttle-demo.git" ref="master" collection="sample-collection-gitlab"/>
3+
<collection name="tuttle-sample-data">
4+
<default>true</default>
5+
<type>github</type>
6+
<baseurl>https://api.github.com/</baseurl>
7+
<repo>tuttle-sample-data</repo>
8+
<owner>tuttle-sample-data</owner>
9+
<token>XXX</token>
10+
<ref>master</ref>
11+
<hookuser>admin</hookuser>
12+
<hookpasswd></hookpasswd>
13+
</collection>
14+
15+
<collection name="tuttle-sample-gitlab">
16+
<type>gitlab</type>
17+
<baseurl>https://gitlab.com/api/v4/</baseurl>
18+
<project-id>tuttle-sample-data</project-id>
19+
<token>XXX</token>
20+
<ref>master</ref>
21+
<hookuser>admin</hookuser>
22+
<hookpasswd></hookpasswd>
23+
</collection>
624
</repos>
25+
26+
<blacklist>
27+
<file>existdb.json</file>
28+
<file>build.xml</file>
29+
<file>README.md</file>
30+
<file>.gitignore</file>
31+
<file>expath-pkg.xml.tmpl</file>
32+
<file>repo.xml.tmpl</file>
33+
<file>build.properties.xml</file>
34+
</blacklist>
35+
36+
37+
<config prefix="/db/apps" suffix="-stage" lock="git-lock.xml" apikeys="/db/system/auth/tuttle-token.xml">
38+
<sm user="nobody" group="nogroup" mode="rw-r--r--"/>
39+
</config>
40+
41+
742
</tuttle>

src/expath-pkg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package
33
xmlns="http://expath.org/ns/pkg"
44
name="http://e-editiones.org/tuttle"
5-
abbrev="tuttle" version="1.1.0" spec="1.0">
5+
abbrev="tuttle" version="1.1.1" spec="1.0">
66
<title>Tuttle - Git for eXist-db</title>
77
<dependency processor="http://exist-db.org" semver-min="5.3.0"/>
88
<dependency package="http://e-editiones.org/roaster" semver-min="1.0.0"/>

src/js/fore-all.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/modules/api.xql

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ declare variable $api:definitions := ("api.json");
2525
:)
2626
declare function api:get-status($request as map(*)) {
2727
<tuttle>
28-
<default>{$config:default-collection}</default>
28+
<default>{config:default-collection()}</default>
2929
<repos>
30-
{for $collection in map:keys($config:collections)
31-
let $col-config := $config:collections?($collection)
32-
let $collection-path := $config:prefix || "/" || $collection
33-
let $hash-staging := $config:prefix || "/" || $collection || $config:suffix || "/gitsha.xml"
34-
let $hash-deploy := $config:prefix || "/" || $collection || "/gitsha.xml"
30+
{for $collection in config:list-collections()
31+
let $col-config := config:collections($collection)
32+
let $collection-path := config:prefix() || "/" || $collection
33+
let $hash-staging := config:prefix() || "/" || $collection || config:suffix() || "/gitsha.xml"
34+
let $hash-deploy := config:prefix() || "/" || $collection || "/gitsha.xml"
3535
let $hash-git := if($col-config?vcs = "github") then github:get-lastcommit-sha($col-config)
3636
else gitlab:get-lastcommit-sha($col-config)
3737
let $status := if ($hash-git?sha = "" ) then
@@ -66,10 +66,10 @@ declare function api:get-status($request as map(*)) {
6666
:)
6767
declare function api:get-hash($request as map(*)) {
6868
let $git-collection := if (not(exists($request?parameters?collection))) then
69-
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
70-
let $config := $config:collections?($git-collection)
71-
let $collection := $config:prefix || "/" || $git-collection || "/gitsha.xml"
72-
let $collection-staging := $config:prefix || "/" || $git-collection || $config:suffix || "/gitsha.xml"
69+
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
70+
let $config := config:collections($git-collection)
71+
let $collection := config:prefix() || "/" || $git-collection || "/gitsha.xml"
72+
let $collection-staging := config:prefix() || "/" || $git-collection || config:suffix() || "/gitsha.xml"
7373

7474
return
7575
if (exists($config)) then (
@@ -90,15 +90,15 @@ declare function api:get-hash($request as map(*)) {
9090
:)
9191
declare function api:lock-remove($request as map(*)) {
9292
let $git-collection := if (not(exists($request?parameters?collection))) then
93-
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
94-
let $config := $config:collections?($git-collection)
95-
let $lockfile-path := $config:prefix || "/" || $git-collection
96-
let $lockfile := $lockfile-path || "/" || $config:lock
93+
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
94+
let $config := config:collections($git-collection)
95+
let $lockfile-path := config:prefix() || "/" || $git-collection
96+
let $lockfile := $lockfile-path || "/" || config:lock()
9797

9898
return
9999
if (exists($config)) then (
100100
if (exists(doc($lockfile))) then (
101-
let $remove := xmldb:remove($lockfile-path, $config:lock)
101+
let $remove := xmldb:remove($lockfile-path, config:lock())
102102
let $message := "lockfile removed: " || $lockfile
103103
return
104104
map { "message" : $message}
@@ -118,10 +118,10 @@ declare function api:lock-remove($request as map(*)) {
118118
:)
119119
declare function api:lock-print($request as map(*)) {
120120
let $git-collection := if (not(exists($request?parameters?collection))) then
121-
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
122-
let $config := $config:collections?($git-collection)
123-
let $lockfile-path := $config:prefix || "/" || $git-collection
124-
let $lockfile := $lockfile-path || "/" || $config:lock
121+
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
122+
let $config := config:collections($git-collection)
123+
let $lockfile-path := config:prefix() || "/" || $git-collection
124+
let $lockfile := $lockfile-path || "/" || config:lock()
125125

126126
return
127127
if (exists($config)) then (
@@ -144,12 +144,12 @@ declare function api:lock-print($request as map(*)) {
144144
:)
145145
declare function api:git-pull($request as map(*)) {
146146
let $git-collection := if (not(exists($request?parameters?collection))) then
147-
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
148-
let $config := $config:collections?($git-collection)
149-
let $collection-staging := $config:prefix || "/" || $git-collection || $config:suffix
150-
let $collection-staging-sha := $config:prefix || "/" || $git-collection || $config:suffix || "/gitsha.xml"
151-
let $lockfile := $config:prefix || "/" || $git-collection || "/" || $config:lock
152-
let $collection-destination := $config:prefix || "/" || $git-collection
147+
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
148+
let $config := config:collections($git-collection)
149+
let $collection-staging := config:prefix() || "/" || $git-collection || config:suffix()
150+
let $collection-staging-sha := config:prefix() || "/" || $git-collection || config:suffix() || "/gitsha.xml"
151+
let $lockfile := config:prefix() || "/" || $git-collection || "/" || config:lock()
152+
let $collection-destination := config:prefix() || "/" || $git-collection
153153

154154
return
155155
if (exists($config)) then (
@@ -183,13 +183,13 @@ declare function api:git-pull($request as map(*)) {
183183

184184
declare function api:git-deploy($request as map(*)) {
185185
let $git-collection := if (not(exists($request?parameters?collection))) then
186-
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
187-
let $config := $config:collections?($git-collection)
188-
let $collection-staging := $git-collection || $config:suffix
189-
let $collection-staging-uri := $config:prefix || "/" || $collection-staging
190-
let $collection-destination := $config:prefix || "/" || $git-collection
186+
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
187+
let $config := config:collections($git-collection)
188+
let $collection-staging := $git-collection || config:suffix()
189+
let $collection-staging-uri := config:prefix() || "/" || $collection-staging
190+
let $collection-destination := config:prefix() || "/" || $git-collection
191191
let $collection-destination-sha := $collection-destination || "/gitsha.xml"
192-
let $lockfile := $collection-destination || "/" || $config:lock
192+
let $lockfile := $collection-destination || "/" || config:lock()
193193

194194
return
195195
if (exists($config)) then (
@@ -203,7 +203,7 @@ declare function api:git-deploy($request as map(*)) {
203203
else (
204204
let $check-lock-dst := if (xmldb:collection-available($collection-destination)) then ()
205205
else (
206-
xmldb:create-collection($config:prefix, $git-collection)
206+
xmldb:create-collection(config:prefix(), $git-collection)
207207
)
208208
let $write-lock := app:lock-write($collection-destination, "deploy")
209209
let $xar-list := xmldb:get-child-resources($collection-staging-uri)
@@ -251,8 +251,8 @@ declare function api:git-deploy($request as map(*)) {
251251
:)
252252
declare function api:get-commit($request as map(*)) {
253253
let $git-collection := if (not(exists($request?parameters?collection))) then
254-
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
255-
let $config := $config:collections?($git-collection)
254+
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
255+
let $config := config:collections($git-collection)
256256

257257
return
258258
if (exists($config)) then (
@@ -276,10 +276,10 @@ declare function api:get-commit($request as map(*)) {
276276
:)
277277
declare function api:incremental($request as map(*)) {
278278
let $git-collection := if (not(exists($request?parameters?collection))) then
279-
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
280-
let $config := $config:collections?($git-collection)
281-
let $collection-path := $config:prefix || "/" || $git-collection
282-
let $lockfile := $collection-path || "/" || $config:lock
279+
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
280+
let $config := config:collections($git-collection)
281+
let $collection-path := config:prefix() || "/" || $git-collection
282+
let $lockfile := $collection-path || "/" || config:lock()
283283
let $collection-destination-sha := $collection-path || "/gitsha.xml"
284284

285285
return
@@ -335,9 +335,9 @@ declare function api:incremental($request as map(*)) {
335335
: APIKey generation for webhooks
336336
:)
337337
declare function api:api-keygen($request as map(*)) {
338-
let $git-collection := $config:default-collection
339-
let $config := $config:collections?($git-collection)
340-
let $collection := $config:default-collection
338+
let $git-collection := config:default-collection()
339+
let $config := config:collections($git-collection)
340+
let $collection := config:default-collection()
341341

342342
return
343343
if (exists($config)) then (
@@ -357,12 +357,12 @@ declare function api:api-keygen($request as map(*)) {
357357
:)
358358
declare function api:hook($request as map(*)) {
359359
let $git-collection := if (not(exists($request?parameters?collection))) then
360-
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
361-
let $config := $config:collections?($git-collection)
360+
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
361+
let $config := config:collections($git-collection)
362362

363363
return
364364
if (exists($config)) then (
365-
let $apikey := doc($config:apikeys)//apikeys/collection[name = $collection]/key/text()
365+
let $apikey := doc(config:apikeys())//apikeys/collection[name = $collection]/key/text()
366366
return
367367
if ($apikey) then (
368368
let $apikey-header :=
@@ -374,8 +374,8 @@ declare function api:hook($request as map(*)) {
374374
request:get-header("X-Gitlab-Token")
375375
return
376376
if ($apikey-header = $apikey) then (
377-
let $collection-path := $config:prefix || "/" || $git-collection
378-
let $lockfile := $collection-path || "/" || $config:lock
377+
let $collection-path := config:prefix() || "/" || $git-collection
378+
let $lockfile := $collection-path || "/" || config:lock()
379379
let $collection-destination-sha := $collection-path || "/gitsha.xml"
380380
let $login := xmldb:login($collection-path, $config:hookuser, $config:hookpasswd)
381381

0 commit comments

Comments
 (0)