Skip to content

Commit c03676f

Browse files
author
Luis Cabrera
committed
We need to refresh SAS tokens or they will expire.
1 parent 1bca62d commit c03676f

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

02 - Web UI Template/CognitiveSearch.UI/Controllers/HomeController.cs

+26-28
Original file line numberDiff line numberDiff line change
@@ -261,39 +261,37 @@ private string GetToken(string decodedPath)
261261
/// <returns></returns>
262262
private string[] GetContainerSasUris()
263263
{
264-
if (tokens == null)
265-
{
266-
tokens = new string[3];
267-
containerAddresses = new string[3];
264+
// We need to refresh the tokens every time or they will become invalid.
265+
tokens = new string[3];
266+
containerAddresses = new string[3];
268267

269-
string accountName = _configuration.GetSection("StorageAccountName")?.Value;
270-
string accountKey = _configuration.GetSection("StorageAccountKey")?.Value;
268+
string accountName = _configuration.GetSection("StorageAccountName")?.Value;
269+
string accountKey = _configuration.GetSection("StorageAccountKey")?.Value;
271270

272-
SharedAccessBlobPolicy adHocPolicy = new SharedAccessBlobPolicy()
273-
{
274-
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
275-
Permissions = SharedAccessBlobPermissions.Read
276-
};
271+
SharedAccessBlobPolicy adHocPolicy = new SharedAccessBlobPolicy()
272+
{
273+
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
274+
Permissions = SharedAccessBlobPermissions.Read
275+
};
277276

278-
containerAddresses[0] = _configuration.GetSection("StorageContainerAddress")?.Value.ToLower();
279-
CloudBlobContainer container = new CloudBlobContainer(new Uri(containerAddresses[0]), new StorageCredentials(accountName, accountKey));
280-
tokens[0] = container.GetSharedAccessSignature(adHocPolicy, null);
277+
containerAddresses[0] = _configuration.GetSection("StorageContainerAddress")?.Value.ToLower();
278+
CloudBlobContainer container = new CloudBlobContainer(new Uri(containerAddresses[0]), new StorageCredentials(accountName, accountKey));
279+
tokens[0] = container.GetSharedAccessSignature(adHocPolicy, null);
281280

282-
// Get token for second indexer data source
283-
containerAddresses[1] = _configuration.GetSection("StorageContainerAddress2")?.Value.ToLower();
284-
if (!String.Equals(containerAddresses[1], defaultContainerUriValue))
285-
{
286-
CloudBlobContainer container2 = new CloudBlobContainer(new Uri(containerAddresses[1]), new StorageCredentials(accountName, accountKey));
287-
tokens[1] = container2.GetSharedAccessSignature(adHocPolicy, null);
288-
}
281+
// Get token for second indexer data source
282+
containerAddresses[1] = _configuration.GetSection("StorageContainerAddress2")?.Value.ToLower();
283+
if (!String.Equals(containerAddresses[1], defaultContainerUriValue))
284+
{
285+
CloudBlobContainer container2 = new CloudBlobContainer(new Uri(containerAddresses[1]), new StorageCredentials(accountName, accountKey));
286+
tokens[1] = container2.GetSharedAccessSignature(adHocPolicy, null);
287+
}
289288

290-
// Get token for third indexer data source
291-
containerAddresses[2] = _configuration.GetSection("StorageContainerAddress3")?.Value.ToLower();
292-
if (!String.Equals(containerAddresses[2], defaultContainerUriValue))
293-
{
294-
CloudBlobContainer container3 = new CloudBlobContainer(new Uri(containerAddresses[2]), new StorageCredentials(accountName, accountKey));
295-
tokens[2] = container3.GetSharedAccessSignature(adHocPolicy, null);
296-
}
289+
// Get token for third indexer data source
290+
containerAddresses[2] = _configuration.GetSection("StorageContainerAddress3")?.Value.ToLower();
291+
if (!String.Equals(containerAddresses[2], defaultContainerUriValue))
292+
{
293+
CloudBlobContainer container3 = new CloudBlobContainer(new Uri(containerAddresses[2]), new StorageCredentials(accountName, accountKey));
294+
tokens[2] = container3.GetSharedAccessSignature(adHocPolicy, null);
297295
}
298296

299297
return tokens;

0 commit comments

Comments
 (0)