Modernized the get-token.py.
All checks were successful
/ unit-tests (push) Successful in 13s

This commit is contained in:
2025-11-09 10:52:22 +01:00
parent 7d5d451d0c
commit 495ba0b0b3
3 changed files with 34 additions and 9 deletions

3
.gitignore vendored
View File

@@ -12,6 +12,9 @@ prototype_*.py
*.secret *.secret
*.client_secret *.client_secret
# Environment files
*.env
# Certificate files # Certificate files
*.pem *.pem
*.key *.key

View File

@@ -2,5 +2,6 @@
"debug.autoExpandLazyVariables": "off", "debug.autoExpandLazyVariables": "off",
"debug.inlineValues": "off", "debug.inlineValues": "off",
"debugpy.debugJustMyCode": true, "debugpy.debugJustMyCode": true,
"debugpy.showPythonInlineValues": false "debugpy.showPythonInlineValues": false,
"python.terminal.useEnvFile": true
} }

View File

@@ -12,17 +12,38 @@ Usage:
Now you can use the ADO_TOKEN environment variable, for example using curl: Now you can use the ADO_TOKEN environment variable, for example using curl:
curl -H "Authorization: Bearer $ADO_TOKEN" https://dev.azure.com/your_organization/_apis/projects?api-version=7.1 curl -sH "Authorization: Bearer $ADO_TOKEN" "https://dev.azure.com/$ADO_ORGANIZATION_URL/_apis/projects?api-version=7.1"
""" """
from sk.azure import get_token from sk.azure import get_token
from argparse import ArgumentParser
token = get_token( args = ArgumentParser(description="Get Azure DevOps token and print it for exporting as environment variable.")
tenant_id="a7740229-47b6-45de-ad22-83721462b1bf", args.add_argument("--tenant-id", type=str, required=True, help="Azure AD Tenant ID")
client_id="840671c4-5dc4-40e5-aab9-7c3a07bbd652", args.add_argument("--client-id", type=str, required=True, help="Azure AD Client ID")
pem_path="./slawek-mba.pem" args.add_argument("--pem-path", type=str, help="Path to PEM file for authentication (optional)")
) args.add_argument("--client-secret", type=str, help="Client Secret for authentication (optional)")
args = args.parse_args()
# print(f"Obtained token: {token}") if args.pem_path:
token = get_token(
tenant_id=args.tenant_id,
client_id=args.client_id,
pem_path=args.pem_path
)
elif args.client_secret:
if not args.client_secret:
print("Client secret file is empty.")
exit(1)
token = get_token(
tenant_id=args.tenant_id,
client_id=args.client_id,
client_secret=args.client_secret
)
else:
token = get_token(
tenant_id=args.tenant_id,
client_id=args.client_id
)
print(f"export ADO_TOKEN='{token}'") print(f"export ADO_TOKEN='{token}'")