From 9d7fd9d122897cce615accd78ca927765567d697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Wed, 16 Jan 2019 10:16:37 +0100 Subject: [PATCH 01/16] add a function to query repo parameters --- modules/config.xqm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/config.xqm b/modules/config.xqm index ab1c623..eeb92d3 100644 --- a/modules/config.xqm +++ b/modules/config.xqm @@ -60,3 +60,11 @@ declare function config:get($key as xs:string, $module-key as xs:string?) { declare function config:key-available($key as xs:string) as xs:boolean { $config:file/cf:config//*/string(@key) = $key }; + +(:~ + : A function to query the app repo config. + : @param $key – the name of the element to query for + : :) +declare function config:repoget($key as xs:string){ + $config:repo-descriptor//*[local-name() = $key] ! string(.) +}; -- GitLab From c59f4ff140a0c5ca934a98dd09cde271f0f37633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Wed, 16 Jan 2019 10:18:01 +0100 Subject: [PATCH 02/16] fixing a fork issue with resource availablity --- post-install.xq | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/post-install.xq b/post-install.xq index 98cb023..a42ce74 100644 --- a/post-install.xq +++ b/post-install.xq @@ -79,19 +79,20 @@ as xs:string { local:format-test-rate-output($coverage) }; - - let $project-name := tokenize($target, "/")[last()] let $log := util:log-system-out("installing " || $project-name) let $system-path := system:get-exist-home() || util:system-property("file.separator") -let $use-template := xmldb:rename($target || "/textgrid/data", "collection-template.xconf", "collection.xconf") +let $use-template := + if(doc-available($target || "/textgrid/data/collection-template.xconf")) + then xmldb:rename($target || "/textgrid/data", "collection-template.xconf", "collection.xconf") + else true() let $data-xconf := $target || "/textgrid/data/collection.xconf" (: prepare empty Lucene Config files :) let $prepare-config := ( - util:eval("file:serialize-binary( xs:base64Binary(util:base64-encode(""# empty config file ä,ae ö,oe ü,ue"")), $system-path || $project-name || '-charmap.txt')"), - util:eval("file:serialize-binary( xs:base64Binary(util:base64-encode(""# empty config file Backfisch, Tochter, Mädchen"")), $system-path || $project-name || '-synonyms.txt')") + util:eval("file:serialize-binary( xs:base64Binary(util:base64-encode(""# default config file ä,ae ö,oe ü,ue"")), $system-path || $project-name || '-charmap.txt')"), + util:eval("file:serialize-binary( xs:base64Binary(util:base64-encode(""# default config file Backfisch, Tochter, Mädchen"")), $system-path || $project-name || '-synonyms.txt')") ) (: rewrite the local path in index config :) @@ -105,12 +106,14 @@ let $rewrite-synonyms := update value //xconf:lucene/xconf:analyzer/xconf:param[@name="synonyms"] /@value with $system-path || $project-name || "-synonyms.txt" -let $store-xconf := xmldb:store("/db/system/config"||$target||"/textgrid/data", "collection.xconf", doc( $data-xconf )) -let $reindex := xmldb:reindex($target||"/textgrid/data") +let $store-xconf := xmldb:store("/db/system/config" || $target || "/textgrid/data", "collection.xconf", doc( $data-xconf )) +let $reindex := xmldb:reindex($target || "/textgrid/data") + (: we have to test for writable path :) -let $path := $system-path +let $path := $system-path let $user := util:system-property("user.name") -let $message1 := $path || " is not available. Create it and make sure "||$user||" can write there." +let $message1 := $path || " is not available. Create it and make sure " + || $user || " can write there." let $message2 := "Could not write to " || $path || "." return ( if @@ -124,17 +127,11 @@ else $message1 || " " ) , -(: run tests on GitLab Runner or when forced :) -let $jobId := try {file:read("/tmp/ci.job") => xs:int()} catch * { 0 } -let $log := util:log-system-out( "[48;2;"|| "255;0;0" ||"m " || - "This is JOB #" || string($jobId) || "." || " " ) -return - - let $tests := util:eval(xs:anyURI('test.xq')) - let $print := util:log-system-out( $tests ) - let $print := util:log-system-out( local:test-function-rate($tests) ) - let $file-name := system:get-exist-home()||util:system-property('file.separator')||".."||util:system-property('file.separator')||"tests-sade_job-"||string($jobId)||".log.xml" - let $file := file:serialize({ $tests }, $file-name, ()) +let $tests := util:eval(xs:anyURI('test.xq')) +let $print := util:log-system-out( $tests ) +let $print := util:log-system-out( local:test-function-rate($tests) ) +let $file-name := system:get-exist-home()||util:system-property('file.separator')||".."||util:system-property('file.separator')||"tests-sade_job-"||environment-variable("CI_JOB_ID")||".log.xml" +let $file := file:serialize({ $tests }, $file-name, ()) return util:log-system-out($file-name || " saved.") ) -- GitLab From 73eecd4304d372e0dd17752fca80b151b86b82fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Wed, 16 Jan 2019 10:20:12 +0100 Subject: [PATCH 03/16] set a random password for new packages and print it after redirect fixes the password issue we have in the fork mechanism --- docs/forking.md | 12 ++---------- modules/app.xqm | 9 +++++++++ modules/fork.xq | 33 +++++++++++++++++++++++++++++---- templates/publish.html | 9 +++++++++ 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/docs/forking.md b/docs/forking.md index 4461c84..8742087 100644 --- a/docs/forking.md +++ b/docs/forking.md @@ -11,17 +11,9 @@ in the first panel (1). [SCREENSHOT] Click on "create" (2) and wait until you get redirected to your own instance. -[Enter a new secure password!] -To continue you have to enter new credentials to the SADE Plugin configuration. -> URL: append -ProjectName to "/sade -> -> User: ProjectName -> -> Password: - -The username will be the same as the project name and you have to enter the -formerly typed password here as well. +The resulting view should present new credentials at the top. Again you have to +set these credentials in the [preferences in TextGridLab](publish.md#configuration). # Download & Tracking changes You can download any application by clicking on the download button at the SADE diff --git a/modules/app.xqm b/modules/app.xqm index 47d021a..bdcce12 100644 --- a/modules/app.xqm +++ b/modules/app.xqm @@ -27,6 +27,15 @@ declare function app:title($node as node(), $model as map(*)) { config:get("project-title") }; +(:~ + : Get the target of this app by using the repo.xml. + : @param $node the HTML node with the attribute which triggered this call + : @param $model a map containing arbitrary data - used to pass information between template calls + :) +declare function app:target($node as node(), $model as map(*)) { + config:repoget("target") +}; + (:~ : Provides dynamic CSS based on the requested resource name :) declare function app:css-injection($node as node(), $model as map(*), $exist-resource) { diff --git a/modules/fork.xq b/modules/fork.xq index b95c10b..06f0229 100644 --- a/modules/fork.xq +++ b/modules/fork.xq @@ -6,7 +6,7 @@ xquery version "3.1"; : but in the new application. : : @author Mathias Göbel - : @version 0.1 + : @version 0.2 : :) import module namespace dbutil="http://exist-db.org/xquery/dbutil"; @@ -16,7 +16,30 @@ declare namespace cf="https://sade.textgrid.de/ns/configfile"; declare namespace expath="http://expath.org/ns/pkg"; declare namespace repo="http://exist-db.org/xquery/repo"; +(:~ + : Generate a password in the given length. + : + : @param $length the length of the resulting password + : @author Mathias Göbel + : @since 0.2 + : :) +declare function local:passwordGenerator($length as xs:integer) { + if($length lt 10) + then error( QName("https://sade.textgrid.de/ns/error", "FORK04"), "Short Password. use at least 10 chars") + else + let $charset := "abcdefghijklmnopqrstuvwxyz§/ß?-.,;_+*~öäüÖÄÜABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + let $charsetLength := string-length($charset) + let $password := + for $i in 1 to $length + let $num := util:random($charsetLength) + return + substring($charset, $num, 1) + return + string-join($password) +}; + declare variable $target := request:get-parameter("target", "koma"); +declare variable $password := local:passwordGenerator(10); declare variable $referer := request:get-header("Referer"); declare variable $dry-run := request:get-parameter("dry", "false"); @@ -40,7 +63,7 @@ declare variable $repoConf := true application sade-{ $target } - + pre-install.xq post-install.xq { current-dateTime() } @@ -119,6 +142,8 @@ return return if( $complete/@result = "ok" ) then - let $uri := replace($referer, "apps/.+/publish\.html", "apps/"||replace($name, "SADE", "sade")||"/publish.html") - return response:redirect-to(xs:anyURI($uri)) + let $replacement := "apps/" || replace($name, "SADE", "sade") || "/publish.html?newpw=" || $password + let $uri := replace($referer, "apps/.+/publish\.html", $replacement) + return + response:redirect-to(xs:anyURI($uri)) else $complete diff --git a/templates/publish.html b/templates/publish.html index cd6981c..baa2d56 100644 --- a/templates/publish.html +++ b/templates/publish.html @@ -1,4 +1,13 @@
+
-- GitLab From 554433d50febd41c4995174c826f259add3011eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Wed, 16 Jan 2019 10:49:34 +0100 Subject: [PATCH 04/16] remove some special characters chars are passed via get parameter, so we have to omit certain special chars --- modules/fork.xq | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/fork.xq b/modules/fork.xq index 06f0229..cf4986e 100644 --- a/modules/fork.xq +++ b/modules/fork.xq @@ -27,7 +27,7 @@ declare function local:passwordGenerator($length as xs:integer) { if($length lt 10) then error( QName("https://sade.textgrid.de/ns/error", "FORK04"), "Short Password. use at least 10 chars") else - let $charset := "abcdefghijklmnopqrstuvwxyz§/ß?-.,;_+*~öäüÖÄÜABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + let $charset := "abcdefghijklmnopqrstuvwxyz§ß-.,;_+~öäüÖÄÜABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" let $charsetLength := string-length($charset) let $password := for $i in 1 to $length -- GitLab From 0f02126286135def1c85a163021a881128a2db75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20G=C3=B6bel?= Date: Wed, 16 Jan 2019 10:50:36 +0100 Subject: [PATCH 05/16] alert not to close --- templates/publish.html | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/publish.html b/templates/publish.html index baa2d56..13ab260 100644 --- a/templates/publish.html +++ b/templates/publish.html @@ -1,6 +1,5 @@