Commit 9fd5a9d7 authored by Robert Ma's avatar Robert Ma Committed by Commit Bot

[blinkpy] Call //third_party/depot_tools/luci-auth

Instead of relying on PATH, we explicitly call the luci-auth binary
(or luci-auth.bat on Windows) in blinkpy.

Bug: 1017404
Change-Id: Ic44afadad52d17370db4ada910d6c02e37a95289
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879559Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Robert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709463}
parent f30b5f2e
...@@ -7,13 +7,18 @@ ...@@ -7,13 +7,18 @@
The main usage is to get the OAuth access token for the service account on LUCI. The main usage is to get the OAuth access token for the service account on LUCI.
""" """
from blinkpy.common.path_finder import PathFinder
class LuciAuth(object): class LuciAuth(object):
def __init__(self, host): def __init__(self, host):
self._host = host self._host = host
finder = PathFinder(host.filesystem)
luci_auth_bin = 'luci-auth.bat' if host.platform.is_win() else 'luci-auth'
self._luci_auth_path = host.filesystem.join(
finder.depot_tools_base(), luci_auth_bin)
def get_access_token(self): def get_access_token(self):
# ScriptError will be raised if luci-auth fails. # ScriptError will be raised if luci-auth fails.
output = self._host.executive.run_command(['luci-auth', 'token']) output = self._host.executive.run_command([self._luci_auth_path, 'token'])
return output.strip() return output.strip()
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import unittest
from blinkpy.common.host_mock import MockHost
from blinkpy.common.net.luci_auth import LuciAuth
class LuciAuthTest(unittest.TestCase):
def test_run_on_linux(self):
host = MockHost(os_name='linux')
host.filesystem.maybe_make_directory(
'/mock-checkout/third_party/depot_tools')
luci_auth = LuciAuth(host)
luci_auth.get_access_token()
self.assertListEqual(
host.executive.calls,
[['/mock-checkout/third_party/depot_tools/luci-auth', 'token']])
def test_run_on_windows(self):
host = MockHost(os_name='win')
host.filesystem.maybe_make_directory(
'/mock-checkout/third_party/depot_tools')
luci_auth = LuciAuth(host)
luci_auth.get_access_token()
self.assertEqual(
host.executive.calls,
[['/mock-checkout/third_party/depot_tools/luci-auth.bat', 'token']])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment