Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
refactor: refactor to remove the duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
lingy1028 committed Jul 21, 2021
1 parent bd58ff3 commit 8dab52a
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions splunk_connect_for_snmp_mib_server/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ########################################################################
import pymongo
import os
import logging
import os

logger = logging.getLogger(__name__)
import pymongo

logger = logging.getLogger(__name__)

class MibsRepository:
class MongoRepository:
def __init__(self, mongo_config):
self._client = pymongo.MongoClient(
os.environ["MONGO_SERVICE_SERVICE_HOST"],
Expand All @@ -32,6 +32,11 @@ def __init__(self, mongo_config):
os.environ["MONGO_PASS"],
mechanism="SCRAM-SHA-1",
)


class MibsRepository(MongoRepository):
def __init__(self, mongo_config):
super().__init__(mongo_config)
self._mibs = self._client[mongo_config["database"]][mongo_config["collection"]]

def upload_files(self, mib_files_dir):
Expand Down Expand Up @@ -64,18 +69,9 @@ def clear(self):
self._mibs.delete_many({})


class OidsRepository:
class OidsRepository(MongoRepository):
def __init__(self, mongo_config):
self._client = pymongo.MongoClient(
os.environ["MONGO_SERVICE_SERVICE_HOST"],
int(os.environ["MONGO_SERVICE_SERVICE_PORT"]),
)
if os.environ.get("MONGO_USER"):
self._client.admin.authenticate(
os.environ["MONGO_USER"],
os.environ["MONGO_PASS"],
mechanism="SCRAM-SHA-1",
)
super().__init__(mongo_config)
self._oids = self._client[mongo_config["database"]][mongo_config["collection"]]

def contains_oid(self, oid):
Expand Down

0 comments on commit 8dab52a

Please sign in to comment.