private void RequestIndex(Event e) { // we only check for an existing index request, not an actual index. Letting the indexer sort it out later should be cheap var request = new IndexRequest { CreatedTime = DateTime.UtcNow, TargetRepo = e.Target.Repository, TargetDigest = e.Target.Digest, TargetPaths = config.DeepIndexing ? null : config.Documents }; if (!indexQueue.Contains(request)) { indexQueue.Push(request); } logger.LogInformation($"Submitted indexing request for event {e.Id} - {e.Action} {e.Target.MediaType} {e.Target.Digest}"); }
public async Task <IActionResult> GetFilesAsync(string repository, string digest, string targets) { if (string.IsNullOrEmpty(digest)) { return(BadRequest("An image digest is required.")); } if (!digest.IsDigest()) { return(BadRequest("Digest appears invalid.")); } try { if (string.IsNullOrEmpty(RegistryCredentials.Registry)) { return(BadRequest("Session is missing registry information. Try creating a new session.")); } var targetList = string.IsNullOrEmpty(targets) ? Array.Empty <string>() : targets.Split(';'); var client = clientFactory.GetClient(AuthHandler); var imageSet = await client.GetImageSetAsync(repository, digest); if (imageSet.Images.Count() != 1) { return(NotFound("No image was found with the given digest.")); } // if we have a complete index, return it if (indexStore.IndexExists(digest)) { return(Ok(indexStore.GetIndex(digest))); } // otherwise, if they've requested a targeted index, look for that else if (indexStore.IndexExists(digest, targetList)) { return(Ok(indexStore.GetIndex(digest, targetList))); } // no dice, queue an indexing request else { var request = new IndexRequest { Authorization = Request.Headers["Authorization"], CreatedTime = DateTime.UtcNow, TargetRepo = repository, TargetDigest = digest, TargetPaths = targetList }; if (!indexQueue.Contains(request)) { indexQueue.Push(request); } return(StatusCode(202, new { Status = RequestStatus.Pending })); } } catch (RedisConnectionException) { return(StatusCode(503, "Cannot access cache")); } catch (Client.NotFoundException) { return(NotFound()); } catch (Client.AuthenticationException) { return(Unauthorized()); } }