Skip to main content

示例

以下示例为开始使用搜索路由奠定了基础。 请记住,您可以随时更改 rules 数组的内容,使其成为适合您的搜索查询。

# Dependencies to install:
# $ python -m pip install requests

import json
import requests

CLIENT_ID = "YOUR_CLIENT_ID"
CLIENT_SECRET = "YOUR_CLIENT_SECRET"

API_URL = "https://api.getport.io/v1"

credentials = {"clientId": CLIENT_ID, "clientSecret": CLIENT_SECRET}

token_response = requests.post(f"{API_URL}/auth/access_token", json=credentials)

access_token = f"Bearer {token_response.json()['accessToken']}"

# You can now use the value in access_token when making further requests

headers = {
'Authorization': access_token
}

query = {
"combinator": "or",
"rules": [
{
"property": "$title",
"operator": "=",
"value": "admin-prod"
},
{
"property": "$title",
"operator": "=",
"value": "admin-test"
}
]
}

search_req = requests.post(f"{API_URL}/entities/search", headers=headers, json=query)

search_entities = search_req.json()['entities']

for entity in search_entities:
print(json.dumps(entity))

##在工作流程中使用目录搜索

存储在 Port 中的信息可被用作工作流、自动化和 CI/CD 流程的一部分。请参阅我们的service locking 指南,了解有关将 Port 的搜索与 CI/CD 集成的实用示例。