Add display name to subscription creation payload
Also extracts environment -> subscription payload construction to it's own method.
This commit is contained in:
parent
670e135a0e
commit
9acbeeb824
@ -481,7 +481,7 @@ class AzureCloudProvider(CloudProviderInterface):
|
||||
)
|
||||
|
||||
request_body = {
|
||||
"displayName": "Test Sub 1",
|
||||
"displayName": payload.display_name,
|
||||
"skuId": AZURE_SKU_ID,
|
||||
"managementGroupId": payload.parent_group_id,
|
||||
}
|
||||
|
@ -409,6 +409,7 @@ class KeyVaultCredentials(BaseModel):
|
||||
|
||||
|
||||
class SubscriptionCreationCSPPayload(BaseCSPPayload):
|
||||
display_name: str
|
||||
parent_group_id: str
|
||||
billing_account_name: str
|
||||
billing_profile_name: str
|
||||
|
@ -527,6 +527,25 @@ def resend_invite(application_id, application_role_id):
|
||||
)
|
||||
|
||||
|
||||
def build_subscription_payload(environment) -> SubscriptionCreationCSPPayload:
|
||||
csp_data = environment.application.portfolio.csp_data
|
||||
parent_group_id = environment.cloud_id
|
||||
invoice_section_name = csp_data["billing_profile_properties"]["invoice_sections"][
|
||||
0
|
||||
]["invoice_section_name"]
|
||||
|
||||
display_name = f"{environment.application.name}-{environment.name}"
|
||||
|
||||
return SubscriptionCreationCSPPayload(
|
||||
tenant_id=csp_data.get("tenant_id"),
|
||||
display_name=display_name,
|
||||
parent_group_id=parent_group_id,
|
||||
billing_account_name=csp_data.get("billing_account_name"),
|
||||
billing_profile_name=csp_data.get("billing_profile_name"),
|
||||
invoice_section_name=invoice_section_name,
|
||||
)
|
||||
|
||||
|
||||
@applications_bp.route(
|
||||
"/environments/<environment_id>/add_subscription", methods=["POST"]
|
||||
)
|
||||
@ -535,19 +554,7 @@ def create_subscription(environment_id):
|
||||
environment = Environments.get(environment_id)
|
||||
|
||||
try:
|
||||
csp_data = environment.application.portfolio.csp_data
|
||||
parent_group_id = environment.cloud_id
|
||||
invoice_section_name = csp_data["billing_profile_properties"][
|
||||
"invoice_sections"
|
||||
][0]["invoice_section_name"]
|
||||
|
||||
payload = SubscriptionCreationCSPPayload(
|
||||
tenant_id=csp_data.get("tenant_id"),
|
||||
parent_group_id=parent_group_id,
|
||||
billing_account_name=csp_data.get("billing_account_name"),
|
||||
billing_profile_name=csp_data.get("billing_profile_name"),
|
||||
invoice_section_name=invoice_section_name,
|
||||
)
|
||||
payload = build_subscription_payload(environment)
|
||||
app.csp.cloud.create_subscription(payload)
|
||||
flash("environment_subscription_success", name=environment.displayname)
|
||||
|
||||
|
@ -592,7 +592,7 @@ def test_create_subscription_creation(mock_azure: AzureCloudProvider):
|
||||
mock_result.status_code = 202
|
||||
mock_result.headers = {
|
||||
"Location": "https://verify.me",
|
||||
"Retry-After": "10",
|
||||
"Retry-After": 10,
|
||||
}
|
||||
mock_result.json.return_value = {}
|
||||
mock_azure.sdk.requests.put.return_value = mock_result
|
||||
@ -600,6 +600,7 @@ def test_create_subscription_creation(mock_azure: AzureCloudProvider):
|
||||
payload = SubscriptionCreationCSPPayload(
|
||||
**dict(
|
||||
tenant_id="60ff9d34-82bf-4f21-b565-308ef0533435",
|
||||
display_name="application_env_sub1",
|
||||
parent_group_id=management_group_id,
|
||||
billing_account_name="7c89b735-b22b-55c0-ab5a-c624843e8bf6:de4416ce-acc6-44b1-8122-c87c4e903c91_2019-05-31",
|
||||
billing_profile_name="KQWI-W2SU-BG7-TGB",
|
||||
|
@ -802,7 +802,7 @@ def test_create_subscription_success(
|
||||
AzureCloudProvider, "create_subscription", wraps=mock_azure.create_subscription,
|
||||
) as create_subscription:
|
||||
create_subscription.return_value = SubscriptionCreationCSPResult(
|
||||
subscription_verify_url="", subscription_retry_after=""
|
||||
subscription_verify_url="https://zombo.com", subscription_retry_after=10
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
|
Loading…
x
Reference in New Issue
Block a user