rebuilt cli. Added new vault operations

This commit is contained in:
2020-10-07 18:55:51 +02:00
parent 4fd042517e
commit 13c9ae211c
35 changed files with 5452 additions and 295 deletions

67
src/cli/KeyAction.ts Normal file
View File

@@ -0,0 +1,67 @@
/**
* Dennis Gunia (c) 2020
*
* CLI Key-Action CommandLineAction Implementation.
*
* @summary CLI Key-Action CommandLineAction Implementation.
* @author Dennis Gunia <info@dennisgunia.de>
* @license Licensed under the Apache License, Version 2.0 (the "License").
*
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { CommandLineAction, CommandLineFlagParameter, CommandLineChoiceParameter, CommandLineStringParameter } from "@rushstack/ts-command-line";
import { MLLogic_Key } from "../logic/KeyLogic";
export class KeyAction extends CommandLineAction {
private _generate!: CommandLineFlagParameter;
private _pubkey!: CommandLineStringParameter;
private _privkey!: CommandLineStringParameter;
public constructor() {
super({
actionName: 'key',
summary: 'Manage RSA Keypair',
documentation: 'Manage RSA Keypair'
});
}
protected onExecute(): Promise<void> { // abstract
return new Promise<void>((resolve,reject) => {
MLLogic_Key.generate(this._privkey.value,this._pubkey.value);
})
}
protected onDefineParameters(): void { // abstract
this._generate = this.defineFlagParameter({
parameterLongName: '--generate',
parameterShortName: '-g',
description: 'Send to all recipients, regardless if mail was already sent. Overwrites safe with new codes.'
});
this._pubkey = this.defineStringParameter({
parameterLongName: '--pubkey',
parameterShortName: '-p',
description: 'Specify the public key to use',
required: true,
argumentName: "PUBLICKEY"
})
this._privkey = this.defineStringParameter({
parameterLongName: '--privkey',
parameterShortName: '-r',
description: 'Specify the private key to use',
required: true,
argumentName: "PRIVATEKEY"
})
}
}

52
src/cli/OpenTokenCLI.ts Normal file
View File

@@ -0,0 +1,52 @@
import { CommandLineParser, CommandLineFlagParameter } from "@rushstack/ts-command-line";
/**
* Dennis Gunia (c) 2020
*
* CommandLineAction Implementation.
*
* @summary CommandLineAction Implementation.
* @author Dennis Gunia <info@dennisgunia.de>
* @license Licensed under the Apache License, Version 2.0 (the "License").
*
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { KeyAction } from "./KeyAction";
import { SendAction } from "./SendAction";
import { VaultAction } from "./VaultAction";
export class OpenTokenCLI extends CommandLineParser {
private _verbose!: CommandLineFlagParameter;
public constructor() {
super({
toolFilename: 'opentoken',
toolDescription: 'The "opentoken" tool is to generate codes and deliver them to a list of recpipients without disclosing which user has which token.'
});
this.addAction(new SendAction());
this.addAction(new VaultAction());
this.addAction(new KeyAction());
}
protected onDefineParameters(): void { // abstract
this._verbose = this.defineFlagParameter({
parameterLongName: '--verbose',
parameterShortName: '-v',
description: 'Show extra logging detail'
});
}
protected onExecute(): Promise<void> { // override
return super.onExecute();
}
}

108
src/cli/SendAction.ts Normal file
View File

@@ -0,0 +1,108 @@
/**
* Dennis Gunia (c) 2020
*
* CLI Send-Action CommandLineAction Implementation.
*
* @summary CLI Send-Action CommandLineAction Implementation.
* @author Dennis Gunia <info@dennisgunia.de>
* @license Licensed under the Apache License, Version 2.0 (the "License").
*
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { CommandLineAction, CommandLineFlagParameter, CommandLineChoiceParameter, CommandLineStringParameter } from "@rushstack/ts-command-line";
import { MLLogic_Send } from "../logic/SendLogic";
export class SendAction extends CommandLineAction {
private _force!: CommandLineFlagParameter;
private _dryrun!: CommandLineFlagParameter;
private _pubkey!: CommandLineStringParameter;
private _config!: CommandLineStringParameter;
private _safe!: CommandLineStringParameter;
private _template!: CommandLineStringParameter;
private _maillist!: CommandLineStringParameter;
public constructor() {
super({
actionName: 'send',
summary: 'Generates codes, sends mails and stores results in safe',
documentation: 'Generates codes, sends mails and stores results in safe'
});
}
protected onExecute(): Promise<void> { // abstract
return new Promise<void>((resolve,reject) => {
MLLogic_Send.send(
this._force.value,
this._dryrun.value,
this._pubkey.value,
this._config.value,
this._safe.value,
this._template.value,
this._maillist.value,
);
})
}
protected onDefineParameters(): void { // abstract
this._force = this.defineFlagParameter({
parameterLongName: '--force',
parameterShortName: '-f',
description: 'Send to all recipients, regardless if mail was already sent. Overwrites safe with new codes.'
});
this._dryrun = this.defineFlagParameter({
parameterLongName: '--dryrun',
parameterShortName: '-d',
description: 'Pretend to send mails. No outgoing SMTP connection. Safe will not be updated.'
});
this._pubkey = this.defineStringParameter({
parameterLongName: '--pubkey',
parameterShortName: '-p',
description: 'Specify the public key to use',
required: true,
argumentName: "PUBLICKEY"
})
this._config = this.defineStringParameter({
parameterLongName: '--config',
parameterShortName: '-c',
description: 'Specify the config file to use',
required: true,
argumentName: "CONFIGFILE"
})
this._maillist = this.defineStringParameter({
parameterLongName: '--mails',
parameterShortName: '-m',
description: 'Specify the maillist to use',
required: true,
argumentName: "MAILLIST"
})
this._safe = this.defineStringParameter({
parameterLongName: '--safe',
parameterShortName: '-s',
description: 'Specify the safe file to use',
required: true,
argumentName: "SAFEFILE"
})
this._template = this.defineStringParameter({
parameterLongName: '--template',
parameterShortName: '-t',
description: 'Specify the template file to use',
required: true,
argumentName: "HTMLFILE"
})
}
}

109
src/cli/VaultAction.ts Normal file
View File

@@ -0,0 +1,109 @@
/**
* Dennis Gunia (c) 2020
*
* CLI Vault-Action CommandLineAction Implementation.
*
* @summary CLI Vault-Action CommandLineAction Implementation.
* @author Dennis Gunia <info@dennisgunia.de>
* @license Licensed under the Apache License, Version 2.0 (the "License").
*
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { CommandLineAction, CommandLineFlagParameter, CommandLineChoiceParameter, CommandLineStringParameter } from "@rushstack/ts-command-line";
import { MLLogic_Vault } from "../logic/VaultLogic";
export class VaultAction extends CommandLineAction {
private _filter!: CommandLineChoiceParameter;
private _pubkey!: CommandLineStringParameter;
private _privkey!: CommandLineStringParameter;
private _safe!: CommandLineStringParameter;
private _getCodes!: CommandLineFlagParameter;
private _format!: CommandLineChoiceParameter;
private _revoke!: CommandLineStringParameter;
public constructor() {
super({
actionName: 'vault',
summary: 'Manages Securevault file',
documentation: 'Show user - token relations, filter and revoke token'
});
}
protected onExecute(): Promise<void> { // abstract
return new Promise<void>((resolve,reject) => {
MLLogic_Vault.open(
this._filter.value,
this._pubkey.value,
this._privkey.value,
this._safe.value,
this._getCodes.value,
this._format.value,
this._revoke.value
)
})
}
protected onDefineParameters(): void { // abstract
this._filter = this.defineChoiceParameter({
parameterLongName: '--filter',
description: 'Specify the data to show',
alternatives: ['encrypted', 'unencrypted', 'all'],
environmentVariable: 'DATATYPE',
defaultValue: 'all'
});
this._pubkey = this.defineStringParameter({
parameterLongName: '--pubkey',
parameterShortName: '-p',
description: 'Specify the public key to use',
required: true,
argumentName: "PUBLICKEY"
})
this._privkey = this.defineStringParameter({
parameterLongName: '--privkey',
parameterShortName: '-r',
description: 'Specify the private key to use',
required: true,
argumentName: "PRIVATEKEY"
})
this._safe = this.defineStringParameter({
parameterLongName: '--safe',
parameterShortName: '-s',
description: 'Specify the safe file to use',
required: true,
argumentName: "SAFEFILE"
})
this._getCodes = this.defineFlagParameter({
parameterLongName: '--get-codes',
parameterShortName: '-g',
description: 'Get a list of all non revoked codes'
});
this._format = this.defineChoiceParameter({
parameterLongName: '--format',
description: 'Specify the output format of --get-codes',
alternatives: ['json', 'regex'],
environmentVariable: 'FORMAT',
defaultValue: 'json'
});
this._revoke = this.defineStringParameter({
parameterLongName: '--revoke',
description: 'Revokes a token',
required: false,
argumentName: "TOKEN"
})
}
}