Skip to content

Commit d48b6d8

Browse files
author
mdatelle
committed
feat: add description flag, remove console log, and update readme
1 parent eb4c44e commit d48b6d8

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

api/README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,78 @@ root@Devon:~# unraid-api
1717

1818
Unraid API
1919

20-
Thanks for using the official Unraid API
20+
Thanks for using the official Unraid API
2121

2222
Usage:
2323

24-
$ unraid-api command <options>
24+
$ unraid-api command <options>
2525

2626
Commands:
2727

2828
start/stop/restart/version/status/report/switch-env
2929

3030
Options:
3131

32-
-h, --help Prints this usage guide.
33-
-d, --debug Enabled debug mode.
34-
-p, --port string Set the graphql port.
35-
--environment production/staging/development Set the working environment.
36-
--log-level ALL/TRACE/DEBUG/INFO/WARN/ERROR/FATAL/MARK/OFF Set the log level.
32+
-h, --help Prints this usage guide.
33+
-d, --debug Enabled debug mode.
34+
-p, --port string Set the graphql port.
35+
--environment production/staging/development Set the working environment.
36+
--log-level ALL/TRACE/DEBUG/INFO/WARN/ERROR/FATAL/MARK/OFF Set the log level.
3737

3838
Copyright © 2024 Lime Technology, Inc.
3939

4040
```
4141

42+
## Key
43+
44+
To get an existing API key, run:
45+
46+
```
47+
unraid-api key get --name "my-app-key"
48+
```
49+
50+
To get an API key, and create if it doesn't exist, run:
51+
52+
```
53+
unraid-api key get --name "my-app-key" --create
54+
```
55+
56+
To create a new API key with specific roles, run:
57+
58+
```
59+
unraid-api key create --name "backup-app" --roles "admin,guest"
60+
```
61+
62+
To create a new API key with roles and permissions, run:
63+
64+
```
65+
unraid-api key create --name "backup-app" --roles "admin,guest" --permissions "read:any"
66+
```
67+
4268
## Report
69+
4370
To view the current status of the unraid-api and its connection to mothership, run:
71+
4472
```
4573
unraid-api report
4674
```
4775

4876
To view verbose data (anonymized), run:
77+
4978
```
5079
unraid-api report -v
5180
```
5281

5382
To view non-anonymized verbose data, run:
83+
5484
```
5585
unraid-api report -vv
5686
```
5787

5888
## Secrets
89+
5990
If you found this file you're likely a developer. If you'd like to know more about the API and when it's available please join [our discord](https://discord.unraid.net/).
6091

6192
## License
93+
6294
Copyright Lime Technology Inc. All rights reserved.

api/src/cli/commands/key.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ enum Command {
1010
}
1111

1212
type KeyFlags = {
13+
create?: boolean;
1314
command: string;
15+
description?: string;
1416
name: string;
15-
create?: boolean;
16-
roles?: string;
1717
permissions?: string;
18+
roles?: string;
1819
};
1920

2021
const validRoles: Set<Role> = new Set(Object.values(Role));
@@ -42,6 +43,7 @@ const keyOptions: ArgumentConfig<KeyFlags> = {
4243
command: { type: String, description: 'get or create' },
4344
name: { type: String, description: 'Name of the API key', typeLabel: '{underline name}' },
4445
create: { type: Boolean, optional: true, description: "Create the key if it doesn't exist" },
46+
description: { type: String, optional: true, description: 'Description of the API key' },
4547
roles: {
4648
type: String,
4749
optional: true,
@@ -70,12 +72,12 @@ export const key = async (...argv: string[]) => {
7072
const roles = validateRoles(options.roles);
7173
const key = await apiKeyService.create(
7274
options.name,
73-
`CLI generated key: ${options.name}`,
75+
options.description || `CLI generated key: ${options.name}`,
7476
roles,
7577
true
7678
);
7779

78-
console.log('API Key: ', key);
80+
cliLogger.info('API Key: ', key);
7981
cliLogger.info('API key created successfully');
8082

8183
break;
@@ -88,15 +90,15 @@ export const key = async (...argv: string[]) => {
8890
const roles = validateRoles(options.roles);
8991
const newKey = await apiKeyService.create(
9092
options.name,
91-
`CLI generated key: ${options.name}`,
93+
options.description || `CLI generated key: ${options.name}`,
9294
roles,
9395
true
9496
);
9597

96-
console.log('New API Key: ', newKey);
98+
cliLogger.info('New API Key: ', newKey);
9799
cliLogger.info('API key created successfully');
98100
} else if (key) {
99-
console.log('API Key: ', key);
101+
cliLogger.info('API Key: ', key);
100102
} else {
101103
throw new Error(`No API key found with name: ${options.name}`);
102104
}

0 commit comments

Comments
 (0)