Skip to content

Commit c0e4893

Browse files
authored
Merge pull request #32 from softwareone-platform/MPT-8249_simplify_configuration
MPT-8249 simplify configuration
2 parents f85145a + d676997 commit c0e4893

File tree

18 files changed

+55
-68
lines changed

18 files changed

+55
-68
lines changed

app/api/invitations/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def decline_invitation(
5757
invitation_api=invitation_api,
5858
org_api=org_api,
5959
user_api=user_api,
60-
admin_api_key=settings.admin_token,
60+
admin_api_key=settings.optscale_cluster_secret,
6161
)
6262
return JSONResponse(
6363
status_code=response.get("status_code", http_status.HTTP_200_OK),

app/api/organizations/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ async def get_orgs(
8989
try:
9090
# send request with the Secret token to the OptScale API
9191
response = await optscale_api.access_user_org_list_with_admin_key(
92-
user_id=user_id, admin_api_key=settings.admin_token, auth_client=auth_client
92+
user_id=user_id,
93+
admin_api_key=settings.optscale_cluster_secret,
94+
auth_client=auth_client,
9395
)
9496
return JSONResponse(
9597
status_code=response.get("status_code", http_status.HTTP_200_OK),
@@ -198,7 +200,7 @@ async def create_orgs(
198200
org_name=data.org_name,
199201
user_id=data.user_id,
200202
currency=data.currency,
201-
admin_api_key=settings.admin_token,
203+
admin_api_key=settings.optscale_cluster_secret,
202204
auth_client=auth_client,
203205
)
204206
return JSONResponse(

app/api/users/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async def create_user(
9393
email=str(data.email),
9494
display_name=data.display_name,
9595
password=data.password,
96-
admin_token=settings.admin_token,
96+
optscale_cluster_secret=settings.optscale_cluster_secret,
9797
optscale_user_api=optscale_user_api,
9898
)
9999
logger.info(f"Invited User successfully registered: {response}")
@@ -102,7 +102,7 @@ async def create_user(
102102
email=str(data.email),
103103
display_name=data.display_name,
104104
password=data.password,
105-
admin_token=settings.admin_token,
105+
optscale_cluster_secret=settings.optscale_cluster_secret,
106106
optscale_user_api=optscale_user_api,
107107
)
108108
logger.info(f"User successfully created: {response}")

app/api/users/services/optscale_users_registration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def validate_email_and_add_invited_user(
3636
email: str,
3737
display_name: str,
3838
password: str,
39-
admin_token: str,
39+
optscale_cluster_secret: str,
4040
) -> dict | Exception:
4141
"""
4242
It adds a new user to OptScale ONLY if an invitation has been
@@ -49,7 +49,7 @@ async def validate_email_and_add_invited_user(
4949
:param email: the email address of the invited user
5050
:param display_name: The user's name to add
5151
:param password: The user's password to add
52-
:param admin_token: The Secret API Key required to run this operation
52+
:param optscale_cluster_secret: The Secret API Key required to run this operation
5353
:return:
5454
A dict like
5555
{
@@ -78,7 +78,7 @@ async def validate_email_and_add_invited_user(
7878
email=email,
7979
display_name=display_name,
8080
password=password,
81-
admin_api_key=admin_token,
81+
admin_api_key=optscale_cluster_secret,
8282
verified=False,
8383
)
8484
return response
@@ -89,7 +89,7 @@ async def add_new_user(
8989
email: str,
9090
display_name: str,
9191
password: str,
92-
admin_token: str,
92+
optscale_cluster_secret: str,
9393
) -> dict | Exception:
9494
"""
9595
It adds a new user to OptScale. The new user will be already verified
@@ -98,7 +98,7 @@ async def add_new_user(
9898
:param email: The user's email address
9999
:param display_name: The user's name to add
100100
:param password: The user's password to add
101-
:param admin_token: The Secret API Key required to run this operation
101+
:param optscale_cluster_secret: The Secret API Key required to run this operation
102102
:return: A dict like
103103
{
104104
"created_at": 1737449293,
@@ -121,7 +121,7 @@ async def add_new_user(
121121
email=email,
122122
display_name=display_name,
123123
password=password,
124-
admin_api_key=admin_token,
124+
admin_api_key=optscale_cluster_secret,
125125
verified=True,
126126
)
127127
return response

app/core/auth_jwt_bearer.py

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

20-
JWT_SECRET = settings.secret
21-
JWT_ALGORITHM = settings.algorithm
22-
JWT_AUDIENCE = settings.audience
23-
JWT_ISSUER = settings.issuer
24-
JWT_LEEWAY = settings.leeway
20+
JWT_SECRET = settings.jwt_secret
21+
JWT_ALGORITHM = "HS256"
22+
JWT_AUDIENCE = "modifier"
23+
JWT_ISSUER = "SWO"
24+
JWT_LEEWAY = settings.jwt_leeway
2525

2626
logger = logging.getLogger(__name__)
2727

app/core/config.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,12 @@
77

88
class Settings(BaseSettings):
99
# Base
10-
public_url: str
11-
version: str
12-
secret: str
13-
issuer: str
14-
audience: str
15-
opt_scale_auth_api_url: str
16-
opt_scale_rest_api_url: str
17-
admin_token: str
18-
api_v1_prefix: str = "/modifier/v1"
10+
jwt_secret: str
11+
jwt_leeway: float = 30.0
12+
optscale_auth_api_url: str
13+
optscale_rest_api_url: str
14+
optscale_cluster_secret: str
1915
debug: bool = False
20-
project_name: str = "CloudSpend API Modifier"
21-
description: str = "Service to provide custom users and org management"
22-
algorithm: str = "HS256"
23-
leeway: float = 30.0
2416
default_request_timeout: int = 10 # API Client
2517

2618
model_config = SettingsConfigDict(

app/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
logger = logging.getLogger(__name__)
1414

1515
app = FastAPI(
16-
title=settings.project_name,
17-
version=settings.version,
18-
openapi_url=f"{settings.api_v1_prefix}/openapi.json",
16+
title="FinOps for Cloud API Modifier",
17+
version="4.0.0",
18+
root_path="/modifier/v1",
1919
debug=settings.debug,
2020
)
2121
# Todo: remove * from allow_origins
@@ -28,7 +28,7 @@
2828
)
2929

3030

31-
app.include_router(api_router, prefix=settings.api_v1_prefix)
31+
app.include_router(api_router)
3232
app.add_middleware(LogRequestMiddleware)
3333

3434

app/optscale_api/auth_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def build_bearer_token_header(bearer_token: str) -> dict[str, str]:
3333

3434
class OptScaleAuth:
3535
def __init__(self):
36-
self.api_client = APIClient(base_url=settings.opt_scale_auth_api_url)
36+
self.api_client = APIClient(base_url=settings.optscale_auth_api_url)
3737

3838
async def check_user_allowed_to_create_cloud_account(
3939
self, bearer_token: str, org_id: str

app/optscale_api/cloud_accounts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class OptScaleCloudAccountAPI:
1717
def __init__(self):
18-
self.api_client = APIClient(base_url=settings.opt_scale_rest_api_url)
18+
self.api_client = APIClient(base_url=settings.optscale_rest_api_url)
1919

2020
async def link_cloud_account_with_org(
2121
self, user_access_token: str, org_id: str, conf: dict[str, str]

app/optscale_api/invitation_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class OptScaleInvitationAPI:
2020
def __init__(self):
21-
self.api_client = APIClient(base_url=settings.opt_scale_rest_api_url)
21+
self.api_client = APIClient(base_url=settings.optscale_rest_api_url)
2222

2323
async def decline_invitation(self, user_access_token: str, invitation_id: str):
2424
"""
@@ -87,7 +87,9 @@ async def get_list_of_invitations(
8787
raise ValueError("Both 'user_access_token' and 'email' cannot be None.")
8888

8989
if email is not None:
90-
headers = build_admin_api_key_header(admin_api_key=settings.admin_token)
90+
headers = build_admin_api_key_header(
91+
admin_api_key=settings.optscale_cluster_secret
92+
)
9193
params = {"email": email}
9294
else:
9395
headers = build_bearer_token_header(bearer_token=user_access_token)

0 commit comments

Comments
 (0)