mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-16 03:27:01 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Component from '@glimmer/component';
|
|
import { action } from '@ember/object';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import { format } from 'date-fns';
|
|
import type { HTMLElementEvent } from 'forms';
|
|
|
|
/**
|
|
* <PkiNotValidAfterForm /> components are used to manage two mutually exclusive role options in the form.
|
|
*/
|
|
interface Args {
|
|
model: {
|
|
notAfter: string;
|
|
ttl: string | number;
|
|
set: (key: string, value: string | number) => void;
|
|
};
|
|
}
|
|
|
|
export default class RadioSelectTtlOrString extends Component<Args> {
|
|
@tracked groupValue = 'ttl';
|
|
@tracked cachedNotAfter: string;
|
|
@tracked cachedTtl: string | number;
|
|
@tracked formDate: string;
|
|
|
|
constructor(owner: unknown, args: Args) {
|
|
super(owner, args);
|
|
const { model } = this.args;
|
|
this.cachedNotAfter = model.notAfter || '';
|
|
this.formDate = this.calculateFormDate(model.notAfter);
|
|
this.cachedTtl = model.ttl || '';
|
|
if (model.notAfter) {
|
|
this.groupValue = 'specificDate';
|
|
}
|
|
}
|
|
|
|
calculateFormDate(value: string) {
|
|
// API expects and returns full ISO string
|
|
// but the form input only accepts yyyy-MM-dd format
|
|
if (value) {
|
|
return format(new Date(value), 'yyyy-MM-dd');
|
|
}
|
|
return '';
|
|
}
|
|
|
|
@action onRadioButtonChange(selection: string) {
|
|
this.groupValue = selection;
|
|
// Clear the previous selection if they have clicked the other radio button.
|
|
if (selection === 'specificDate') {
|
|
this.args.model.ttl = '';
|
|
this.args.model.notAfter = this.cachedNotAfter;
|
|
this.formDate = this.calculateFormDate(this.cachedNotAfter);
|
|
}
|
|
if (selection === 'ttl') {
|
|
this.args.model.notAfter = '';
|
|
this.args.model.ttl = this.cachedTtl;
|
|
this.formDate = '';
|
|
}
|
|
}
|
|
|
|
@action setAndBroadcastTtl(ttlObject: { enabled: boolean; goSafeTimeString: string }) {
|
|
const { enabled, goSafeTimeString } = ttlObject;
|
|
if (this.groupValue === 'specificDate') {
|
|
// do not save ttl on the model unless the ttl radio button is selected
|
|
return;
|
|
}
|
|
const ttlVal = enabled === true ? goSafeTimeString : 0;
|
|
this.cachedTtl = ttlVal;
|
|
this.args.model.ttl = ttlVal;
|
|
}
|
|
|
|
@action setAndBroadcastInput(evt: HTMLElementEvent<HTMLInputElement>) {
|
|
const setDate = evt.target.valueAsDate?.toISOString();
|
|
if (!setDate) return;
|
|
|
|
this.cachedNotAfter = setDate;
|
|
this.args.model.notAfter = setDate;
|
|
this.formDate = this.calculateFormDate(setDate);
|
|
}
|
|
}
|