vault/ui/app/components/control-group-success.js
Jordan Reimer cd0cd0a175
[UI] Ember Data Migration - Remove Tools Adapter (#30030)
* updates unwrap request in auth-form and control-group-success components to use api service

* removes tools adapter and test

* fixes tests
2025-03-26 13:51:59 -06:00

42 lines
1.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { service } from '@ember/service';
import Component from '@ember/component';
import { task } from 'ember-concurrency';
import apiErrorMessage from 'vault/utils/api-error-message';
export default Component.extend({
router: service(),
controlGroup: service(),
api: service(),
// public attrs
model: null,
controlGroupResponse: null,
//internal state
error: null,
unwrapData: null,
unwrap: task(function* (token) {
this.set('error', null);
try {
const response = yield this.api.sys.unwrap({}, this.api.buildHeaders({ token }));
this.set('unwrapData', response.auth || response.data);
this.controlGroup.deleteControlGroupToken(this.model.id);
} catch (e) {
const error = yield apiErrorMessage(e);
this.error = `Token unwrap failed: ${error}`;
}
}).drop(),
markAndNavigate: task(function* () {
this.controlGroup.markTokenForUnwrap(this.model.id);
const { url } = this.controlGroupResponse.uiParams;
yield this.router.transitionTo(url);
}).drop(),
});