Skip to content

Instantly share code, notes, and snippets.

@Ogaday
Created February 24, 2023 09:40
Show Gist options
  • Save Ogaday/c46843b04f5b652c6a62c8039da7ae7d to your computer and use it in GitHub Desktop.
Save Ogaday/c46843b04f5b652c6a62c8039da7ae7d to your computer and use it in GitHub Desktop.
Azure credential helper
"""
"""
from argparse import ArgumentParser
from artifacts_keyring import CredentialProvider # type: ignore
def get_artifact_token(organization: str, feed: str) -> str:
"""Get credentials for an azure artifacts feed."""
provider = CredentialProvider()
_, token = provider.get_credentials(
f"https://pkgs.dev.azure.com/{organization}/_packaging/{feed}/pypi/simple/"
)
return token
if __name__ == "__main__":
parser = ArgumentParser(
prog="azure_token",
description="Retrieve tokens for Azure Artifact Feeds."
)
parser.add_argument(
"--organization",
"-o",
help="The organization to which the Artifact Feed belongs.",
required=True,
)
parser.add_argument(
"--feed",
"-f",
help="The artifact feed for which to retrieve the token.",
required=True,
)
args = parser.parse_args()
print(get_artifact_credentials(organization=args.organization, feed=args.feed))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment