mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-19 13:41:10 +02:00
* rename wrap test * refactor tool hash component * whoops fix component syntax * random refactor * rewrap component * unwrap component * lookup refactor * wrap refactor * update selectors * delete tool action form component * co-locate templates * Revert "co-locate templates" This reverts commit c52bb9875284a4ee78c773c794f4fe572ae7a7f4. * fix component jsdoc syntax * rename tracked property * rename rewrap token input selector * remove parseint now that input is typed as a number * nvm convert to number * co-locate templates * move to tools/ folder * add flash message to test
62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Component from '@glimmer/component';
|
|
import { action } from '@ember/object';
|
|
import { service } from '@ember/service';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import errorMessage from 'vault/utils/error-message';
|
|
|
|
/**
|
|
* @module ToolsHash
|
|
* ToolsHash components are components that sys/wrapping/hash functionality.
|
|
*
|
|
* @example
|
|
* <Tools::Hash />
|
|
*/
|
|
export default class ToolsHash extends Component {
|
|
@service store;
|
|
@service flashMessages;
|
|
|
|
@tracked algorithm = 'sha2-256';
|
|
@tracked format = 'base64';
|
|
@tracked hashData = '';
|
|
@tracked sum = null;
|
|
@tracked errorMessage = '';
|
|
|
|
@action
|
|
reset() {
|
|
this.algorithm = 'sha2-256';
|
|
this.format = 'base64';
|
|
this.hashData = '';
|
|
this.sum = null;
|
|
this.errorMessage = '';
|
|
}
|
|
|
|
@action
|
|
handleEvent(evt) {
|
|
const { name, value } = evt.target;
|
|
this[name] = value;
|
|
}
|
|
|
|
@action
|
|
async handleSubmit(evt) {
|
|
evt.preventDefault();
|
|
const data = {
|
|
input: this.hashData,
|
|
format: this.format,
|
|
algorithm: this.algorithm,
|
|
};
|
|
|
|
try {
|
|
const response = await this.store.adapterFor('tools').toolAction('hash', data);
|
|
this.sum = response.data.sum;
|
|
this.flashMessages.success('Hash was successful.');
|
|
} catch (error) {
|
|
this.errorMessage = errorMessage(error);
|
|
}
|
|
}
|
|
}
|