可以使用Artifactory REST API实现此功能。 在API文档中,可以看到使用'items”端点返回存档的列表。 可以使用带有'repos”参数的查询指定要搜索的存储库。 下面是一个使用'items”端点搜索以'org.jfrog.test”开头的Artifactory存档的示例代码:
import requests
import json
base_url = "http://localhost:8081/artifactory/api/"
search_endpoint = "search/"
headers = {'Content-Type': 'application/json'}
# Search term, repo to search and max number of results to return
request_data = {
"query": "items.find({\"repo\": {\"$match\": \"*local*\"},\"name\": {\"$match\": \"org.jfrog.test*\"}})"
}
response = requests.post(base_url + search_endpoint, headers=headers,
data=json.dumps(request_data), auth=('username', 'password'))
if response.status_code == 200:
items = response.json()['results']
for item in items:
print(item['path'])
else:
print("Error: failed to search archives.")
可以根据需要更改查询条件和返回结果的数量。