in src/artifacts_keyring/plugin.py [0:0]
def _get_credentials_from_credential_provider(self, url, is_retry):
non_interactive = self._NON_INTERACTIVE_VAR_NAME in os.environ and \
os.environ[self._NON_INTERACTIVE_VAR_NAME] and \
str(os.environ[self._NON_INTERACTIVE_VAR_NAME]).lower() == "true"
proc = Popen(
self.exe + [
"-Uri", url,
"-IsRetry", str(is_retry),
"-NonInteractive", str(non_interactive),
"-CanShowDialog", "False",
"-OutputFormat", "Json"
],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# Read all standard error first, which may either display
# errors from the credential provider or instructions
# from it for Device Flow authentication.
for stderr_line in iter(proc.stderr.readline, b''):
line = stderr_line.decode("utf-8", "ignore")
sys.stdout.write(line)
sys.stdout.flush()
proc.wait()
if proc.returncode != 0:
stderr = proc.stderr.read().decode("utf-8", "ignore")
raise RuntimeError("Failed to get credentials: process with PID {pid} exited with code {code}; additional error message: {error}"
.format(pid=proc.pid, code=proc.returncode, error=stderr))
try:
# stdout is expected to be UTF-8 encoded JSON, so decoding errors are not ignored here.
payload = proc.stdout.read().decode("utf-8")
except ValueError:
raise RuntimeError("Failed to get credentials: the Credential Provider's output could not be decoded using UTF-8.")
try:
parsed = json.loads(payload)
return parsed["Username"], parsed["Password"]
except ValueError:
raise RuntimeError("Failed to get credentials: the Credential Provider's output could not be parsed as JSON.")