protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            _log.Info("Service start.");

            _cancelToken = new CancellationTokenSource();


            var builder = new CxRestContext.CxRestContextBuilder();

            builder.WithSASTServiceURL(Config.Connection.URL).
            WithMNOServiceURL(Config.Connection.MNOUrl)
            .WithOpTimeout(Config.Connection.TimeoutSeconds)
            .WithSSLValidate(Config.Connection.ValidateCertificates)
            .WithUsername(Config.Credentials.Username)
            .WithPassword(Config.Credentials.Password);

            var restCtx = builder.Build();


            _serviceTask = Task.Run(async() =>
            {
                do
                {
                    DateTime start = DateTime.Now;
                    _log.Info("Starting data transformation.");



                    try
                    {
                        Transformer.DoTransform(Config.Service.ConcurrentThreads,
                                                Config.Service.StateDataStoragePath, Config.Service.InstanceIdentifier,
                                                restCtx, _outFactory, new RecordNames()
                        {
                            SASTScanSummary  = Config.Service.SASTScanSummaryRecordName,
                            SASTScanDetail   = Config.Service.SASTScanDetailRecordName,
                            SCAScanSummary   = Config.Service.SCAScanSummaryRecordName,
                            SCAScanDetail    = Config.Service.SCAScanDetailRecordName,
                            ProjectInfo      = Config.Service.ProjectInfoRecordName,
                            PolicyViolations = Config.Service.PolicyViolationsRecordName
                        },
                                                _cancelToken.Token);
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Transformation aborted due to unhandled exception.", ex);
                    }

                    _log.InfoFormat("Data transformation finished in {0:0.00} minutes.", DateTime.Now.Subtract(start).TotalMinutes);
                    await Task.Delay(Config.Service.ProcessPeriodMinutes * 60 * 1000, _cancelToken.Token);
                } while (!_cancelToken.Token.IsCancellationRequested);

                _cancelToken.Token.ThrowIfCancellationRequested();
            }, _cancelToken.Token);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            appLog.Info("Start");

            appLog.InfoFormat("CWD: {0}", Directory.GetCurrentDirectory());


            var builder = new CxRestContext.CxRestContextBuilder();

            builder.WithSASTServiceURL(Config.Connection.URL)
            .WithOpTimeout(Config.Connection.TimeoutSeconds)
            .WithSSLValidate(Config.Connection.ValidateCertificates)
            .WithUsername(Config.Credentials.Username)
            .WithPassword(Config.Credentials.Password).
            WithMNOServiceURL(Config.Connection.MNOUrl);

            using (CancellationTokenSource t = new CancellationTokenSource())
            {
                try
                {
                    var outFactory = MakeFactory();

                    CxRestContext ctx = builder.Build();
                    Transformer.DoTransform(Config.Service.ConcurrentThreads,
                                            Config.Service.StateDataStoragePath, Config.Service.InstanceIdentifier,
                                            ctx,
                                            outFactory,
                                            new RecordNames()
                    {
                        SASTScanSummary  = Config.Service.SASTScanSummaryRecordName,
                        SASTScanDetail   = Config.Service.SASTScanDetailRecordName,
                        SCAScanSummary   = Config.Service.SCAScanSummaryRecordName,
                        SCAScanDetail    = Config.Service.SCAScanDetailRecordName,
                        ProjectInfo      = Config.Service.ProjectInfoRecordName,
                        PolicyViolations = Config.Service.PolicyViolationsRecordName
                    },
                                            t.Token);


                    AuditTrailCrawler.CrawlAuditTrails(outFactory, t.Token);
                }
                catch (ProcessFatalException pfe)
                {
                    appLog.Error("Fatal exception caught, program ending.", pfe);
                }
                catch (Exception ex)
                {
                    appLog.Error("Unhandled exception caught, program ending.", ex);
                }
            }

            appLog.Info("End");
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            appLog.Info("Start");

            appLog.InfoFormat("CWD: {0}", Directory.GetCurrentDirectory());


            var builder = new CxRestContext.CxRestContextBuilder();

            builder.WithSASTServiceURL(Config.Connection.URL)
            .WithOpTimeout(Config.Connection.TimeoutSeconds)
            .WithSSLValidate(Config.Connection.ValidateCertificates)
            .WithUsername(Config.Credentials.Username)
            .WithPassword(Config.Credentials.Password).
            WithMNOServiceURL(Config.Connection.MNOUrl);

            using (CancellationTokenSource t = new CancellationTokenSource())
            {
                CxRestContext ctx = builder.Build();
                Transformer.DoTransform(Config.Service.ConcurrentThreads,
                                        Config.Service.StateDataStoragePath, Config.Service.InstanceIdentifier,
                                        ctx,
                                        MakeFactory(),
                                        new RecordNames()
                {
                    SASTScanSummary  = Config.Service.SASTScanSummaryRecordName,
                    SASTScanDetail   = Config.Service.SASTScanDetailRecordName,
                    SCAScanSummary   = Config.Service.SCAScanSummaryRecordName,
                    SCAScanDetail    = Config.Service.SCAScanDetailRecordName,
                    ProjectInfo      = Config.Service.ProjectInfoRecordName,
                    PolicyViolations = Config.Service.PolicyViolationsRecordName
                },
                                        t.Token);
            }


            appLog.Info("End");
        }
Exemplo n.º 4
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _log.Info("Daemon start.");

            var builder = new CxRestContext.CxRestContextBuilder();

            builder.WithSASTServiceURL(Config.Connection.URL).
            WithMNOServiceURL(Config.Connection.MNOUrl)
            .WithOpTimeout(Config.Connection.TimeoutSeconds)
            .WithSSLValidate(Config.Connection.ValidateCertificates)
            .WithUsername(Config.Credentials.Username)
            .WithPassword(Config.Credentials.Password);

            var restCtx = builder.Build();

            _cancelToken = new CancellationTokenSource();

            _serviceTask = Task.Run(async() =>
            {
                do
                {
                    DateTime start = DateTime.Now;
                    _log.Info("Starting data transformation.");

                    try
                    {
                        Transformer.DoTransform(Config.Service.ConcurrentThreads,
                                                Config.Service.StateDataStoragePath, Config.Service.InstanceIdentifier,
                                                restCtx, _outFactory, new RecordNames()
                        {
                            SASTScanSummary  = Config.Service.SASTScanSummaryRecordName,
                            SASTScanDetail   = Config.Service.SASTScanDetailRecordName,
                            SCAScanSummary   = Config.Service.SCAScanSummaryRecordName,
                            SCAScanDetail    = Config.Service.SCAScanDetailRecordName,
                            ProjectInfo      = Config.Service.ProjectInfoRecordName,
                            PolicyViolations = Config.Service.PolicyViolationsRecordName
                        }, _cancelToken.Token);
                    }
                    catch (ProcessFatalException pfe)
                    {
                        _log.Error("Fatal exception caught, program ending.", pfe);
                        Program._tokenSrc.Cancel();
                        break;
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Vulnerability data transformation aborted due to unhandled exception.", ex);
                    }

                    _log.InfoFormat("Vulnerability data transformation finished in {0:0.00} minutes.",
                                    DateTime.Now.Subtract(start).TotalMinutes);

                    start = DateTime.Now;

                    try
                    {
                        if (!cancellationToken.IsCancellationRequested)
                        {
                            AuditTrailCrawler.CrawlAuditTrails(_outFactory, _cancelToken.Token);
                        }
                    }
                    catch (ProcessFatalException pfe)
                    {
                        _log.Error("Fatal exception caught, program ending.", pfe);
                        Program._tokenSrc.Cancel();
                        break;
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Audit data transformation aborted due to unhandled exception.", ex);
                    }

                    _log.InfoFormat("Audit data transformation finished in {0:0.00} minutes.",
                                    DateTime.Now.Subtract(start).TotalMinutes);

                    await Task.Delay(Config.Service.ProcessPeriodMinutes * 60 * 1000, _cancelToken.Token);
                } while (!_cancelToken.Token.IsCancellationRequested);

                _cancelToken.Token.ThrowIfCancellationRequested();
            }, _cancelToken.Token);

            return(Task.CompletedTask);
        }
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            _log.Info("Service start.");

            _cancelToken = new CancellationTokenSource();


            var builder = new CxRestContext.CxRestContextBuilder();

            builder.WithSASTServiceURL(Config.Connection.URL).
            WithMNOServiceURL(Config.Connection.MNOUrl)
            .WithOpTimeout(Config.Connection.TimeoutSeconds)
            .WithSSLValidate(Config.Connection.ValidateCertificates)
            .WithUsername(Config.Credentials.Username)
            .WithPassword(Config.Credentials.Password);

            var restCtx = builder.Build();

            _serviceTask = Task.Run(async() =>
            {
                do
                {
                    DateTime start = DateTime.Now;
                    _log.Info("Starting data transformation.");

                    try
                    {
                        Transformer.DoTransform(Config.Service.ConcurrentThreads,
                                                Config.Service.StateDataStoragePath, Config.Service.InstanceIdentifier,
                                                restCtx,
                                                new FilterImpl(Config.GetConfig <CxFilter>("ProjectFilterRegex").TeamRegex,
                                                               Config.GetConfig <CxFilter>("ProjectFilterRegex").ProjectRegex),
                                                new RecordNames()
                        {
                            SASTScanSummary  = Config.Service.SASTScanSummaryRecordName,
                            SASTScanDetail   = Config.Service.SASTScanDetailRecordName,
                            SCAScanSummary   = Config.Service.SCAScanSummaryRecordName,
                            SCAScanDetail    = Config.Service.SCAScanDetailRecordName,
                            ProjectInfo      = Config.Service.ProjectInfoRecordName,
                            PolicyViolations = Config.Service.PolicyViolationsRecordName
                        }, _cancelToken.Token);
                    }
                    catch (ProcessFatalException pfe)
                    {
                        Fatal(pfe);
                        break;
                    }
                    catch (TypeInitializationException ex)
                    {
                        Fatal(ex);
                        break;
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Vulnerability data transformation aborted due to unhandled exception.", ex);
                    }

                    _log.InfoFormat("Vulnerability data transformation finished in {0:0.00} minutes.",
                                    DateTime.Now.Subtract(start).TotalMinutes);

                    start = DateTime.Now;

                    try
                    {
                        if (!_cancelToken.Token.IsCancellationRequested)
                        {
                            AuditTrailCrawler.CrawlAuditTrails(_cancelToken.Token);
                        }
                    }
                    catch (ProcessFatalException pfe)
                    {
                        _log.Error("Fatal exception caught, program ending.", pfe);
                        new Task(() => Stop()).Start();
                        break;
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Audit data transformation aborted due to unhandled exception.", ex);
                    }

                    _log.InfoFormat("Audit data transformation finished in {0:0.00} minutes.",
                                    DateTime.Now.Subtract(start).TotalMinutes);

                    await Task.Delay(Config.Service.ProcessPeriodMinutes * 60 * 1000, _cancelToken.Token);
                } while (!_cancelToken.Token.IsCancellationRequested);

                _cancelToken.Token.ThrowIfCancellationRequested();
            }, _cancelToken.Token);
        }