mirror of
https://github.com/hashicorp/vault.git
synced 2025-09-02 12:31:08 +02:00
* adds linting for types to scripts and lint staged * fixes issue with AdapterError type * moves lint-staged setup out of package.json and into config file * fixes ember data store service type * fixes route params types * fixes model types * fixes general type errors * fixes ts declaration errors in js files * adds missing copyright headers * fixes issue accessing capabilities model properties * ignores AdapterError import type error * more updates to AdapterError type * adds comment to lint-staged config * moves ember data store type to @ember-data namespace * updates store import * moves AdapterError type to @ember-data namespace * turns ember-data import eslint rule back on
68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Route from '@ember/routing/route';
|
|
import { service } from '@ember/service';
|
|
import { action } from '@ember/object';
|
|
import errorMessage from 'vault/utils/error-message';
|
|
|
|
import type FlashMessageService from 'vault/services/flash-messages';
|
|
import type RouterService from '@ember/routing/router-service';
|
|
import type LdapLibraryModel from 'vault/models/ldap/library';
|
|
import type Controller from '@ember/controller';
|
|
import type Transition from '@ember/routing/transition';
|
|
import type { Breadcrumb } from 'vault/vault/app-types';
|
|
import { LdapLibraryCheckOutCredentials } from 'vault/vault/adapters/ldap/library';
|
|
import { ldapBreadcrumbs, libraryRoutes } from 'ldap/utils/ldap-breadcrumbs';
|
|
|
|
interface LdapLibraryCheckOutController extends Controller {
|
|
breadcrumbs: Array<Breadcrumb>;
|
|
model: LdapLibraryCheckOutCredentials;
|
|
}
|
|
|
|
export default class LdapLibraryCheckOutRoute extends Route {
|
|
@service declare readonly flashMessages: FlashMessageService;
|
|
@service('app-router') declare readonly router: RouterService;
|
|
|
|
accountsRoute = 'vault.cluster.secrets.backend.ldap.libraries.library.details.accounts';
|
|
|
|
beforeModel(transition: Transition) {
|
|
// transition must be from the details.accounts route to ensure it was initiated by the check-out action
|
|
if (transition.from?.name !== this.accountsRoute) {
|
|
this.router.replaceWith(this.accountsRoute);
|
|
}
|
|
}
|
|
model(_params: object, transition: Transition) {
|
|
const ttl = transition.to?.queryParams['ttl'] as string;
|
|
const library = this.modelFor('libraries.library') as LdapLibraryModel;
|
|
return library.checkOutAccount(ttl);
|
|
}
|
|
setupController(
|
|
controller: LdapLibraryCheckOutController,
|
|
resolvedModel: LdapLibraryCheckOutCredentials,
|
|
transition: Transition
|
|
) {
|
|
super.setupController(controller, resolvedModel, transition);
|
|
const library = this.modelFor('libraries.library') as LdapLibraryModel;
|
|
const routeParams = (childResource: string) => {
|
|
return [library.backend, childResource];
|
|
};
|
|
controller.breadcrumbs = [
|
|
{ label: library.backend, route: 'overview' },
|
|
{ label: 'Libraries', route: 'libraries' },
|
|
...ldapBreadcrumbs(library.name, routeParams, libraryRoutes),
|
|
{ label: 'Check-Out' },
|
|
];
|
|
}
|
|
|
|
@action
|
|
error(error: Error) {
|
|
// if check-out fails, return to library details route
|
|
const message = errorMessage(error, 'Error checking out account. Please try again or contact support.');
|
|
this.flashMessages.danger(message);
|
|
this.router.replaceWith(this.accountsRoute);
|
|
}
|
|
}
|