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 mail deliverybox #653

Merged
merged 22 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e9c5bb0
fix: yarn install
tillwestpfahl Jul 15, 2024
030de8d
feat: add 'create' deliverybox
tillwestpfahl Jul 15, 2024
59d2171
Merge branch 'master' into feat/add-mail-deliverybox
martin-helmich Aug 22, 2024
e8521c1
chore: re-generate README
martin-helmich Aug 22, 2024
c04227d
Apply suggestions from code review
tillwestpfahl Aug 26, 2024
88f46ad
chore: re-generate README
tillwestpfahl Aug 26, 2024
238dfde
feat: use the 'exclusive' flag, to prevent simulatneous use of both p…
tillwestpfahl Aug 26, 2024
f1339ff
chore: re-generate README
tillwestpfahl Aug 26, 2024
db2b589
refactor: use existing 'generatePassword' method
tillwestpfahl Aug 26, 2024
8f07b26
refactor: extract duplicate password logic
tillwestpfahl Aug 26, 2024
3994691
fix: import { Text } from 'ink'
tillwestpfahl Aug 27, 2024
564cb7b
refactor: replace 'deliverybox' with 'delivery box'
tillwestpfahl Aug 28, 2024
f36f5a6
feat: add delivery box 'update'; also some refactoring
tillwestpfahl Aug 28, 2024
c47f069
chore: re-generate README
tillwestpfahl Aug 28, 2024
b33d383
fix: remove unused import
tillwestpfahl Aug 28, 2024
52f59d7
feat: add delivery box 'delete'
tillwestpfahl Aug 28, 2024
283548a
chore: re-generate README
tillwestpfahl Aug 28, 2024
5e77b9c
refactor: naming consistency
tillwestpfahl Aug 28, 2024
ed9bdf6
refactor: move library/util code to lib/resources/mail
tillwestpfahl Aug 28, 2024
2310072
fix: replace 'makeProjectFlagSet' with simple 'new FlagSetBuilder'
tillwestpfahl Aug 28, 2024
5d60e2e
Merge remote-tracking branch 'origin/master' into feat/add-mail-deliv…
martin-helmich Aug 28, 2024
95aaebf
chore: re-generate README
martin-helmich 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
156 changes: 152 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,11 @@ USAGE
* [`mw mail address get ID`](#mw-mail-address-get-id)
* [`mw mail address list`](#mw-mail-address-list)
* [`mw mail address update MAILADDRESS-ID`](#mw-mail-address-update-mailaddress-id)
* [`mw mail deliverybox create`](#mw-mail-deliverybox-create)
* [`mw mail deliverybox delete ID`](#mw-mail-deliverybox-delete-id)
* [`mw mail deliverybox get ID`](#mw-mail-deliverybox-get-id)
* [`mw mail deliverybox list`](#mw-mail-deliverybox-list)
* [`mw mail deliverybox update MAILDELIVERYBOX-ID`](#mw-mail-deliverybox-update-maildeliverybox-id)
* [`mw org delete [ORG-ID]`](#mw-org-delete-org-id)
* [`mw org get [ORG-ID]`](#mw-org-get-org-id)
* [`mw org invite`](#mw-org-invite)
Expand Down Expand Up @@ -3938,7 +3941,7 @@ Create a new mail address
```
USAGE
$ mw mail address create -a <value> [-p <value>] [-q] [--catch-all] [--enable-spam-protection] [--quota <value>]
[--password <value>] [--random-password] [--forward-to <value>...]
[--password <value> | --random-password] [--forward-to <value>...]

FLAGS
-a, --address=<value> (required) mail address
Expand Down Expand Up @@ -4167,6 +4170,92 @@ FLAG DESCRIPTIONS
--quiet, the password will be printed to stdout.
```

## `mw mail deliverybox create`

Create a new mail delivery box

```
USAGE
$ mw mail deliverybox create -d <value> [-p <value>] [-q] [--password <value> | --random-password]

FLAGS
-d, --description=<value> (required) mail delivery box description
-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.
--password=<value> delivery box password
--random-password generate a random password

DESCRIPTION
Create a new mail delivery box

This command can be used to create a new mail delivery box in a project.

When running this command with the --quiet flag, the output will contain the ID of the newly created delivery box.
In addition, when run with --generated-password the output will be the ID of the newly created delivery box, followed
by a tab character and the generated password.

EXAMPLES
Create non-interactively with password

$ read -s PASSWORD && \
mw mail deliverybox create --password $PASSWORD --description 'my personal delivery box'

Create non-interactively with random password

$ mw mail deliverybox create --random-password --description 'my personal delivery box'

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.

--password=<value> delivery box password

This is the password that should be used for the delivery box; if omitted, the command will prompt interactively for
a password.

CAUTION: providing this flag may log your password in your shell history!

--random-password generate a random password

This flag will cause the command to generate a random 32-character password for the delivery box; when running with
--quiet, the delivery box ID and the password will be printed to stdout, separated by a tab character.
```

## `mw mail deliverybox delete ID`

Delete a mail delivery box

```
USAGE
$ mw mail deliverybox delete ID [-q] [-f]

ARGUMENTS
ID Mail delivery box ID

FLAGS
-f, --force Do not ask for confirmation
-q, --quiet suppress process output and only display a machine-readable summary.

DESCRIPTION
Delete a mail delivery box

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 mail deliverybox get ID`

Get a specific delivery box
Expand All @@ -4176,7 +4265,7 @@ USAGE
$ mw mail deliverybox get ID [-o json|yaml | | ]

ARGUMENTS
ID ID of the deliverybox you want to retrieve
ID ID of the delivery box you want to retrieve

FLAGS
-o, --output=<option> output in a more machine friendly format
Expand All @@ -4188,7 +4277,7 @@ DESCRIPTION

## `mw mail deliverybox list`

Get all deliveryboxes by project ID
Get all delivery boxes by project ID

```
USAGE
Expand All @@ -4208,7 +4297,7 @@ FLAGS
--no-truncate do not truncate output to fit screen

DESCRIPTION
Get all deliveryboxes by project ID
Get all delivery boxes by project ID

FLAG DESCRIPTIONS
-p, --project-id=<value>
Expand All @@ -4219,6 +4308,65 @@ FLAG DESCRIPTIONS
to persistently set a default project for all commands that accept this flag.
```

## `mw mail deliverybox update MAILDELIVERYBOX-ID`

Update a mail delivery box

```
USAGE
$ mw mail deliverybox update MAILDELIVERYBOX-ID [-q] [--description <value>] [--password <value>] [--random-password]

ARGUMENTS
MAILDELIVERYBOX-ID ID or short ID of a maildeliverybox

FLAGS
-q, --quiet suppress process output and only display a machine-readable summary.
--description=<value> delivery box description
--password=<value> delivery box password
--random-password generate a random password

DESCRIPTION
Update a mail delivery box

This command can be used to update a mail delivery box in a project.

A mail delivery box is either associated with a mailbox, or forwards to another address.

When running this command with --generated-password the output will be the newly generated and set password.

EXAMPLES
Update non-interactively with password

$ read -s PASSWORD && \
mw mail deliverybox update --password $PASSWORD --description 'my personal delivery box'

Update non-interactively with random password

$ mw mail deliverybox update --random-password --description 'my personal delivery box'

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.

--description=<value> delivery box description

If set, the delivery description will be updated to this password. If omitted, the description will remain
unchanged.

--password=<value> delivery box password

If set, the delivery box will be updated to this password. If omitted, the password will remain unchanged.

CAUTION: providing this flag may log your password in your shell history!

--random-password generate a random password

This flag will cause the command to generate a random 32-character password for the delivery box; when running with
--quiet, the password will be printed to stdout.
```

## `mw org delete [ORG-ID]`

Delete an organization
Expand Down
24 changes: 8 additions & 16 deletions src/commands/mail/address/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import { Text } from "ink";
import { Success } from "../../../rendering/react/components/Success.js";
import { ReactNode } from "react";
import { ProcessRenderer } from "../../../rendering/process/process.js";
import * as crypto from "crypto";
import { Value } from "../../../rendering/react/components/Value.js";
import { FlagInput, OutputFlags } from "@oclif/core/lib/interfaces/parser.js";
import ByteQuantity from "../../../lib/units/ByteQuantity.js";
import { generateRandomPassword } from "../commons.js";

type CreateResult = {
addressId: string;
Expand Down Expand Up @@ -58,11 +57,13 @@ export default class Create extends ExecRenderBaseCommand<
}),
password: Flags.string({
summary: "mailbox password",
exclusive: ["random-password"],
tillwestpfahl marked this conversation as resolved.
Show resolved Hide resolved
description:
"This is the password that should be used for the mailbox; if omitted, the command will prompt interactively for a password.\n\nCAUTION: providing this flag may log your password in your shell history!",
}),
"random-password": Flags.boolean({
summary: "generate a random password",
exclusive: ["password"],
description:
"This flag will cause the command to generate a random 32-character password for the mailbox; when running with --quiet, the address ID and the password will be printed to stdout, separated by a tab character.",
}),
Expand Down Expand Up @@ -113,22 +114,13 @@ export default class Create extends ExecRenderBaseCommand<
}

if (this.flags["random-password"]) {
const generated = await process.runStep(
"generating random password",
async () => {
return crypto.randomBytes(32).toString("base64").substring(0, 32);
},
);

process.addInfo(
<Text>
generated password: <Value>{generated}</Value>
</Text>,
);
return [generated, true];
return [await generateRandomPassword(process), true];
}

return [await process.addInput(<Text>Mailbox password</Text>, true), false];
return [
await process.addInput(<Text>enter mailbox password</Text>, true),
false,
];
}

protected async createForwardAddress(
Expand Down
9 changes: 2 additions & 7 deletions src/commands/mail/address/update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
mailAddressArgs,
withMailAddressId,
} from "../../../lib/resources/mail/flags.js";
import crypto from "crypto";
import { generateRandomPassword } from "../commons.js";

type UpdateResult = {
generatedPassword: string | null;
Expand Down Expand Up @@ -220,12 +220,7 @@ export default class Update extends ExecRenderBaseCommand<
if (this.flags.password) {
await this.setPassword(mailAddressId, this.flags.password, process);
} else if (this.flags["random-password"]) {
password = await process.runStep(
"generating random password",
async () => {
return crypto.randomBytes(32).toString("base64").substring(0, 32);
},
);
password = await generateRandomPassword(process);

await this.setPassword(mailAddressId, password, process);
}
Expand Down
21 changes: 21 additions & 0 deletions src/commands/mail/commons.tsx
martin-helmich marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { generatePassword } from "../../lib/util/password/generatePassword.js";
import { Value } from "../../rendering/react/components/Value.js";
import { ProcessRenderer } from "../../rendering/process/process.js";
import { Text } from "ink";

export async function generateRandomPassword(
process: ProcessRenderer,
): Promise<string> {
const generated = await process.runStep(
"generating random password",
async () => generatePassword(32),
);

process.addInfo(
<Text>
{" "}
generated password: <Value>{generated}</Value>{" "}
</Text>,
);
return generated;
}
Loading