public IHttpActionResult Blob(string path, string accountName) { if (String.IsNullOrEmpty(path) || String.IsNullOrEmpty(accountName)) { return(Unauthorized()); } // When linking to a blob, we must resolve the account name to handle cases // where multiple storage accounts are being used. CloudStorageAccount account = AccountProvider.GetAccountByName(accountName); if (account == null) { return(Unauthorized()); } BlobPath parsed = BlobPath.Parse(path); LocalBlobDescriptor descriptor = new LocalBlobDescriptor { ContainerName = parsed.ContainerName, BlobName = parsed.BlobName }; var blob = descriptor.GetBlockBlob(account); // Get a SAS for the next 10 mins string sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy { Permissions = SharedAccessBlobPermissions.Read, SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10) }); // Redirect to it return(Redirect(blob.Uri.AbsoluteUri + sas)); }
public IHttpActionResult Blob(string path) { if (String.IsNullOrEmpty(path)) { return(Unauthorized()); } if (_account == null) { return(Unauthorized()); } BlobPath parsed = BlobPath.Parse(path); LocalBlobDescriptor descriptor = new LocalBlobDescriptor { ContainerName = parsed.ContainerName, BlobName = parsed.BlobName }; var blob = descriptor.GetBlockBlob(_account); // Get a SAS for the next 10 mins string sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy { Permissions = SharedAccessBlobPermissions.Read, SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10) }); // Redirect to it return(Redirect(blob.Uri.AbsoluteUri + sas)); }
public void ToString_BlobPath_ReturnsExpectedResult() { BlobPath path = BlobPath.Parse("container/blob", false); Assert.Equal("container/blob", path.ToString()); path = BlobPath.Parse("container", true); Assert.Equal("container", path.ToString()); path = new BlobPath("container", null); Assert.Equal("container", path.ToString()); }
public void ToString_BlobPath_ReturnsExpectedResult() { BlobPath path = BlobPath.Parse("container/blob", false); Assert.Equal("container/blob", path.ToString()); // '[' ad ']' are valid in blob names path = BlobPath.Parse("container/blob[0]", false); Assert.Equal("container/blob[0]", path.ToString()); path = BlobPath.Parse("container", true); Assert.Equal("container", path.ToString()); path = new BlobPath("container", null); Assert.Equal("container", path.ToString()); }
private static IDictionary <string, string> Match(string a, string b) { var pathA = BlobPathSource.Create(a); var pathB = BlobPath.Parse(b, false); IReadOnlyDictionary <string, object> bindingData = pathA.CreateBindingData(pathB); if (bindingData == null) { return(null); } IDictionary <string, string> matches = new Dictionary <string, string>(); foreach (KeyValuePair <string, object> item in bindingData) { matches.Add(item.Key, item.Value.ToString()); } return(matches); }
public ActionResult SearchBlob(string path) { ViewBag.Path = path; if (String.IsNullOrEmpty(path)) { return(View()); } if (_account == null) { TempData["Message.Text"] = "Account not found"; TempData["Message.Level"] = "danger"; return(View()); } ICloudBlob blob = null; try { BlobPath parsed = BlobPath.Parse(path); LocalBlobDescriptor descriptor = new LocalBlobDescriptor { ContainerName = parsed.ContainerName, BlobName = parsed.BlobName }; IReadOnlyDictionary <string, CloudStorageAccount> accounts = AccountProvider.GetAccounts(); foreach (var account in accounts.Values) { blob = descriptor.GetBlockBlob(account); if (blob.Exists()) { break; } else { blob = null; } } } catch (FormatException e) { TempData["Message.Text"] = e.Message; TempData["Message.Level"] = "danger"; return(View()); } catch { blob = null; } if (blob == null) { TempData["Message.Text"] = "No invocation found for: " + path; TempData["Message.Level"] = "warning"; return(View()); } Guid?guid; try { guid = BlobCausalityReader.GetParentId(blob); } catch { guid = null; } if (!guid.HasValue) { TempData["Message.Text"] = "No invocation found for: " + path; TempData["Message.Level"] = "warning"; return(View()); } TempData["Message.Text"] = "Invocation found for: " + path; TempData["Message.Level"] = "info"; return(Redirect("~/#/functions/invocations/" + guid)); }