Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/advance search #227

Merged
merged 19 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2768276
🔧refactor: aws account add filter and extra vairables params
D10S0VSkY-OSS Dec 27, 2023
cf35ff5
🔧refactor: aws add update account
D10S0VSkY-OSS Dec 28, 2023
2c605b1
🐛fix: disbale pagination cloud accounts and add edit schedule when de…
D10S0VSkY-OSS Dec 28, 2023
d9e60be
⬆ Bump: apply hotfix cloud account v3.4.1
D10S0VSkY-OSS Dec 28, 2023
ac4dacd
🔧refactor: aws backend
D10S0VSkY-OSS Dec 28, 2023
722272f
🔧refactor: aws backend activity logs
D10S0VSkY-OSS Dec 28, 2023
4411991
🔧refactor: aws ui add extra variables for new accounts
D10S0VSkY-OSS Dec 29, 2023
1244981
🔧refactor: aws update extra varibles add feature for edit key value
D10S0VSkY-OSS Dec 29, 2023
3198ed6
🔧refactor: aws update check if use by deployment
D10S0VSkY-OSS Dec 30, 2023
f95a2cc
🔧refactor: aws account repository
D10S0VSkY-OSS Dec 30, 2023
6b5b29a
🔧refactor: aws new account dashboard
D10S0VSkY-OSS Dec 30, 2023
4b915da
🔧refactor: azure backend accounts
D10S0VSkY-OSS Dec 30, 2023
88c42cb
🔧refactor: gcp backend account
D10S0VSkY-OSS Dec 30, 2023
e4c001a
🔧refactor: decrypt secrets to worker
D10S0VSkY-OSS Dec 30, 2023
115920a
🔧refactor: gcp export extra_varibles
D10S0VSkY-OSS Dec 30, 2023
89e1f5c
🔧refactor: azure export extra_varibles
D10S0VSkY-OSS Dec 30, 2023
6bc967d
🔥feat: Add advance search and extra variables cloud accounts
D10S0VSkY-OSS Dec 31, 2023
4d20e4c
🔥feat: Add advance search and extra variables cloud accounts
D10S0VSkY-OSS Dec 31, 2023
c2d65eb
Merge branch 'master' into feature/advance_search
D10S0VSkY-OSS Dec 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions sld-api-backend/src/aws/api/container/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,29 @@ async def create_new_aws_profile(
current_user: schemas_users.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.",
)
db_aws_account = crud_aws.get_squad_aws_profile(
db=db, squad=aws.squad, environment=aws.environment
filters = schemas_aws.AwsAccountFilter()
filters.squad = aws.squad
filters.environment = aws.environment
db_aws_account = await crud_aws.get_all_aws_profile(
db=db, filters=filters
)
if db_aws_account:
raise HTTPException(status_code=409, detail="Account already exists")
try:
result = crud_aws.create_aws_profile(db=db, aws=aws)
result = await 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}",
)
return {"result": f"Create AWS account {aws.squad} {aws.environment}"}
return result
except Exception as err:
raise HTTPException(status_code=400, detail=str(err))
31 changes: 21 additions & 10 deletions sld-api-backend/src/aws/api/container/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,36 @@

from src.activityLogs.infrastructure import repositories as crud_activity
from src.aws.infrastructure import repositories as crud_aws
from src.aws.domain.entities import aws as schemas_aws
from src.shared.security import deps
from src.users.domain.entities import users as schemas_users
from src.users.infrastructure import repositories as crud_users
from src.shared.domain.exeptions.in_use import ResourceInUseError


async def aws_account_by_id(
aws_account_id: int,
current_user: schemas_users.User = Depends(deps.get_current_active_user),
db: Session = Depends(deps.get_db),
):
) -> schemas_aws.AwsAsumeProfile:

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)
crud_activity.create_activity_log(
db=db,
username=current_user.username,
squad=current_user.squad,
action=f"Delete AWS account {aws_account_id}",
)
return result
filters = schemas_aws.AwsAccountFilter()
filters.id = aws_account_id
db_aws_account = await crud_aws.get_all_aws_profile(db=db, filters=filters)
if not db_aws_account:
raise HTTPException(status_code=404, detail="Account not found")
try:
result = await crud_aws.delete_aws_profile_by_id(db=db, aws_account_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}",
)
return result
except ResourceInUseError as err:
raise HTTPException(status_code=409, detail=str(err))
except Exception as err:
raise err
16 changes: 9 additions & 7 deletions sld-api-backend/src/aws/api/container/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
from sqlalchemy.orm import Session

from src.aws.infrastructure import repositories as crud_aws
from src.aws.domain.entities import aws as schemas_aws
from src.shared.security import deps
from src.users.domain.entities import users as schemas_users
from src.users.infrastructure import repositories as crud_users


async def get_all_aws_accounts(
current_user: schemas_users.User = Depends(deps.get_current_active_user),
skip: int = 0,
limit: int = 100,
db: Session = Depends(deps.get_db),
):
# Check if the user has privileges
current_user: schemas_users.User = Depends(deps.get_current_active_user),
filters: schemas_aws.AwsAccountFilter = Depends(schemas_aws.AwsAccountFilter),

) -> list[schemas_aws.AwsAccountResponse]:
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_all_aws_profile(db=db)
filters.squad = current_user.squad
return await crud_aws.get_all_aws_profile(db=db, filters=filters, skip=skip, limit=limit)
38 changes: 38 additions & 0 deletions sld-api-backend/src/aws/api/container/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from fastapi import Depends, HTTPException
from sqlalchemy.orm import Session

from src.activityLogs.infrastructure import repositories as crud_activity
from src.aws.domain.entities import aws as schemas_aws
from src.aws.infrastructure import repositories as crud_aws
from src.shared.security import deps
from src.users.domain.entities import users as schemas_users
from src.users.infrastructure import repositories as crud_users
from src.shared.domain.exeptions.in_use import ResourceInUseError


async def update_aws_account(
aws_account_id: int,
aws: schemas_aws.AwsAccountUpdate,
current_user: schemas_users.User = Depends(deps.get_current_active_user),
db: Session = Depends(deps.get_db),
) -> schemas_aws.AwsAsumeProfile:
if not crud_users.is_master(db, current_user):
raise HTTPException(status_code=403, detail="Not enough permissions")
try:
filters = schemas_aws.AwsAccountFilter()
filters.id = aws_account_id
db_aws_account = await crud_aws.get_all_aws_profile(db=db, filters=filters)
if not db_aws_account:
raise HTTPException(status_code=404, detail="Account not found")
result = await crud_aws.update_aws_profile(db=db, aws_account_id=aws_account_id, updated_aws=aws)
crud_activity.create_activity_log(
db=db,
username=current_user.username,
squad=current_user.squad,
action=f"Update AWS account {aws.squad} {aws.environment}",
)
return result
except ResourceInUseError as err:
raise HTTPException(status_code=409, detail=str(err))
except Exception as err:
raise err
15 changes: 12 additions & 3 deletions sld-api-backend/src/aws/api/v1/aws.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
from fastapi import APIRouter, Depends

from src.aws.api.container import create, delete, get
from src.aws.api.container import create, delete, get, update
from src.aws.domain.entities import aws as schemas_aws

router = APIRouter()


@router.post("/", status_code=200)
async def create_new_aws_profile(
async def create_new_aws_account(
create_aws_profile: schemas_aws.AwsAsumeProfile = Depends(
create.create_new_aws_profile
),
):
return create_aws_profile


@router.patch("/{aws_account_id}", status_code=200)
async def update_aws_account(
update_account: schemas_aws.AwsAsumeProfile = Depends(
update.update_aws_account
),
):
return update_account


@router.get("/", status_code=200, response_model=list[schemas_aws.AwsAccountResponse])
async def get_all_aws_accounts(
get_aws_profile: schemas_aws.AwsAsumeProfile = Depends(get.get_all_aws_accounts),
get_aws_profile: schemas_aws.AwsAccountResponse = Depends(get.get_all_aws_accounts),
):
return get_aws_profile

Expand Down
67 changes: 51 additions & 16 deletions sld-api-backend/src/aws/domain/entities/aws.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,70 @@
from typing import Optional
import datetime
from typing import Optional, Dict, Any

from pydantic import BaseModel, Field, constr
from pydantic import BaseModel, constr, SecretStr


class AwsBase(BaseModel):
squad: constr(strip_whitespace=True)
environment: constr(strip_whitespace=True)
access_key_id: constr(strip_whitespace=True)
secret_access_key: Optional[constr(strip_whitespace=True)] = Field(
None, example="string"
)
secret_access_key: constr(strip_whitespace=True)
default_region: constr(strip_whitespace=True)
extra_variables: Optional[Dict[str, Any]] = None

default_region: constr(strip_whitespace=True)

class AwsAsumeProfile(AwsBase):
profile_name: Optional[constr(strip_whitespace=True)] = None
role_arn: Optional[constr(strip_whitespace=True)] = None
source_profile: Optional[constr(strip_whitespace=True)] = None


class Aws(AwsBase):
id: int
class AwsId(BaseModel):
id: Optional[int] = None

class Config:
from_attributes = True

class AwsAccountResponse(BaseModel):

class AwsAccountResponseBase(BaseModel):
id: int
squad: constr(strip_whitespace=True)
environment: constr(strip_whitespace=True)
profile_name: Optional[constr(strip_whitespace=True)] = None
role_arn: Optional[constr(strip_whitespace=True)] = None
source_profile: Optional[constr(strip_whitespace=True)] = None
squad: str
environment: str
default_region: Optional[str]
role_arn: Optional[str]
created_at: Optional[datetime.datetime] = None
updated_at: Optional[datetime.datetime] = None

class Config:
from_attributes = True


class AwsAccountResponse(AwsAccountResponseBase):
extra_variables: Optional[Dict[str, SecretStr]]

class Config:
from_attributes = True


class AwsAccountResponseRepo(AwsAccountResponseBase):
access_key_id: str
secret_access_key: str
extra_variables: Optional[Dict[str, Any]] = None

class Config:
from_attributes = True


class AwsAccount(BaseModel):
squad: Optional[str] = None
environment: Optional[str] = None
default_region: Optional[str] = None
role_arn: Optional[str] = None
access_key_id: Optional[str] = None


class AwsAccountFilter(AwsAccount, AwsId):
pass


class AwsAccountUpdate(AwsAccount):
secret_access_key: Optional[str] = None
extra_variables: Optional[Dict[str, Any]] = None
6 changes: 4 additions & 2 deletions sld-api-backend/src/aws/infrastructure/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime

from config.database import Base
from sqlalchemy import Column, DateTime, Integer, String, UniqueConstraint
from sqlalchemy import Column, DateTime, Integer, String, UniqueConstraint, JSON


class Aws_provider(Base):
Expand All @@ -12,8 +12,10 @@ class Aws_provider(Base):
access_key_id = Column(String(200), nullable=False)
secret_access_key = Column(String(200), nullable=False)
default_region = Column(String(200))
profile_name = Column(String(200), nullable=False)
profile_name = Column(String(200), nullable=True)
role_arn = Column(String(200), nullable=True)
source_profile = Column(String(200), nullable=True)
extra_variables = Column(JSON, nullable=True)
created_at = Column(DateTime, default=datetime.datetime.now())
updated_at = Column(DateTime, nullable=True)
__table_args__ = (UniqueConstraint("squad", "environment"),)
Loading