mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
feat: CLI options for adding and deleting users
This commit is contained in:
@@ -19,6 +19,7 @@ import { SwitchEnvCommand } from '@app/unraid-api/cli/switch-env.command';
|
||||
import { VersionCommand } from '@app/unraid-api/cli/version.command';
|
||||
import { RemoveSSOUserCommand } from '@app/unraid-api/cli/sso/remove-sso-user.command';
|
||||
import { RemoveSSOUserQuestionSet } from '@app/unraid-api/cli/sso/remove-sso-user.questions';
|
||||
import { ListSSOUserCommand } from '@app/unraid-api/cli/sso/list-sso-user.command';
|
||||
|
||||
@Module({
|
||||
providers: [
|
||||
@@ -26,6 +27,7 @@ import { RemoveSSOUserQuestionSet } from '@app/unraid-api/cli/sso/remove-sso-use
|
||||
AddSSOUserQuestionSet,
|
||||
RemoveSSOUserCommand,
|
||||
RemoveSSOUserQuestionSet,
|
||||
ListSSOUserCommand,
|
||||
LogService,
|
||||
StartCommand,
|
||||
StopCommand,
|
||||
|
||||
@@ -30,7 +30,7 @@ export class AddSSOUserCommand extends CommandRunner {
|
||||
async run(_input: string[], options: AddSSOUserCommandOptions): Promise<void> {
|
||||
try {
|
||||
options = await this.inquirerService.prompt(AddSSOUserQuestionSet.name, options);
|
||||
|
||||
console.log(options);
|
||||
if (options.disclaimer === 'y' && options.username) {
|
||||
await store.dispatch(loadConfigFile());
|
||||
store.dispatch(addSsoUser(options.username));
|
||||
@@ -47,18 +47,30 @@ export class AddSSOUserCommand extends CommandRunner {
|
||||
}
|
||||
|
||||
@Option({
|
||||
flags: '--username [username]',
|
||||
flags: '--username <username>',
|
||||
description: 'Cognito Username',
|
||||
})
|
||||
parseUsername(val: string) {
|
||||
return val;
|
||||
parseUsername(input: string) {
|
||||
if (
|
||||
!/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(input)
|
||||
) {
|
||||
throw new Error('Username must be in the format of a UUID (e.g., ${v4()}}\n');
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@Option({
|
||||
flags: '--disclaimer [disclaimer]',
|
||||
flags: '--disclaimer <disclaimer>',
|
||||
description: 'Disclaimer (y/n)',
|
||||
})
|
||||
parseDisclaimer(val: string) {
|
||||
return val;
|
||||
parseDisclaimer(input: string) {
|
||||
if (!input || !['y', 'n'].includes(input.toLowerCase())) {
|
||||
throw new Error('Please answer the diclaimer with (y/n)\n');
|
||||
}
|
||||
if (input.toLowerCase() === 'n') {
|
||||
process.exit(1);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
28
api/src/unraid-api/cli/sso/list-sso-user.command.ts
Normal file
28
api/src/unraid-api/cli/sso/list-sso-user.command.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { CommandRunner, SubCommand } from 'nest-commander';
|
||||
|
||||
import { store } from '@app/store/index';
|
||||
import { loadConfigFile } from '@app/store/modules/config';
|
||||
import { LogService } from '@app/unraid-api/cli/log.service';
|
||||
|
||||
@Injectable()
|
||||
@SubCommand({
|
||||
name: 'list-users',
|
||||
aliases: ['list', 'l'],
|
||||
description: 'List all users for SSO',
|
||||
})
|
||||
export class ListSSOUserCommand extends CommandRunner {
|
||||
constructor(
|
||||
private readonly logger: LogService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async run(_input: string[]): Promise<void> {
|
||||
await store.dispatch(loadConfigFile());
|
||||
this.logger.info(
|
||||
store.getState().config.remote.ssoSubIds.split(',').filter(Boolean).join('\n')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -36,4 +36,23 @@ export class RemoveSSOUserCommand extends CommandRunner {
|
||||
}
|
||||
writeConfigSync('flash');
|
||||
}
|
||||
|
||||
@Option({
|
||||
name: 'username',
|
||||
flags: '--username <username>',
|
||||
description: 'Cognito Username',
|
||||
})
|
||||
parseUsername(input: string) {
|
||||
if (!input) {
|
||||
throw new Error('Username is required\n');
|
||||
}
|
||||
|
||||
if (
|
||||
!/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(input)
|
||||
) {
|
||||
throw new Error('Username must be in the format of a UUID (e.g., ${v4()}}\n');
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@ import { LogService } from '@app/unraid-api/cli/log.service';
|
||||
import { ValidateTokenCommand } from '@app/unraid-api/cli/sso/validate-token.command';
|
||||
import { AddSSOUserCommand } from '@app/unraid-api/cli/sso/add-sso-user.command';
|
||||
import { RemoveSSOUserCommand } from '@app/unraid-api/cli/sso/remove-sso-user.command';
|
||||
import { ListSSOUserCommand } from '@app/unraid-api/cli/sso/list-sso-user.command';
|
||||
|
||||
@Injectable()
|
||||
@Command({
|
||||
name: 'sso',
|
||||
description: 'Main Command to Configure / Validate SSO Tokens',
|
||||
subCommands: [ValidateTokenCommand, AddSSOUserCommand, RemoveSSOUserCommand],
|
||||
subCommands: [ValidateTokenCommand, AddSSOUserCommand, RemoveSSOUserCommand, ListSSOUserCommand],
|
||||
})
|
||||
export class SSOCommand extends CommandRunner {
|
||||
constructor(private readonly logger: LogService) {
|
||||
|
||||
Reference in New Issue
Block a user