Skip to content

Commit 833cd4f

Browse files
author
oglowa
committed
glo03-666: initial commit
1 parent 4b84f75 commit 833cd4f

File tree

6 files changed

+223
-0
lines changed

6 files changed

+223
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@ fabric.properties
7777
# Android studio 3.1+ serialized cache file
7878
.idea/caches/build_file_checksums.ser
7979

80+
.idea/

script/browse.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# Requirements:
4+
# - Windows Commandline
5+
# - Cygwin + curl (Intune-Client)
6+
# - Alternative: https://curl.se/windows/
7+
#
8+
# (c) 2024 Oliver Glowa (glo03) / Arvato Systems GmbH
9+
#
10+
11+
source ./common/env-restapi.sh
12+
13+
14+
REQ_01="${CONF_RESTAPI_URL}?expand=space&limit=10"
15+
REQ_02="${CONF_RESTAPI_URL}/scan?expand=space&limit=10"
16+
REQ_03="${CONF_RESTAPI_URL}?expand=space&limit=10&spaceKey=NMAS"
17+
REQ_04="${CONF_RESTAPI_URL}/scan?expand=space&limit=10&spaceKey=NMAS"
18+
19+
echo -e "\n--------"
20+
echo "Browse OLD Variant"
21+
echo "--------"
22+
echo "${REQ_01}"
23+
24+
curl -s -H "${CONF_AUTH}" "${REQ_01}" | jq -r "${RESP_RESULTS}"
25+
26+
echo -e "\n--------"
27+
echo "Scan NEW Variant"
28+
echo "--------"
29+
echo "${REQ_02}"
30+
31+
curl -s -H "${CONF_AUTH}" "${REQ_02}" | jq -r "${RESP_RESULTS}"
32+
33+
echo -e "\n--------"
34+
echo "Browse OLD Variant with space key"
35+
echo "--------"
36+
echo "${REQ_03}"
37+
38+
curl -s -H "${CONF_AUTH}" "${REQ_03}" | jq -r "${RESP_RESULTS}"
39+
40+
echo -e "\n--------"
41+
echo "Scan NEW Variant with space key"
42+
echo "--------"
43+
echo "${REQ_04}"
44+
45+
curl -s -H "${CONF_AUTH}" "${REQ_04}" | jq -r "${RESP_RESULTS}"

script/common/env-restapi.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Requirements:
4+
# - Windows Commandline
5+
# - Cygwin + curl (Intune-Client)
6+
# - Alternative: https://curl.se/windows/
7+
#
8+
# (c) 2024 Oliver Glowa (glo03) / Arvato Systems GmbH
9+
#
10+
# !!!! Works only with privat access token (PAT) !!!!
11+
12+
TS=`date`
13+
14+
CONF_AUTH="Authorization: Bearer ${CONF_PAT_TEST}"
15+
16+
CONF_BASE_URL_TEST=https://nma-s-confluence-test.arvato-systems.de
17+
CONF_BASE_URL_INTE=https://nma-s-confluence-mig.arvato-systems.de
18+
CONF_BASE_URL=${CONF_BASE_URL_TEST}
19+
20+
CONF_RESTAPI_URL=${CONF_BASE_URL}/rest/api/content
21+
DL_DIR=${TEMP}
22+
23+
REQP_LIGHT='&expand=space'
24+
REQP_FULL='&expand=body.storage,version,space'
25+
26+
RESP_SINGLE='.id + " " + .space.key + " " + .title'
27+
RESP_RESULTS='.results[]| .id + " " + .space.key + " " + .title'
28+
RESP_BODY_SINGLE='.id + " " + .space.key + " " + .title,.body.storage.value'
29+
RESP_BODY_RESULTS='.results[]| .id + " " + .space.key + " " + .title + "\n" + .body.storage.value'
30+
31+
32+
# Check
33+
if [ "${CONF_AUTH}" = "" ]; then
34+
echo -e "No PAT (personal access token) in environment defined!"
35+
exit 10
36+
fi

script/read-children.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
# Requirements:
4+
# - Windows Commandline
5+
# - Cygwin + curl (Intune-Client)
6+
# - Alternative: https://curl.se/windows/
7+
#
8+
# (c) 2024 Oliver Glowa (glo03) / Arvato Systems GmbH
9+
#
10+
11+
source ./common/env-restapi.sh
12+
13+
# set the maximum level of recursion
14+
MAX_LEVEL=2
15+
16+
PAGE_ID=532951146
17+
#532951146 #98 Playground
18+
#125380876 #Health%20and%Public
19+
20+
if [ "$1" != "" ]; then
21+
PAGE_ID=$1
22+
fi
23+
24+
LEVEL=0
25+
if [ "$2" != "" ]; then
26+
LEVEL=$2
27+
((LEVEL=LEVEL+1))
28+
fi
29+
30+
STOP_BRANCH=0
31+
if [ ${LEVEL} -ge ${MAX_LEVEL} ]; then
32+
STOP_BRANCH=1
33+
fi
34+
35+
# set the indentation by level
36+
INDENT=$(printf "%-${LEVEL}s")$(printf "%-${LEVEL}s")
37+
38+
# read the page
39+
PARENT_URL="${CONF_RESTAPI_URL}/${PAGE_ID}?expand=space"
40+
CURL_RESULT=$(curl -s -H "${CONF_AUTH}" "${PARENT_URL}")
41+
PARENT_INFO=$(jq -r '.id + " [" + .space.key + "] \"" + .title +"\""'<<<"${CURL_RESULT}")
42+
43+
# get the children URL
44+
CHILD_URL=$(jq -r '._expandable.children'<<<"${CURL_RESULT}")
45+
CHILD_URL=${CONF_BASE_URL}${CHILD_URL}"/page?expand=space"
46+
47+
# Some output
48+
echo -e "\n${INDENT}LEV.${LEVEL}"
49+
echo -e "${INDENT}│\t\t\t\t${PARENT_URL}"
50+
echo -e "${INDENT}│\t\t\t\t${CHILD_URL}"
51+
52+
# read the child pages
53+
CURL_RESULT=$(curl -s -H "${CONF_AUTH}" "${CHILD_URL}")
54+
55+
CHILD_IDX=-1
56+
jq -r '.results[] | .id + " " + .space.key + " " + .title +""'<<<"${CURL_RESULT}" |
57+
{
58+
while read -r CHILD_PAGE_ID CHILD_SPACE CHILD_TITLE ; do
59+
# looop through the child pages
60+
((CHILD_IDX=CHILD_IDX+1))
61+
62+
# some output
63+
echo "${INDENT}"
64+
echo "${INDENT}├- PAGE : ${PARENT_INFO}"
65+
echo "${INDENT}└- ${CHILD_IDX}.CHILD: ${CHILD_PAGE_ID} [${CHILD_SPACE}] \"${CHILD_TITLE}\""
66+
67+
if [ ${STOP_BRANCH} -eq 0 ]; then
68+
# call the script recursively for the next level
69+
./"$0" "${CHILD_PAGE_ID}" ${LEVEL}
70+
else
71+
# stop the recursion for this branch
72+
echo -e "${INDENT} ## STOP_BRANCH ON LEV.${LEVEL} ##\n"
73+
fi
74+
done
75+
76+
if [ ${CHILD_IDX} -lt 0 ]; then
77+
# branch has no children
78+
echo "${INDENT}├- PAGE : ${PARENT_INFO}"
79+
echo -e "${INDENT}└- x.CHILD: No children found\n"
80+
fi
81+
}

script/read.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# Requirements:
4+
# - Windows Commandline
5+
# - Cygwin + curl (Intune-Client)
6+
# - Alternative: https://curl.se/windows/
7+
#
8+
# (c) 2024 Oliver Glowa (glo03) / Arvato Systems GmbH
9+
#
10+
11+
source ./common/env-restapi.sh
12+
13+
PAGE_ID=591855803
14+
PAGE_NAME_01="title=REST-API%2001"
15+
PAGE_NAME_02="spaceKey=NMAS&title=98"
16+
17+
REQ_01="${CONF_RESTAPI_URL}/${PAGE_ID}?${REQP_LIGHT}"
18+
REQ_02="${CONF_RESTAPI_URL}?${PAGE_NAME_01}${REQP_FULL}"
19+
REQ_03="${CONF_RESTAPI_URL}?${PAGE_NAME_02}${REQP_FULL}"
20+
21+
echo -e "\n--------"
22+
echo "Get by Page ID"
23+
echo "--------"
24+
echo "${REQ_01}"
25+
26+
curl -s -H "${CONF_AUTH}" "${REQ_01}" | jq -r "${RESP_BODY_SINGLE}"
27+
28+
echo -e "\n--------"
29+
echo "Get by Page Title"
30+
echo "--------"
31+
echo "${REQ_02}"
32+
33+
curl -s -H "${CONF_AUTH}" "${REQ_02}" | jq -r "${RESP_BODY_RESULTS}"
34+
#| sortc -k 2
35+
36+
echo -e "\n--------"
37+
echo "Get by Space and Page Title"
38+
echo "--------"
39+
echo "${REQ_03}"
40+
41+
curl -s -H "${CONF_AUTH}" "${REQ_03}" | jq -r "${RESP_BODY_RESULTS}"
42+
43+
44+

script/upload.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Requirements:
4+
# - Windows Commandline
5+
# - Cygwin + curl (Intune-Client)
6+
# - Alternative: https://curl.se/windows/
7+
#
8+
# (c) 2024 Oliver Glowa (glo03) / Arvato Systems GmbH
9+
#
10+
# - https://confluence.atlassian.com/confkb/using-the-confluence-rest-api-to-upload-an-attachment-to-one-or-more-pages-1014274390.html
11+
12+
source ./env-restapi.sh
13+
14+
echo -e "\bDo the upload\n"
15+
16+
curl -s -H "Authorization: Bearer ${CONF_AUTH}" -X POST -H "X-Atlassian-Token: no-check" -F "file=@${ATTACHMENT_FILE}" -F "comment=attached at ${TS}" ${CONF_RESTAPI_URL}/${PAGE_ID}/child/attachment?allowDuplicated=true | jq -r

0 commit comments

Comments
 (0)