Skip to content

Commit

Permalink
updated infra folder structure to account for org_mgmt vs child_accou…
Browse files Browse the repository at this point in the history
…nts separate cloudformation templates
  • Loading branch information
righteousgambit committed Jun 30, 2024
1 parent 8a98731 commit d7ff72b
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 41 deletions.
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions infra/org_mgmt_account/api/app/config/connections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import boto3
from botocore.exceptions import NoCredentialsError, PartialCredentialsError

class AWSConnections:
def __init__(self, region_name: str = "us-east-1"):
self.region_name = region_name
self.sqs_client = None
self.dynamodb_client = None

def create_sqs_client(self):
try:
self.sqs_client = boto3.client('sqs', region_name=self.region_name)
print("SQS client created successfully")
except (NoCredentialsError, PartialCredentialsError) as e:
print(f"Error creating SQS client: {e}")

def create_dynamodb_client(self):
try:
self.dynamodb_client = boto3.client('dynamodb', region_name=self.region_name)
print("DynamoDB client created successfully")
except (NoCredentialsError, PartialCredentialsError) as e:
print(f"Error creating DynamoDB client: {e}")

def get_sqs_client(self):
if not self.sqs_client:
self.create_sqs_client()
return self.sqs_client

def get_dynamodb_client(self):
if not self.dynamodb_client:
self.create_dynamodb_client()
return self.dynamodb_client

aws_connections = AWSConnections()
20 changes: 20 additions & 0 deletions infra/org_mgmt_account/api/app/config/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import logging

def configure_logging():
# Define the logging configuration
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[
logging.StreamHandler()
]
)

# Create a logger instance
logger = logging.getLogger("quiet_riot")
return logger

# Example usage
if __name__ == "__main__":
logger = configure_logging()
logger.info("Logging is configured.")
53 changes: 12 additions & 41 deletions infra/org_mgmt_account/api/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import os
from pathlib import Path
from typing import Any, Dict, List, Optional, Union

from fastapi import FastAPI
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from typing import List, Union
from enum import Enum
from config.logging import configure_logging
from config.connections import AWSConnections, aws_connections
from routers import query, live

# Using the AWSConnections class to create SQS and DynamoDB clients
sqs_client = aws_connections.get_sqs_client()
dynamodb_client = aws_connections.get_dynamodb_client()

app = FastAPI(
title="Quiet Riot",
Expand All @@ -27,42 +30,10 @@
openapi_url="/openapi.json"
)

class PrincipalType(str, Enum):
AWS_ACCOUNT_IDS = "AWS Account IDs"
MICROSOFT_365_DOMAINS = "Microsoft 365 Domains"
AWS_SERVICES_FOOTPRINTING = "AWS Services Footprinting"
AWS_ROOT_USER_EMAIL_ADDRESS = "AWS Root User E-mail Address"
AWS_IAM_PRINCIPALS = "AWS IAM Principals"
IAM_ROLES = "IAM Roles"
IAM_USERS = "IAM Users"
MICROSOFT_365_USERS = "Microsoft 365 Users (e-mails)"
GOOGLE_WORKSPACE_USERS = "Google Workspace Users (e-mails)"

class QueryRequest(BaseModel):
principal_type: PrincipalType
principal_value: str

class BulkQueryRequest(BaseModel):
principal_values: List[str]

@app.get("/live")
async def live():
return {"status": "alive"}

@app.post("/query")
async def query(request: QueryRequest):
# Placeholder for actual query logic
if not request.principal_value:
raise HTTPException(status_code=400, detail="Invalid principal value")
return {"principal_type": request.principal_type, "principal_value": request.principal_value, "status": "queried"}

@app.post("/bulk-query")
async def bulk_query(request: BulkQueryRequest):
# Placeholder for actual bulk query logic
if not request.principal_values:
raise HTTPException(status_code=400, detail="Invalid principal values")
return {"principal_values": request.principal_values, "status": "bulk queried"}
# Include the routers
app.include_router(query.router)
app.include_router(live.router)

if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=3000)
uvicorn.run(app, host="0.0.0.0", port=8000)
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions infra/org_mgmt_account/api/app/routers/live.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from fastapi import APIRouter
from enum import Enum

router = APIRouter()

@router.get("/live")
async def live():
return {"status": "alive"}
45 changes: 45 additions & 0 deletions infra/org_mgmt_account/api/app/routers/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from fastapi import APIRouter
from enum import Enum
from pydantic import BaseModel
from typing import List, Union

router = APIRouter()

class PrincipalType(str, Enum):
AWS_ACCOUNT_IDS = "AWS Account IDs"
MICROSOFT_365_DOMAINS = "Microsoft 365 Domains"
AWS_SERVICES_FOOTPRINTING = "AWS Services Footprinting"
AWS_ROOT_USER_EMAIL_ADDRESS = "AWS Root User E-mail Address"
AWS_IAM_PRINCIPALS = "AWS IAM Principals"
IAM_ROLES = "IAM Roles"
IAM_USERS = "IAM Users"
MICROSOFT_365_USERS = "Microsoft 365 Users (e-mails)"
GOOGLE_WORKSPACE_USERS = "Google Workspace Users (e-mails)"


class QueryRequest(BaseModel):
principal_type: PrincipalType
principal_value: str


class BulkQueryRequest(BaseModel):
principal_values: List[str]

@router.post("/query")
async def query(request: QueryRequest):
# Placeholder for actual query logic
if not request.principal_value:
raise HTTPException(status_code=400, detail="Invalid principal value")
return {
"principal_type": request.principal_type,
"principal_value": request.principal_value,
"status": "queried",
}


@router.post("/bulk-query")
async def bulk_query(request: BulkQueryRequest):
# Placeholder for actual bulk query logic
if not request.principal_values:
raise HTTPException(status_code=400, detail="Invalid principal values")
return {"principal_values": request.principal_values, "status": "bulk queried"}

0 comments on commit d7ff72b

Please sign in to comment.