| 1 | from enum import Enum |
| 2 | from typing import List |
| 3 | |
| 4 | from fastapi import HTTPException |
| 5 | from pydantic import BaseModel |
| 6 | from pydantic import Field |
| 7 | from pydantic import model_validator |
| 8 | |
| 9 | |
| 10 | class ScoutSuiteReportOptions(str, Enum): |
| 11 | aws = "aws" |
| 12 | azure = "azure" |
| 13 | gcp = "gcp" |
| 14 | |
| 15 | |
| 16 | class ScoutSuiteReportOptionsResponse(BaseModel): |
| 17 | options: List[ScoutSuiteReportOptions] = Field( |
| 18 | ..., |
| 19 | description="The available report generation options", |
| 20 | examples=[["aws", "azure", "gcp"]], |
| 21 | ) |
| 22 | success: bool |
| 23 | message: str |
| 24 | |
| 25 | |
| 26 | class AWSScoutSuiteReportRequest(BaseModel): |
| 27 | report_type: str = Field(..., description="The type of report to generate", examples=["aws"]) |
| 28 | access_key_id: str = Field(..., description="The AWS access key ID", examples=["AKIAIOSFODNN7EXAMPLE"]) |
| 29 | secret_access_key: str = Field(..., description="The AWS secret access key", examples=["wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"]) |
| 30 | report_name: str = Field(..., description="The name of the report", examples=["aws-report"]) |
| 31 | |
| 32 | @model_validator(mode="after") |
| 33 | def validate_report_type(self): |
| 34 | if self.report_type != ScoutSuiteReportOptions.aws: |
| 35 | raise HTTPException(status_code=400, detail="Invalid report type.") |
| 36 | return self |
| 37 | |
| 38 | |
| 39 | class AzureScoutSuiteReportRequest(BaseModel): |
| 40 | report_type: str = Field(..., description="The type of report to generate", examples=["azure"]) |
| 41 | username: str = Field(..., description="The username used to auth to Azure", examples=["scoutsuite@socfortress.co"]) |
| 42 | password: str = Field(..., description="The password used to auth to Azure", examples=["EXAMPLE_PASSWORD"]) |
| 43 | tenant_id: str = Field(..., description="The tenant ID used to auth to Azure", examples=["EXAMPLE_TENANT_ID"]) |
| 44 | report_name: str = Field(..., description="The name of the report", examples=["aws-report"]) |
| 45 | |
| 46 | @model_validator(mode="after") |
| 47 | def validate_report_type(self): |
| 48 | if self.report_type != ScoutSuiteReportOptions.azure: |
| 49 | raise HTTPException(status_code=400, detail="Invalid report type.") |
| 50 | return self |
| 51 | |
| 52 | |
| 53 | class GCPScoutSuiteReportRequest(BaseModel): |
| 54 | report_name: str = Field(..., description="The name of the report", examples=["gcp-report"]) |
| 55 | file_path: str = Field(..., description="The path to the GCP credentials file", examples=["gcp-credentials.json"]) |
| 56 | |
| 57 | |
| 58 | class GCPScoutSuiteJSON(BaseModel): |
| 59 | type: str |
| 60 | project_id: str |
| 61 | private_key_id: str |
| 62 | private_key: str |
| 63 | client_email: str |
| 64 | client_id: str |
| 65 | auth_uri: str |
| 66 | token_uri: str |
| 67 | auth_provider_x509_cert_url: str |
| 68 | client_x509_cert_url: str |
| 69 | universe_domain: str |
| 70 | |
| 71 | |
| 72 | class ScoutSuiteReportResponse(BaseModel): |
| 73 | success: bool |
| 74 | message: str |
| 75 | |
| 76 | |
| 77 | class AvailableScoutSuiteReportsResponse(BaseModel): |
| 78 | success: bool |
| 79 | message: str |
| 80 | available_reports: List[str] |