Skip to content

Instantly share code, notes, and snippets.

@thbkrkr
Created November 30, 2016 10:43
Show Gist options
  • Select an option

  • Save thbkrkr/c080eb2342db18fab91f20ca593f303e to your computer and use it in GitHub Desktop.

Select an option

Save thbkrkr/c080eb2342db18fab91f20ca593f303e to your computer and use it in GitHub Desktop.
Simple Swift HTTP API wrapper
#!/bin/bash -eu
#
# Simple Swift HTTP API wrapper
#
AUTH_TOKEN=??
CONTAINER_URL=https://??
CONTAINER_NAME=??
help() {
echo 'Usage: o42 COMMAND
Commands:
ls List all files
put Upload a file
get Get a file
rm Delete a file
'
}
_api() {
declare uri=${1:-""} && shift
curl \
-H "X-Auth-Token: $AUTH_TOKEN" \
$CONTAINER_URL/$CONTAINER_NAME$uri $@ \
-w "\n{\"status\":%{response_code},\"time\":\"%{time_total}s\"}\n";
}
main() {
declare cmd=${1:-help} && shift
case $cmd in
ls) _api "/" -XGET ;;
put) _api "/" -XPUT -T $1 ;;
get) _api "/$1" ;;
rm) _api "/$1" -XDELETE ;;
*) help ;;
esac
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment