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>
This commit is contained in:
Takuto Ikuta
2022-01-20 00:24:57 +00:00
committed by LUCI CQ
parent b674278ce7
commit a657331e90
5 changed files with 56 additions and 24 deletions

View File

@@ -26,8 +26,6 @@ import subprocess
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 @@ ALLOWLISTED_CONFIGS = ('symbol_level', 'use_goma', 'is_debug',
'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 @@ def main():
# Disable logging.
logging.disable(logging.CRITICAL)
if not IsGoogler(args.server):
if not IsGoogler():
return 0
ninjalog = args.ninjalog or GetNinjalog(args.cmdline)