feat: add description flag, remove console log, and update readme

This commit is contained in:
mdatelle
2025-01-16 10:07:10 -05:00
committed by Eli Bosley
parent 796cb09c61
commit 85cdb8f525
2 changed files with 49 additions and 15 deletions

View File

@@ -17,11 +17,11 @@ root@Devon:~# unraid-api
Unraid API Unraid API
Thanks for using the official Unraid API Thanks for using the official Unraid API
Usage: Usage:
$ unraid-api command <options> $ unraid-api command <options>
Commands: Commands:
@@ -29,34 +29,66 @@ Commands:
Options: Options:
-h, --help Prints this usage guide. -h, --help Prints this usage guide.
-d, --debug Enabled debug mode. -d, --debug Enabled debug mode.
-p, --port string Set the graphql port. -p, --port string Set the graphql port.
--environment production/staging/development Set the working environment. --environment production/staging/development Set the working environment.
--log-level ALL/TRACE/DEBUG/INFO/WARN/ERROR/FATAL/MARK/OFF Set the log level. --log-level ALL/TRACE/DEBUG/INFO/WARN/ERROR/FATAL/MARK/OFF Set the log level.
Copyright © 2024 Lime Technology, Inc. Copyright © 2024 Lime Technology, Inc.
``` ```
## Key
To get an existing API key, run:
```
unraid-api key get --name "my-app-key"
```
To get an API key, and create if it doesn't exist, run:
```
unraid-api key get --name "my-app-key" --create
```
To create a new API key with specific roles, run:
```
unraid-api key create --name "backup-app" --roles "admin,guest"
```
To create a new API key with roles and permissions, run:
```
unraid-api key create --name "backup-app" --roles "admin,guest" --permissions "read:any"
```
## Report ## Report
To view the current status of the unraid-api and its connection to mothership, run: To view the current status of the unraid-api and its connection to mothership, run:
``` ```
unraid-api report unraid-api report
``` ```
To view verbose data (anonymized), run: To view verbose data (anonymized), run:
``` ```
unraid-api report -v unraid-api report -v
``` ```
To view non-anonymized verbose data, run: To view non-anonymized verbose data, run:
``` ```
unraid-api report -vv unraid-api report -vv
``` ```
## Secrets ## Secrets
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/). 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/).
## License ## License
Copyright Lime Technology Inc. All rights reserved. Copyright Lime Technology Inc. All rights reserved.

View File

@@ -10,11 +10,12 @@ enum Command {
} }
type KeyFlags = { type KeyFlags = {
command: string;
name: string;
create?: boolean; create?: boolean;
roles?: string; command: string;
description?: string;
name: string;
permissions?: string; permissions?: string;
roles?: string;
}; };
const validRoles: Set<Role> = new Set(Object.values(Role)); const validRoles: Set<Role> = new Set(Object.values(Role));
@@ -42,6 +43,7 @@ const keyOptions: ArgumentConfig<KeyFlags> = {
command: { type: String, description: 'get or create' }, command: { type: String, description: 'get or create' },
name: { type: String, description: 'Name of the API key', typeLabel: '{underline name}' }, name: { type: String, description: 'Name of the API key', typeLabel: '{underline name}' },
create: { type: Boolean, optional: true, description: "Create the key if it doesn't exist" }, create: { type: Boolean, optional: true, description: "Create the key if it doesn't exist" },
description: { type: String, optional: true, description: 'Description of the API key' },
roles: { roles: {
type: String, type: String,
optional: true, optional: true,
@@ -70,12 +72,12 @@ export const key = async (...argv: string[]) => {
const roles = validateRoles(options.roles); const roles = validateRoles(options.roles);
const key = await apiKeyService.create( const key = await apiKeyService.create(
options.name, options.name,
`CLI generated key: ${options.name}`, options.description || `CLI generated key: ${options.name}`,
roles, roles,
true true
); );
console.log('API Key: ', key); cliLogger.info('API Key: ', key);
cliLogger.info('API key created successfully'); cliLogger.info('API key created successfully');
break; break;
@@ -88,15 +90,15 @@ export const key = async (...argv: string[]) => {
const roles = validateRoles(options.roles); const roles = validateRoles(options.roles);
const newKey = await apiKeyService.create( const newKey = await apiKeyService.create(
options.name, options.name,
`CLI generated key: ${options.name}`, options.description || `CLI generated key: ${options.name}`,
roles, roles,
true true
); );
console.log('New API Key: ', newKey); cliLogger.info('New API Key: ', newKey);
cliLogger.info('API key created successfully'); cliLogger.info('API key created successfully');
} else if (key) { } else if (key) {
console.log('API Key: ', key); cliLogger.info('API Key: ', key);
} else { } else {
throw new Error(`No API key found with name: ${options.name}`); throw new Error(`No API key found with name: ${options.name}`);
} }