/// <summary> /// The remote URL and signature are encoded in the "file" part /// of the virtualPath parameter as follows: /// path/path/.../path/url_b64.hmac.ext /// </summary> /// <param name="virtualPath"></param> /// <returns></returns> public async Task <IBlobData> Fetch(string virtualPath) { var remote = virtualPath .Split('/') .Last()? .Split('.'); if (remote == null || remote.Length < 2) { logger?.LogWarning("Invalid remote path: {VirtualPath}", virtualPath); throw new BlobMissingException($"Invalid remote path: {virtualPath}"); } var urlBase64 = remote[0]; var hmac = remote[1]; var sig = Signatures.SignString(urlBase64, options.SigningKey, 8); if (hmac != sig) { logger?.LogWarning("Missing or Invalid signature on remote path: {VirtualPath}", virtualPath); throw new BlobMissingException($"Missing or Invalid signature on remote path: {virtualPath}"); } var url = EncodingUtils.FromBase64UToString(urlBase64); if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) { logger?.LogWarning("RemoteReader blob {VirtualPath} not found. Invalid Uri: {Url}", virtualPath, url); throw new BlobMissingException($"RemoteReader blob \"{virtualPath}\" not found. Invalid Uri: {url}"); } var httpClientName = httpClientSelector(uri); using var http = httpFactory.CreateClient(httpClientName); try { var resp = await http.GetAsync(url); if (!resp.IsSuccessStatusCode) { logger?.LogWarning("RemoteReader blob {VirtualPath} not found. The remote {Url} responded with status: {StatusCode}", virtualPath, url, resp.StatusCode); throw new BlobMissingException($"RemoteReader blob \"{virtualPath}\" not found. The remote \"{url}\" responded with status: {resp.StatusCode}"); } return(new RemoteReaderBlob(resp)); } catch (BlobMissingException) { throw; } catch (Exception ex) { logger?.LogWarning(ex, "RemoteReader blob error retrieving {Url} for {VirtualPath}.", url, virtualPath); throw new BlobMissingException($"RemoteReader blob error retrieving \"{url}\" for \"{virtualPath}\".", ex); } }
/// <summary> /// The remote URL and signature are encoded in the "file" part /// of the virtualPath parameter as follows: /// path/path/.../path/urlb64.hmac.ext /// </summary> /// <param name="virtualPath"></param> /// <returns></returns> public async Task <IBlobData> Fetch(string virtualPath) { var remote = virtualPath .Split('/') .Last() .Split('.'); var urlb64 = remote[0]; var hmac = remote[1]; var sig = Signatures.SignString(urlb64, _options.SigningKey, 8); if (hmac != sig) { throw new BlobMissingException($"Missing or Invalid signature on remote path: {virtualPath}"); } var url = EncodingUtils.FromBase64UToString(urlb64); var resp = await _http.GetAsync(url); return(new RemoteReaderBlob(resp)); }