vault/ui/app/components/get-credentials-card.js
hashicorp-copywrite[bot] 0b12cdcfd1
[COMPLIANCE] License changes (#22290)
* 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>
2023-08-10 18:14:03 -07:00

67 lines
2.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
/**
* @module GetCredentialsCard
* GetCredentialsCard components are card-like components that display a title, and SearchSelect component that sends you to a credentials route for the selected item.
* They are designed to be used in containers that act as flexbox or css grid containers.
*
* @example
* ```js
* <GetCredentialsCard @title="Get Credentials" @searchLabel="Role to use" @models={{array 'database/roles'}} @type="role" @backend={{model.backend}}/>
* ```
* @param {string} title - The title displays the card title
* @param {string} searchLabel - The text above the searchSelect component
* @param {array} models - An array of model types to fetch from the API. Passed through to SearchSelect component
* @param {string} type - 'role' or 'secret' - determines where the transitionTo goes
* @param {boolean} [renderInputSearch=false] - If true, renders InputSearch instead of SearchSelect
* @param {string} [subText] - Text below title
* @param {string} [placeholder] - Input placeholder text (default for SearchSelect is 'Search', none for InputSearch)
* @param {string} backend - Passed to SearchSelect query method to fetch dropdown options
*/
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class GetCredentialsCard extends Component {
@service router;
@service store;
@tracked role = '';
@tracked secret = '';
get buttonDisabled() {
return !this.role && !this.secret;
}
@action
transitionToCredential() {
const role = this.role;
const secret = this.secret;
if (role) {
this.router.transitionTo('vault.cluster.secrets.backend.credentials', role);
}
if (secret) {
this.router.transitionTo('vault.cluster.secrets.backend.show', secret);
}
}
@action
handleInput(value) {
if (this.args.type === 'role') {
// if it comes in from the fallback component then the value is a string otherwise it's an array
// which currently only happens if type is role.
if (Array.isArray(value)) {
this.role = value[0];
} else {
this.role = value;
}
}
if (this.args.type === 'secret') {
this.secret = value;
}
}
}