1# Copyright 2018 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import tempfile
6
7from autotest_lib.client.common_lib import file_utils
8
9_URL_BASE = ('https://sites.google.com/a/chromium.org/dev/chromium-os'
10             '/testing/power-testing/pltp')
11_PLTG_URL = _URL_BASE + '/pltg'
12_PLTU_URL = _URL_BASE + '/pltu'
13_PLTP_URL = _URL_BASE + '/pltp'
14_MEETU_URL = _URL_BASE + '/meetu'
15_MEETP_URL = _URL_BASE + '/meetp'
16
17
18def _get_content(url):
19    """Reads the content of the file at the given |URL|.
20
21    Args:
22        url: URL to be fetched.
23
24    Return:
25        The content of the fetched file.
26    """
27    with tempfile.NamedTemporaryFile() as named_file:
28        file_utils.download_file(url, named_file.name)
29        return named_file.read().rstrip()
30
31
32def use_gaia_login():
33    """Returns whether Gaia login should be used by default for load testing."""
34    res = _get_content(_PLTG_URL)
35    return res == 'True' or res == 'true'
36
37
38def get_username():
39    """Returns username for load testing."""
40    return _get_content(_PLTU_URL)
41
42
43def get_password():
44    """Returns password for load testing."""
45    return _get_content(_PLTP_URL)
46
47
48def get_meet_username():
49    """Returns username for meet testing."""
50    return _get_content(_MEETU_URL)
51
52
53def get_meet_password():
54    """Returns password for meet testing."""
55    return _get_content(_MEETP_URL)
56