mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-23 19:51:09 +01:00
* license: update headers to IBM Corp. * `make proto` * update offset because source file changed Signed-off-by: Ryan Cragun <me@ryan.ec> Co-authored-by: Ryan Cragun <me@ryan.ec>
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
/**
|
|
* Copyright IBM Corp. 2016, 2025
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Component from '@glimmer/component';
|
|
import { service } from '@ember/service';
|
|
import { action } from '@ember/object';
|
|
import { tracked } from '@glimmer/tracking';
|
|
|
|
import type ApiService from 'vault/services/api';
|
|
import type FlashMessageService from 'vault/services/flash-messages';
|
|
import type { HTMLElementEvent } from 'vault/forms';
|
|
|
|
/**
|
|
* @module ToolsRandom
|
|
* ToolsRandom components are components that perform sys/wrapping/random functionality.
|
|
* @example
|
|
* <Tools::Random />
|
|
*/
|
|
|
|
export default class ToolsRandom extends Component {
|
|
@service declare readonly api: ApiService;
|
|
@service declare readonly flashMessages: FlashMessageService;
|
|
|
|
@tracked bytes = 32;
|
|
@tracked format = 'base64';
|
|
@tracked randomBytes = '';
|
|
@tracked errorMessage = '';
|
|
|
|
@action
|
|
reset() {
|
|
this.bytes = 32;
|
|
this.format = 'base64';
|
|
this.randomBytes = '';
|
|
this.errorMessage = '';
|
|
}
|
|
|
|
@action
|
|
handleSelect(evt: HTMLElementEvent<HTMLSelectElement>) {
|
|
const { value } = evt.target;
|
|
this.format = value;
|
|
}
|
|
|
|
@action
|
|
async handleSubmit(evt: HTMLElementEvent<HTMLFormElement>) {
|
|
evt.preventDefault();
|
|
const data = { bytes: Number(this.bytes), format: this.format };
|
|
try {
|
|
const { random_bytes } = await this.api.sys.generateRandom(data);
|
|
this.randomBytes = random_bytes || '';
|
|
this.flashMessages.success('Generated random bytes successfully.');
|
|
} catch (error) {
|
|
const { message } = await this.api.parseError(error);
|
|
this.errorMessage = message;
|
|
}
|
|
}
|
|
}
|