private async Task LogSummaryAsync(IAcrClient acrClient, List <string> deletedRepos, List <string> deletedImages) { _loggerService.WriteHeading("SUMMARY"); _loggerService.WriteSubheading("Deleted repositories:"); foreach (string deletedRepo in deletedRepos) { _loggerService.WriteMessage($"\t{deletedRepo}"); } _loggerService.WriteMessage(); _loggerService.WriteSubheading("Deleted images:"); foreach (string deletedImage in deletedImages) { _loggerService.WriteMessage($"\t{deletedImage}"); } _loggerService.WriteMessage(); _loggerService.WriteSubheading("DELETED DATA"); _loggerService.WriteMessage($"Total images deleted: {deletedImages.Count}"); _loggerService.WriteMessage($"Total repos deleted: {deletedRepos.Count}"); _loggerService.WriteMessage(); _loggerService.WriteMessage("<Querying remaining data...>"); // Requery the catalog to get the latest info after things have been deleted Catalog catalog = await acrClient.GetCatalogAsync(); _loggerService.WriteSubheading($"Total repos remaining: {catalog.RepositoryNames.Count}"); }
public override async Task ExecuteAsync() { _repoNameFilterRegex = new Regex(ManifestFilter.GetFilterRegexPattern(Options.RepoName)); _loggerService.WriteHeading("FINDING IMAGES TO CLEAN"); _loggerService.WriteSubheading($"Connecting to ACR '{Options.RegistryName}'"); using IAcrClient acrClient = await _acrClientFactory.CreateAsync( Options.RegistryName, Options.ServicePrincipal.Tenant, Options.ServicePrincipal.ClientId, Options.ServicePrincipal.Secret); _loggerService.WriteSubheading($"Querying catalog of ACR '{Options.RegistryName}'"); Catalog catalog = await acrClient.GetCatalogAsync(); _loggerService.WriteHeading("DELETING IMAGES"); List <string> deletedRepos = new List <string>(); List <string> deletedImages = new List <string>(); IEnumerable <Task> cleanupTasks = catalog.RepositoryNames .Where(repoName => _repoNameFilterRegex.IsMatch(repoName)) .Select(repoName => acrClient.GetRepositoryAsync(repoName)) .Select(getRepoTask => ProcessRepoAsync(acrClient, getRepoTask, deletedRepos, deletedImages)) .ToArray(); await Task.WhenAll(cleanupTasks); await LogSummaryAsync(acrClient, deletedRepos, deletedImages); }