fixup! feat: create a service account from the run-as picker at deploy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Guilhem Lemouel
2026-10-29 12:21:04 -07:00
co-authored by Claude Opus 5.5
parent 4947c514f7
commit 62ebe343e1
3 changed files with 24 additions and 0 deletions
@@ -1,6 +1,7 @@
<script lang="ts">
import DeployOnBehalfOfDialog from '$lib/components/itemSettings/DeployOnBehalfOfDialog.svelte'
import { useDeployAs } from '$lib/components/access/deployAs.svelte'
import { dropStalePending } from '$lib/components/access/serviceAccounts.svelte'
import { deployAsksOnBehalfOf } from '$lib/components/itemSettings/onBehalfOf'
import { useFolderDefaultPermissionedAs } from '$lib/components/useFolderDefaultPermissionedAs.svelte'
import {
@@ -203,6 +204,10 @@
// indicatorPath is the matching draft path.
const opWorkspace = $derived(autosaveWorkspace ?? $operatingWorkspace)
const indicatorPath = $derived(autosavePath ?? liveEditorDraftStoragePath)
dropStalePending(
untrack(() => opWorkspace),
flowStore.val
)
let initialPathStore = writable(initialPath)
@@ -1,6 +1,7 @@
<script lang="ts">
import DeployOnBehalfOfDialog from '$lib/components/itemSettings/DeployOnBehalfOfDialog.svelte'
import { useDeployAs } from '$lib/components/access/deployAs.svelte'
import { dropStalePending } from '$lib/components/access/serviceAccounts.svelte'
import { deployAsksOnBehalfOf } from '$lib/components/itemSettings/onBehalfOf'
import { useFolderDefaultPermissionedAs } from '$lib/components/useFolderDefaultPermissionedAs.svelte'
import {
@@ -239,6 +240,10 @@
const opWorkspace = $derived(autosaveWorkspace ?? $operatingWorkspace)
const deployAs = useDeployAs(() => $operatingWorkspace)
const indicatorPath = $derived(autosavePath ?? userDraftPath)
dropStalePending(
untrack(() => opWorkspace),
script
)
// The shared `workerTags` store caches tags for the navigation workspace. A
// session editor deploys to `opWorkspace` (a fork), so it keeps a local list to
@@ -46,6 +46,19 @@ export function getPendingServiceAccount(
return permissionedAs ? pending.get(key(workspace, permissionedAs)) : undefined
}
/** Clears a run-as that names a placeholder email this tab no longer holds an account for, as a
* draft saved before its deploy does after a reload: the server knows no such user. */
export function dropStalePending(
workspace: string | undefined,
item: { on_behalf_of?: string; on_behalf_of_email?: string }
): void {
const email = item.on_behalf_of_email
if (!workspace || !email?.endsWith(`@${PENDING_EMAIL_DOMAIN}`)) return
if (getPendingServiceAccount(workspace, `u/${email.split('@')[0]}`)) return
item.on_behalf_of = undefined
item.on_behalf_of_email = undefined
}
const TTL_MS = 60_000
const asked = new Map<string, { at: number; accounts: Promise<ServiceAccount[]> }>()
@@ -165,6 +178,7 @@ export async function createPolicyServiceAccount(
workspace: string,
policy: { on_behalf_of?: string; on_behalf_of_email?: string }
): Promise<boolean> {
dropStalePending(workspace, policy)
try {
const email = await createPendingServiceAccount(workspace, policy.on_behalf_of)
if (email) policy.on_behalf_of_email = email