Exemple #1
0
        public bool ConformConfiguration(ApplicationProfile app, File[] files, Module[] configModules, bool isTest)
        {
            try
            {
                if (!_veracodeService.DoesAppExist(app))
                {
                    throw new Exception($"Application Profile {app.application_name} does not exist, uou need to run -configure first.");
                }

                var app_id = _veracodeRepository.GetAllApps().SingleOrDefault(x => x.app_name == app.application_name).app_id;
                app.id = $"{app_id}";

                if (!_veracodeService.IsPolicyScanInProgress(app))
                {
                    var scan_id = _veracodeService.CreateScan(app);
                    _logger.LogInformation($"New scan created with Build Id {scan_id}. Uploading files");
                    UploadFiles(app, scan_id, files);
                    RunScan(app, scan_id, "", _veracodeService.StartPreScan,
                            BuildStatusType.PreScanSubmitted, BuildStatusType.PreScanFailed);

                    var prescanModules  = _veracodeService.GetModules(app.id, scan_id);
                    var doesScanConform = DoesModuleConfigConform(scan_id, configModules, prescanModules);

                    if (isTest)
                    {
                        _logger.LogInformation($"Test Finished. Deleting Build Id {scan_id}.");
                    }

                    if (doesScanConform)
                    {
                        _logger.LogInformation($"Configuration conforms.");
                    }
                    else
                    {
                        _logger.LogInformation($"Scan does not conform. Deleting Build Id {scan_id}.");
                    }


                    if (isTest || !doesScanConform)
                    {
                        _veracodeService.DeleteScan(app.id);
                    }

                    return(doesScanConform);
                }
                else
                {
                    _logger.LogWarning($"Policy scan for {app.application_name} already in progress.");
                    _logger.LogWarning($"This must be cancelled or completed before this job can be continued.");
                    return(false);
                }
            }
            catch (Exception e)
            {
                _logger.LogInformation($"{e.Message}.");
                if (!e.Message.Contains("Profile"))
                {
                    _veracodeService.DeleteScan(app.id);
                }

                return(false);
            }
        }