public async Task <Uri> GetPackageUriAsync(string id, string version, CancellationToken cancellationToken) { var serviceIndex = await _sourceRepository.GetResourceAsync <ServiceIndexResourceV3>(cancellationToken); var packageBaseAddress = serviceIndex.GetServiceEntryUri(ServiceTypes.PackageBaseAddress); if (packageBaseAddress != null) { return(new Uri(packageBaseAddress, $"{id}/{version}/{id}.{version}.nupkg")); } else { _logger.LogDebug("Upstream repository does not support flat container, falling back to registration"); // If there is no flat container resource fall back to using the registration resource to find the download url. using (var sourceCacheContext = new SourceCacheContext()) { // Read the url from the registration information var pid = new PackageIdentity(id, NuGetVersion.Parse(version)); var blob = await _regResource.GetPackageMetadata(pid, sourceCacheContext, _loggerAdapter, cancellationToken); if (blob != null && blob["packageContent"] != null) { return(new Uri(blob["packageContent"].ToString())); } else { throw new InvalidOperationException("Could not determine upstream url for download"); } } } }
} // End Task InvokeAsync private async System.Threading.Tasks.Task ProcessAcmeChallenge(Microsoft.AspNetCore.Http.HttpContext context) { string path = context.Request.Path.ToString(); _logger.LogDebug("Challenge invoked: {challengePath} by {IpAddress}", path, context.Connection.RemoteIpAddress); // var allChallenges = await _persistenceService.GetPersistedChallengesAsync(); MatchingChallenge[] allChallenges = new MatchingChallenge[] { new MatchingChallenge() }; MatchingChallenge matchingChallenge = null; if (path.Length > s_lenMagicPrefix) { string requestedToken = path.Substring($"{MagicPrefix}/".Length); for (int i = 0; i < allChallenges.Length; ++i) { if (string.Equals(allChallenges[i].Token, requestedToken, System.StringComparison.Ordinal)) { matchingChallenge = allChallenges[i]; break; } // End if (string.Equals(allChallenges[i].Token, requestedToken, System.StringComparison.Ordinal)) } // Next i } // End if (path.Length > MagicPrefix.Length) if (matchingChallenge == null) { _logger.LogInformation("The given challenge did not match {challengePath} among {allChallenges}", path, allChallenges); context.Response.StatusCode = (int)System.Net.HttpStatusCode.PreconditionFailed; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync( text : "d'OH.", cancellationToken : context.RequestAborted ); await context.Response.CompleteAsync(); return; } // End if (matchingChallenge == null) // token response is always in ASCII so char_count would be equal to byte_count here context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK; context.Response.ContentLength = matchingChallenge.Response.Length; // context.Response.ContentType = "application/octet-stream"; context.Response.ContentType = "text/plain; charset=ascii"; await context.Response.WriteAsync( text : matchingChallenge.Response, cancellationToken : context.RequestAborted); } // End Task ProcessAcmeChallenge
public void LogDebug(string message, params object[] args) { _logger.LogDebug(message, args); }
public void Debug(Exception ex, Dictionary <string, string> extra = null) { _logger.LogDebug(ex, ex.Message); }
public void Debug(object message, Exception exception = null) { _logger.LogDebug(message.ToString()); }