#!/bin/sh

list='{
  "http://storehttp.example.com/": "hello",
  "storehost.example.com": "hello",
  "storetoken.example.com": "<token>",
  "https://index.docker.io/v1/helper-token": "<token>"
}'

registry_http='
{ "ServerURL": "http://storehttp.example.com/",
  "Username": "hello",
  "Secret": "universe"
}
'
registry_testhost='
{ "ServerURL": "storehost.example.com",
  "Username": "hello",
  "Secret": "world"
}
'
registry_testtoken='
{ "ServerURL": "storetoken.example.com",
  "Username": "<token>",
  "Secret": "deadbeefcafe"
}
'
registry_testhelper_token='
{ "ServerURL": "https://index.docker.io/v1/helper-token",
  "Username": "<token>",
  "Secret": "deadbeefcafe"
}
'

if [ "$1" = "get" ]; then
  read hostname
  case "$hostname" in
    http://storehttp.example.com/)
      echo "${registry_http}"
      exit 0
      ;;
    storehost.example.com)
      echo "${registry_testhost}"
      exit 0
      ;;
    storetoken.example.com)
      echo "${registry_testtoken}"
      exit 0
      ;;
    https://index.docker.io/v1/helper-token)
      echo "${registry_testhelper_token}"
      exit 0
      ;;
  esac
elif [ "$1" = "list" ]; then
  echo "${list}"
  exit 0
fi
# unhandled request
exit 1
