* [COMPLIANCE] Add Copyright and License Headers * chore: 🤖 update Copyright headers to satisfy our lint rules --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import Route from '@ember/routing/route';
|
|
import { all } from 'rsvp';
|
|
import { action } from '@ember/object';
|
|
import { loading } from 'ember-loading';
|
|
import { confirm } from 'core/decorators/confirm';
|
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
|
import { inject as service } from '@ember/service';
|
|
|
|
export default class ScopesScopeTargetsTargetInjectedApplicationCredentialSourcesRoute extends Route {
|
|
// =services
|
|
|
|
@service store;
|
|
|
|
// =methods
|
|
|
|
/**
|
|
* Loads all credential sources under the current target.
|
|
* @return {Promise{[CredentialLibraryModel, CredentialModel]}}
|
|
*/
|
|
beforeModel() {
|
|
const { injected_application_credential_source_ids: sourceIDFragments } =
|
|
this.modelFor('scopes.scope.targets.target');
|
|
return all(
|
|
sourceIDFragments.map(({ value }) => {
|
|
const isStatic = value.includes('cred');
|
|
if (isStatic) {
|
|
return this.store.findRecord('credential', value, {
|
|
reload: true,
|
|
});
|
|
} else {
|
|
return this.store.findRecord('credential-library', value, {
|
|
reload: true,
|
|
});
|
|
}
|
|
})
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns the previously loaded target instance.
|
|
* @return {TargetModel}
|
|
*/
|
|
model() {
|
|
return this.modelFor('scopes.scope.targets.target');
|
|
}
|
|
|
|
// =actions
|
|
|
|
/**
|
|
* Remove a credential source from the current target.
|
|
* @param {TargetModel} target
|
|
* @param {CredentialLibraryModel, credentialModel} credentialSource
|
|
*/
|
|
@action
|
|
@loading
|
|
@confirm('questions.remove-confirm')
|
|
@notifyError(({ message }) => message, { catch: true })
|
|
@notifySuccess('notifications.remove-success')
|
|
async removeInjectedApplicationCredentialSource(target, credentialSource) {
|
|
await target.removeInjectedApplicationCredentialSource(credentialSource.id);
|
|
this.refresh();
|
|
}
|
|
}
|