|
1 | 1 | import logging |
2 | 2 |
|
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 |
7 | 5 |
|
8 | 6 | logger = logging.getLogger("__name__") |
| 7 | +ALLOWED_PROVIDERS = ["aws_cnr", "gcp_cnr", "azure_cnr", "azure_tenant"] |
9 | 8 |
|
10 | 9 |
|
11 | 10 | 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, |
17 | 12 | org_id: str, |
18 | 13 | user_access_token: str, |
19 | 14 | ): |
20 | 15 | """ |
21 | 16 |
|
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 | + } |
27 | 29 | :param org_id: The org ID to link the Cloud Account to |
28 | 30 | :param user_access_token: The user's access token the org belongs to |
29 | 31 | :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( |
57 | 59 | Rethrow APIResponseError if an error occurred during the communication with the |
58 | 60 | OptScale API. |
59 | 61 | """ |
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 | | - ) |
68 | 62 |
|
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 |
75 | 68 | 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}" |
77 | 75 | ) |
78 | | - logger.info(f"The Cloud Account {type} has been linked to the org {org_id}") |
79 | 76 | return response |
0 commit comments