0

我正在尝试使用 jClouds BlobStore 功能为存储在 OpenStack Swift 容器中的对象实现生成临时 GET URI。

但是我收到这些错误:

java.lang.IllegalStateException: Suppliers.memoizeWithExpiration(get().getTemporaryUrlKey() using {annotationParser={caller=SwiftApi.accountApiInRegion[RegionOne]}}, 60000000000, NANOS) returned a null temporaryUrlKey!
    at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
    at org.jclouds.openstack.swift.v1.TemporaryUrlSigner.hmacSHA1(TemporaryUrlSigner.java:63)
    at org.jclouds.openstack.swift.v1.TemporaryUrlSigner.sign(TemporaryUrlSigner.java:57)
    at org.jclouds.openstack.swift.v1.blobstore.RegionScopedTemporaryUrlBlobSigner.sign(RegionScopedTemporaryUrlBlobSigner.java:100)
    at org.jclouds.openstack.swift.v1.blobstore.RegionScopedTemporaryUrlBlobSigner.signGetBlob(RegionScopedTemporaryUrlBlobSigner.java:73)

这是一个代码示例:

public class BlobStoreObjectSignerService implements ObjectSignerService {

    @Autowired
    private BlobRequestSigner blobRequestSigner;

    @Value("${blobStore.private.container}")
    String privateContainerName;

    /**
    * Generates signed request With GET Method to access allocated object.
    *   
    * @param objectName         name of the stored file
    * @param principalName      name of the principal (user) which is putted the file
    * @param temporary          defines if file should be available for a limited time
    * @param timeToLive         time in seconds file will be available for fetching
    */
    public HttpRequest generateGetRequestForObject( String objectName, 
                                                    String principalName, 
                                                    boolean temporary, 
                                                    long timeToLive ) {
        if (temporary) {
            return this.generateTemporaryGetRequestForObject(objectName,  principalName, timeToLive);
        } else {
            return this.generatePermanentGetRequestForObject(objectName,  principalName);
        }
    }

    public HttpRequest generatePermanentGetRequestForObject( String objectName, 
                                                             String principalName ) {
        return this.generatePermanentGetRequestForObject( privateContainerName,
                                                          String.format( "/%s/%s", principalName, objectName ) );
    }

    public HttpRequest generateTemporaryGetRequestForObject( String objectName, 
                                                             String principalName,
                                                             long timeToLive ) {
        return this.generateTemporaryGetRequestForObject( privateContainerName,
                                                          String.format( "/%s/%s", principalName, objectName ),
                                                          timeToLive );
    }

    public HttpRequest generatePermanentGetRequestForObject(String containerName, String objectName) {
        return this.blobRequestSigner.signGetBlob(containerName, objectName);
    }

    public HttpRequest generateTemporaryGetRequestForObject(String containerName, String objectName, long timeToLive) {
        return this.blobRequestSigner.signGetBlob(containerName, objectName, timeToLive);
    }

}

至于公共容器,我仍然可以通过获取标头/元数据来获取对象链接,这有点偏题,但我仍然需要签名的 URI 来发布存储在私有容器中的对象。

使用 BlobStore 将文件放入容器中工作得很好。所有推送的内容通常都由 OpenStack Dashboard 显示。

我仅在开发环境中使用为 Swift 配置的 Java 7 和 DevStack。jClouds 版本是 1.7.2。

4

1 回答 1

2

根据例外情况,您似乎没有在帐户上设置临时 URL 密钥。您可以通过以下方式将密钥更新为新值AccountApi

SwiftApi swiftApi = ContextBuilder.newBuilder(PROVIDER)
           .credentials("{username}", "{apiKey}")
           .buildApi(SwiftApi.class);

// Access the accountApi
AccountApi accountApi = swiftApi.getAccountApiForRegion("{regionId");
accountApi.updateTemporaryUrlKey("{newKey}");

// Access the key
String tempUrlKey;
if (accountApi.getTemporaryUrlKey().isPresent()) {
   tempUrlKey = accountApi.get().getTemporaryUrlKey().get();
}

希望有帮助!

于 2014-05-28T04:40:58.460 回答