public async Task <string> ExecuteAsync(CommandLineOptions options) { if (string.IsNullOrEmpty(options.Project)) { return(null); } _logger.LogDebug("Query the projects collection"); var whitelist = await _ipWhitelistRepository.FindAllAsync(options.Project); return(whitelist.ToJson()); }
public async Task <string> ExecuteAsync(CommandLineOptions options) { if (string.IsNullOrEmpty(options.Project) || string.IsNullOrEmpty(options.Values)) { return(null); } _logger.LogDebug("Retrieve ip whitelist for project"); var whitelist = await _ipWhitelistRepository.FindAllAsync(options.Project); var input = options.Values.Split(","); var existingEntries = new List <IpWhitelistRecordModel>(); foreach (var entry in input) { var ipAddress = entry.Split(":")[0]; var cidr = $"{ipAddress}/32"; if (whitelist.Any(x => x.CidrBlock == cidr || x.IpAddress == ipAddress)) { existingEntries.Add(new IpWhitelistRecordModel { CidrBlock = cidr }); } } if (existingEntries.Any()) { _logger.LogDebug($"Remove {existingEntries.Count} entrie(s) from the ip whitelist entrie(s)"); foreach (var existing in existingEntries) { await _ipWhitelistRepository.DeleteAsync(options.Project, existing); } } return($"IP white list updated ({existingEntries.Count} removed on initial {whitelist.Count})"); }
public async Task <string> ExecuteAsync(CommandLineOptions options) { if (string.IsNullOrEmpty(options.Project) || string.IsNullOrEmpty(options.Values)) { return(null); } _logger.LogDebug("Retrieve ip whitelist for project"); var whitelist = await _ipWhitelistRepository.FindAllAsync(options.Project); var input = options.Values.Split(","); var newEntries = new List <IpWhitelistRecordModel>(); foreach (var entry in input) { var ipAddress = entry.Split(":")[0]; var comment = entry.Contains(':') ? entry.Split(":")[1] : "Created by mdbatlas"; var cidr = $"{ipAddress}/32"; if (!whitelist.Any(x => x.CidrBlock == cidr || x.IpAddress == ipAddress)) { newEntries.Add(new IpWhitelistRecordModel { CidrBlock = cidr, Comment = comment }); } } if (newEntries.Any()) { _logger.LogDebug($"Add {newEntries.Count} new ip whitelist entrie(s)"); _ = await _ipWhitelistRepository.CreateAsync(options.Project, newEntries); } return($"IP white list updated ({newEntries.Count} added on initial {whitelist.Count})"); }