Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add sftp and ssh user creation and update #687

Merged
merged 29 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fd52a77
start feature - basic setup of args and flags
niristius May 7, 2024
200e07f
Merge remote-tracking branch 'origin' into feature/cronjob-update
niristius May 8, 2024
940cdda
Merge remote-tracking branch 'origin/master' into feature/cronjob-update
niristius Jul 31, 2024
8629001
finish cronjob update command
niristius Aug 1, 2024
07be974
please linter
niristius Aug 1, 2024
9b10d8f
implement ssh|sftp creation and update
niristius Aug 2, 2024
19f6cdd
update readme
niristius Aug 2, 2024
2cbd9ee
Merge branch 'master' into feature/ssh-ftp-user
martin-helmich Aug 22, 2024
06f1356
chore: re-generate README
martin-helmich Aug 22, 2024
75b2273
fix typos, capitalize all initialisms (SFTP, SSH, CLI), add username …
niristius Aug 26, 2024
ef96fa4
chore: re-generate README
niristius Aug 26, 2024
2d68291
implement "inferred" types and expire flags for the create and update…
niristius Aug 26, 2024
ec4ad8c
Merge remote-tracking branch 'origin/feature/ssh-ftp-user' into featu…
niristius Aug 26, 2024
0a06c6d
chore: re-generate README
niristius Aug 26, 2024
fc9ce4a
remove cronjob files that dont belong in this branch
niristius Aug 27, 2024
7280b5d
chore: re-generate README
niristius Aug 27, 2024
7bf2a39
centralize flags for sftp user commands
niristius Aug 28, 2024
9b37d06
chore: re-generate README
niristius Aug 28, 2024
96ad68f
Set useful summaries and description for sftp user flags
niristius Aug 28, 2024
96cf68d
Merge remote-tracking branch 'origin/feature/ssh-ftp-user' into featu…
niristius Aug 28, 2024
e4de364
chore: re-generate README
niristius Aug 28, 2024
1edf731
centralize ssh user flags
niristius Aug 28, 2024
24c364b
Merge remote-tracking branch 'origin/feature/ssh-ftp-user' into featu…
niristius Aug 28, 2024
aeaaa1d
chore: re-generate README
niristius Aug 28, 2024
701bff6
set useful ssh user flag summaries and descriptions
niristius Aug 28, 2024
62aa6dd
Merge remote-tracking branch 'origin/feature/ssh-ftp-user' into featu…
niristius Aug 28, 2024
0d96184
chore: re-generate README
niristius Aug 28, 2024
b78b6a9
Update src/commands/sftp-user/update.tsx
niristius Aug 28, 2024
8d221ad
chore: re-generate README
niristius Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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)
Expand Down Expand Up @@ -247,10 +248,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)
Expand Down Expand Up @@ -2722,6 +2727,41 @@ FLAG DESCRIPTIONS
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 <value>] [--interval <value>] [--disable | --enable] [--email
<value>] [--timeout <value>] [--url <value>] [--command <value>] [--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=<value> Set file and parameters to execute on cron job execution
--description=<value> Set cron job description
--disable Disable cron job automated execution
--email=<value> Set target email to send error messages to
--enable Enable cron job automated execution
--interpreter=<option> Set interpreter to use for execution
<options: bash|php>
--interval=<value> Set cron job execution interval
--timeout=<value> Set timeout in seconds after wich the process is killed
--url=<value> Set url to use on cron job execution

DESCRIPTION
Update an existing cron job

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 database mysql charsets`

List available MySQL character sets and collations, optionally filtered by a MySQLVersion.
Expand Down Expand Up @@ -5262,6 +5302,41 @@ DESCRIPTION
List servers for an organization or user.
```

## `mw sftp-user create`

Create a new sftp user

```
USAGE
$ mw sftp-user create --description <value> --directories <value>... [-p <value>] [-q] [--public-key <value>]
[--password <value>] [--expires <value>] [--access-level read|full]

FLAGS
-p, --project-id=<value> 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.
--access-level=<option> Set access level privileges for the sftp user
<options: read|full>
--description=<value> (required) Description of sftp user
--directories=<value>... (required) Set directories to restrict the sftp users access to
--expires=<value> Date at wich the sftp user get disabled automatically
--password=<value> Password used for authentication
--public-key=<value> Public Key used for authentication

FLAG DESCRIPTIONS
-p, --project-id=<value>

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=<VALUE>" 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 sftp-user delete SFTP-USER-ID`

Delete an SFTP user
Expand Down Expand Up @@ -5323,6 +5398,72 @@ FLAG DESCRIPTIONS
to persistently set a default project for all commands that accept this flag.
```

## `mw sftp-user update SFTP-USER-ID`

Update an existing sftp user

```
USAGE
$ mw sftp-user update SFTP-USER-ID [-q] [--description <value>] [--public-key <value> | --password <value>]
[--expires <value>] [--access-level read|full] [--directories <value>...] [--disable | --enable]

ARGUMENTS
SFTP-USER-ID The ID of the sftp user to update

FLAGS
-q, --quiet suppress process output and only display a machine-readable summary.
--access-level=<option> Set access level privileges for the sftp user
<options: read|full>
--description=<value> Set the sftp users description
--directories=<value>... Set directories to restrict the sftp users access to
--disable Disable sftp user
--enable Enable sftp user
--expires=<value> Date at wich the sftp user will be disabled automatically
--password=<value> Password used for authentication
--public-key=<value> Public Key used for authentication

DESCRIPTION
Update an existing sftp user

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 ssh-user create`

Create a new ssh user

```
USAGE
$ mw ssh-user create --description <value> [-p <value>] [-q] [--expires <value>] [--public-key <value>] [--password
<value>]

FLAGS
-p, --project-id=<value> 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=<value> (required) Description of ssh user
--expires=<value> Date at wich the ssh user get disabled automatically
--password=<value> Password used for authentication
--public-key=<value> Public Key used for authentication

FLAG DESCRIPTIONS
-p, --project-id=<value>

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=<VALUE>" 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 ssh-user delete SSH-USER-ID`

Delete an SSH user
Expand Down Expand Up @@ -5384,6 +5525,37 @@ FLAG DESCRIPTIONS
to persistently set a default project for all commands that accept this flag.
```

## `mw ssh-user update SSH-USER-ID`

Update an existing cron job

```
USAGE
$ mw ssh-user update SSH-USER-ID [-q] [--description <value>] [--public-key <value>] [--password <value>]
[--expires <value>] [--disable | --enable]

ARGUMENTS
SSH-USER-ID The ID of the SSH user to update

FLAGS
-q, --quiet suppress process output and only display a machine-readable summary.
--description=<value> Set cron job description
--disable Disable ssh user
--enable Enable ssh user
--expires=<value> Date at wich the User get disabled automatically
--password=<value> Password used for authentication
--public-key=<value> Public Key used for authentication

DESCRIPTION
Update an existing cron job

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 update [CHANNEL]`

update the mw CLI
Expand Down
153 changes: 153 additions & 0 deletions src/commands/cronjob/update.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { ExecRenderBaseCommand } from "../../lib/basecommands/ExecRenderBaseCommand.js";
import { Args, Flags } 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";
import { MittwaldAPIV2 } from "@mittwald/api-client";

type UpdateResult = void;

export default class Update extends ExecRenderBaseCommand<
typeof Update,
UpdateResult
> {
static description = "Update an existing cron job";
static args = {
"cronjob-id": Args.string({
description: "ID of the cron job to be updated.",
required: true,
}),
};
static flags = {
description: Flags.string({
description: "Set cron job description",
}),
interval: Flags.string({
description: "Set cron job execution interval",
}),
disable: Flags.boolean({
description: "Disable cron job automated execution",
exclusive: ["enable"],
}),
enable: Flags.boolean({
description: "Enable cron job automated execution",
exclusive: ["disable"],
}),
email: Flags.string({
description: "Set target email to send error messages to",
}),
timeout: Flags.integer({
description: "Set timeout in seconds after wich the process is killed",
}),
url: Flags.string({
description: "Set url to use on cron job execution",
}),
command: Flags.string({
description: "Set file and parameters to execute on cron job execution",
}),
interpreter: Flags.string({
description: "Set interpreter to use for execution",
options: ["bash", "php"],
}),
...processFlags,
};

protected async exec(): Promise<void> {
type destinationType =
| MittwaldAPIV2.Components.Schemas.CronjobCronjobCommand
| MittwaldAPIV2.Components.Schemas.CronjobCronjobUrl;

type cronjobUpdatePayload = {
active: boolean;
description: string;
destination: destinationType;
email: string;
timeout: number;
interval: string;
};

const process = makeProcessRenderer(this.flags, "Updating cron job");

const { "cronjob-id": cronjobId } = this.args;
const currentCronjob = await this.apiClient.cronjob.getCronjob({
cronjobId,
});
assertSuccess(currentCronjob);

const {
description,
interval,
email,
timeout,
url,
interpreter,
command,
disable,
enable,
} = this.flags;

let cronjobActive: boolean;
if (enable) {
cronjobActive = true;
} else if (disable) {
cronjobActive = false;
} else {
cronjobActive = currentCronjob.data.active as boolean;
}

let destination: destinationType = currentCronjob.data
.destination as destinationType;

if (url) {
destination = {
url,
};
} else if (interpreter) {
let destinationInterpreter = interpreter;
if (interpreter == "bash") {
destinationInterpreter = "/bin/bash";
} else if (interpreter == "php") {
destinationInterpreter = "/usr/bin/php";
}

if (url) {
destination = { url };
} else if (interpreter) {
destination = {
interpreter: destinationInterpreter,
path: command as string,
};
}
}

const data: cronjobUpdatePayload = {
active: cronjobActive,
description: description
? description
: (currentCronjob.data.description as string),
destination: destination,
email: email ? email : (currentCronjob.data.email as string),
timeout: timeout ? timeout : (currentCronjob.data.timeout as number),
interval: interval ? interval : (currentCronjob.data.interval as string),
};

await process.runStep("Updating cron job", async () => {
const response = await this.apiClient.cronjob.updateCronjob({
cronjobId,
data,
});
assertSuccess(response);
});

const successText: string = "Your cron job has successfully been updated.";
await process.complete(<Success>{successText}</Success>);
}

protected render(): ReactNode {
return true;
}
}
Loading