Beispiel #1
0
        public async Task SyncAssets()
        {
            var providerService        = _providerFactory.GetProviderService(_configuration["ProviderEmailDomain"]);
            var privateHackerOneAssets = await providerService.GetAssets(true);

            var publicHackerOneAssets = await providerService.GetAssets(false);

            var assets = await _assetRepository.GetAll();

            foreach (var asset in assets)
            {
                var assetList = asset.Key.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();

                var  privateAsset = privateHackerOneAssets.Where(x => assetList.Contains(x.Name.Trim())).ToList();
                var  publicAsset  = publicHackerOneAssets.Where(x => assetList.Contains(x.Name.Trim())).ToList();
                bool?isPublic     = !publicAsset.Any() && !privateAsset.Any() ? null : publicAsset.Any();
                var  newAsset     = new AssetEntity
                {
                    IsOnHackerOne     = isPublic.HasValue,
                    IsOnPublicProgram = isPublic.HasValue && isPublic.Value,
                    Programs          = string.Join(Const.DatabaseSeparator, publicAsset.Select(p => p.Program).Concat(privateAsset.Select(p => p.Program)).Distinct())
                };

                if (NeedsToUpdate(newAsset, asset))
                {
                    await _assetRepository.Update(asset);
                }
            }
        }