gpt4 book ai didi

azure - 从 Azure Data Lake Storage(第 2 代)检索审核日志

转载 作者:行者123 更新时间:2023-12-03 04:11:16 26 4
gpt4 key购买 nike

我正在尝试从 Azure Data Lake Storage(第 2 代)检索审核日志..

到目前为止,我已尝试在 Gen 2 中使用 AZCOPY、REST API(目前不支持)来检索(连接)审核日志,并寻找用于检索日志的替代解决方案

当使用AZCOPY连接时,它只使用基于API的调用,当我尝试检索日志时,我收到了分层命名空间帐户不支持API调用的错误。添加图像以供引用。 Snapshot of AZCOPY error

对于此用例是否有任何解决方法或我可以尝试检索日志的任何其他方法?

最佳答案

更新:

我可以使用读取 API 从 ADLS GEN2 获取文件内容。我可以为您提供一个由 py​​thon 代码编写的示例(您可以根据我的代码更改为任何其他语言)。从下面的代码中,您可以直接获取文件内容,或者获取可以在postman中使用的Authorization

Python 3.7 代码如下:

import requests
import datetime
import hmac
import hashlib
import base64

storage_account_name = 'xxx'
storage_account_key = 'xxx'
api_version = '2018-11-09'
request_time = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
#the file path on adls gen2
FILE_SYSTEM_NAME='dd1/myfile.txt'

string_params = {
'verb': 'GET',
'Content-Encoding': '',
'Content-Language': '',
'Content-Length': '',
'Content-MD5': '',
'Content-Type': '',
'Date': '',
'If-Modified-Since': '',
'If-Match': '',
'If-None-Match': '',
'If-Unmodified-Since': '',
'Range': '',
'CanonicalizedHeaders': 'x-ms-date:' + request_time + '\nx-ms-version:' + api_version,
'CanonicalizedResource': '/' + storage_account_name+'/'+FILE_SYSTEM_NAME
}

string_to_sign = (string_params['verb'] + '\n'
+ string_params['Content-Encoding'] + '\n'
+ string_params['Content-Language'] + '\n'
+ string_params['Content-Length'] + '\n'
+ string_params['Content-MD5'] + '\n'
+ string_params['Content-Type'] + '\n'
+ string_params['Date'] + '\n'
+ string_params['If-Modified-Since'] + '\n'
+ string_params['If-Match'] + '\n'
+ string_params['If-None-Match'] + '\n'
+ string_params['If-Unmodified-Since'] + '\n'
+ string_params['Range'] + '\n'
+ string_params['CanonicalizedHeaders']+'\n'
+ string_params['CanonicalizedResource'])

signed_string = base64.b64encode(hmac.new(base64.b64decode(storage_account_key), msg=string_to_sign.encode('utf-8'), digestmod=hashlib.sha256).digest()).decode()

#print out the datetime
print(request_time)
#print out the Authorization
print('SharedKey ' + storage_account_name + ':' + signed_string)

headers = {
'x-ms-date' : request_time,
'x-ms-version' : api_version,
'Authorization' : ('SharedKey ' + storage_account_name + ':' + signed_string)
}
url = ('https://' + storage_account_name + '.dfs.core.windows.net/'+FILE_SYSTEM_NAME)
#print out the url
print(url)
r = requests.get(url, headers = headers)

#print out the file content
print(r.text)

运行代码后,获取文件内容:

enter image description here

您还可以在 postman 中使用上述代码中生成的值,例如授权/日期:

enter image description here

<小时/>

您可能知道 SDK 尚未为 Azure Data Lake gen 2 做好准备,因此到目前为止,解决方案正在使用 ADLS Gen2 Read api .

检索文件内容后,您可以保存它。

您可以自行完成身份验证工作。如果您对如何使用 ADLS Gen 2 api 阅读有任何问题,请随时告诉我。

关于azure - 从 Azure Data Lake Storage(第 2 代)检索审核日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56543444/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com