我在docker-compose中使用Azurite进行本地开发。我有一个使用Java Azure SDK与之对话的简单应用程序。我尝试使用默认的Azurite连接字符串DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==
进行连接,但是当我尝试连接时,出现身份验证错误:
app | RequestId:648770d1-301e-00a3-28d6-dcfab7000000
app | Time:2020-02-06T10:19:10.6959018Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'vSVMXMpgTMISc9Fgx2bu0kg7uu0duhmdn6dllfc4r1g=' is not the same as any computed signature. Server used following string to sign: 'GET
app |
app |
app |
app |
app |
app | Thu, 06 Feb 2020 10:19:09 GMT
app |
app |
app |
app |
app |
app | x-ms-client-request-id:4bd883d4-229a-4dec-bf6f-221f3636dccf
app | x-ms-version:2019-02-02
app | /devstoreaccount1/
app | comp:list'.</AuthenticationErrorDetail></Error>"; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Status code 403, "<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
app | RequestId:648770d1-301e-00a3-28d6-dcfab7000000
app | Time:2020-02-06T10:19:10.6959018Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'vSVMXMpgTMISc9Fgx2bu0kg7uu0duhmdn6dllfc4r1g=' is not the same as any computed signature. Server used following string to sign: 'GET
app |
app |
app |
app |
app |
app | Thu, 06 Feb 2020 10:19:09 GMT
app |
app |
app |
app |
app |
app | x-ms-client-request-id:4bd883d4-229a-4dec-bf6f-221f3636dccf
app | x-ms-version:2019-02-02
app | /devstoreaccount1/
app | comp:list'.</AuthenticationErrorDetail></Error>"]
我不确定是什么问题,我还没有找到在线解决方案。任何想法将不胜感激。
我正在使用以下依赖项:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.3.0</version>
</dependency>
这是我简单的控制器:
package com.sky.video.azuritedemo
import com.azure.core.http.rest.PagedIterable
import com.azure.storage.blob.BlobServiceClientBuilder
import com.azure.storage.blob.models.BlobContainerItem
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
@RestController
class AzureController() {
@GetMapping("/container")
fun getContainers(): PagedIterable<BlobContainerItem>? {
val connectionString = System.getenv("AZURE_STORAGE_CONNECTION_STRING")
val client = BlobServiceClientBuilder()
.connectionString(connectionString)
.buildClient()
return client
.listBlobContainers()
}
}
然后在docker-compose中设置env变量:
version: '3'
services:
app:
build:
context: .
command: "mvn spring-boot:run"
container_name: app
depends_on:
- azure
environment:
AZURE_STORAGE_CONNECTION_STRING: "DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
links:
- azure
ports:
- 5005:5005
- 8080:8080
volumes:
- ~/.m2:/root/.m2
- .:/app
azure:
command: "azurite --blobHost 0.0.0.0 --queueHost 0.0.0.0 -d /tmp/logs/debug.log"
container_name: azure
environment:
EXECUTABLE: blob
image: mcr.microsoft.com/azure-storage/azurite
ports:
- "10000:10000"
- "10001:10001"
volumes:
- ./logs:/tmp/logs
进一步的调查显示,当我直接在本地计算机上运行Azurite和应用程序时,也会遇到相同的问题。
答案 0 :(得分:3)
请尝试使用以下连接字符串:
UseDevelopmentStorage=true
上述连接字符串将尝试连接到默认IP地址(127.0.0.1)和端口(例如,用于blob存储的10000)。
如果使用其他IP地址和端口,请使用以下连接字符串:
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
BlobEndpoint=http://<ip-address>:<blob-port>/devstoreaccount1;
代替
DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==