62 lines
1.4 KiB
Bash
Executable File
62 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/bash
|
|
|
|
|
|
# Must specify a JSON with a following structure:
|
|
|
|
# [
|
|
# {
|
|
# "api": "endpoint",
|
|
# "content": [
|
|
# {} //obj to populate
|
|
# ]
|
|
# },
|
|
# ]
|
|
|
|
ENDPOINT="http://localhost:49618"
|
|
if [[ $DOCKER_ENVIRONMENT ]]; then
|
|
ENDPOINT="http://oc-catalog:49618"
|
|
fi
|
|
|
|
if [[ $DOCKER_ENDPOINT ]]; then
|
|
ENDPOINT="$DOCKER_ENDPOINT"
|
|
fi
|
|
|
|
[[ -z $1 ]] && { echo "Must specify a json path"; exit 1; }
|
|
[[ ! -f $1 ]] && { echo "$1 is not a file"; exit 1; }
|
|
cat "$1" | jq empty || { echo "$1 is not a valid JSON"; exit 1; }
|
|
|
|
########
|
|
|
|
while read row; do
|
|
TRGT_ENDPOINT=$(echo $row | jq -r '.api')
|
|
|
|
while read item; do
|
|
|
|
img_data=$(echo $item | jq -r '.logo')
|
|
# If is a path, replace with base64 encoded image
|
|
if [[ $img_data =~ ^\./.* ]]; then
|
|
if [[ ! -f ./scripts/"$img_data" ]]; then
|
|
echo "File ./scripts/$img_data doesn't exist"; exit 1
|
|
fi
|
|
|
|
item=$(echo $item | jq ".logo |= \"$(base64 -w0 ./scripts/"$img_data")\"")
|
|
fi
|
|
|
|
echo `echo $item | jq -r '.name'` to $ENDPOINT${TRGT_ENDPOINT}
|
|
|
|
answer=$(curl --fail "$ENDPOINT${TRGT_ENDPOINT}" \
|
|
-X POST \
|
|
--data-binary "$item")
|
|
|
|
if [[ $? -ne 0 || "$answer" == *"<html>"* ]]; then
|
|
echo -e "\nERROR: Some error ocurred when submitting"
|
|
exit 1
|
|
fi
|
|
done < <(echo "$row" | jq -c '.content[]')
|
|
done < <(jq -c '.[]' $1)
|
|
|
|
|
|
echo
|
|
echo
|
|
echo
|
|
echo "All models submitted correctly!" |