Skip to content

Commit d55b77e

Browse files
Mpt 14598 api modifier remove validation for cloud providers configuration (#40)
* [WIP] Add initial logic for managing DataSources. Move the service's APIs and files to the API folder. Add Custom Exceptions to handle DataSources errors * [MPT-14598] - Remove verification for Cloud Account conf. Adjust tests
1 parent 0f36382 commit d55b77e

28 files changed

+540
-1195
lines changed

app/api/cloud_account/cloud_accounts_conf/__init__.py

Whitespace-only changes.

app/api/cloud_account/cloud_accounts_conf/aws.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/api/cloud_account/cloud_accounts_conf/azure.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/api/cloud_account/cloud_accounts_conf/cloud_config_strategy.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

app/api/cloud_account/cloud_accounts_conf/gcp.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/api/cloud_account/cloud_accounts_manager.py

Lines changed: 0 additions & 168 deletions
This file was deleted.

app/api/invitations/model.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from __future__ import annotations
22

3-
from pydantic import BaseModel, ConfigDict, EmailStr, constr
3+
from typing import Annotated
4+
5+
from pydantic import BaseModel, ConfigDict, EmailStr, StringConstraints
46

57

68
class RegisterInvitedUser(BaseModel):
79
email: EmailStr
810
display_name: str
9-
password: constr(min_length=8)
11+
password: Annotated[str, StringConstraints(min_length=8)]
1012
model_config = ConfigDict(
1113
json_schema_extra={
1214
"example": [

app/api/organizations/api.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,13 @@ async def link_cloud_account(
117117
try:
118118
# here, we need to validate the bearer token to ensure that any authorization
119119
# related errors will be checked first. In case of an invalid/expired token,
120-
# an APIResponseError with a http statu 401 will re raised
120+
# an APIResponseError with an http status 401 will be raised
121121

122122
await auth_client.check_user_allowed_to_create_cloud_account(
123123
bearer_token=user_access_token, org_id=org_id
124124
)
125125
response = await link_cloud_account_to_org(
126-
name=data.name,
127-
type=data.type,
128-
config=data.config,
129-
process_recommendations=data.process_recommendations,
130-
auto_import=data.auto_import,
126+
cloud_account_data=data.model_dump(),
131127
org_id=org_id,
132128
user_access_token=user_access_token,
133129
)
Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
import logging
22

3-
from app.api.cloud_account.cloud_accounts_manager import (
4-
CloudStrategyConfiguration,
5-
CloudStrategyManager,
6-
)
3+
from app.core.exceptions import CloudAccountNotAllowed
4+
from app.optscale_api.cloud_accounts import OptScaleCloudAccountAPI
75

86
logger = logging.getLogger("__name__")
7+
ALLOWED_PROVIDERS = ["aws_cnr", "gcp_cnr", "azure_cnr", "azure_tenant"]
98

109

1110
async def link_cloud_account_to_org(
12-
name: str,
13-
type: str,
14-
config: dict,
15-
process_recommendations: bool,
16-
auto_import: bool,
11+
cloud_account_data: dict,
1712
org_id: str,
1813
user_access_token: str,
1914
):
2015
"""
2116
22-
:param name: The name of the Cloud Account
23-
:param type: One of the Cloud Account allowed types
24-
:param config: The whole config of the given Cloud Account
25-
:param process_recommendations: a value required by OptScale
26-
:param auto_import: a value required by OptScale
17+
:param cloud_account_data: The whole config of the given Cloud Account
18+
{
19+
"name":"Test2",
20+
"type":"azure_tenasssssssssnt",
21+
"config":{
22+
"client_id":"cd945f4b-0554-4a16-9a09-96a2f30bc0ef",
23+
"tenant":"1dc9b339-fadb-432e-86df-423c38a0fcb8",
24+
"secret":"QOt8Q~r.ZkpDN1p2cFsYTCQFDtbB8pzzm6xxydlA"
25+
},
26+
"auto_import": false,
27+
"process_recommendations": false
28+
}
2729
:param org_id: The org ID to link the Cloud Account to
2830
:param user_access_token: The user's access token the org belongs to
2931
:return: If the given cloud account is linked, a dict like this one will be returned
@@ -57,23 +59,18 @@ async def link_cloud_account_to_org(
5759
Rethrow APIResponseError if an error occurred during the communication with the
5860
OptScale API.
5961
"""
60-
# Here the config as received is validated
61-
cloud_account_config = CloudStrategyConfiguration(
62-
name=name,
63-
provider_type=type,
64-
config=config,
65-
process_recommendations=process_recommendations,
66-
auto_import=auto_import,
67-
)
6862

69-
# let's select the correct strategy for the given cloud account
70-
cloud_account_strategy = cloud_account_config.select_strategy()
71-
strategy_manager = CloudStrategyManager(strategy=cloud_account_strategy)
72-
# here the conf will be processed in order to use the OptScale API
73-
response = await strategy_manager.add_cloud_account(
74-
config=cloud_account_config,
63+
if cloud_account_data["type"] not in ALLOWED_PROVIDERS:
64+
raise CloudAccountNotAllowed()
65+
optscale_cloud_account_api = OptScaleCloudAccountAPI()
66+
response = await optscale_cloud_account_api.link_cloud_account_with_org(
67+
user_access_token=user_access_token, # noqa: E501
7568
org_id=org_id,
76-
user_access_token=user_access_token,
69+
conf=cloud_account_data,
70+
)
71+
datasource_type = cloud_account_data["type"]
72+
73+
logger.info(
74+
f"The Cloud Account {datasource_type} has been added to the org {org_id}"
7775
)
78-
logger.info(f"The Cloud Account {type} has been linked to the org {org_id}")
7976
return response

app/core/auth_jwt_bearer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from typing import Optional
32

43
import jwt
54
from fastapi import Request
@@ -26,7 +25,7 @@
2625
logger = logging.getLogger(__name__)
2726

2827

29-
def decode_jwt(token: str) -> Optional[dict]: # noqa: UP007
28+
def decode_jwt(token: str) -> dict | None:
3029
"""
3130
Decodes a JWT token and validates its critical claims,
3231
including time-based and issuer/audience claims.

0 commit comments

Comments
 (0)