
[英]Why does a Personal Access Token (PAT) need full access to serve the Azure DevOps REST API?
[英]Databricks REST API call for updating branch error : User Settings > Git Integration to set up an Azure DevOps personal access token
我在使用https://docs.databricks.com/dev-tools/api/latest/repos.html#operation/update-repo中提到的 databricks rest api 将 repo 更新到不同的分支时遇到错误。
我已经使用服务主体进行了身份验证并生成了 dbrks_bearer_token 和 dbrks_management_token。
请在下面找到相同的代码:-
import requests
import os
import json
TOKEN_REQ_BODY = {
'grant_type': 'client_credentials',
'client_id': 'client_id',
'client_secret': 'client_secret'
}
TOKEN_BASE_URL = 'https://login.microsoftonline.com/' + 'tenant_id' + '/oauth2/token'
TOKEN_REQ_HEADERS = {'Content-Type': 'application/x-www-form-urlencoded'}
def dbrks_management_token():
TOKEN_REQ_BODY['resource'] = 'https://management.core.windows.net/'
response = requests.get(TOKEN_BASE_URL, headers=TOKEN_REQ_HEADERS, data=TOKEN_REQ_BODY)
if response.status_code == 200:
print(response.status_code)
return response.json()['access_token']
else:
raise Exception(response.text)
return response.json()['access_token']
def dbrks_bearer_token():
TOKEN_REQ_BODY['resource'] = '2ff814a6-3304-4ab8-85cb-cd0e6f879c1d'
response = requests.get(TOKEN_BASE_URL, headers=TOKEN_REQ_HEADERS, data=TOKEN_REQ_BODY)
if response.status_code == 200:
print(response.status_code)
else:
raise Exception(response.text)
return response.json()['access_token']
DBRKS_BEARER_TOKEN = dbrks_bearer_token()
DBRKS_MANAGEMENT_TOKEN = dbrks_management_token()
DBRKS_REQ_HEADERS = {
'Authorization': 'Bearer ' + DBRKS_BEARER_TOKEN,
'X-Databricks-Azure-Workspace-Resource-Id':
'/subscriptions/susbcriptionid' +
'/resourceGroups/rg-dev/providers/Microsoft.Databricks/workspaces/dbr-dev',
'X-Databricks-Azure-SP-Management-Token': DBRKS_MANAGEMENT_TOKEN }
DBRKS_CLUSTER_ID = {'cluster_id': 'cluster_id'}
def update_repo():
DBRKS_START_ENDPOINT = 'api/2.0/repos/0328767704612345'
postjson = """{
"branch": "main"
}"""
response = requests.patch("https://adb-1234582271731234.0.azuredatabricks.net/"
+ DBRKS_START_ENDPOINT,
headers=DBRKS_REQ_HEADERS,
json=json.loads(postjson))
print(response.status_code)
if response.status_code != 200:
raise Exception(response.text)
os.environ["DBRKS_CLUSTER_ID"] = response.json()["cluster_id"]
print(response.content)
update_repo()
我收到以下错误:-
Traceback (most recent call last):
File "C:/Users/IdeaProjects/DBCluster/DB_rest_api.py", line 109, in <module>
update_repo()
File "C:/Users/IdeaProjects/DBCluster/DB_rest_api.py", line 104, in update_repo
raise Exception(response.text)
Exception: {"error_code":"PERMISSION_DENIED","message":"Missing Git provider credentials. Go to User Settings > Git Integration to add your personal access token."}
403
有人可以让我知道我是否还需要在 azure devops git 配置级别明确地做任何事情吗?
非常感谢..!!
要对 Databricks Repos 进行任何操作,您需要设置一个 Git 个人访问令牌。 因为您使用的是服务主体,所以您无法通过 UI 设置该个人访问令牌,但您可以使用最近实施的Git Credentials REST API执行该 Git 令牌的设置 - 只需为您的服务主体执行一次(或当 Git PAT expires),然后 Repos 操作将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.