Skip to content

Commit

Permalink
[fix] add cloud events (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
sijav authored May 22, 2024
1 parent ef63885 commit 5b7ab7d
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 39 deletions.
29 changes: 16 additions & 13 deletions src/locales/de-DE/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ msgstr "{0} Prüfungen sind fehlgeschlagen."
msgid "{0} checks fixed."
msgstr "{0} Prüfungen behoben"

#: src/shared/event-button/EventButton.tsx:57
#: src/shared/event-button/EventButton.tsx:63
msgid "{0} Cloud account configured, id: {1}"
msgstr "{0} Cloud-Konto konfiguriert, ID: {1}"

#: src/shared/event-button/EventButton.tsx:69
#: src/shared/event-button/EventButton.tsx:75
msgid "{0} Cloud account degraded, id: {1}"
msgstr "{0} Cloud-Konto beeinträchtigt, ID: {1}"

#: src/shared/event-button/EventButton.tsx:81
#: src/shared/event-button/EventButton.tsx:87
msgid "{0} Cloud account discovered, id: {1}"
msgstr "{0} Cloud-Konto entdeckt, ID: {1}"

#: src/pages/panel/workspace-settings-billing/ProductTierComp.tsx:63
msgid "{0} cloud accounts included"
msgstr "{0} Cloud-Konten enthalten"
Expand Down Expand Up @@ -464,18 +479,6 @@ msgstr "Schließen"
msgid "Cloud"
msgstr "Cloud"

#: src/shared/event-button/EventButton.tsx:57
msgid "Cloud account configured, id: {0}"
msgstr "Cloud-Konto konfiguriert, ID: {0}"

#: src/shared/event-button/EventButton.tsx:63
msgid "Cloud account degraded, id: {0}"
msgstr "Cloud-Konto beeinträchtigt, ID: {0}"

#: src/shared/event-button/EventButton.tsx:69
msgid "Cloud account discovered, id: {0}"
msgstr "Cloud-Konto entdeckt, ID: {0}"

#: src/shared/layouts/panel-layout/PanelBreadcrumbs.tsx:14
msgid "Cloud Setup"
msgstr "Cloud Setup"
Expand Down Expand Up @@ -765,7 +768,7 @@ msgstr "Engineers kennzeichnen ihre temporären Ressourcen gerne mit der Zeichen
msgid "Enterprise"
msgstr "Unternehmen"

#: src/shared/event-button/EventButton.tsx:103
#: src/shared/event-button/EventButton.tsx:121
msgid "Events"
msgstr "Veranstaltungen"

Expand Down
29 changes: 16 additions & 13 deletions src/locales/en-US/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ msgstr "{0} checks failed."
msgid "{0} checks fixed."
msgstr "{0} checks fixed."

#: src/shared/event-button/EventButton.tsx:57
#: src/shared/event-button/EventButton.tsx:63
msgid "{0} Cloud account configured, id: {1}"
msgstr "{0} Cloud account configured, id: {1}"

#: src/shared/event-button/EventButton.tsx:69
#: src/shared/event-button/EventButton.tsx:75
msgid "{0} Cloud account degraded, id: {1}"
msgstr "{0} Cloud account degraded, id: {1}"

#: src/shared/event-button/EventButton.tsx:81
#: src/shared/event-button/EventButton.tsx:87
msgid "{0} Cloud account discovered, id: {1}"
msgstr "{0} Cloud account discovered, id: {1}"

#: src/pages/panel/workspace-settings-billing/ProductTierComp.tsx:63
msgid "{0} cloud accounts included"
msgstr "{0} cloud accounts included"
Expand Down Expand Up @@ -464,18 +479,6 @@ msgstr "Close"
msgid "Cloud"
msgstr "Cloud"

#: src/shared/event-button/EventButton.tsx:57
msgid "Cloud account configured, id: {0}"
msgstr "Cloud account configured, id: {0}"

#: src/shared/event-button/EventButton.tsx:63
msgid "Cloud account degraded, id: {0}"
msgstr "Cloud account degraded, id: {0}"

#: src/shared/event-button/EventButton.tsx:69
msgid "Cloud account discovered, id: {0}"
msgstr "Cloud account discovered, id: {0}"

#: src/shared/layouts/panel-layout/PanelBreadcrumbs.tsx:14
msgid "Cloud Setup"
msgstr "Cloud Setup"
Expand Down Expand Up @@ -765,7 +768,7 @@ msgstr "Engineers like to tag their temporary resources with the string \"delete
msgid "Enterprise"
msgstr "Enterprise"

#: src/shared/event-button/EventButton.tsx:103
#: src/shared/event-button/EventButton.tsx:121
msgid "Events"
msgstr "Events"

Expand Down
2 changes: 1 addition & 1 deletion src/pages/panel/setup-cloud/SetupCloudPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function SetupCloud() {

useEffect(() => {
return addListener('event-button', (ev) => {
if (ev.kind === 'aws_account_discovered') {
if (ev.kind === 'aws_account_discovered' || ev.kind === 'cloud_account_discovered') {
navigate(hasBenchmark ? '/accounts' : '/security')
}
})
Expand Down
42 changes: 37 additions & 5 deletions src/shared/event-button/EventButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,55 @@ export const EventButton = () => {
predicate: (query) => typeof query.queryKey[0] === 'string' && query.queryKey[0].startsWith('workspace'),
})
break
case 'aws_account_configured':
case 'cloud_account_configured':
void queryClient.invalidateQueries({
predicate: (query) => typeof query.queryKey[0] === 'string' && query.queryKey[0].startsWith('workspace-cloud-accounts'),
})
void showSnackbar(t`Cloud account configured, id: ${ev.data.aws_account_id}`, { severity: 'success', autoHideDuration: null })
void showSnackbar(t`${ev.data.cloud.toUpperCase()} Cloud account configured, id: ${ev.data.account_id}`, {
severity: 'success',
autoHideDuration: null,
})
break
case 'aws_account_configured': // TODO: remove aws specific events
void queryClient.invalidateQueries({
predicate: (query) => typeof query.queryKey[0] === 'string' && query.queryKey[0].startsWith('workspace-cloud-accounts'),
})
void showSnackbar(t`${ev.data.aws_account_id ? 'AWS' : ''} Cloud account configured, id: ${ev.data.aws_account_id}`, {
severity: 'success',
autoHideDuration: null,
})
break
case 'cloud_account_degraded':
void queryClient.invalidateQueries({
predicate: (query) => typeof query.queryKey[0] === 'string' && query.queryKey[0].startsWith('workspace-cloud-accounts'),
})
void showSnackbar(t`${ev.data.cloud.toUpperCase()} Cloud account degraded, id: ${ev.data.account_id}`, {
severity: 'warning',
autoHideDuration: null,
})
break
case 'aws_account_degraded':
void queryClient.invalidateQueries({
predicate: (query) => typeof query.queryKey[0] === 'string' && query.queryKey[0].startsWith('workspace-cloud-accounts'),
})
void showSnackbar(t`Cloud account degraded, id: ${ev.data.aws_account_id}`, { severity: 'warning', autoHideDuration: null })
void showSnackbar(t`${ev.data.aws_account_id ? 'AWS' : ''} Cloud account degraded, id: ${ev.data.aws_account_id}`, {
severity: 'warning',
autoHideDuration: null,
})
break
case 'cloud_account_discovered':
void queryClient.invalidateQueries({
predicate: (query) => typeof query.queryKey[0] === 'string' && query.queryKey[0].startsWith('workspace-cloud-accounts'),
})
void showSnackbar(t`${ev.data.cloud.toUpperCase()} Cloud account discovered, id: ${ev.data.account_id}`, { severity: 'info' })
break
case 'aws_account_discovered':
void queryClient.invalidateQueries({
predicate: (query) => typeof query.queryKey[0] === 'string' && query.queryKey[0].startsWith('workspace-cloud-accounts'),
})
void showSnackbar(t`Cloud account discovered, id: ${ev.data.aws_account_id}`, { severity: 'info' })
void showSnackbar(t`${ev.data.aws_account_id ? 'AWS' : ''} Cloud account discovered, id: ${ev.data.aws_account_id}`, {
severity: 'info',
})
break
case 'collect-error':
void queryClient.invalidateQueries({
Expand Down Expand Up @@ -100,7 +132,7 @@ export const EventButton = () => {

return hasNoEvents ? null : (
<Box display="inline-flex" alignItems="center" justifyContent="center">
<Tooltip title={t`Events`}>
<Tooltip title={t`Events`} arrow>
<IconButton sx={{ p: 0, color: 'white', mr: 2 }} size="large" onClick={handleToggleUserMenu} ref={anchorEl}>
<EventIcon fontSize="large" />
</IconButton>
Expand Down
11 changes: 10 additions & 1 deletion src/shared/event-button/EventItem.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ const meta = {
at: { control: 'date' },
id: { control: 'text' },
kind: {
options: ['aws_account_discovered', 'aws_account_configured', 'aws_account_deleted', 'aws_account_degraded'],
options: [
'cloud_account_discovered',
'aws_account_discovered',
'cloud_account_configured',
'aws_account_configured',
'cloud_account_deleted',
'aws_account_deleted',
'cloud_account_degraded',
'aws_account_degraded',
],
},
publisher: { control: 'text' },
data: {
Expand Down
5 changes: 5 additions & 0 deletions src/shared/event-button/EventItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ interface EventItemProps {
}

const getSeverity = (kind: WebSocketEvent['kind']): AlertProps['severity'] => {
// TODO: remove aws specific events
switch (kind) {
case 'cloud_account_configured':
case 'aws_account_configured':
return 'success'
case 'cloud_account_degraded':
case 'aws_account_degraded':
return 'warning'
case 'cloud_account_discovered':
case 'aws_account_discovered':
case 'collect-progress':
return 'info'
case 'cloud_account_deleted':
case 'aws_account_deleted':
case 'collect-error':
return 'error'
Expand Down
63 changes: 57 additions & 6 deletions src/shared/types/server/web-socket-event/WebSocketEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@ interface WebSocketGenericEvent<Kind extends WebSocketEventKind, Data extends ob
data: Data
}

type CloudAccountType = 'aws' | 'gcp'

// TODO: remove aws specific events
type WebSocketEventKind =
| 'aws_account_discovered'
| 'cloud_account_configured'
| 'aws_account_configured'
| 'cloud_account_deleted'
| 'aws_account_deleted'
| 'cloud_account_discovered'
| 'aws_account_discovered'
| 'cloud_account_degraded'
| 'aws_account_degraded'
| 'collect-progress'
| 'collect-error'
| 'tenant_accounts_collected'

export type AWSAccountDiscoveredEvent = WebSocketGenericEvent<
'aws_account_discovered',
export type CloudAccountConfiguredEvent = WebSocketGenericEvent<
'cloud_account_configured',
{
cloud: CloudAccountType
cloud_account_id: string
workspace_id: string
aws_account_id: string
account_id: string
}
>

Expand All @@ -33,6 +41,16 @@ export type AWSAccountConfiguredEvent = WebSocketGenericEvent<
}
>

export type CloudAccountDeletedEvent = WebSocketGenericEvent<
'cloud_account_deleted',
{
cloud: CloudAccountType
cloud_account_id: string
workspace_id: string
account_id: string
}
>

export type AWSAccountDeletedEvent = WebSocketGenericEvent<
'aws_account_deleted',
{
Expand All @@ -42,6 +60,35 @@ export type AWSAccountDeletedEvent = WebSocketGenericEvent<
}
>

export type CloudAccountDiscoveredEvent = WebSocketGenericEvent<
'cloud_account_discovered',
{
cloud: CloudAccountType
cloud_account_id: string
workspace_id: string
account_id: string
}
>

export type AWSAccountDiscoveredEvent = WebSocketGenericEvent<
'aws_account_discovered',
{
cloud_account_id: string
workspace_id: string
aws_account_id: string
}
>

export type CloudAccountDegradedEvent = WebSocketGenericEvent<
'cloud_account_degraded',
{
cloud: CloudAccountType
cloud_account_id: string
workspace_id: string
account_id: string
}
>

export type AWSAccountDegradedEvent = WebSocketGenericEvent<
'aws_account_degraded',
{
Expand All @@ -51,7 +98,7 @@ export type AWSAccountDegradedEvent = WebSocketGenericEvent<
}
>

export type AWSTenantAccountCollectedEvent = WebSocketGenericEvent<
export type TenantAccountCollectedEvent = WebSocketGenericEvent<
'tenant_accounts_collected',
{
tenant_id: string
Expand Down Expand Up @@ -98,10 +145,14 @@ export type CollectErrorEvent = WebSocketGenericEvent<
>

export type WebSocketEvent =
| CloudAccountConfiguredEvent
| AWSAccountConfiguredEvent
| CloudAccountDegradedEvent
| AWSAccountDegradedEvent
| CloudAccountDeletedEvent
| AWSAccountDeletedEvent
| CloudAccountDiscoveredEvent
| AWSAccountDiscoveredEvent
| AWSTenantAccountCollectedEvent
| TenantAccountCollectedEvent
| CollectProgressEvent
| CollectErrorEvent
2 changes: 2 additions & 0 deletions src/shared/types/server/web-socket-event/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export type {
AWSAccountDegradedEvent,
AWSAccountDeletedEvent,
AWSAccountDiscoveredEvent,
CloudAccountConfiguredEvent,
CloudAccountDeletedEvent,
CollectErrorEvent,
CollectProgressEvent,
WebSocketEvent,
Expand Down

0 comments on commit 5b7ab7d

Please sign in to comment.