Athlectual の回答は現在の openstack.net NuGet パッケージには当てはまらないようですが、試行錯誤しながら最新バージョン (1.1.2.1) で動作させることができました。うまくいけば、これは他の人を助けるでしょう
私の場合、一時 URL メタデータ キーは既に設定されているため、設定する必要はなかったようです。アカウントの作成時にランダムに生成する必要があります。したがって、機能する一時 URL を取得するコードは次のとおりです。
Nb認証に Username と APIKey を使用しました。代わりに Password を使用できると思います。APIKey は、Rackspace Cloud Control Panel Web サイトのアカウントの詳細の下にあります。
private static string GetCloudFilesTempUrl(Uri storageUrl, string username, string apiKey, string containerName, string filename)
{
var cloudIdentity = new CloudIdentity()
{
Username = username,
APIKey = apiKey
};
var provider = new CloudFilesProvider(cloudIdentity);
var accountMetaData = provider.GetAccountMetaData();
var tempUrlKey = accountMetaData["Temp-Url-Key"];
//Set the link to expire after 60 seconds (in epoch time)
var epochExpire = ((int) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds) + 60;
//The path to the cloud file
var path = string.Format("{0}/{1}/{2}", storageUrl.AbsolutePath, containerName, filename);
var hmacBody = string.Format("GET\n{0}\n{1}", epochExpire, path);
var hashSaltBytes = Encoding.ASCII.GetBytes(tempUrlKey);
string sig;
using (var myhmacMd5 = new HMACSHA1(hashSaltBytes))
{
var ticketBytes = Encoding.ASCII.GetBytes(hmacBody);
var checksum = myhmacMd5.ComputeHash(ticketBytes);
var hexaHash = new StringBuilder();
foreach (var b in checksum)
{
hexaHash.Append(String.Format("{0:x2}", b));
}
sig = hexaHash.ToString();
}
var cloudFileUrl = string.Format("https://{0}{1}", storageUrl.Host, path);
//Compile the temporary URL
return string.Format("{0}?temp_url_sig={1}&temp_url_expires={2}", cloudFileUrl, sig, epochExpire);
}
ストレージ URL を取得する方法がわかりませんが、試行錯誤を重ねてこれを管理しました。
private static string GetCloudFilesStorageUrl(string username, string apiKey)
{
var cloudIdentity = new CloudIdentity()
{
Username = username,
APIKey = apiKey
};
var identityProvider = new CloudIdentityProvider(cloudIdentity);
return identityProvider.GetUserAccess(cloudIdentity)
.ServiceCatalog
.Single(x => x.Name == "cloudFiles")
.Endpoints[0].PublicURL;
}
前述のとおり、一時 URL キーを設定する必要はありませんでした。必要な場合は、次のようにする必要があると思います。
private static void SetCloudFilesTempUrlKey(string username, string apiKey, string tempUrlKey)
{
var cloudIdentity = new CloudIdentity()
{
Username = username,
APIKey = apiKey
};
var provider = new CloudFilesProvider(cloudIdentity);
provider.UpdateAccountMetadata(new Metadata
{
{ "Temp-Url-Key", tempUrlKey }
});
}