Skip to content

Commit

Permalink
Xml configuration (#3)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
domnik23 and dominik kuehne authored Apr 1, 2022
1 parent 39f8d75 commit f4298a6
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
.vscode
.DS_Store
*.xar
src/data/test.xml
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Synchronizes your data collection with GitHub and GitLab.

## Current restrictions

In version 1.1.0 not implemented:
In version 1.1.1 not implemented:
- webhooks are not fully implemented.

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

## Configuration

Tuttle is configured in `modules/config.xqm`.
Tuttle is configured in `data/tuttle.xml`.

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

An example:
```xquery
"sample-collection-github" : map {
"vcs" : "github",
"baseurl" : "https://api.github.com/",
"repo" : "tuttle-demo",
"owner" : "Jinntec",
"ref" : "master",
"token" : "146152be6a97a9efe9dd4647e71da8f3e4faf263",
"hookuser" : "admin",
"hookpasswd" : ""
},
"sample-collection-gitlab" : map {
"vcs" : "gitlab",
"baseurl" : "https://gitlab.com/api/v4/",
"project-id" : "25852323",
"ref" : "master",
"token" : "9vq6jmzbxCMtNkobUfoM",
"hookuser" : "admin",
"hookpasswd" : ""
}
```xml
<repos>
<collection name="tuttle-sample-data">
<default>true</default>
<type>github</type>
<baseurl>https://api.github.com/</baseurl>
<repo>tuttle-sample-data</repo>
<owner>tuttle-sample-data</owner>
<token>XXX</token>
<ref>master</ref>
<hookuser>admin</hookuser>
<hookpasswd></hookpasswd>
</collection>

<collection name="tuttle-sample-gitlab">
<type>gitlab</type>
<baseurl>https://gitlab.com/api/v4/</baseurl>
<project-id>tuttle-sample-data</project-id>
<token>XXX</token>
<ref>master</ref>
<hookuser>admin</hookuser>
<hookpasswd></hookpasswd>
</collection>
</repos>
```

#### vcs
#### type
Gitserver type: 'github' or 'gitlab'

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

### API endpoint description

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

#### Fetch to staging collection

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tuttle",
"version": "1.1.0",
"version": "1.1.1",
"description": "tuttle - a Git-integration for eXist-db",
"scripts": {
"test": "gulp install && mocha --exit",
Expand Down
2 changes: 1 addition & 1 deletion src/api.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi": "3.0.0",
"info": {
"version": "1.1.0",
"version": "1.1.1",
"title": "Tuttle API",
"description": "API for Tuttle Git integration"
},
Expand Down
41 changes: 38 additions & 3 deletions src/data/tuttle.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
<tuttle>
<default>sample-collection-github</default>
<repos>
<repo type="github" url="https://github.com/Jinntec/tuttle-demo" ref="master" collection="sample-collection-github"/>
<repo type="gitlab" url="https://gitlab.com/tuttle-test/tuttle-demo.git" ref="master" collection="sample-collection-gitlab"/>
<collection name="tuttle-sample-data">
<default>true</default>
<type>github</type>
<baseurl>https://api.github.com/</baseurl>
<repo>tuttle-sample-data</repo>
<owner>tuttle-sample-data</owner>
<token>XXX</token>
<ref>master</ref>
<hookuser>admin</hookuser>
<hookpasswd></hookpasswd>
</collection>

<collection name="tuttle-sample-gitlab">
<type>gitlab</type>
<baseurl>https://gitlab.com/api/v4/</baseurl>
<project-id>tuttle-sample-data</project-id>
<token>XXX</token>
<ref>master</ref>
<hookuser>admin</hookuser>
<hookpasswd></hookpasswd>
</collection>
</repos>

<blacklist>
<file>existdb.json</file>
<file>build.xml</file>
<file>README.md</file>
<file>.gitignore</file>
<file>expath-pkg.xml.tmpl</file>
<file>repo.xml.tmpl</file>
<file>build.properties.xml</file>
</blacklist>


<config prefix="/db/apps" suffix="-stage" lock="git-lock.xml" apikeys="/db/system/auth/tuttle-token.xml">
<sm user="nobody" group="nogroup" mode="rw-r--r--"/>
</config>


</tuttle>
2 changes: 1 addition & 1 deletion src/expath-pkg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package
xmlns="http://expath.org/ns/pkg"
name="http://e-editiones.org/tuttle"
abbrev="tuttle" version="1.1.0" spec="1.0">
abbrev="tuttle" version="1.1.1" spec="1.0">
<title>Tuttle - Git for eXist-db</title>
<dependency processor="http://exist-db.org" semver-min="5.3.0"/>
<dependency package="http://e-editiones.org/roaster" semver-min="1.0.0"/>
Expand Down
1 change: 1 addition & 0 deletions src/js/fore-all.js.map

Large diffs are not rendered by default.

92 changes: 46 additions & 46 deletions src/modules/api.xql
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ declare variable $api:definitions := ("api.json");
:)
declare function api:get-status($request as map(*)) {
<tuttle>
<default>{$config:default-collection}</default>
<default>{config:default-collection()}</default>
<repos>
{for $collection in map:keys($config:collections)
let $col-config := $config:collections?($collection)
let $collection-path := $config:prefix || "/" || $collection
let $hash-staging := $config:prefix || "/" || $collection || $config:suffix || "/gitsha.xml"
let $hash-deploy := $config:prefix || "/" || $collection || "/gitsha.xml"
{for $collection in config:list-collections()
let $col-config := config:collections($collection)
let $collection-path := config:prefix() || "/" || $collection
let $hash-staging := config:prefix() || "/" || $collection || config:suffix() || "/gitsha.xml"
let $hash-deploy := config:prefix() || "/" || $collection || "/gitsha.xml"
let $hash-git := if($col-config?vcs = "github") then github:get-lastcommit-sha($col-config)
else gitlab:get-lastcommit-sha($col-config)
let $status := if ($hash-git?sha = "" ) then
Expand Down Expand Up @@ -66,10 +66,10 @@ declare function api:get-status($request as map(*)) {
:)
declare function api:get-hash($request as map(*)) {
let $git-collection := if (not(exists($request?parameters?collection))) then
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
let $config := $config:collections?($git-collection)
let $collection := $config:prefix || "/" || $git-collection || "/gitsha.xml"
let $collection-staging := $config:prefix || "/" || $git-collection || $config:suffix || "/gitsha.xml"
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
let $config := config:collections($git-collection)
let $collection := config:prefix() || "/" || $git-collection || "/gitsha.xml"
let $collection-staging := config:prefix() || "/" || $git-collection || config:suffix() || "/gitsha.xml"

return
if (exists($config)) then (
Expand All @@ -90,15 +90,15 @@ declare function api:get-hash($request as map(*)) {
:)
declare function api:lock-remove($request as map(*)) {
let $git-collection := if (not(exists($request?parameters?collection))) then
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
let $config := $config:collections?($git-collection)
let $lockfile-path := $config:prefix || "/" || $git-collection
let $lockfile := $lockfile-path || "/" || $config:lock
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
let $config := config:collections($git-collection)
let $lockfile-path := config:prefix() || "/" || $git-collection
let $lockfile := $lockfile-path || "/" || config:lock()

return
if (exists($config)) then (
if (exists(doc($lockfile))) then (
let $remove := xmldb:remove($lockfile-path, $config:lock)
let $remove := xmldb:remove($lockfile-path, config:lock())
let $message := "lockfile removed: " || $lockfile
return
map { "message" : $message}
Expand All @@ -118,10 +118,10 @@ declare function api:lock-remove($request as map(*)) {
:)
declare function api:lock-print($request as map(*)) {
let $git-collection := if (not(exists($request?parameters?collection))) then
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
let $config := $config:collections?($git-collection)
let $lockfile-path := $config:prefix || "/" || $git-collection
let $lockfile := $lockfile-path || "/" || $config:lock
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
let $config := config:collections($git-collection)
let $lockfile-path := config:prefix() || "/" || $git-collection
let $lockfile := $lockfile-path || "/" || config:lock()

return
if (exists($config)) then (
Expand All @@ -144,12 +144,12 @@ declare function api:lock-print($request as map(*)) {
:)
declare function api:git-pull($request as map(*)) {
let $git-collection := if (not(exists($request?parameters?collection))) then
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
let $config := $config:collections?($git-collection)
let $collection-staging := $config:prefix || "/" || $git-collection || $config:suffix
let $collection-staging-sha := $config:prefix || "/" || $git-collection || $config:suffix || "/gitsha.xml"
let $lockfile := $config:prefix || "/" || $git-collection || "/" || $config:lock
let $collection-destination := $config:prefix || "/" || $git-collection
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
let $config := config:collections($git-collection)
let $collection-staging := config:prefix() || "/" || $git-collection || config:suffix()
let $collection-staging-sha := config:prefix() || "/" || $git-collection || config:suffix() || "/gitsha.xml"
let $lockfile := config:prefix() || "/" || $git-collection || "/" || config:lock()
let $collection-destination := config:prefix() || "/" || $git-collection

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

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

return
if (exists($config)) then (
Expand All @@ -203,7 +203,7 @@ declare function api:git-deploy($request as map(*)) {
else (
let $check-lock-dst := if (xmldb:collection-available($collection-destination)) then ()
else (
xmldb:create-collection($config:prefix, $git-collection)
xmldb:create-collection(config:prefix(), $git-collection)
)
let $write-lock := app:lock-write($collection-destination, "deploy")
let $xar-list := xmldb:get-child-resources($collection-staging-uri)
Expand Down Expand Up @@ -251,8 +251,8 @@ declare function api:git-deploy($request as map(*)) {
:)
declare function api:get-commit($request as map(*)) {
let $git-collection := if (not(exists($request?parameters?collection))) then
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
let $config := $config:collections?($git-collection)
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
let $config := config:collections($git-collection)

return
if (exists($config)) then (
Expand All @@ -276,10 +276,10 @@ declare function api:get-commit($request as map(*)) {
:)
declare function api:incremental($request as map(*)) {
let $git-collection := if (not(exists($request?parameters?collection))) then
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
let $config := $config:collections?($git-collection)
let $collection-path := $config:prefix || "/" || $git-collection
let $lockfile := $collection-path || "/" || $config:lock
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
let $config := config:collections($git-collection)
let $collection-path := config:prefix() || "/" || $git-collection
let $lockfile := $collection-path || "/" || config:lock()
let $collection-destination-sha := $collection-path || "/gitsha.xml"

return
Expand Down Expand Up @@ -335,9 +335,9 @@ declare function api:incremental($request as map(*)) {
: APIKey generation for webhooks
:)
declare function api:api-keygen($request as map(*)) {
let $git-collection := $config:default-collection
let $config := $config:collections?($git-collection)
let $collection := $config:default-collection
let $git-collection := config:default-collection()
let $config := config:collections($git-collection)
let $collection := config:default-collection()

return
if (exists($config)) then (
Expand All @@ -357,12 +357,12 @@ declare function api:api-keygen($request as map(*)) {
:)
declare function api:hook($request as map(*)) {
let $git-collection := if (not(exists($request?parameters?collection))) then
$config:default-collection else xmldb:decode-uri($request?parameters?collection)
let $config := $config:collections?($git-collection)
config:default-collection() else xmldb:decode-uri($request?parameters?collection)
let $config := config:collections($git-collection)

return
if (exists($config)) then (
let $apikey := doc($config:apikeys)//apikeys/collection[name = $collection]/key/text()
let $apikey := doc(config:apikeys())//apikeys/collection[name = $collection]/key/text()
return
if ($apikey) then (
let $apikey-header :=
Expand All @@ -374,8 +374,8 @@ declare function api:hook($request as map(*)) {
request:get-header("X-Gitlab-Token")
return
if ($apikey-header = $apikey) then (
let $collection-path := $config:prefix || "/" || $git-collection
let $lockfile := $collection-path || "/" || $config:lock
let $collection-path := config:prefix() || "/" || $git-collection
let $lockfile := $collection-path || "/" || config:lock()
let $collection-destination-sha := $collection-path || "/gitsha.xml"
let $login := xmldb:login($collection-path, $config:hookuser, $config:hookpasswd)

Expand Down
Loading

0 comments on commit f4298a6

Please sign in to comment.