feat(api): show a user pool's Lambda triggers
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import {ScrollText, Zap} from 'lucide-react'
|
||||
import type {CloudResource} from '@/types/resource'
|
||||
|
||||
type LambdaTrigger = {trigger: string; label: string; functionArn: string; functionName: string; version: string | null}
|
||||
|
||||
export function CognitoTriggersSection({pool}: {pool?: CloudResource}) {
|
||||
const triggers = triggersOf(pool)
|
||||
return <>
|
||||
<div className="input-row resource-table-bar">
|
||||
<div><p className="eyebrow">Lambda triggers</p><span className="muted">Functions Cognito runs during sign-up, sign-in and token issue</span></div>
|
||||
</div>
|
||||
{pool && triggers.length === 0 && <p className="muted padded">This pool runs no Lambda triggers.</p>}
|
||||
{triggers.length > 0 && <div className="cognito-table"><table className="table"><thead><tr><th>Trigger</th><th>Function</th><th>Version</th><th/></tr></thead><tbody>{triggers.map((trigger) => (
|
||||
<tr key={trigger.trigger}>
|
||||
<td>{trigger.label}</td>
|
||||
<td><code title={trigger.functionArn}>{trigger.functionName}</code></td>
|
||||
<td>{trigger.version ? <code>{trigger.version}</code> : '—'}</td>
|
||||
<td className="cognito-row-actions">
|
||||
<a className="button" href={`/cloud-explorer/aws/serverless?resource=${encodeURIComponent(trigger.functionName)}`} aria-label={`Open function ${trigger.functionName}`}><Zap size={13}/> Function</a>
|
||||
<a className="button" href={`/cloud-explorer/aws/logs?resource=${encodeURIComponent(`/aws/lambda/${trigger.functionName}`)}`} aria-label={`Open logs for ${trigger.functionName}`}><ScrollText size={13}/> Logs</a>
|
||||
</td>
|
||||
</tr>
|
||||
))}</tbody></table></div>}
|
||||
</>
|
||||
}
|
||||
|
||||
function triggersOf(pool?: CloudResource): LambdaTrigger[] {
|
||||
const triggers = pool?.metadata.lambdaTriggers
|
||||
if (!Array.isArray(triggers)) return []
|
||||
return triggers.filter((trigger): trigger is LambdaTrigger => typeof trigger?.functionName === 'string' && typeof trigger?.label === 'string')
|
||||
}
|
||||
@@ -64,6 +64,24 @@ test('shows the app client id and the pool users', async () => {
|
||||
expect(api.getCloudResource).toHaveBeenCalledWith('aws', 'userpools', summary.id, expect.anything())
|
||||
})
|
||||
|
||||
test('lists the pool\'s Lambda triggers with links to the function and its logs', async () => {
|
||||
api.getCloudResource.mockResolvedValue({...pool('email'), metadata: {...pool('email').metadata, lambdaTriggers: [
|
||||
{trigger: 'PreTokenGeneration', label: 'Pre token generation', functionArn: 'arn:aws:lambda:us-east-1:000000000000:function:notes-demo-pre-token', functionName: 'notes-demo-pre-token', version: null},
|
||||
]}})
|
||||
renderPanel()
|
||||
|
||||
expect(await screen.findByText('Pre token generation')).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', {name: 'Open function notes-demo-pre-token'})).toHaveAttribute('href', '/cloud-explorer/aws/serverless?resource=notes-demo-pre-token')
|
||||
expect(screen.getByRole('link', {name: 'Open logs for notes-demo-pre-token'})).toHaveAttribute('href', '/cloud-explorer/aws/logs?resource=%2Faws%2Flambda%2Fnotes-demo-pre-token')
|
||||
})
|
||||
|
||||
test('says when a pool has no Lambda triggers', async () => {
|
||||
api.getCloudResource.mockResolvedValue(pool('email'))
|
||||
renderPanel()
|
||||
|
||||
expect(await screen.findByText('This pool runs no Lambda triggers.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('creates an email user who can sign in immediately', async () => {
|
||||
const user = userEvent.setup()
|
||||
api.getCloudResource.mockResolvedValue(pool('email'))
|
||||
|
||||
@@ -4,6 +4,7 @@ import {useEffect, useState} from 'react'
|
||||
import {deleteFlatItem, getCloudResource, listFlatItems, listUserPoolGroups, putFlatItem} from '@/api/cloudProxyClient'
|
||||
import {CognitoGroupsSection} from '@/components/CognitoGroupsSection'
|
||||
import {CognitoSignInTest} from '@/components/CognitoSignInTest'
|
||||
import {CognitoTriggersSection} from '@/components/CognitoTriggersSection'
|
||||
import {CognitoUserDetail} from '@/components/CognitoUserDetail'
|
||||
import {CopyValueButton} from '@/components/CopyValueButton'
|
||||
import {useAccountId} from '@/lib/accountStore'
|
||||
@@ -97,6 +98,8 @@ export function CognitoUsersPanel({resource, runtimeReachable}: Props) {
|
||||
<tr key={client.clientId}><td>{client.clientName || '—'}</td><td><span className="copy-value mono">{client.clientId}<CopyValueButton value={client.clientId} label="Client ID"/></span></td></tr>
|
||||
))}</tbody></table></div>}
|
||||
|
||||
<CognitoTriggersSection pool={poolQuery.data ?? undefined}/>
|
||||
|
||||
<CognitoSignInTest poolId={resource.id} appClients={appClients} loginLabel={loginLabel} runtimeReachable={runtimeReachable}/>
|
||||
|
||||
<CognitoGroupsSection poolId={resource.id} groupsQuery={groupsQuery} groupsKey={groupsKey} runtimeReachable={runtimeReachable}/>
|
||||
|
||||
Reference in New Issue
Block a user