Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add import of web app configs #9

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ RUN chmod +x /entrypoint.sh
RUN apt update && apt-get -y install git

WORKDIR /opt/irisbuild
RUN chown ${ISC_PACKAGE_MGRUSER}:${ISC_PACKAGE_IRISGROUP} /opt/irisbuild
RUN \
mkdir /webapplications &&\
mkdir /converted-webapps &&\
chown ${ISC_PACKAGE_MGRUSER}:${ISC_PACKAGE_IRISGROUP} /opt/irisbuild /webapplications /converted-webapps
USER ${ISC_PACKAGE_MGRUSER}

COPY src src
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Make sure you have [Git](https://git-scm.com/book/en/v2/Getting-Started-Installi
- generation of folder hierarchy based on the class names
- handling of the most common file types (for example ".cls", ".lut", ".hl7", ".inc", ".gbl").
- convenient use in combination with the VS Code Extensions from InterSystems
- considers webapplication settings during conversion process


## Good to know
Expand All @@ -33,13 +34,17 @@ Add a Studio export file (.xml) in any arbitary directory and add a folder named

Replace **<YOUR_STUDIO_EXPORT>** with the filename of your export file and execute the following command in this directory.

If your project depends on web applications that are included in IRIS, you can include their configuration settings so that the converter takes them into account during the conversion process. To do this, [export the webapp configuration](https://docs.intersystems.com/iris20233/csp/documatic/%25CSP.Documatic.cls?LIBRARY=%25SYS&CLASSNAME=Security.Applications#Export) and save the xml-files in a separate folder, e.g. ``./webapps/``.

On Windows:
```
docker run -v "${pwd}/<YOUR_STUDIO_EXPORT>.xml:/irisrun/export.xml" -v "${pwd}/src:/irisrun/udl-export" --rm ghcr.io/hbtgmbh/xml-to-udl/converter:latest
docker run -v "${pwd}/<YOUR_STUDIO_EXPORT>.xml:/irisrun/export.xml" -v "${pwd}/src:/irisrun/udl-export" -v "${pwd}/webapps:/webapplications" --rm ghcr.io/hbtgmbh/xml-to-udl/converter:latest
```
*Note that there a three volumes mounted: 1. for your studio-export.xml-file, 2. your project source directory, 3. (optional) folder of your webapp config export files.*

On Linux:
```
./import-studio-export.sh --xml-file "$(pwd)/<YOUR_STUDIO_EXPORT>.xml" --source-folder "$(pwd)/src" --image ghcr.io/hbtgmbh/xml-to-udl/converter:latest
./import-studio-export.sh --xml-file "$(pwd)/<YOUR_STUDIO_EXPORT>.xml" --source-folder "$(pwd)/src" --webapps-folder "$(pwd)/webapps" --image ghcr.io/hbtgmbh/xml-to-udl/converter:latest
```

After the conversion is finished you should now see the generated sources under "src".
Expand Down
26 changes: 26 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
#!/bin/bash

# prepare web application configurations
if [ "$(ls -A /webapplications/ | grep -E '.*xml$')" != "" ] ; then
echo "found web application confiugurations ..."
cp /webapplications/*.xml /converted-webapps/
for inputfile in /converted-webapps/*.xml ; do
echo "prepare web appclication config file '$inputfile' for import"
# replace namespace with default namespace USER
sed -i -E "s/<NameSpace>.*<\/NameSpace>/<NameSpace>USER<\/NameSpace>/" $inputfile
done
fi

# start IRIS
iris start IRIS quietly > /dev/null

# import web application configurations
if [ "$(ls -A /converted-webapps/ | grep -E '.*xml$')" != "" ] ; then
for inputfile in /converted-webapps/*.xml ; do
echo "import web application config from $inputfile"
# call web application import-method from IRIS terminal session
cat << EOF | iris session IRIS
zn "%SYS"
Write !,##class(Security.Applications).Import("$inputfile")
zn "USER"
Halt
EOF
done
fi


# if sucessfully started, call conversion method and print terminal session to stdout
if [[ $? -eq 0 ]]; then
cat << EOF | iris session IRIS
Expand Down
18 changes: 15 additions & 3 deletions import-studio-export.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
## This is a helper script for importing a studio-export-xml-file (via the xml-to-udl tool) on linux.
##
## Usage: import-studio-export.sh [-d,--delete] -x,--xml-file /abs/path/to/export.xml -s,--source-folder /abs/path/to/source-folder [-i,--image tag-of-converter-image]
## Usage: import-studio-export.sh [-d,--delete] -x,--xml-file /abs/path/to/export.xml -s,--source-folder /abs/path/to/source-folder [-i,--image tag-of-converter-image] [-w,--webapps-folder] /abs/path/to/webapps-folder]
##
## Background:
## The need for such a script is that on linux the local file permission and ownership are passed to the docker volume and
Expand All @@ -16,11 +16,12 @@
IRIS_OWNER_ID=51773
XML_FILE=""
SOURCE_DIR=""
WEBAPPS_DIR=""
XML_TO_UDL_IMAGE="ghcr.io/hbtgmbh/xml-to-udl/converter:latest"
DELETE_EXTRANEOUS_FILES=false

# get script arguments
ARGS=$(getopt -o 'dx:s:i:' --long 'delete,xml-file:,source-folder:,image::' -- "$@") || exit
ARGS=$(getopt -o 'dx:s:i:w:' --long 'delete,xml-file:,source-folder:,image::webapps-folder::' -- "$@") || exit
eval "set -- $ARGS"

# handle script arguments
Expand All @@ -38,6 +39,9 @@ while true; do
# handle delete flag
(-d|--delete)
DELETE_EXTRANEOUS_FILES=true; shift;;
# handle webapp folder argument
(-w|--webapps-folder)
WEBAPPS_DIR=$2; shift 2;;
(--)
shift; break;;
# any other arg
Expand Down Expand Up @@ -78,6 +82,14 @@ else
check_for_abspath_to_dir "source folder" $SOURCE_DIR
fi

# check for webapps folder path
if [[ ! $WEBAPPS_DIR ]]; then
echo -e "Argument -w,--webapps-folder is missing. Please provide a path to a source directory." >&2
exit 1
else
check_for_abspath_to_dir "webapps folder" $WEBAPPS_DIR
fi

# store current owner of source directory
USER=`ls -ld $SOURCE_DIR | awk '{print $3}'`
GROUP=`ls -ld $SOURCE_DIR | awk '{print $4}'`
Expand All @@ -94,7 +106,7 @@ sudo chown -R $IRIS_OWNER_ID $SOURCE_DIR

# run xml-to-udl converter
echo "[STEP] Start converter container image $XML_TO_UDL_IMAGE."
docker run -v "$XML_FILE:/irisrun/export.xml" -v "$SOURCE_DIR/:/irisrun/udl-export" --rm --name xml-to-udl $XML_TO_UDL_IMAGE
docker run -v "$XML_FILE:/irisrun/export.xml" -v "$SOURCE_DIR/:/irisrun/udl-export" -v "$WEBAPPS_DIR/:/webapplications:ro" --rm --name xml-to-udl $XML_TO_UDL_IMAGE

# change owner of source folder back to original owner
echo "[STEP] Change owner of source files back to $USER:$GROUP."
Expand Down