#!/bin/sh

list='{
  "https://index.docker.io/v1/": "hubuser",
  "http://http.example.com/": "hello",
  "host.example.org": "hello",
  "testenvhelper.example.com": "hienv",
  "testhost.example.com": "hello",
  "testtoken.example.com": "<token>"
}'

registry_hub='
{ "ServerURL": "https://index.docker.io/v1/",
  "Username": "hubuser",
  "Secret": "password123"
}
'
registry_http='
{ "ServerURL": "http://http.example.com/",
  "Username": "hello",
  "Secret": "universe"
}
'
registry_host_org='
{ "ServerURL": "host.example.org",
  "Username": "hello",
  "Secret": "world"
}
'
registry_testenvhelper='
{ "ServerURL": "testenvhelper.example.com",
  "Username": "hienv",
  "Secret": "stillworks"
}
'
registry_testhost='
{ "ServerURL": "testhost.example.com",
  "Username": "hello",
  "Secret": "world"
}
'
registry_testtoken='
{ "ServerURL": "testtoken.example.com",
  "Username": "<token>",
  "Secret": "deadbeefcafe"
}
'

if [ "$1" = "get" ]; then
  read hostname
  case "$hostname" in
    https://index.docker.io/v1/)
      echo "${registry_hub}"
      exit 0
      ;;
    http://http.example.com/)
      echo "${registry_http}"
      exit 0
      ;;
    host.example.org)
      echo "${registry_host_org}"
      exit 0
      ;;
    testenvhelper.example.com)
      echo "${registry_testenvhelper}"
      exit 0
      ;;
    testhost.example.com)
      echo "${registry_testhost}"
      exit 0
      ;;
    testtoken.example.com)
      echo "${registry_testtoken}"
      exit 0
      ;;
  esac
elif [ "$1" = "list" ]; then
  echo "${list}"
  exit 0
fi
# unhandled request
exit 1
