-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from D10S0VSkY-OSS/feature/create-stack-role-dv
Feature/create stack role dv
- Loading branch information
Showing
90 changed files
with
4,238 additions
and
3,238 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
select = C,E,F,W,B,B9 | ||
ignore = E203, E501, W503 | ||
exclude = __init__.py |
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,26 @@ | ||
#!/bin/sh -e | ||
set -x | ||
|
||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-api-backend/api_v1 --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-api-backend/config --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-api-backend/db --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-api-backend/crud --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-api-backend/core --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-api-backend/helpers --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-api-backend/schemas --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-api-backend/security --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-api-backend/tasks --exclude=__init__.py | ||
|
||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-dashboard/ --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-remote-state --exclude=__init__.py | ||
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place ../sld-schedule --exclude=__init__.py | ||
|
||
black ../sld-api-backend/ | ||
black ../sld-dashboard/ | ||
black ../sld-remote-state | ||
black ../sld-schedule | ||
|
||
isort ../sld-api-backend/ --skip=../sld-api-backend/env/ | ||
isort ../sld-dashboard/ --skip=../sld-dashboard/env/ | ||
isort ../sld-remote-state --skip=../sld-remote-state/env/ | ||
isort ../sld-schedule --skip=../sld-schedule/env/ |
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 |
---|---|---|
@@ -1,22 +1,19 @@ | ||
from api_v1.endpoints import (activity_logs, auth, aws, azure, deploy, gcp, | ||
healthy, plan, schedule, stacks, tasks, users, | ||
variables) | ||
from fastapi import APIRouter | ||
|
||
from api_v1.endpoints import users, auth, stacks | ||
from api_v1.endpoints import aws, azure, gcp | ||
from api_v1.endpoints import deploy, tasks, variables, healthy | ||
from api_v1.endpoints import activity_logs, plan, schedule | ||
|
||
|
||
api_router = APIRouter() | ||
api_router.include_router(users.router, prefix="/users", tags=["Users"]) | ||
api_router.include_router(auth.router,prefix="/authenticate",tags=["AccessToken"]) | ||
api_router.include_router(aws.router,prefix="/accounts/aws",tags=["Aws"]) | ||
api_router.include_router(gcp.router,prefix="/accounts/gcp",tags=["Gcloud"]) | ||
api_router.include_router(azure.router,prefix="/accounts/azure",tags=["Azure"]) | ||
api_router.include_router(auth.router, prefix="/authenticate", tags=["AccessToken"]) | ||
api_router.include_router(aws.router, prefix="/accounts/aws", tags=["Aws"]) | ||
api_router.include_router(gcp.router, prefix="/accounts/gcp", tags=["Gcloud"]) | ||
api_router.include_router(azure.router, prefix="/accounts/azure", tags=["Azure"]) | ||
api_router.include_router(stacks.router, prefix="/stacks", tags=["Stacks"]) | ||
api_router.include_router(plan.router, prefix="/plan", tags=["Plan"]) | ||
api_router.include_router(deploy.router, prefix="/deploy", tags=["Deploy"]) | ||
api_router.include_router(schedule.router, prefix="/schedule", tags=["Schedule"]) | ||
api_router.include_router(tasks.router, prefix="/tasks", tags=["Tasks"]) | ||
api_router.include_router(activity_logs.router, prefix="/activity", tags=["Logs"]) | ||
api_router.include_router(variables.router,prefix="/variables",tags=["Variables"]) | ||
api_router.include_router(variables.router, prefix="/variables", tags=["Variables"]) | ||
api_router.include_router(healthy.router, tags=["Healthy"]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,74 @@ | ||
from sqlalchemy.orm import Session | ||
from fastapi import APIRouter, Depends, HTTPException, Response | ||
|
||
from schemas import schemas | ||
from crud import activityLogs as crud_activity | ||
from crud import aws as crud_aws | ||
from crud import user as crud_users | ||
from crud import activityLogs as crud_activity | ||
from fastapi import APIRouter, Depends, HTTPException, Response | ||
from schemas import schemas | ||
from security import deps | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/", status_code=200) | ||
async def create_new_aws_profile( | ||
aws: schemas.AwsAsumeProfile, | ||
response: Response, | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db)): | ||
aws: schemas.AwsAsumeProfile, | ||
response: Response, | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db), | ||
): | ||
# Check if the user has privileges | ||
if not crud_users.is_master(db, current_user): | ||
raise HTTPException(status_code=403, detail="Not enough permissions") | ||
if "string" in [aws.squad, aws.environment]: | ||
raise HTTPException( | ||
status_code=409, | ||
detail="The squad or environment field must have a value that is not a string.") | ||
detail="The squad or environment field must have a value that is not a string.", | ||
) | ||
db_aws_account = crud_aws.get_squad_aws_profile( | ||
db=db, squad=aws.squad, environment=aws.environment) | ||
db=db, squad=aws.squad, environment=aws.environment | ||
) | ||
if db_aws_account: | ||
raise HTTPException( | ||
status_code=409, | ||
detail="Account already exists") | ||
raise HTTPException(status_code=409, detail="Account already exists") | ||
try: | ||
result = crud_aws.create_aws_profile(db=db, aws=aws) | ||
crud_activity.create_activity_log( | ||
db=db, | ||
username=current_user.username, | ||
squad=current_user.squad, | ||
action=f'Create AWS account {aws.squad} {aws.environment}' | ||
action=f"Create AWS account {aws.squad} {aws.environment}", | ||
) | ||
return {"result": f'Create AWS account {aws.squad} {aws.environment}'} | ||
return {"result": f"Create AWS account {aws.squad} {aws.environment}"} | ||
except Exception as err: | ||
raise HTTPException(status_code=400, detail=str(err)) | ||
|
||
|
||
@router.get("/") | ||
async def get_all_aws_accounts( | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db)): | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db), | ||
): | ||
# Check if the user has privileges | ||
if not crud_users.is_master(db, current_user): | ||
return crud_aws.get_squad_aws_profile(db=db, squad=current_user.squad, environment=None ) | ||
return crud_aws.get_squad_aws_profile( | ||
db=db, squad=current_user.squad, environment=None | ||
) | ||
return crud_aws.get_all_aws_profile(db=db) | ||
|
||
|
||
@router.delete("/{aws_account_id}") | ||
async def delete_aws_account_by_id( | ||
aws_account_id: int, | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db)): | ||
aws_account_id: int, | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db), | ||
): | ||
|
||
if not crud_users.is_master(db, current_user): | ||
raise HTTPException(status_code=403, detail="Not enough permissions") | ||
result = crud_aws.delete_aws_profile_by_id( | ||
db=db, aws_profile_id=aws_account_id) | ||
result = crud_aws.delete_aws_profile_by_id(db=db, aws_profile_id=aws_account_id) | ||
crud_activity.create_activity_log( | ||
db=db, | ||
username=current_user.username, | ||
squad=current_user.squad, | ||
action=f'Delete AWS account {aws_account_id}' | ||
action=f"Delete AWS account {aws_account_id}", | ||
) | ||
return result |
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 |
---|---|---|
@@ -1,71 +1,75 @@ | ||
from sqlalchemy.orm import Session | ||
from fastapi import APIRouter, Depends, HTTPException, Response | ||
|
||
from schemas import schemas | ||
from crud import activityLogs as crud_activity | ||
from crud import azure as crud_azure | ||
from crud import user as crud_users | ||
from crud import activityLogs as crud_activity | ||
from fastapi import APIRouter, Depends, HTTPException, Response | ||
from schemas import schemas | ||
from security import deps | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/", status_code=200) | ||
async def create_new_azure_profile( | ||
azure: schemas.AzureBase, | ||
response: Response, | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db)): | ||
azure: schemas.AzureBase, | ||
response: Response, | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db), | ||
): | ||
|
||
if not crud_users.is_master(db, current_user): | ||
raise HTTPException(status_code=403, detail="Not enough permissions") | ||
if "string" in [azure.squad, azure.environment]: | ||
raise HTTPException( | ||
status_code=409, | ||
detail="The squad or environment field must have a value that is not a string.") | ||
detail="The squad or environment field must have a value that is not a string.", | ||
) | ||
db_azure_account = crud_azure.get_squad_azure_profile( | ||
db=db, squad=azure.squad, environment=azure.environment) | ||
db=db, squad=azure.squad, environment=azure.environment | ||
) | ||
if db_azure_account: | ||
raise HTTPException( | ||
status_code=409, | ||
detail="Account already exists") | ||
raise HTTPException(status_code=409, detail="Account already exists") | ||
try: | ||
result = crud_azure.create_azure_profile(db=db, azure=azure) | ||
crud_activity.create_activity_log( | ||
db=db, | ||
username=current_user.username, | ||
squad=current_user.squad, | ||
action=f'Create Azure Account {azure.subscription_id}' | ||
action=f"Create Azure Account {azure.subscription_id}", | ||
) | ||
return {"result": f'Create Azure account {azure.squad} {azure.environment}'} | ||
return {"result": f"Create Azure account {azure.squad} {azure.environment}"} | ||
except Exception as err: | ||
raise HTTPException(status_code=400, detail=str(err)) | ||
|
||
|
||
@router.get("/") | ||
async def get_all_azure_accounts( | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db)): | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db), | ||
): | ||
if not crud_users.is_master(db, current_user): | ||
return crud_azure.get_squad_azure_profile(db=db, squad=current_user.squad, environment=None) | ||
return crud_azure.get_squad_azure_profile( | ||
db=db, squad=current_user.squad, environment=None | ||
) | ||
return crud_azure.get_all_azure_profile(db=db) | ||
|
||
|
||
@router.delete("/{azure_account_id}") | ||
async def delete_azure_account_by_id( | ||
azure_account_id: int, | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db)): | ||
azure_account_id: int, | ||
current_user: schemas.User = Depends(deps.get_current_active_user), | ||
db: Session = Depends(deps.get_db), | ||
): | ||
|
||
if not crud_users.is_master(db, current_user): | ||
raise HTTPException(status_code=403, detail="Not enough permissions") | ||
result = crud_azure.delete_azure_profile_by_id( | ||
db=db, azure_profile_id=azure_account_id) | ||
db=db, azure_profile_id=azure_account_id | ||
) | ||
crud_activity.create_activity_log( | ||
db=db, | ||
username=current_user.username, | ||
squad=current_user.squad, | ||
action=f'Delete Azure account {azure_account_id}' | ||
action=f"Delete Azure account {azure_account_id}", | ||
) | ||
return result |
Oops, something went wrong.