Skip to content

Add manage:delete-sandbox-workspaces command#92

Open
jirkasemmler wants to merge 4 commits into
mainfrom
jirka/delete-sandbox-workspaces
Open

Add manage:delete-sandbox-workspaces command#92
jirkasemmler wants to merge 4 commits into
mainfrom
jirka/delete-sandbox-workspaces

Conversation

@jirkasemmler
Copy link
Copy Markdown
Contributor

Summary

  • New manage:delete-sandbox-workspaces CLI command that cleans up keboola.sandboxes workspaces in a project (--project-id) or across an entire organization (--organization-id).
  • For each workspace it pulls editor sessions from Editor Service and matches them by connection.schema; workspaces with an active session are skipped. The rest are deleted in the order configuration → workspace (configuration deleted twice = trash + purge, matching existing cleanup commands).
  • Scoped by a creation-date window (--created-after / --created-before, default -30 daysnow) and gated by --force (dry-run by default). Verbose per-workspace logging always on, plus per-branch / per-project / final summaries with skip-reason breakdown.

Test plan

  • php cli.php manage:delete-sandbox-workspaces --help shows the new options
  • Dry-run against a real project (--project-id) and inspect the candidate list and skip-reason counts
  • Dry-run against an organization (--organization-id)
  • Re-run with --force against a throwaway project and verify configs + workspaces disappear and active-session workspaces are untouched

🤖 Generated with Claude Code

jirkasemmler and others added 2 commits May 20, 2026 12:36
Adds a new CLI command that deletes keboola.sandboxes workspaces in a
project or organization. It pulls the workspace list from Connection,
skips any workspace whose schema still has an active session in the
Editor Service, then deletes the workspace configuration followed by
the workspace itself for the remaining ones. Scoped by --project-id or
--organization-id (mutually exclusive), filtered by a creation-date
window, with --force gating real deletions and verbose per-workspace
logging in dry-run as well.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new CLI maintenance command to identify and (optionally) delete keboola.sandboxes workspaces that have no active Editor Service session, scoped by project/organization and a creation-date window.

Changes:

  • Introduces manage:delete-sandbox-workspaces with --project-id / --organization-id, --created-after / --created-before, and --force (dry-run default).
  • Implements per-project branching traversal, session-by-schema matching, and deletion order (configuration trash+purge → workspace) with summarized reporting.
  • Registers the new command in the CLI application bootstrap.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Keboola/Console/Command/DeleteSandboxWorkspaces.php New command implementation: discovery, filtering, session matching, deletion, and reporting.
cli.php Registers the new command in the application.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +361 to +369
} catch (StorageClientException $e) {
if (str_contains($e->getMessage(), 'not found')) {
$output->writeln(sprintf(
' Configuration %s/%s already gone',
self::COMPONENT_ID,
$configurationId,
));
$configDeleted = true;
} else {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s tím celkem souhlasím

(string) $workspaceId,
$createdStr,
));
$projectSkippedComponent++;
$editorClient = new EditorServiceClient($editorUrl, $storageToken['token']);

// Index editor sessions by workspaceSchema for O(1) lookup against workspace credentials.
$sessionsBySchema = [];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no ony mají workspaceId

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hypoteticky muzes narazit na session, ktera WS nema, protoze se zrovna vytváí, ale nemyslím si, ze by to tady neco rozbilo

}

if ($configurationId === '') {
$output->writeln(sprintf(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no jestli jsou pro komponentu keboola.sandboxes a současně ta konfigurace neexistuje, tak bych je smazal ne? co s nima.


class DeleteSandboxWorkspaces extends Command
{
private const string COMPONENT_ID = 'keboola.sandboxes';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a tak pojďmě přihodit ještě keboola.snowflake-transformation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ono je asi ne zvážení jestli to nedát configurovatelný a s defaultem na keboola.sandboxes anebo chceš dělat ještě nějakej další command?

null,
InputOption::VALUE_REQUIRED,
'Only consider workspaces created at or after this date '
. '(strtotime expression, e.g. "-30 days", "2026-01-01"). Default: "-30 days".',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to jsou takový divný defaulty - je to spíš naopak, ty měsíc starý asi jako mazat nechceš

odinuv added 2 commits May 22, 2026 16:02
- Make --component configurable (default keboola.sandboxes); empty value
  permitted so workspaces with no component can be targeted.
- Enrich SKIP/DELETE log lines and the per-project candidates listing with
  component, configurationId, loginType and owner email (from
  creatorToken.description), falling back to "(none)" when absent.
- Override the active-editor-session SKIP when the workspace points at a
  configurationId that no longer exists: GET the config, treat 404 as a
  stale session, log a NOTICE and proceed to delete the workspace.
The earlier SKIP for empty configurationId already returns, so the
nested check inside the active-session branch was unreachable as false.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants