bin: Fix import-account to take additional ENV variable to specify required user/pwd and tenant key/secret
Also add a new action to allow both export and import into one 'go'
KILLBILL_HOST=${KILLBILL_HOST-127.0.0.1}
KILLBILL_URL=http://${KILLBILL_HOST}:8080
+# USER/PWD
+KILLBILL_USER=${KILLBILL_USER-admin}
+KILLBILL_PWD=${KILLBILL_PWD-password}
+
+# TENANT KEY
+KILLBILL_API_KEY=${KILLBILL_API_KEY-bob}
+KILLBILL_API_SECRET=${KILLBILL_API_SECRET-lazar}
+
# Destination database
DATABASE=${DATABASE-killbill}
USERNAME=${USERNAME-root}
@@ -84,7 +92,8 @@ function fix_dates() {
function export_data() {
local account_id=$1
- curl $KILLBILL_URL/1.0/kb/export/$1 -H"X-Killbill-CreatedBy: $WHO" > $TMP_DIR/kbdump
+ curl $KILLBILL_URL/1.0/kb/export/$1 -u "$KILLBILL_USER:$KILLBILL_PWD" -H "X-Killbill-ApiKey: $KILLBILL_API_KEY" -H "X-Killbill-ApiSecret: $KILLBILL_API_SECRET" -H"X-Killbill-CreatedBy: $WHO" > $TMP_DIR/kbdump
+ echo "Data exported under $TMP_DIR/kbdump"
}
function import_data() {
@@ -131,7 +140,7 @@ eval set -- "${ARGS}"
function usage() {
echo -n "./import-account"
- echo -n " -a|--action <export|import>"
+ echo -n " -a|--action <export|import|all>"
echo -n " --help this message"
echo
exit 1
@@ -145,24 +154,28 @@ while true; do
esac
done
+
if [ -z $ACTION ]; then
echo "Need to specify an action"
usage
fi
-if [ $ACTION == "export" ]; then
+if [ $ACTION == "export" ] || [ $ACTION == "all" ]; then
if [ -z $1 ]; then
echo "Need to specify an account id"
usage
fi
export_data $1
- sanitize_and_import $TMP_DIR/kbdump
fi
-if [ $ACTION == "import" ]; then
+if [ $ACTION == "import" ] || [ $ACTION == "all" ]; then
if [ -z $1 ]; then
echo "Need to specify a file"
usage
fi
+ if [ $ACTION == "import" ]; then
sanitize_and_import $1
+ else
+ sanitize_and_import $TMP_DIR/kbdump
+ fi
fi
