Я хочу иметь доступ к моей учетной записи Azure Data Lake Storage Gen2 через скрипт ruby, чтобы я мог добавлять файлы / каталоги.
sniff adls gen2 storage api звонки
http://sql.pawlikowski.pro/2019/03/09/how-to-sniff-adls-gen2-storage-rest-api-calls-to-azure-using-azure-storage-explorer/
подключение к хранилищу Azure Data Lake gen2 из powershell с помощью rest api
http://sql.pawlikowski.pro/2019/03/10/connecting-to-azure-data-lake-storage-gen2-from-powershell-using-rest-api-a-step-by-step-guide/
Я пытался следовать приведенным выше инструкциям, пытаясь воспроизвести сценарии powershell в коде ruby. Я также попробовал оба ключа из ключей доступа к учетной записи хранения, и все еще получаю ту же ошибку.
require 'rubygems'
require 'rest_client'
require 'json'
require 'net/http'
require 'uri'
require 'securerandom'
require 'openssl'
require 'base64'
require 'digest'
access_key = "ACCESS KEY HERE"
shared_key = encode_string(access_key)
storage_account_name = 'r1dltest'
target_filesystem = 'datalake'
uri_string = "https://#{storage_account_name}.dfs.core.windows.net/#{target_filesystem}?directory='/'&maxresults=5000&recursive=false&resource=filesystem"
## Parse URI
puts("> Parsing URI: #{uri_string}")
uri = URI.parse(uri_string)
## PUT request.
puts("> Setting up PUT request.")
request = Net::HTTP::Get.new(uri)
## Set headers.
puts("> Setting authorization headers")
puts ("Auth Header Key: #{storage_account_name}:#{shared_key}")
request["Authorization"] = "SharedKey #{storage_account_name}:#{shared_key}"
request["x-ms-version"] = "2018-11-09"
## Options
req_options = {
use_ssl: uri.scheme == "https",
}
## Execute request.
puts("> Executing request...")
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
puts(response.body)
def encode_string(key)
n = ""
method = "GET"
date = ""
version = "2018-11-09"
storage_account_name = "saname"
file_system_name = "fsname"
stringToSign = method + n
stringToSign += n # Content-Encoding
stringToSign += n # Content-Language
stringToSign += n # Content-Length
stringToSign += n # Content-MD5
stringToSign += n # Content-Type
stringToSign += n # Date
stringToSign += n # If-Modified-Since
stringToSign += n # If-Match
stringToSign += n # If-None-Match
stringToSign += n # If-Unmodified-Since
stringToSign += n # Range
stringToSign += "x-ms-date:" + n +
"x-ms-version: #{version}" + n
stringToSign += "/#{storage_account_name}/#{file_system_name}" + n +
"recursive: true" + n
"resource: filesystem" + n
puts(stringToSign)
shared_key = Base64.decode64(key)
hashedKey = OpenSSL::HMAC.digest('sha256', shared_key, stringToSign)
signedString = Base64.strict_encode64(Digest::SHA256.digest(hashedKey))
return signedString
end
вывод из моего кода.