[Origin Trials] Improve developer tools ergonomics

This CL fixes two pain points with the generate_token.py tool:
1. Prints out the token details with the token itself (since we moved to v2
tokens, it's impossible to see at a glance what origin and feature a token is
for.)
2. Rejects hostnames without a '.' character, with a special exception for
localhost. This is becuase hostname and feature name are positional arguments,
and it's easy to swap them accidentally and produce broken tokens.

Review-Url: https://codereview.chromium.org/2064393003
Cr-Commit-Position: refs/heads/master@{#400108}
diff --git a/tools/origin_trials/generate_token.py b/tools/origin_trials/generate_token.py
index 3b4447bb..1dca546 100755
--- a/tools/origin_trials/generate_token.py
+++ b/tools/origin_trials/generate_token.py
@@ -14,6 +14,7 @@
 """
 import argparse
 import base64
+from datetime import datetime
 import json
 import re
 import os
@@ -43,6 +44,8 @@
     return None
   if arg[-1] == ".":
     arg = arg[:-1]
+  if "." not in arg and arg != "localhost":
+    return None
   if all(DNS_LABEL_REGEX.match(label) for label in arg.split(".")):
     return arg.lower()
 
@@ -145,8 +148,15 @@
     print "(The original error was: %s)" % exc
     sys.exit(1)
 
-  # Output a properly-formatted token. Version 1 is hard-coded, as it is
-  # the only defined token version.
+
+  # Output the token details
+  print "Token details:"
+  print " Origin: %s" % args.origin
+  print " Feature: %s" % args.trial_name
+  print " Expiry: %d (%s UTC)" % (expiry, datetime.utcfromtimestamp(expiry))
+  print
+
+  # Output the properly-formatted token.
   print FormatToken(VERSION, signature, token_data)
 
 if __name__ == "__main__":