vault/ui/lib/replication/addon/controllers/replication-mode.js
Chelsea Shaw 349e449d49
UI: Glimmerize replication enable form (#26417)
* Glimmerize replication controllers

* Add enable-replication-form component with tests

* use EnableReplicationForm in index and mode routes

* clean up enable action from replication-actions mixin

* fix test failure for structuredClone

* stabilize tests, remove enable action from replication-actions and replication-summary

* Update ui/lib/replication/addon/controllers/replication-mode.js

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>

* address PR comments

* stabilize oidc test?

---------

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
2024-04-15 15:30:33 -05:00

77 lines
2.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { service } from '@ember/service';
import Controller from '@ember/controller';
import { task, timeout } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import { action } from '@ember/object';
export default class ReplicationModeBaseController extends Controller {
@service('replication-mode') rm;
@service router;
@service store;
get replicationMode() {
return this.rm.mode;
}
get replicationForMode() {
if (!this.replicationMode || !this.model) return null;
return this.model[this.replicationMode];
}
@task
@waitFor
*waitForNewClusterToInit(replicationMode) {
// waiting for the newly enabled cluster to init
// this ensures we don't hit a capabilities-self error, called in the model of the mode/index route
yield timeout(1000);
this.router.transitionTo('vault.cluster.replication.mode', replicationMode);
}
@action
onDisable() {
this.router.transitionTo('vault.cluster.replication.index');
}
@action
async onEnableSuccess(resp, replicationMode, clusterMode, doTransition = false) {
// this is extrapolated from the replication-actions mixin "submitSuccess"
const cluster = this.model;
if (!cluster) {
return;
}
// do something to show model is pending
cluster.set(
replicationMode,
this.store.createRecord('replication-attributes', {
mode: 'bootstrapping',
})
);
if (clusterMode === 'secondary' && replicationMode === 'performance') {
// if we're enabing a secondary, there could be mount filtering,
// so we should unload all of the backends
this.store.unloadAll('secret-engine');
}
try {
await cluster.reload();
} catch (e) {
// no error handling here
}
cluster.rollbackAttributes();
// we should only do the transitions if called from vault.cluster.replication.index
if (doTransition) {
if (replicationMode == 'dr' && clusterMode === 'secondary') {
this.router.transitionTo('vault.cluster');
} else if (replicationMode === 'dr') {
this.router.transitionTo('vault.cluster.replication.mode', replicationMode);
} else {
this.waitForNewClusterToInit.perform(replicationMode);
}
}
}
}