我正在尝试检查 PAT 令牌何时到期,以便我可以在特定令牌即将到期时创建警报/通知,并在到期之前替换它。
有一个 API 可查询组织内的所有 PAT: https://learn.microsoft.com/en-us/rest/api/azure/devops/tokenadmin/personal%20access%20tokens/list ?view=azure-devops-休息-5.1
遗憾的是,这个 API 需要组织本身的写入权限,而我没有。使用下面的脚本我收到以下错误:
azure.devops.exceptions.AzureDevOpsServiceError: Access Denied: XXX needs the following permission(s) to perform this action: Edit instance-level information
这让我想到了我的问题:有没有一种方法/API 可以在没有组织本身权限的情况下查询我的个人 PAT?
这里是Python脚本的当前草案,用于检查PAT以供参考:
#!/usr/bin/env python
from msrest.authentication import BasicAuthentication
from azure.devops.connection import Connection
# Fill in with your personal access token and org URL
personal_access_token = 'XXX'
organization_url = 'https://dev.azure.com/XXX'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
# Get personal subject_descriptor by mail
graph_client …Run Code Online (Sandbox Code Playgroud)