Skip to content

Commit

Permalink
add account name to the message
Browse files Browse the repository at this point in the history
  • Loading branch information
meln1k committed Mar 11, 2024
1 parent e400554 commit d0a6210
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
5 changes: 4 additions & 1 deletion fixbackend/cloud_accounts/service_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ def compute_failed_scan_count(acc: CloudAccount) -> int:
await self.notification_service.send_message_to_workspace(
workspace_id=degraded_event.tenant_id,
message=email.AccountDegraded(
cloud_account_id=degraded_event.aws_account_id, tenant_id=degraded_event.tenant_id
cloud_account_id=degraded_event.aws_account_id,
tenant_id=degraded_event.tenant_id,
account_name=degraded_event.aws_account_name,
),
)
await send_pub_sub_message(degraded_event)
Expand Down Expand Up @@ -765,6 +767,7 @@ def set_degraded(cloud_account: CloudAccount) -> CloudAccount:
cloud_account_id=account.id,
tenant_id=account.workspace_id,
aws_account_id=account.account_id,
aws_account_name=account.final_name(),
error=error,
)
)
Expand Down
1 change: 1 addition & 0 deletions fixbackend/domain_events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class AwsAccountDegraded(Event):
cloud_account_id: FixCloudAccountId
tenant_id: WorkspaceId
aws_account_id: CloudAccountId
aws_account_name: Optional[str]
error: str


Expand Down
13 changes: 10 additions & 3 deletions fixbackend/notification/email/email_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import Any, Union
from typing import Any, Optional, Union
from attrs import frozen

from pathlib import Path
Expand Down Expand Up @@ -144,13 +144,20 @@ def html(self) -> str:
@frozen(kw_only=True)
class AccountDegraded:
cloud_account_id: CloudAccountId
account_name: Optional[str]
tenant_id: WorkspaceId

def account_info(self) -> str:
formatted = (
f"{self.account_name} ({self.cloud_account_id})" if self.account_name else f"{self.cloud_account_id}"
)
return formatted

def subject(self) -> str:
return f"Account {self.cloud_account_id} cannot be accessed due to permission issues."
return f"""Account {self.account_info()} cannot be accessed due to permission issues."""

def text(self) -> str:
return f"""We were not able to collect latest resource information for Account {self.cloud_account_id}. Please ensure the account exists and that the necessary permissions are granted for access.
return f"""We were not able to collect latest resource information for account {self.account_info()}. Please ensure the account exists and that the necessary permissions are granted for access.
Please visit https://app.global.fixcloud.io/workspace-settings/accounts#{self.tenant_id} for more details."""

Expand Down
7 changes: 4 additions & 3 deletions fixbackend/notification/email/templates/account_degraded.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

<div class="f-fallback">
<h1 style="margin-top: 0; color: #333333; font-size: 22px; font-weight: bold; text-align: left;" align="left">
Account {{ message.cloud_account_id }} cannot be accessed due to permission issues.
Account {{ message.account_info() }} cannot be accessed due to permission issues.
</h1>

<p style="font-size: 16px; line-height: 1.625; color: #333; margin: .4em 0 1.1875em;">
We were not able to collect latest resource information for Account {{ message.cloud_account_id }}. Please
We were not able to collect latest resource information for account {{ message.account_info() }}. Please
ensure the account exists and that the necessary permissions are granted for access.

Please visit https://app.global.fixcloud.io/workspace-settings/accounts#{{ message.tenant_id}} for more details.
Please visit <a href="https://app.global.fixcloud.io/workspace-settings/accounts#{{ message.tenant_id }}">the
settings page</a> for more details.
</p>

</div>
Expand Down
2 changes: 2 additions & 0 deletions tests/fixbackend/cloud_accounts/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ def get_account(state_updated_at: datetime) -> CloudAccount:
assert event.cloud_account_id == account.id
assert event.aws_account_id == account_id
assert event.tenant_id == account.workspace_id
assert event.aws_account_name == account.final_name()


@pytest.mark.asyncio
Expand Down Expand Up @@ -958,3 +959,4 @@ async def test_move_to_degraded(
assert published_event.aws_account_id == account_id
assert published_event.tenant_id == account.workspace_id
assert published_event.error == "Too many consecutive failed scans"
assert published_event.aws_account_name == account.final_name()
3 changes: 2 additions & 1 deletion tests/fixbackend/domain_events/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
AwsAccountDiscovered(fix_cloud_account_id, workspace_id, cloud_account_id),
AwsAccountConfigured(fix_cloud_account_id, workspace_id, cloud_account_id),
AwsAccountDeleted(user_id, fix_cloud_account_id, workspace_id, cloud_account_id),
AwsAccountDegraded(fix_cloud_account_id, workspace_id, cloud_account_id, "some error"),
AwsAccountDegraded(fix_cloud_account_id, workspace_id, cloud_account_id, "aws final name", "some error"),
TenantAccountsCollected(workspace_id, {fix_cloud_account_id: collect_info}, now + timedelta(hours=1)),
WorkspaceCreated(workspace_id, user_id),
]
Expand Down Expand Up @@ -75,6 +75,7 @@
"cloud_account_id": "69dea3e9-bafe-4e80-9c9d-5a7e1b519767",
"tenant_id": "35dfca88-3028-4990-9d30-a269228d0b01",
"aws_account_id": "123",
"aws_accoun_name": "aws final name",
"error": "some error",
},
TenantAccountsCollected: {
Expand Down
19 changes: 12 additions & 7 deletions tests/fixbackend/notification/notification_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,21 @@ async def test_send_degraded_message(
workspace: Workspace,
email_sender: InMemoryEmailSender,
) -> None:
message = AccountDegraded(cloud_account_id=CloudAccountId("12345"), tenant_id=workspace.id)
message = AccountDegraded(
cloud_account_id=CloudAccountId("12345"), tenant_id=workspace.id, account_name="Development"
)
await notification_service.send_message_to_workspace(workspace_id=workspace.id, message=message)

assert len(email_sender.call_args) == 1
assert email_sender.call_args[0].subject == "Account 12345 cannot be accessed due to permission issues."
assert "Account 12345 cannot be accessed due to permission issues." in (email_sender.call_args[0].html or "")
assert "We were not able to collect latest resource information for Account 12345." in (
assert (
email_sender.call_args[0].subject == "Account Development (12345) cannot be accessed due to permission issues."
)
assert "Account Development (12345) cannot be accessed due to permission issues." in (
email_sender.call_args[0].html or ""
)
assert (
f"Please visit https://app.global.fixcloud.io/workspace-settings/accounts#{workspace.id} for more details."
in (email_sender.call_args[0].html or "")
assert "We were not able to collect latest resource information for account Development (12345)." in (
email_sender.call_args[0].html or ""
)
assert f"""Please visit <a href="https://app.global.fixcloud.io/workspace-settings/accounts#{workspace.id}">""" in (
email_sender.call_args[0].html or ""
)

0 comments on commit d0a6210

Please sign in to comment.