Exemple #1
0
        static MongoDBOutFactory()
        {
            try
            {
                _outputConfig = Config.GetConfig <MongoOutConfig>(MongoOutConfig.SECTION_NAME);
                _conConfig    = Config.GetConfig <MongoConnectionConfig>(MongoConnectionConfig.SECTION_NAME);


                if (_log.IsDebugEnabled)
                {
                    foreach (var spec in _outputConfig.ShardKeys)
                    {
                        _log.DebugFormat("Shard Key: {0}", spec);
                    }
                }

                if (_outputConfig.ShardKeys.Count > 0)
                {
                    _log.InfoFormat("{0} calculated shard keys have been defined.", _outputConfig.ShardKeys.Count);
                }

                MongoUrl mu = GetMongoConnectionString();

                _client = new MongoClient(mu);

                if (!_client.ListDatabaseNames().ToList().Contains(mu.DatabaseName))
                {
                    _log.Warn($"Database {mu.DatabaseName} does not exist, it will be created.");
                }

                _db = _client.GetDatabase(mu.DatabaseName);


                // It is a violation of OOP principles for this component to know about these records.  At some point the schema
                // creation may be moved to an installer that initializes the DB prior to running the application.
                _schemas.Add(Config.Service.SASTScanDetailRecordName,
                             MongoDBOut.CreateInstance <SastDetailSchema>(_db, Config.Service.SASTScanDetailRecordName, _outputConfig.ShardKeys[Config.Service.SASTScanDetailRecordName]));

                _schemas.Add(Config.Service.SASTScanSummaryRecordName, MongoDBOut.CreateInstance <SastSummarySchema>(_db, Config.Service.SASTScanSummaryRecordName,
                                                                                                                     _outputConfig.ShardKeys[Config.Service.SASTScanSummaryRecordName]));

                _schemas.Add(Config.Service.SCAScanSummaryRecordName, MongoDBOut.CreateInstance <SCASummarySchema>(_db, Config.Service.SCAScanSummaryRecordName,
                                                                                                                   _outputConfig.ShardKeys[Config.Service.SCAScanSummaryRecordName]));

                _schemas.Add(Config.Service.SCAScanDetailRecordName, MongoDBOut.CreateInstance <SCADetailSchema>(_db, Config.Service.SCAScanDetailRecordName,
                                                                                                                 _outputConfig.ShardKeys[Config.Service.SCAScanDetailRecordName]));

                _schemas.Add(Config.Service.ProjectInfoRecordName, MongoDBOut.CreateInstance <ProjectInfoSchema>(_db, Config.Service.ProjectInfoRecordName,
                                                                                                                 _outputConfig.ShardKeys[Config.Service.ProjectInfoRecordName]));

                _schemas.Add(Config.Service.PolicyViolationsRecordName, MongoDBOut.CreateInstance <PolicyViolationsSchema>(_db, Config.Service.PolicyViolationsRecordName,
                                                                                                                           _outputConfig.ShardKeys[Config.Service.PolicyViolationsRecordName]));
            }
            catch (Exception ex)
            {
                _log.Error("Error initializing MongoDB connectivity.", ex);
                _client = null;
            }
        }
Exemple #2
0
        static MongoDBOutFactory()
        {
            try
            {
                _cfg = Config.GetConfig <MongoOutConfig>(MongoOutConfig.SECTION_NAME);

                foreach (var spec in _cfg.ShardKeys)
                {
                    _log.DebugFormat("Shard Key: {0}", spec);
                }

                if (_cfg.ShardKeys.Count > 0)
                {
                    _log.InfoFormat("{0} calculated shard keys have been defined.", _cfg.ShardKeys.Count);
                }

                var mu = new MongoUrl(_cfg.ConnectionString);
                _client = new MongoClient(mu);


                if (!_client.ListDatabaseNames().ToList().Contains(mu.DatabaseName))
                {
                    _log.Warn($"Database {mu.DatabaseName} does not exist, it will be created.");
                }

                _db = _client.GetDatabase(mu.DatabaseName);

                _schemas.Add(Config.Service.SASTScanDetailRecordName,
                             MongoDBOut.CreateInstance <SastDetailSchema>(_db, Config.Service.SASTScanDetailRecordName, _cfg.ShardKeys[Config.Service.SASTScanDetailRecordName]));

                _schemas.Add(Config.Service.SASTScanSummaryRecordName, MongoDBOut.CreateInstance <SastSummarySchema>(_db, Config.Service.SASTScanSummaryRecordName,
                                                                                                                     _cfg.ShardKeys[Config.Service.SASTScanSummaryRecordName]));

                _schemas.Add(Config.Service.SCAScanSummaryRecordName, MongoDBOut.CreateInstance <SCASummarySchema>(_db, Config.Service.SCAScanSummaryRecordName,
                                                                                                                   _cfg.ShardKeys[Config.Service.SCAScanSummaryRecordName]));

                _schemas.Add(Config.Service.SCAScanDetailRecordName, MongoDBOut.CreateInstance <SCADetailSchema>(_db, Config.Service.SCAScanDetailRecordName,
                                                                                                                 _cfg.ShardKeys[Config.Service.SCAScanDetailRecordName]));

                _schemas.Add(Config.Service.ProjectInfoRecordName, MongoDBOut.CreateInstance <ProjectInfoSchema>(_db, Config.Service.ProjectInfoRecordName,
                                                                                                                 _cfg.ShardKeys[Config.Service.ProjectInfoRecordName]));

                _schemas.Add(Config.Service.PolicyViolationsRecordName, MongoDBOut.CreateInstance <PolicyViolationsSchema>(_db, Config.Service.PolicyViolationsRecordName,
                                                                                                                           _cfg.ShardKeys[Config.Service.PolicyViolationsRecordName]));
            }
            catch (Exception ex)
            {
                _log.Error("Error initializing database connectivity.", ex);
            }
        }