-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from mittwald/feature/backup-commands
Add commands for backup management
- Loading branch information
Showing
24 changed files
with
778 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { ExecRenderBaseCommand } from "../../../rendering/react/ExecRenderBaseCommand.js"; | ||
import { | ||
makeProcessRenderer, | ||
processFlags, | ||
} from "../../../rendering/process/process_flags.js"; | ||
import { projectFlags, withProjectId } from "../../../lib/project/flags.js"; | ||
import React, { ReactNode } from "react"; | ||
import { Flags } from "@oclif/core"; | ||
import { | ||
expirationDateFromFlags, | ||
expireFlagsRequired, | ||
} from "../../../lib/expires.js"; | ||
import { assertStatus } from "@mittwald/api-client-commons"; | ||
import { Success } from "../../../rendering/react/components/Success.js"; | ||
import { waitFlags, waitUntil } from "../../../lib/wait.js"; | ||
import { Text } from "ink"; | ||
|
||
type CreateResult = { | ||
backupId: string; | ||
}; | ||
|
||
export class Create extends ExecRenderBaseCommand<typeof Create, CreateResult> { | ||
static summary = "Create a new backup of a project"; | ||
static flags = { | ||
...processFlags, | ||
...projectFlags, | ||
description: Flags.string({ | ||
description: "a description for the backup.", | ||
}), | ||
...expireFlagsRequired("backup"), | ||
...waitFlags, | ||
}; | ||
|
||
protected async exec(): Promise<CreateResult> { | ||
const p = makeProcessRenderer(this.flags, "Creating backup"); | ||
const projectId = await withProjectId( | ||
this.apiClient, | ||
this.flags, | ||
this.args, | ||
this.config, | ||
); | ||
const { description } = this.flags; | ||
const expirationTime = expirationDateFromFlags(this.flags); | ||
|
||
const backup = await p.runStep("creating backup", async () => { | ||
const r = await this.apiClient.backup.createProjectBackup({ | ||
pathParameters: { projectId }, | ||
data: { | ||
description, | ||
expirationTime: expirationTime.toJSON(), | ||
}, | ||
}); | ||
|
||
assertStatus(r, 201); | ||
|
||
return r.data; | ||
}); | ||
|
||
if (this.flags.wait) { | ||
const stepWaiting = p.addStep( | ||
<Text>waiting for backup to be complete</Text>, | ||
); | ||
|
||
await waitUntil(async () => { | ||
const backupResponse = await this.apiClient.backup.getProjectBackup({ | ||
pathParameters: { projectBackupId: backup.id }, | ||
}); | ||
|
||
if ( | ||
backupResponse.status === 200 && | ||
backupResponse.data.status === "Completed" | ||
) { | ||
return true; | ||
} | ||
}, this.flags["wait-timeout"]); | ||
|
||
stepWaiting.complete(); | ||
} | ||
|
||
p.complete(<Success>Backup successfully created.</Success>); | ||
|
||
return { backupId: backup.id }; | ||
} | ||
|
||
protected render(executionResult: CreateResult): ReactNode { | ||
if (this.flags.quiet) { | ||
return executionResult.backupId; | ||
} | ||
} | ||
} |
Oops, something went wrong.