get customer provisioning details
Taylor committed
Dec 12, 2023 at 17:41 UTC
32416b89c4cf65566c27c5a893cfbf9fe14b2efb
2 files changed
+59
backend/app/customer_provisioning/routes/provision.py
+47
@@ -8,7 +8,12 @@ from sqlalchemy.ext.asyncio import AsyncSession
8
from sqlalchemy.future import select
9
10
from app.auth.utils import AuthHandler
11
+from app.connectors.grafana.schema.dashboards import Office365Dashboard
12
+from app.connectors.grafana.schema.dashboards import WazuhDashboard
13
from app.customer_provisioning.schema.provision import CustomerProvisionResponse
14
+from app.customer_provisioning.schema.provision import CustomerSubsctipion
15
+from app.customer_provisioning.schema.provision import GetDashboardsResponse
16
+from app.customer_provisioning.schema.provision import GetSubscriptionsResponse
17
from app.customer_provisioning.schema.provision import ProvisionNewCustomer
18
from app.customer_provisioning.services.provision import provision_wazuh_customer
19
from app.db.db_session import get_session
@@ -20,6 +25,22 @@ from app.db.universal_models import Customers
25
customer_provisioning_router = APIRouter()
26
27
28
+def get_available_dashboards():
29
+ try:
30
+ wazuh_dashboards = [dashboard.name for dashboard in WazuhDashboard]
31
+ office365_dashboards = [dashboard.name for dashboard in Office365Dashboard]
32
+ return wazuh_dashboards + office365_dashboards
33
+ except Exception as e:
34
+ raise HTTPException(status_code=500, detail=f"Error getting available dashboards: {e}")
35
+
36
+
37
+def get_available_subscriptions():
38
+ try:
39
+ return [subscription.value for subscription in CustomerSubsctipion]
40
+ except Exception as e:
41
+ raise HTTPException(status_code=500, detail=f"Error getting available subscriptions: {e}")
42
+
43
+
44
async def check_customer_exists(customer_name: str, session: AsyncSession = Depends(get_session)) -> Customers:
45
logger.info(f"Checking if customer {customer_name} exists")
46
result = await session.execute(select(Customers).filter(Customers.customer_name == customer_name))
@@ -45,3 +66,29 @@ async def provision_customer_route(
66
logger.info("Provisioning new customer")
67
customer_provision = await provision_wazuh_customer(request, session=session)
68
return customer_provision
69
+
70
+
71
+@customer_provisioning_router.get(
72
+ "/provision/dashboards",
73
+ response_model=GetDashboardsResponse,
74
+ description="Return the list of dashboards available for provisioning",
75
+ dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))],
76
+)
77
+async def get_dashboards_route():
78
+ logger.info("Getting list of dashboards")
79
+ available_dashboards = get_available_dashboards()
80
+ return GetDashboardsResponse(available_dashboards=available_dashboards, success=True, message="Dashboards retrieved successfully")
81
+
82
+
83
+@customer_provisioning_router.get(
84
+ "/provision/subscriptions",
85
+ response_model=GetSubscriptionsResponse,
86
+ description="Return the list of subscriptions available for provisioning",
87
+ dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))],
88
+)
89
+async def get_subscriptions_route():
90
+ logger.info("Getting list of subscriptions")
91
+ available_subscriptions = get_available_subscriptions()
92
+ return GetSubscriptionsResponse(
93
+ available_subscriptions=available_subscriptions, success=True, message="Subscriptions retrieved successfully",
94
+ )
backend/app/customer_provisioning/schema/provision.py
+12
@@ -71,3 +71,15 @@ class CustomerProvisionResponse(BaseModel):
71
success: bool = Field(..., description="Whether the customer provisioning process was successful or not")
72
customer_meta: CustomersMeta = Field(..., description="Customer meta data for the newly provisioned customer")
73
wazuh_worker_provisioned: Optional[bool] = Field(None, description="Whether the Wazuh worker was provisioned successfully")
74
+
75
+
76
+class GetDashboardsResponse(BaseModel):
77
+ available_dashboards: List[str] = Field(..., description="List of dashboards available for provisioning")
78
+ message: str = Field(..., description="Message indicating the status of the request")
79
+ success: bool = Field(..., description="Whether the request was successful or not")
80
+
81
+
82
+class GetSubscriptionsResponse(BaseModel):
83
+ available_subscriptions: List[str] = Field(..., description="List of subscriptions available for provisioning")
84
+ message: str = Field(..., description="Message indicating the status of the request")
85
+ success: bool = Field(..., description="Whether the request was successful or not")