From f037e9edf18c014ab38c921a8dea39cb527f0863 Mon Sep 17 00:00:00 2001 From: Michel Hopfner Date: Wed, 14 Aug 2024 11:42:40 +0200 Subject: [PATCH 01/15] implement create, delete and update commands for backup schedule. --- src/commands/backup/schedule/create.tsx | 100 ++++++++++++++++++++++++ src/commands/backup/schedule/delete.tsx | 57 ++++++++++++++ src/commands/backup/schedule/update.tsx | 98 +++++++++++++++++++++++ 3 files changed, 255 insertions(+) create mode 100644 src/commands/backup/schedule/create.tsx create mode 100644 src/commands/backup/schedule/delete.tsx create mode 100644 src/commands/backup/schedule/update.tsx diff --git a/src/commands/backup/schedule/create.tsx b/src/commands/backup/schedule/create.tsx new file mode 100644 index 00000000..f5abed80 --- /dev/null +++ b/src/commands/backup/schedule/create.tsx @@ -0,0 +1,100 @@ +import { ExecRenderBaseCommand } from "../../../lib/basecommands/ExecRenderBaseCommand.js"; +import { + makeProcessRenderer, + processFlags, +} from "../../../rendering/process/process_flags.js"; +import { ReactNode } from "react"; +import { Flags } from "@oclif/core"; +import { assertStatus } from "@mittwald/api-client-commons"; +import { Success } from "../../../rendering/react/components/Success.js"; +import { Value } from "../../../rendering/react/components/Value.js"; + +import { projectFlags } from "../../../lib/resources/project/flags.js"; + +type Result = { + projectBackupScheduleId: string; +}; + +export class Create extends ExecRenderBaseCommand { + static summary = "Create a new backup schedule"; + static flags = { + ...projectFlags, + ...processFlags, + description: Flags.string({ + description: "Set the description for the backup schedule", + }), + schedule: Flags.string({ + required: true, + description: "Define the schedule itself", + }), + ttl: Flags.string({ + required: true, + description: + "Define the backup storage period in days, for through this schedule created backups", + }), + }; + + protected async exec(): Promise { + const process = makeProcessRenderer(this.flags, "Creating a new sftp User"); + const projectId = await this.withProjectId(Create); + const { description, schedule, ttl } = this.flags; + + const createBackupSchedulePayload: { + description?: string | undefined; + schedule: string; + ttl: string; + } = { + schedule, + ttl, + }; + + if (description) { + createBackupSchedulePayload.description = description; + } + + const { id: projectBackupScheduleId } = await process.runStep( + "creating backup schedule", + async () => { + const r = await this.apiClient.backup.createProjectBackupSchedule({ + projectId, + data: createBackupSchedulePayload, + }); + assertStatus(r, 201); + return r.data; + }, + ); + + const projectBackupSchedule = await process.runStep( + "checking newly created backup schedule", + async () => { + const r = await this.apiClient.backup.getProjectBackupSchedule({ + projectBackupScheduleId, + }); + assertStatus(r, 200); + return r.data; + }, + ); + + if (description) { + process.complete( + + The backup schedule " + {projectBackupSchedule.description}" was successfully + created. + , + ); + } else { + process.complete( + The backup schedule was successfully created., + ); + } + + return { projectBackupScheduleId }; + } + + protected render({ projectBackupScheduleId }: Result): ReactNode { + if (this.flags.quiet) { + return projectBackupScheduleId; + } + } +} diff --git a/src/commands/backup/schedule/delete.tsx b/src/commands/backup/schedule/delete.tsx new file mode 100644 index 00000000..7477f93a --- /dev/null +++ b/src/commands/backup/schedule/delete.tsx @@ -0,0 +1,57 @@ +import { DeleteBaseCommand } from "../../../lib/basecommands/DeleteBaseCommand.js"; +import { assertStatus } from "@mittwald/api-client-commons"; +import { Args, Flags } from "@oclif/core"; +import { + makeProcessRenderer, + processFlags, +} from "../../../rendering/process/process_flags.js"; + +export class Delete extends DeleteBaseCommand { + static description = "Delete a backup schedule"; + static resourceName = "backupSchedule"; + static args = { + backupScheduleId: Args.string({ + description: "ID of schedule to delete", + }), + }; + static flags = { + ...processFlags, + backupScheduleId: Flags.string({ + description: "ID of backup schedule to delete", + }), + }; + + protected async deleteResource(): Promise { + // TODO: implement withBackupScheduleId() + + const process = makeProcessRenderer(this.flags, "Updating backup schedule"); + let projectBackupScheduleId: string = ""; + if (this.flags.backupScheduleId) { + projectBackupScheduleId = this.flags.backupScheduleId; + } else if (this.args.backupScheduleId) { + projectBackupScheduleId = this.args.backupScheduleId; + } else { + await process.error( + "Please provide a backup schedule id as flag or argument", + ); + } + + const currentBackupSchedule = + await this.apiClient.backup.getProjectBackupSchedule({ + projectBackupScheduleId, + }); + + if (currentBackupSchedule.data.isSystemBackup) { + await process.error( + "The system backup created through this schedule is reserved to restore your project in an emergency. " + + "It can not be deleted.", + ); + } + + const response = await this.apiClient.backup.deleteProjectBackupSchedule({ + projectBackupScheduleId, + }); + + assertStatus(response, 204); + } +} diff --git a/src/commands/backup/schedule/update.tsx b/src/commands/backup/schedule/update.tsx new file mode 100644 index 00000000..cc3ae67c --- /dev/null +++ b/src/commands/backup/schedule/update.tsx @@ -0,0 +1,98 @@ +import { ExecRenderBaseCommand } from "../../../lib/basecommands/ExecRenderBaseCommand.js"; +import { Flags, Args } from "@oclif/core"; +import { ReactNode } from "react"; +import { + makeProcessRenderer, + processFlags, +} from "../../../rendering/process/process_flags.js"; +import { Success } from "../../../rendering/react/components/Success.js"; +import assertSuccess from "../../../lib/apiutil/assert_success.js"; + +type UpdateResult = void; + +export default class Create extends ExecRenderBaseCommand< + typeof Create, + UpdateResult +> { + static description = "Update an existing backup schedule"; + static args = { + scheduleId: Args.string({ + description: "Define the backup schedule that is to be updated", + }), + }; + static flags = { + ...processFlags, + scheduleId: Flags.string({ + description: "Define the backup schedule that is to be updated", + }), + description: Flags.string({ + description: "Set the description for the backup schedule", + }), + schedule: Flags.string({ + description: "Define the schedule itself", + }), + ttl: Flags.string({ + description: + "Define the backup storage period in days, for through this schedule created backups", + }), + }; + + protected async exec(): Promise { + const process = makeProcessRenderer(this.flags, "Updating backup schedule"); + + // TODO: implement withBackupScheduleId() + let projectBackupScheduleId: string = ""; + if (this.flags.scheduleId) { + projectBackupScheduleId = this.flags.scheduleId; + } else if (this.args.scheduleId) { + projectBackupScheduleId = this.args.scheduleId; + } else { + await process.error( + "Please provide a backup schedule id as flag or argument", + ); + } + + const { description, schedule, ttl } = this.flags; + + const backupScheduleCreatePayload: { + description?: string | undefined; + schedule?: string | undefined; + ttl?: string | undefined; + } = {}; + + if (description) { + backupScheduleCreatePayload.description = description; + } + + if (schedule) { + backupScheduleCreatePayload.schedule = schedule; + } + + if (ttl) { + backupScheduleCreatePayload.ttl = ttl; + } + + if (Object.keys(backupScheduleCreatePayload).length == 0) { + await process.complete( + Nothing to change. Have a good day!, + ); + } else { + await process.runStep("Updating backup schedule", async () => { + const response = + await this.apiClient.backup.updateProjectBackupSchedule({ + projectBackupScheduleId, + data: backupScheduleCreatePayload, + }); + assertSuccess(response); + }); + + await process.complete( + Your backup schedule has successfully been updated., + ); + } + } + + protected render(): ReactNode { + return true; + } +} From e47afcc08c2472a2c11a43d259202c13688942cf Mon Sep 17 00:00:00 2001 From: Michel Hopfner Date: Wed, 14 Aug 2024 11:46:13 +0200 Subject: [PATCH 02/15] update readme --- README.md | 443 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 301 insertions(+), 142 deletions(-) diff --git a/README.md b/README.md index 065e489c..9cfb6fe0 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,10 @@ USAGE * [`mw backup download BACKUP-ID`](#mw-backup-download-backup-id) * [`mw backup get BACKUP-ID`](#mw-backup-get-backup-id) * [`mw backup list`](#mw-backup-list) +* [`mw backup schedule create`](#mw-backup-schedule-create) +* [`mw backup schedule delete [BACKUPSCHEDULEID]`](#mw-backup-schedule-delete-backupscheduleid) * [`mw backup schedule list`](#mw-backup-schedule-list) +* [`mw backup schedule update [SCHEDULEID]`](#mw-backup-schedule-update-scheduleid) * [`mw context get`](#mw-context-get) * [`mw context reset`](#mw-context-reset) * [`mw context set`](#mw-context-set) @@ -168,6 +171,7 @@ USAGE * [`mw cronjob execution logs CRONJOB-ID EXECUTION-ID`](#mw-cronjob-execution-logs-cronjob-id-execution-id) * [`mw cronjob get CRONJOB-ID`](#mw-cronjob-get-cronjob-id) * [`mw cronjob list`](#mw-cronjob-list) +* [`mw cronjob update CRONJOB-ID`](#mw-cronjob-update-cronjob-id) * [`mw database mysql charsets`](#mw-database-mysql-charsets) * [`mw database mysql create`](#mw-database-mysql-create) * [`mw database mysql delete DATABASE-ID`](#mw-database-mysql-delete-database-id) @@ -247,10 +251,14 @@ USAGE * [`mw project update [PROJECT-ID]`](#mw-project-update-project-id) * [`mw server get [SERVER-ID]`](#mw-server-get-server-id) * [`mw server list`](#mw-server-list) +* [`mw sftp-user create`](#mw-sftp-user-create) * [`mw sftp-user delete SFTP-USER-ID`](#mw-sftp-user-delete-sftp-user-id) * [`mw sftp-user list`](#mw-sftp-user-list) +* [`mw sftp-user update SFTP-USER-ID`](#mw-sftp-user-update-sftp-user-id) +* [`mw ssh-user create`](#mw-ssh-user-create) * [`mw ssh-user delete SSH-USER-ID`](#mw-ssh-user-delete-ssh-user-id) * [`mw ssh-user list`](#mw-ssh-user-list) +* [`mw ssh-user update SSH-USER-ID`](#mw-ssh-user-update-ssh-user-id) * [`mw update [CHANNEL]`](#mw-update-channel) * [`mw user api-token create`](#mw-user-api-token-create) * [`mw user api-token get TOKEN-ID`](#mw-user-api-token-get-token-id) @@ -314,9 +322,7 @@ DESCRIPTION Creates new custom Node.js installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -362,9 +368,7 @@ DESCRIPTION Creates new custom PHP installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -411,9 +415,7 @@ DESCRIPTION Creates new custom python site installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -459,9 +461,7 @@ DESCRIPTION Creates new custom static site installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -688,9 +688,7 @@ DESCRIPTION Creates new Contao installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -777,9 +775,7 @@ DESCRIPTION Creates new Drupal installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -856,9 +852,7 @@ DESCRIPTION Creates new Grav installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -942,9 +936,7 @@ DESCRIPTION Creates new Joomla! installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1031,9 +1023,7 @@ DESCRIPTION Creates new Matomo installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1108,9 +1098,7 @@ DESCRIPTION Creates new Moodle installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1185,9 +1173,7 @@ DESCRIPTION Creates new NEOS installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1262,9 +1248,7 @@ DESCRIPTION Creates new Nextcloud installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1343,9 +1327,7 @@ DESCRIPTION Creates new PrestaShop installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1440,9 +1422,7 @@ DESCRIPTION Creates new Shopware 5 installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1554,9 +1534,7 @@ DESCRIPTION Creates new Shopware 6 installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1664,9 +1642,7 @@ DESCRIPTION Creates new TYPO3 installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1748,9 +1724,7 @@ DESCRIPTION Creates new WordPress installation. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1823,9 +1797,7 @@ DESCRIPTION List installed apps in a project. FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -1961,9 +1933,7 @@ DESCRIPTION Upgrade app installation to target version FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -2109,9 +2079,7 @@ ALIASES $ mw project backup create FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. @@ -2248,12 +2216,65 @@ ALIASES $ mw project backup list FLAG DESCRIPTIONS - -p, --project-id= + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context + + May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command + to persistently set a default project for all commands that accept this flag. +``` + +## `mw backup schedule create` - ID or short ID of a project; this flag is optional if a default project is set in the context +Create a new backup schedule + +``` +USAGE + $ mw backup schedule create --schedule --ttl [-p ] [-q] [--description ] + +FLAGS + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the + context + -q, --quiet suppress process output and only display a machine-readable summary. + --description= Set the description for the backup schedule + --schedule= (required) Define the schedule itself + --ttl= (required) Define the backup storage period in days, for through this schedule created + backups + +FLAG DESCRIPTIONS + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. + + -q, --quiet suppress process output and only display a machine-readable summary. + + This flag controls if you want to see the process output or only a summary. When using mw non-interactively (e.g. in + scripts), you can use this flag to easily get the IDs of created resources for further processing. +``` + +## `mw backup schedule delete [BACKUPSCHEDULEID]` + +Delete a backup schedule + +``` +USAGE + $ mw backup schedule delete [BACKUPSCHEDULEID] [-q] [-f] [--backupScheduleId ] + +ARGUMENTS + BACKUPSCHEDULEID ID of schedule to delete + +FLAGS + -f, --force Do not ask for confirmation + -q, --quiet suppress process output and only display a machine-readable summary. + --backupScheduleId= ID of backup schedule to delete + +DESCRIPTION + Delete a backup schedule + +FLAG DESCRIPTIONS + -q, --quiet suppress process output and only display a machine-readable summary. + + This flag controls if you want to see the process output or only a summary. When using mw non-interactively (e.g. in + scripts), you can use this flag to easily get the IDs of created resources for further processing. ``` ## `mw backup schedule list` @@ -2284,14 +2305,41 @@ ALIASES $ mw project backupschedule list FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. ``` +## `mw backup schedule update [SCHEDULEID]` + +Update an existing backup schedule + +``` +USAGE + $ mw backup schedule update [SCHEDULEID] [-q] [--scheduleId ] [--description ] [--schedule ] [--ttl + ] + +ARGUMENTS + SCHEDULEID Define the backup schedule that is to be updated + +FLAGS + -q, --quiet suppress process output and only display a machine-readable summary. + --description= Set the description for the backup schedule + --schedule= Define the schedule itself + --scheduleId= Define the backup schedule that is to be updated + --ttl= Define the backup storage period in days, for through this schedule created backups + +DESCRIPTION + Update an existing backup schedule + +FLAG DESCRIPTIONS + -q, --quiet suppress process output and only display a machine-readable summary. + + This flag controls if you want to see the process output or only a summary. When using mw non-interactively (e.g. in + scripts), you can use this flag to easily get the IDs of created resources for further processing. +``` + ## `mw context get` Print an overview of currently set context parameters @@ -2714,14 +2762,47 @@ ALIASES $ mw project cronjob list FLAG DESCRIPTIONS - -p, --project-id= - - ID or short ID of a project; this flag is optional if a default project is set in the context + -p, --project-id= ID or short ID of a project; this flag is optional if a default project is set in the context May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=" command to persistently set a default project for all commands that accept this flag. ``` +## `mw cronjob update CRONJOB-ID` + +Update an existing cron job + +``` +USAGE + $ mw cronjob update CRONJOB-ID [--description ] [--interval ] [--disable | --enable] [--email + ] [--timeout ] [--url ] [--command ] [--interpreter bash|php] [-q] + +ARGUMENTS + CRONJOB-ID ID of the cron job to be updated. + +FLAGS + -q, --quiet suppress process output and only display a machine-readable summary. + --command= Set file and parameters to execute on cron job execution + --description= Set cron job description + --disable Disable cron job automated execution + --email= Set target email to send error messages to + --enable Enable cron job automated execution + --interpreter=