Skip to content
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
58 changes: 47 additions & 11 deletions dev/script/create-root-collection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,54 @@ set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR=${DIR}/../..

COLLECTION_NAME=${1:-TEST}
while [[ $# -gt 0 ]] && [[ "$1" == "--"* ]] ;
do
opt="$1";
shift;
case "$opt" in
"--api-key" )
api_key="$1"; shift;;
"--domain" )
domain="$1"; shift;;
"--name" )
name="$1"; shift;;
* )
echo >&2 "Invalid option: $@"; exit 1;;
esac
done

# load values from .env into environment variables
# see https://stackoverflow.com/a/30969768/3868241
set -o allexport
# shellcheck source=../.env
source "$ROOT_DIR/dev/.env"
set +o allexport
if [[ -z "$api_key" && -z "$domain" ]]; then
echo >&2 "API key and domain unset, setting from dotenv file"
# load values from .env into environment variables
# see https://stackoverflow.com/a/30969768/3868241
set -o allexport
# shellcheck source=../.env
source "$ROOT_DIR/dev/.env"
set +o allexport
fi

echo "creating root collection $COLLECTION_NAME"
if [[ -z "$api_key" || -z "$domain" || -z "$name" ]]; then
echo >&2 "Missing setting(s).

curl -s -X POST -H "X-Gu-Media-Key: $API_KEY" \
Usage: $0 --api-key <key> --domain <domain> --name <name>

--api-key API key for authenticating grid access
--domain Root domain for grid instance (eg. local.dev-gutools.co.uk)
--name Name of new root collection"
exit 1
fi

echo "creating root collection $name"

curl -s -X POST -H "X-Gu-Media-Key: $api_key" \
-H "Content-Type: application/json" \
-d '{ "data": "'"$COLLECTION_NAME"'" }' \
"https://media-collections.$DOMAIN/collections"
-d '{ "data": "'"$name"'" }' \
"https://media-collections.$domain/collections"

outcome="$?"

if [[ "$outcome" == "0" ]]; then
echo "collection created"
else
echo "creation failed..."
fi
3 changes: 2 additions & 1 deletion docs/03-apis/02-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ ROOT COLLECTION 2
```

## Root collections

Currently, root collections can only be created via the API. That is, Kahuna doesn't have a UI for it.

We can use [create-root-collection.sh](../../dev/script/create-root-collection.sh) to create a root collection:

```shell script
./dev/script/create-root-collection.sh COLLECTION_NAME
./dev/script/create-root-collection.sh --api-key [api key] --domain [root domain] --name [collection name]
```
Loading