-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-apps.sh
executable file
·44 lines (34 loc) · 1.35 KB
/
create-apps.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /bin/bash
# Usage: ${APIGEE_MIGRATE_EDGE_TO_X_TOOLS_DIR}/create-apps.sh
# Add check for variables used
echo $EDGE_ORG
echo $APIGEE_MIGRATE_EDGE_TO_X_TOOLS_DIR
echo $EDGE_EXPORT_DIR
echo $X_IMPORT_DIR
RESULT='/tmp/apps.json'
TMP_RESULT='/tmp/apps_batches.json'
BATCH='/tmp/apps_batch.json'
# Get the first batch
# BUG: apptype doesn't filter results
curl -s -H "$EDGE_AUTH" "https://api.enterprise.apigee.com/v1/organizations/$EDGE_ORG/apps?expand=true&apptype=developer" | jq -r .app > $RESULT
COUNT=$(jq '. | length' $RESULT)
echo FIRST_COUNT=$COUNT
while [ $COUNT -ne 0 ]
do
# Get the last appId for the startKey
START_KEY=$(jq -r '.[-1].appId' $RESULT)
# echo START_KEY=$START_KEY
# Get all the records after the start key
curl -s -H "$EDGE_AUTH" "https://api.enterprise.apigee.com/v1/organizations/$EDGE_ORG/apps?expand=true&apptype=developer&startKey=$START_KEY" | jq -r .app[1:] > $BATCH
COUNT=$(jq '. | length' $BATCH)
echo BATCH_COUNT=$COUNT
# Slurp the batch into the apps
if [ $COUNT -ne 0 ]; then
jq -s '. | add' $RESULT $BATCH > $TMP_RESULT
mv $TMP_RESULT $RESULT
else
echo DONE_COUNT=$(jq '. | length' $RESULT)
fi
done
cp $RESULT $EDGE_EXPORT_DIR/apps.json
python3 ${APIGEE_MIGRATE_EDGE_TO_X_TOOLS_DIR}/convert-apps-edge-x.py $EDGE_EXPORT_DIR/apps.json | jq > $X_IMPORT_DIR/apps.json