ninjalog_uploader: use goma_auth to detect googler

Bug: 1288639
Change-Id: I447e2f66603ffb8d68599dcf22023fd7857dc4fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3400398
Reviewed-by: Fumitoshi Ukai <ukai@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Takuto Ikuta <tikuta@chromium.org>
diff --git a/ninjalog_uploader.py b/ninjalog_uploader.py
index 3aa0239..18ca64d 100755
--- a/ninjalog_uploader.py
+++ b/ninjalog_uploader.py
@@ -26,8 +26,6 @@
 import sys
 import time
 
-from third_party.six.moves import http_client
-from third_party.six.moves.urllib import error
 from third_party.six.moves.urllib import request
 
 # These build configs affect build performance.
@@ -39,13 +37,17 @@
                        'use_errorprone_java_compiler', 'incremental_install')
 
 
-def IsGoogler(server):
-  """Check whether this script run inside corp network."""
-  try:
-    resp = request.urlopen('https://' + server + '/should-upload')
-    return resp.read() == b'Success'
-  except (error.URLError, http_client.RemoteDisconnected):
+def IsGoogler():
+  """Check whether this user is Googler or not."""
+  p = subprocess.run('goma_auth info',
+                     capture_output=True,
+                     text=True,
+                     shell=True)
+  if p.returncode != 0:
     return False
+  l = p.stdout.splitlines()[0]
+  # |l| will be like 'Login as <user>@google.com' for googler using goma.
+  return l.startswith('Login as ') and l.endswith('@google.com')
 
 
 def ParseGNArgs(gn_args):
@@ -190,7 +192,7 @@
     # Disable logging.
     logging.disable(logging.CRITICAL)
 
-  if not IsGoogler(args.server):
+  if not IsGoogler():
     return 0
 
   ninjalog = args.ninjalog or GetNinjalog(args.cmdline)