Skip to content

Commit d6715e3

Browse files
xuming-msCopilot
andcommitted
CI: let the managed-environment probe run in Cloud Shell too
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 06cad19 commit d6715e3

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

.github/scripts/check_managed_environment.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# Licensed under the MIT License. See License.txt in the project root for license information.
55
# --------------------------------------------------------------------------------------------
66

7-
"""Assert the plaintext fallback warning is suppressed on a real platform-managed agent.
7+
"""Assert the plaintext fallback warning is suppressed on a real platform-managed host.
88
9-
Meant to be run on an Azure Pipelines or GitHub Actions agent, and needs no sign-in: the warning is
10-
decided by build_persistence and warn_if_encryption_unavailable alone.
9+
Meant to be run on an Azure Pipelines agent, a GitHub Actions runner or in Cloud Shell, and needs no
10+
sign-in: the warning is decided by build_persistence and warn_if_encryption_unavailable alone.
1111
12-
The unit tests mock the environment, so they cannot show that an agent really sets TF_BUILD or
13-
GITHUB_ACTIONS. This runs the same code against whatever the agent actually provides, then repeats
14-
it with those variables removed, so a pass means the gate is what silenced the warning and not a
15-
fallback that never happened.
12+
The unit tests mock the environment, so they cannot show that a real host sets TF_BUILD,
13+
GITHUB_ACTIONS or ACC_CLOUD. This runs the same code against whatever the host actually provides,
14+
then repeats it with those variables removed, so a pass means the gate is what silenced the warning
15+
and not a fallback that never happened.
1616
"""
1717

1818
import logging
@@ -21,9 +21,10 @@
2121
import tempfile
2222

2323
from azure.cli.core.auth import persistence
24-
from azure.cli.core.util import in_ci, in_managed_environment
24+
from azure.cli.core.util import in_ci, in_cloud_console, in_managed_environment
2525

26-
CI_VARIABLES = ('TF_BUILD', 'GITHUB_ACTIONS', 'CI')
26+
# Every variable in_managed_environment() consults, so the control below can take them all away.
27+
MANAGED_VARIABLES = ('TF_BUILD', 'GITHUB_ACTIONS', 'CI', 'ACC_CLOUD')
2728

2829

2930
def _collect(level):
@@ -60,24 +61,23 @@ def _warnings_from_sign_in():
6061

6162

6263
def main():
63-
seen = {name: os.environ.get(name) for name in CI_VARIABLES}
64-
print('agent environment: ' + ', '.join(
64+
seen = {name: os.environ.get(name) for name in MANAGED_VARIABLES}
65+
print('host environment: ' + ', '.join(
6566
f'{name}={value!r}' if value is not None else f'{name}=<unset>' for name, value in seen.items()))
66-
print(f'in_ci()={in_ci()}, in_managed_environment()={in_managed_environment()}')
67+
print(f'in_ci()={in_ci()}, in_cloud_console()={bool(in_cloud_console())}, '
68+
f'in_managed_environment()={in_managed_environment()}')
6769

6870
failures = []
69-
if not in_ci():
70-
failures.append('this agent sets none of the variables in_ci() looks for, so the gate this '
71-
'checks would never apply here')
7271
if not in_managed_environment():
73-
failures.append('in_managed_environment() is False on a CI agent')
72+
failures.append('this host sets none of the variables in_managed_environment() looks for, '
73+
'so the gate this checks would never apply here')
7474

7575
# The fallback itself has to happen, or there would be no warning to suppress and a pass would
7676
# mean nothing.
7777
store, debug = _fall_back()
7878
if store.is_encrypted:
7979
failures.append('the persistence reports itself as encrypted, so there was no fallback to '
80-
'observe on this agent')
80+
'observe on this host')
8181
if not isinstance(store, persistence.FilePersistence):
8282
failures.append(f'expected a plaintext FilePersistence, got {type(store).__name__}')
8383
if not persistence._encryption_fallback: # pylint: disable=protected-access
@@ -86,12 +86,12 @@ def main():
8686
failures.append('the reason libsecret was unusable never reached the debug log')
8787

8888
if _warnings_from_sign_in():
89-
failures.append('sign-in warned about plaintext storage on a platform-managed agent, where '
89+
failures.append('sign-in warned about plaintext storage on a platform-managed host, where '
9090
'the user cannot act on it')
9191

92-
# Same process, same fallback, with only the CI variables taken away. Without this a silent
92+
# Same process, same fallback, with only those variables taken away. Without this a silent
9393
# warning path would pass just as happily as a working gate.
94-
removed = {name: os.environ.pop(name) for name in CI_VARIABLES if name in os.environ}
94+
removed = {name: os.environ.pop(name) for name in MANAGED_VARIABLES if name in os.environ}
9595
try:
9696
if not _warnings_from_sign_in():
9797
failures.append(f'with {", ".join(removed)} removed the sign-in still said nothing, so '
@@ -105,7 +105,7 @@ def main():
105105
return 1
106106

107107
print('the fallback happened, was explained in the debug log, and the warning was suppressed '
108-
'only because this is a platform-managed agent')
108+
'only because this is a platform-managed host')
109109
return 0
110110

111111

0 commit comments

Comments
 (0)