Skip to content

Commit 6fbffd5

Browse files
authored
Merge pull request #33 from softwareone-platform/MPT-8308_align_config_with_operations_api
MPT-8308 align config with operations api
2 parents c0e4893 + 178b8a3 commit 6fbffd5

13 files changed

+34
-30
lines changed

app/core/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class Settings(BaseSettings):
99
# Base
1010
jwt_secret: str
1111
jwt_leeway: float = 30.0
12-
optscale_auth_api_url: str
13-
optscale_rest_api_url: str
12+
optscale_auth_api_base_url: str
13+
optscale_rest_api_base_url: str
1414
optscale_cluster_secret: str
1515
debug: bool = False
1616
default_request_timeout: int = 10 # API Client

app/optscale_api/auth_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
from app.core.api_client import APIClient
77
from app.core.exceptions import UserAccessTokenError, raise_api_response_exception
88

9-
AUTH_TOKEN_ENDPOINT = "/auth/v2/tokens" # nosec B105
10-
AUTH_TOKEN_AUTHORIZE_ENDPOINT = "/auth/v2/authorize" # nosec B105"
119
logger = logging.getLogger(__name__)
1210

11+
AUTH_TOKEN_ENDPOINT = "/tokens" # nosec B105
12+
AUTH_TOKEN_AUTHORIZE_ENDPOINT = "/authorize" # nosec B105"
13+
1314

1415
def build_admin_api_key_header(admin_api_key: str) -> dict[str, str]:
1516
"""
@@ -33,7 +34,7 @@ def build_bearer_token_header(bearer_token: str) -> dict[str, str]:
3334

3435
class OptScaleAuth:
3536
def __init__(self):
36-
self.api_client = APIClient(base_url=settings.optscale_auth_api_url)
37+
self.api_client = APIClient(base_url=settings.optscale_auth_api_base_url)
3738

3839
async def check_user_allowed_to_create_cloud_account(
3940
self, bearer_token: str, org_id: str

app/optscale_api/cloud_accounts.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
)
1111

1212
logger = logging.getLogger(__name__)
13-
CLOUD_ACCOUNT_ENDPOINT = "/restapi/v2/organizations"
13+
14+
CLOUD_ACCOUNT_ENDPOINT = "/organizations"
1415

1516

1617
class OptScaleCloudAccountAPI:
1718
def __init__(self):
18-
self.api_client = APIClient(base_url=settings.optscale_rest_api_url)
19+
self.api_client = APIClient(base_url=settings.optscale_rest_api_base_url)
1920

2021
async def link_cloud_account_with_org(
2122
self, user_access_token: str, org_id: str, conf: dict[str, str]

app/optscale_api/invitation_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
build_bearer_token_header,
1313
)
1414

15-
INVITATION_ENDPOINT = "/restapi/v2/invites"
1615
logger = logging.getLogger(__name__)
1716

17+
INVITATION_ENDPOINT = "/invites"
18+
1819

1920
class OptScaleInvitationAPI:
2021
def __init__(self):
21-
self.api_client = APIClient(base_url=settings.optscale_rest_api_url)
22+
self.api_client = APIClient(base_url=settings.optscale_rest_api_base_url)
2223

2324
async def decline_invitation(self, user_access_token: str, invitation_id: str):
2425
"""

app/optscale_api/orgs_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
get_user_access_token,
1818
)
1919

20-
ORG_ENDPOINT = "/restapi/v2/organizations"
2120
logger = logging.getLogger(__name__)
2221

23-
ORG_CREATION_ERROR = "An error occurred creating an organization for user {}."
22+
ORG_ENDPOINT = "/organizations"
2423

24+
ORG_CREATION_ERROR = "An error occurred creating an organization for user {}."
2525
ORG_FETCHING_ERROR = "An error occurred getting organizations for user {}."
2626

2727

2828
class OptScaleOrgAPI:
2929
def __init__(self):
30-
self.api_client = APIClient(base_url=settings.optscale_rest_api_url)
30+
self.api_client = APIClient(base_url=settings.optscale_rest_api_base_url)
3131

3232
async def get_user_org_list(
3333
self, user_access_token: str

app/optscale_api/users_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
from .auth_api import build_admin_api_key_header
1010

11-
AUTH_USERS_ENDPOINT = "/auth/v2/users"
1211
logger = logging.getLogger(__name__)
1312

13+
AUTH_USERS_ENDPOINT = "/users"
14+
1415

1516
class OptScaleUserAPI:
1617
def __init__(self):
17-
self.api_client = APIClient(base_url=settings.optscale_auth_api_url)
18+
self.api_client = APIClient(base_url=settings.optscale_auth_api_base_url)
1819

1920
# todo: check the password lenght and strength
2021
async def create_user(

env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# BASE
33
FFC_MODIFIER_DEBUG=True
44
# CLoudSpend API
5-
FFC_MODIFIER_OPTSCALE_AUTH_API_URL="https://your-optscaledomain.com"
6-
FFC_MODIFIER_OPTSCALE_REST_API_URL="https://your-optscaledomain.com"
5+
FFC_MODIFIER_OPTSCALE_AUTH_API_BASE_URL="https://your-optscaledomain.com/auth/v2"
6+
FFC_MODIFIER_OPTSCALE_REST_API_BASE_URL="https://your-optscaledomain.com/restapi/v2"
77
FFC_MODIFIER_OPTSCALE_CLUSTER_SECRET="your cluster secret here"
88
# JWT TOKEN
99
FFC_MODIFIER_JWT_SECRET="my_super_secret_here"

tests/test_external_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def test_create_duplicate_user(caplog, optscale_api, test_data: dict, mock
112112
admin_api_key="test_key",
113113
)
114114
mock_post.assert_called_once_with(
115-
endpoint="/auth/v2/users",
115+
endpoint="/users",
116116
data={
117117
"email": EMAIL,
118118
"display_name": DISPLAY_NAME,

tests/test_optscale_cloud_accounts_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def test_create_cloud_account(
4242

4343
# Assert that mock_post was called with expected arguments
4444
mock_api_client_post.assert_called_once_with(
45-
endpoint="/restapi/v2/organizations/ABC-101-DEF-1001/cloud_accounts",
45+
endpoint="/organizations/ABC-101-DEF-1001/cloud_accounts",
4646
data=payload,
4747
headers={"Authorization": "Bearer good token"},
4848
)

tests/test_optscale_organizations_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def test_create_user_org(
8484

8585
# Assert that mock_post was called with expected arguments
8686
mock_api_client_post.assert_called_once_with(
87-
endpoint="/restapi/v2/organizations",
87+
endpoint="/organizations",
8888
data={"name": "MyOrg", "currency": "USD"},
8989
headers={"Authorization": "Bearer good token"},
9090
)
@@ -146,7 +146,7 @@ async def test_get_user_org_empty_response(
146146
)
147147
assert result == {"organizations": []}
148148
mock_api_client_get.assert_called_once_with(
149-
endpoint="/restapi/v2/organizations",
149+
endpoint="/organizations",
150150
headers={"Authorization": "Bearer good token"},
151151
)
152152

0 commit comments

Comments
 (0)