Update CredProvider tool path logic

This commit is contained in:
Coby Allred 2024-10-28 15:03:43 -07:00
Родитель 7ff77f7c7d
Коммит db7d66d48a
4 изменённых файлов: 24 добавлений и 6 удалений

Просмотреть файл

@ -54,6 +54,12 @@ The `artifacts-keyring` package is layered on top of our [Azure Artifacts Creden
- `ARTIFACTS_KEYRING_NONINTERACTIVE_MODE`: Controls whether the underlying credential provider can issue interactive prompts.
- `ARTIFACTS_KEYRING_USE_NET8`: Controls whether or not to download the .NET 8 version of the Azure Artifacts Credential Provider.
## Local development
1. Install build dependencies with `pip install .`
2. Build the project using `python -m build --outdir %DIRECTORY%`
3. Open a new terminal window in `%DIRECTORY%`, then run `pip install ***.whl --force-reinstall`
## Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a

Просмотреть файл

@ -16,7 +16,7 @@ import urllib.request
CREDENTIAL_PROVIDER_BASE = "https://github.com/Microsoft/artifacts-credprovider/releases/download/v1.3.0/"
CREDENTIAL_PROVIDER_NETFX = CREDENTIAL_PROVIDER_BASE + "Microsoft.NuGet.CredentialProvider.tar.gz"
CREDENTIAL_PROVIDER_NET8 = CREDENTIAL_PROVIDER + "Microsoft.Net8.NuGet.CredentialProvider.tar.gz"
CREDENTIAL_PROVIDER_NET8 = CREDENTIAL_PROVIDER_BASE + "Microsoft.Net8.NuGet.CredentialProvider.tar.gz"
CREDENTIAL_PROVIDER_NET_VER_VAR_NAME = "ARTIFACTS_KEYRING_USE_NET8"
def download_credential_provider(root):
@ -26,11 +26,12 @@ def download_credential_provider(root):
os.makedirs(dest)
print("Downloading and extracting to", dest)
with urllib.request.urlopen(get_download_url(root)) as fileobj:
download_url = get_download_url()
print("Downloading artifacts-credprovider from", download_url)
with urllib.request.urlopen(download_url) as fileobj:
tar = tarfile.open(mode="r|gz", fileobj=fileobj)
tar.extractall(dest)
def get_version(root):
src = os.path.join(root, "src", "artifacts_keyring", "__init__.py")
@ -40,7 +41,7 @@ def get_version(root):
m = re.search(r"__version__\s*=\s*['\"](.+?)['\"]", txt)
return m.group(1) if m else "0.1.0"
def get_download_url(root):
def get_download_url():
use_net_8 = CREDENTIAL_PROVIDER_NET_VER_VAR_NAME in os.environ and \
os.environ[CREDENTIAL_PROVIDER_NET_VER_VAR_NAME] and \
str(os.environ[CREDENTIAL_PROVIDER_NET_VER_VAR_NAME]).lower() == "true"

Просмотреть файл

@ -6,7 +6,7 @@
from __future__ import absolute_import
__author__ = "Microsoft Corporation <python@microsoft.com>"
__version__ = "0.4.0"
__version__ = "0.5.0"
import json
import subprocess

Просмотреть файл

@ -22,6 +22,8 @@ class CredentialProvider(object):
def __init__(self):
if sys.platform.startswith("win"):
# by default, attempt to search netfx plugins folder.
# if that doesn't exist, search netcore for newer credprovider versions.
tool_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"plugins",
@ -30,6 +32,16 @@ class CredentialProvider(object):
"CredentialProvider.Microsoft",
"CredentialProvider.Microsoft.exe",
)
tool_path = tool_path if os.path.exists(tool_path) else os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"plugins",
"plugins",
"netcore",
"CredentialProvider.Microsoft",
"CredentialProvider.Microsoft.exe",
)
self.exe = [tool_path]
else:
try:
@ -57,7 +69,6 @@ class CredentialProvider(object):
if not os.path.exists(tool_path):
raise RuntimeError("Unable to find credential provider in the expected path: " + tool_path)
def get_credentials(self, url):
# Public feed short circuit: return nothing if not getting credentials for the upload endpoint
# (which always requires auth) and the endpoint is public (can authenticate without credentials).