This repository has been archived by the owner on May 1, 2023. It is now read-only.
generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactored to organize routes and client (#106)
* chore: refactored to organize routes and client * chore: bandit scan and linting fixes * fix: script permissions
- Loading branch information
Showing
16 changed files
with
164 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Source code security scan using Bandit | ||
on: | ||
pull_request: | ||
paths: | ||
- "**/*.py" | ||
|
||
jobs: | ||
bandit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Bandit | ||
run: | | ||
.github/workflows/scripts/run_bandit_scan.sh | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
# Make sure we are using the latest version | ||
docker pull cytopia/bandit:latest | ||
|
||
# Scan source code and only report on high severity issues | ||
docker run --rm -v "$(pwd)":/data cytopia/bandit -r /data -ll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from os import environ | ||
from fastapi import FastAPI | ||
|
||
from front_end import view | ||
from .routers import ops, organisations, scans | ||
|
||
if "DEV_ENVIRONMENT" in environ: | ||
app = FastAPI() | ||
else: | ||
# This is only needed until a dedicated domain name is live | ||
app = FastAPI(root_path="/v1") | ||
|
||
app.include_router(ops.router, prefix="/ops", tags=["ops"]) | ||
app.include_router( | ||
organisations.router, | ||
prefix="/organisations", | ||
tags=["organisations"], | ||
) | ||
app.include_router(scans.router, prefix="/scans", tags=["scans"]) | ||
app.include_router(view.router) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from os import environ | ||
from fastapi import APIRouter, Depends | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.orm import Session | ||
from database.db import db_session | ||
from logger import log | ||
|
||
router = APIRouter() | ||
|
||
|
||
# Dependency | ||
def get_db(): | ||
db = db_session() | ||
try: | ||
yield db | ||
finally: | ||
db.close() | ||
|
||
|
||
@router.get("/version") | ||
def version(): | ||
return {"version": environ.get("GIT_SHA", "unknown")} | ||
|
||
|
||
def get_db_version(session): | ||
|
||
query = "SELECT version_num FROM alembic_version" | ||
full_name = session.execute(query).fetchone()[0] | ||
return full_name | ||
|
||
|
||
@router.get("/healthcheck") | ||
def healthcheck(session: Session = Depends(get_db)): | ||
try: | ||
full_name = get_db_version(session) | ||
db_status = {"able_to_connect": True, "db_version": full_name} | ||
except SQLAlchemyError as err: | ||
log.error(err) | ||
db_status = {"able_to_connect": False} | ||
|
||
return {"database": db_status} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from fastapi import APIRouter, Depends, Response, status | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.orm import Session | ||
from fastapi.responses import RedirectResponse | ||
from database.db import db_session | ||
from logger import log | ||
|
||
from models.Organisation import Organisation | ||
from schemas.Organization import OrganizationCreate | ||
|
||
router = APIRouter() | ||
|
||
|
||
# Dependency | ||
def get_db(): | ||
db = db_session() | ||
try: | ||
yield db | ||
finally: | ||
db.close() | ||
|
||
|
||
# TODO Require auth and redirect to home | ||
# TODO Push errors to cloudwatch metric and response when debug enabled | ||
@router.post("/create", response_class=RedirectResponse) | ||
def create_organisation( | ||
organisation: OrganizationCreate, | ||
response: Response, | ||
session: Session = Depends(get_db), | ||
): | ||
|
||
try: | ||
new_organisation = Organisation(name=organisation.name) | ||
session.add(new_organisation) | ||
session.commit() | ||
return RedirectResponse("/dashboard") | ||
except SQLAlchemyError as err: | ||
log.error(err) | ||
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR | ||
return {"error": f"error creating organisation: {err}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from fastapi import APIRouter | ||
from logger import log | ||
from pydantic import BaseModel | ||
from crawler.crawler import crawl | ||
import uuid | ||
|
||
router = APIRouter() | ||
|
||
|
||
class CrawlUrl(BaseModel): | ||
url: str | ||
|
||
|
||
@router.post("/crawl") | ||
def crawl_endpoint(crawl_url: CrawlUrl): | ||
log.info(f"Crawling {crawl_url}") | ||
crawl(uuid.uuid4(), crawl_url.url) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters