| 1 | from typing import List |
| 2 | from typing import Optional |
| 3 | |
| 4 | from pydantic import BaseModel |
| 5 | from pydantic import ConfigDict |
| 6 | from pydantic import Field |
| 7 | |
| 8 | |
| 9 | class AuthKey(BaseModel): |
| 10 | auth_key_name: str |
| 11 | |
| 12 | |
| 13 | class IntegrationWithAuthKeys(BaseModel): |
| 14 | id: int |
| 15 | integration_name: str |
| 16 | description: str |
| 17 | integration_details: str |
| 18 | auth_keys: List[AuthKey] |
| 19 | |
| 20 | |
| 21 | class AvailableIntegrationsResponse(BaseModel): |
| 22 | available_integrations: List[IntegrationWithAuthKeys] |
| 23 | message: str |
| 24 | success: bool |
| 25 | |
| 26 | |
| 27 | class CreateIntegrationService(BaseModel): |
| 28 | auth_type: str = Field( |
| 29 | ..., |
| 30 | description="The authentication type.", |
| 31 | examples=["OAuth"], |
| 32 | ) |
| 33 | config_key: str = Field( |
| 34 | ..., |
| 35 | description="The configuration key.", |
| 36 | examples=["endpoint"], |
| 37 | ) |
| 38 | config_value: str = Field( |
| 39 | ..., |
| 40 | description="The configuration value.", |
| 41 | examples=["https://api.mimecast.com"], |
| 42 | ) |
| 43 | |
| 44 | |
| 45 | class CreateIntegrationAuthKeys(BaseModel): |
| 46 | auth_key_name: str = Field( |
| 47 | ..., |
| 48 | description="The auth key.", |
| 49 | examples=["username"], |
| 50 | ) |
| 51 | auth_value: str = Field( |
| 52 | ..., |
| 53 | description="The auth value.", |
| 54 | examples=["test-user"], |
| 55 | ) |
| 56 | |
| 57 | |
| 58 | class CustomerIntegrationCreate(BaseModel): |
| 59 | customer_code: str = Field( |
| 60 | ..., |
| 61 | description="The customer code.", |
| 62 | examples=["00002"], |
| 63 | ) |
| 64 | customer_name: str = Field( |
| 65 | ..., |
| 66 | description="The customer name.", |
| 67 | examples=["SOCFortress"], |
| 68 | ) |
| 69 | integration_name: str = Field( |
| 70 | ..., |
| 71 | description="The integration name.", |
| 72 | examples=["Mimecast"], |
| 73 | ) |
| 74 | integration_config: CreateIntegrationService = Field( |
| 75 | ..., |
| 76 | description="The integration service.", |
| 77 | ) |
| 78 | # integration_auth_key: CreateIntegrationAuthKeys = Field( |
| 79 | # ..., |
| 80 | # description="The integration metadata.", |
| 81 | # ) |
| 82 | integration_auth_keys: List[CreateIntegrationAuthKeys] = Field( |
| 83 | ..., |
| 84 | description="The integration auth keys.", |
| 85 | ) |
| 86 | |
| 87 | |
| 88 | class CustomerIntegrationCreateResponse(BaseModel): |
| 89 | message: str = Field( |
| 90 | ..., |
| 91 | description="The message.", |
| 92 | ) |
| 93 | success: bool = Field( |
| 94 | ..., |
| 95 | description="The success status.", |
| 96 | ) |
| 97 | additional_info: Optional[str] = Field( |
| 98 | None, |
| 99 | description="The additional information of manaul steps that need to be performed for the integration.", |
| 100 | ) |
| 101 | |
| 102 | |
| 103 | class CustomerIntegrationDeleteResponse(BaseModel): |
| 104 | message: str = Field( |
| 105 | ..., |
| 106 | description="The message.", |
| 107 | ) |
| 108 | success: bool = Field( |
| 109 | ..., |
| 110 | description="The success status.", |
| 111 | ) |
| 112 | additional_info: Optional[str] = Field( |
| 113 | None, |
| 114 | description="The additional information of manaul steps that need to be performed for the integration.", |
| 115 | ) |
| 116 | |
| 117 | |
| 118 | # class IntegrationConfig(BaseModel): |
| 119 | # config_id: int |
| 120 | # config_value: str |
| 121 | # config_key: str |
| 122 | |
| 123 | # class IntegrationService(BaseModel): |
| 124 | # auth_type: str |
| 125 | # service_name: str |
| 126 | # id: int |
| 127 | |
| 128 | # class IntegrationSubscription(BaseModel): |
| 129 | # id: int |
| 130 | # customer_id: int |
| 131 | # integration_service_id: int |
| 132 | # integration_service: IntegrationService |
| 133 | # integration_config: IntegrationConfig |
| 134 | |
| 135 | # class CustomerIntegrations(BaseModel): |
| 136 | # customer_code: str |
| 137 | # id: int |
| 138 | # customer_name: str |
| 139 | # integration_subscriptions: List[IntegrationSubscription] |
| 140 | |
| 141 | # class CustomerIntegrationsResponse(BaseModel): |
| 142 | # available_integrations: List[CustomerIntegrations] |
| 143 | # message: str |
| 144 | # success: bool |
| 145 | |
| 146 | |
| 147 | class IntegrationAuthKeys(BaseModel): |
| 148 | id: int |
| 149 | auth_key_name: str |
| 150 | auth_value: str |
| 151 | subscription_id: int |
| 152 | |
| 153 | model_config = ConfigDict(from_attributes=True) |
| 154 | |
| 155 | |
| 156 | class IntegrationService(BaseModel): |
| 157 | auth_type: str |
| 158 | service_name: str |
| 159 | id: int |
| 160 | |
| 161 | model_config = ConfigDict(from_attributes=True) |
| 162 | |
| 163 | |
| 164 | class IntegrationSubscription(BaseModel): |
| 165 | id: int |
| 166 | customer_id: int |
| 167 | integration_service_id: int |
| 168 | integration_service: IntegrationService |
| 169 | integration_auth_keys: List[IntegrationAuthKeys] # Changed from IntegrationConfig |
| 170 | |
| 171 | model_config = ConfigDict(from_attributes=True) |
| 172 | |
| 173 | |
| 174 | class CustomerIntegrations(BaseModel): |
| 175 | customer_code: str |
| 176 | id: int |
| 177 | customer_name: str |
| 178 | integration_subscriptions: List[IntegrationSubscription] |
| 179 | integration_service_id: Optional[int] = Field( |
| 180 | None, |
| 181 | description="The integration service id.", |
| 182 | examples=[1], |
| 183 | ) |
| 184 | integration_service_name: Optional[str] = Field( |
| 185 | ..., |
| 186 | description="The integration service name.", |
| 187 | examples=["Mimecast"], |
| 188 | ) |
| 189 | deployed: Optional[bool] = Field( |
| 190 | None, |
| 191 | description="The deployment status.", |
| 192 | examples=[True], |
| 193 | ) |
| 194 | |
| 195 | model_config = ConfigDict(from_attributes=True) |
| 196 | |
| 197 | |
| 198 | class CustomerIntegrationsResponse(BaseModel): |
| 199 | available_integrations: List[CustomerIntegrations] |
| 200 | message: str |
| 201 | success: bool |
| 202 | |
| 203 | |
| 204 | class DeleteCustomerIntegration(BaseModel): |
| 205 | customer_code: str = Field( |
| 206 | ..., |
| 207 | description="The customer code.", |
| 208 | examples=["00002"], |
| 209 | ) |
| 210 | integration_name: str = Field( |
| 211 | ..., |
| 212 | description="The integration name.", |
| 213 | examples=["Mimecast"], |
| 214 | ) |
| 215 | |
| 216 | |
| 217 | class UpdateCustomerIntegration(BaseModel): |
| 218 | integration_name: str = Field( |
| 219 | ..., |
| 220 | description="The integration name.", |
| 221 | examples=["Mimecast"], |
| 222 | ) |
| 223 | integration_auth_keys: List[CreateIntegrationAuthKeys] = Field( |
| 224 | ..., |
| 225 | description="The integration auth keys.", |
| 226 | ) |
| 227 | |
| 228 | |
| 229 | class CustomerIntegrationsMetaSchema(BaseModel): |
| 230 | id: Optional[int] = None |
| 231 | customer_code: str |
| 232 | integration_name: str |
| 233 | graylog_input_id: Optional[str] = None |
| 234 | graylog_index_id: str |
| 235 | graylog_stream_id: str |
| 236 | grafana_org_id: str |
| 237 | grafana_dashboard_folder_id: str |
| 238 | grafana_datasource_uid: Optional[str] = None |
| 239 | model_config = ConfigDict(from_attributes=True) |
| 240 | |
| 241 | |
| 242 | class CustomerIntegrationsMetaResponse(BaseModel): |
| 243 | message: str |
| 244 | success: bool |
| 245 | customer_integrations_meta: Optional[List[CustomerIntegrationsMetaSchema]] = Field( |
| 246 | None, |
| 247 | description="The customer integrations metadata.", |
| 248 | ) |
| 249 | |
| 250 | |
| 251 | class CustomerByAuthKeyResponse(BaseModel): |
| 252 | """ |
| 253 | Response model for the get_customer_by_auth_key endpoint. |
| 254 | """ |
| 255 | |
| 256 | customer_code: str |
| 257 | customer_name: str |
| 258 | integration_name: str |
| 259 | auth_key_name: str |
| 260 | success: bool = True |
| 261 | message: str = "Customer found successfully." |
| 262 | |
| 263 | |
| 264 | class UpdateMetaAutoRequest(BaseModel): |
| 265 | customer_code: str = Field(..., description="Customer code identifier") |
| 266 | integration_name: str = Field(..., description="Integration or network connector name") |
| 267 | graylog_input_id: Optional[str] = Field(None, description="Graylog input ID") |
| 268 | graylog_index_id: Optional[str] = Field(None, description="Graylog index ID") |
| 269 | graylog_stream_id: Optional[str] = Field(None, description="Graylog stream ID") |
| 270 | graylog_pipeline_id: Optional[str] = Field(None, description="Graylog pipeline ID (network connectors only)") |
| 271 | graylog_content_pack_input_id: Optional[str] = Field(None, description="Graylog content pack input ID (network connectors only)") |
| 272 | graylog_content_pack_stream_id: Optional[str] = Field(None, description="Graylog content pack stream ID (network connectors only)") |
| 273 | grafana_org_id: Optional[str] = Field(None, description="Grafana organization ID") |
| 274 | grafana_dashboard_folder_id: Optional[str] = Field(None, description="Grafana dashboard folder ID") |
| 275 | grafana_datasource_uid: Optional[str] = Field(None, description="Grafana datasource UID (network connectors only)") |
| 276 | |
| 277 | |
| 278 | class UpdateMetaResponse(BaseModel): |
| 279 | success: bool |
| 280 | message: str |