2016-09-30 3 views
0

공개 저장소가 아닌 계정에 대해 푸른 저장소 API에 대한 요청을 만들고 인증 요청이 필요합니다. Azure Blob 저장소 사용 https가있는 REST API

나는 헤더이 페이지를 따르려고 : https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx

간단히 말해서 나는이 일을 할 수 없습니다. 항상 "ResourceNotFound"오류가 발생합니다. 저장소 계정이나 컨테이너 이름을 잘못 입력하지 않아서 설명 할 수 없습니다. Power BI와 동일한 계정, 컨테이너 및 키를 사용하여 성공적으로 연결했습니다.

내가 생각할 수있는 유일한 문제는 서명 생성과 관련이 있습니다. 인코딩에서 손실 될 수 있습니다 (처음으로 그런 일을하고 있습니다). 그러나 오류 메시지가 설명되지 않습니다. "ResourceNotFound". 다음은 요청 코드 (R)입니다.

#azure storage endpoint to hit against 
account <- "myaccount" 
container <- "mycontainer" 
requestProperties <- "comp=list" 
endPoint <- paste("https://", account, ".blob.core.windows.net/", sep = "") 
endPoint 
#[1] "https://myaccount.blob.core.windows.net/" 


#date header 
timeStamp <- Sys.time() 
timeString <- format(timeStamp, format="%y-%m-%d %H:%M:%S", tz="GMT", usetz = TRUE) 
timeString <- "Fri, 30 Sep 2016 14:54:30 GMT" 
dateHeader <- paste("x-ms-date", timeString, sep = ":") 
dateHeader 
#[1] "x-ms-date:Fri, 30 Sep 2016 14:54:30 GMT" 

#version header 
versionHeader <- "x-ms-version:2015-02-21" 

#authorization header 
requestVerb <- "GET" 
authType <- "SharedKey" 
azureKey <- "myAccountKey" 

newLines <- "\n\n\n\n\n\n\n\n\n\n" 
canonicalizedHeaders <- paste(dateHeader,versionHeader, sep = "\n") 

#build canonicalized resource 
resourceAccount <- paste("/",account, sep = "") 
resourceContainer <- paste ("/",container, sep = "") 
resource <- paste(resourceAccount, resourceContainer, sep = " ") 

canonicalizedResource <- paste(resource, requestProperties, sep = "\n") 
canonicalizedResource 
#[1] "/myaccount /mycontainer\ncomp=list" 

#build authentication signed string 
stringToSign <- paste(requestVerb, newLines, canonicalizedHeaders, canonicalizedResource, sep = "\n") 
stringToSign <- enc2utf8(stringToSign) 
stringToSign 
#[1] "GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:Fri, 30 Sep 2016 14:54:30 GMT\nx-ms-version:2015-02-21\n/myaccount /mycontainer\ncomp=list" 

Signature <- digest::hmac(object = stringToSign, key = azureKey, algo = "sha256", serialize = FALSE) 

#authentication header 
authorization <- paste(account, Signature, sep = ":") 
authorization 
#[1] "myaccount:b4761595ea09d0e9d56223bd0a14233bca2b9fc3bb043031586215942f5c6d06" 

authHeader <- paste("Authorization:", authType, authorization, sep = " ") 
authHeader 
#[1] "Authorization: SharedKey myaccount:b4761595ea09d0e9d56223bd0a14233bca2b9fc3bb043031586215942f5c6d06" 


#build the actual request 
request <- paste(endPoint, requestProperties, sep = "?") 
request 
#[1] "https://myaccount.blob.core.windows.net/?comp=list" 

azureRequest <- httr::GET(request, httr::add_headers(dateHeader, versionHeader, authHeader)) 
responseContent <- httr::content(azureRequest, as = "text") 
responseContent 
#[1] "<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>ResourceNotFound</Code><Message>The specified resource does not exist.\nRequestId:b1e87500-0001-0003-6231-1b7598000000\nTime:2016-09-30T15:44:52.3452448Z</Message></Error>" 

요청을 생성하는 동안 뭔가가 누락 되었습니까? REST API를 통해 액세스를 허용하려면 내 계정으로 무언가를해야합니까?

+0

MS는 데모 용으로 공개적으로 사용 가능한 인증 키가 포함 된 더미 계정을 제공하지 않으므로? 그렇지 않으면 Azure 전용 포럼으로 가야합니다. 왜냐하면 나머지 Azure가 아닌 사용자는 응답을 테스트 할 수 없기 때문입니다. –

+0

진짜 SharedKey가 아니길 바란다 – Paparazzi

+0

경로에 컨테이너를 넣으십시오. 예 : – Paparazzi

답변

0

이 논리를 수행하는 저장소 SDK를 사용하지 않는 이유가 있습니까? 모든 주요 언어로 제공됩니다.이 Getting Started 가이드의 맨 위에있는 탭 목록을 참조하십시오. 또는 GitHub에서 사용할 수있는이 라이브러리의 모든 소스 코드 (예 : - NET source code)가 있으며 소스 코드 내부에서 서명 논리를 볼 수 있습니다. SAS 토큰의 SharedAccessSignatureHelper (here)를 확인하십시오.

+0

R로 직접 통합하는 Power BI에 데이터를 가져 오면서이 작업을 R에서 수행하려고했습니다. 이걸 다시 볼 시간이 있 자마자 너와 군인이 나에게 도움을 줄 수 있는지 알기 위해 링크를 살펴 보겠다. 감사 – Zepee

관련 문제