Skip to content

Commit

Permalink
fix: mongo (keephq#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl authored Dec 12, 2023
1 parent cd11ff2 commit 9086303
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 36 deletions.
22 changes: 15 additions & 7 deletions keep/providers/mongodb_provider/mongodb_provider.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import dataclasses
import os

import pydantic
from pymongo import MongoClient

from keep.contextmanager.contextmanager import ContextManager
from keep.providers.base.base_provider import BaseProvider
from keep.providers.models.provider_config import ProviderConfig, ProviderScope
import pydantic
import dataclasses


@pydantic.dataclasses.dataclass
class MongoDBProviderAuthConfig:
class MongodbProviderAuthConfig:
uri: str | None = dataclasses.field(
metadata={"required": False, "description": "MongoDB connection URI"}
)
username: str = dataclasses.field(
metadata={"required": False, "description": "MongoDB username"}
)
password: str = dataclasses.field(
metadata={"required": False, "description": "MongoDB password", "sensitive": True}
metadata={
"required": False,
"description": "MongoDB password",
"sensitive": True,
}
)
host: str = dataclasses.field(
metadata={"required": False, "description": "MongoDB hostname"}
Expand All @@ -24,7 +31,8 @@ class MongoDBProviderAuthConfig:
metadata={"required": False, "description": "MongoDB database name"}
)

class MongoDBProvider(BaseProvider):

class MongodbProvider(BaseProvider):
"""Enrich alerts with data from MongoDB."""

PROVIDER_SCOPES = [
Expand Down Expand Up @@ -84,7 +92,7 @@ def validate_config(self):
"""
Validates required configuration for MongoDB's provider.
"""
self.authentication_config = MongoDBProviderAuthConfig(
self.authentication_config = MongodbProviderAuthConfig(
**self.config.authentication
)

Expand Down Expand Up @@ -121,7 +129,7 @@ def _query(
tenant_id="singletenant",
workflow_id="test",
)
mongodb_provider = MongoDBProvider(context_manager, "mongodb-prod", config)
mongodb_provider = MongodbProvider(context_manager, "mongodb-prod", config)
query = {"find": "restaurants", "limit": 5}
results = mongodb_provider.query(query=query)
print(results)
Loading

0 comments on commit 9086303

Please sign in to comment.