mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-22 15:11:07 +02:00
* updates api client vars to snake_case for custom messages * updates api client vars to snake_case for tools * updates api client vars to snake_case for sync * updates api client vars to snake_case for secrets engine * updates api client vars to snake_case for auth * updates api client vars to snake_case for usage * updates api client dep to point to gh repo * fixes custom-messages service unit tests * fixes configure-ssh test * fixes configure-ssh test...again
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* 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 { addSeconds } from 'date-fns';
|
|
|
|
import type ApiService from 'vault/services/api';
|
|
import type FlashMessageService from 'vault/services/flash-messages';
|
|
import type { HTMLElementEvent } from 'vault/forms';
|
|
import type { ReadWrappingPropertiesResponse } from '@hashicorp/vault-client-typescript';
|
|
|
|
/**
|
|
* @module ToolsLookup
|
|
* ToolsLookup components are components that sys/wrapping/lookup functionality.
|
|
*
|
|
* @example
|
|
* <Tools::Lookup />
|
|
*/
|
|
export default class ToolsLookup extends Component {
|
|
@service declare readonly api: ApiService;
|
|
@service declare readonly flashMessages: FlashMessageService;
|
|
|
|
@tracked token = '';
|
|
@tracked lookupData: ReadWrappingPropertiesResponse | null = null;
|
|
@tracked errorMessage = '';
|
|
|
|
@action
|
|
reset() {
|
|
this.token = '';
|
|
this.lookupData = null;
|
|
this.errorMessage = '';
|
|
}
|
|
|
|
get expirationDate() {
|
|
if (this.lookupData) {
|
|
const { creation_time, creation_ttl } = this.lookupData;
|
|
if (creation_time && creation_ttl) {
|
|
// returns new Date with seconds added.
|
|
return addSeconds(creation_time, Number(creation_ttl));
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@action
|
|
async handleSubmit(evt: HTMLElementEvent<HTMLFormElement>) {
|
|
evt.preventDefault();
|
|
const payload = { token: this.token.trim() };
|
|
try {
|
|
const data = await this.api.sys.readWrappingProperties(payload);
|
|
this.lookupData = data;
|
|
this.flashMessages.success('Lookup was successful.');
|
|
} catch (e) {
|
|
const { message } = await this.api.parseError(e);
|
|
this.errorMessage = message;
|
|
}
|
|
}
|
|
}
|