2018-09-25 16:28:26 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import { get, computed } from '@ember/object';
|
|
|
|
import Component from '@ember/component';
|
2018-04-03 14:16:57 +00:00
|
|
|
import decodeConfigFromJWT from 'vault/utils/decode-config-from-jwt';
|
|
|
|
import ReplicationActions from 'vault/mixins/replication-actions';
|
2018-09-25 16:28:26 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
const DEFAULTS = {
|
|
|
|
mode: 'primary',
|
|
|
|
token: null,
|
|
|
|
id: null,
|
|
|
|
loading: false,
|
|
|
|
errors: [],
|
|
|
|
primary_api_addr: null,
|
|
|
|
primary_cluster_addr: null,
|
|
|
|
ca_file: null,
|
|
|
|
ca_path: null,
|
|
|
|
replicationMode: 'dr',
|
|
|
|
};
|
|
|
|
|
2018-08-28 05:03:55 +00:00
|
|
|
export default Component.extend(ReplicationActions, DEFAULTS, {
|
2018-09-25 16:28:26 +00:00
|
|
|
wizard: service(),
|
|
|
|
version: service(),
|
2018-04-03 14:16:57 +00:00
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
const initialReplicationMode = this.get('initialReplicationMode');
|
|
|
|
if (initialReplicationMode) {
|
|
|
|
this.set('replicationMode', initialReplicationMode);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
showModeSummary: false,
|
|
|
|
initialReplicationMode: null,
|
|
|
|
cluster: null,
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
replicationAttrs: alias('cluster.replicationAttrs'),
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
tokenIncludesAPIAddr: computed('token', function() {
|
|
|
|
const config = decodeConfigFromJWT(get(this, 'token'));
|
|
|
|
return config && config.addr ? true : false;
|
|
|
|
}),
|
|
|
|
|
|
|
|
disallowEnable: computed(
|
|
|
|
'replicationMode',
|
|
|
|
'version.hasPerfReplication',
|
|
|
|
'mode',
|
|
|
|
'tokenIncludesAPIAddr',
|
|
|
|
'primary_api_addr',
|
|
|
|
function() {
|
|
|
|
const inculdesAPIAddr = this.get('tokenIncludesAPIAddr');
|
|
|
|
if (this.get('replicationMode') === 'performance' && this.get('version.hasPerfReplication') === false) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
this.get('mode') !== 'secondary' ||
|
|
|
|
inculdesAPIAddr ||
|
|
|
|
(!inculdesAPIAddr && this.get('primary_api_addr'))
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
),
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
this.setProperties(DEFAULTS);
|
|
|
|
},
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
submit: task(function*() {
|
|
|
|
yield this.submitHandler(...arguments);
|
|
|
|
let wizard = this.get('wizard');
|
|
|
|
wizard.transitionFeatureMachine(wizard.get('featureState'), 'ENABLEREPLICATION');
|
|
|
|
}),
|
|
|
|
|
2018-04-03 14:16:57 +00:00
|
|
|
actions: {
|
|
|
|
onSubmit(/*action, mode, data, event*/) {
|
2018-09-25 16:28:26 +00:00
|
|
|
this.get('submit').perform(...arguments);
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
this.reset();
|
|
|
|
this.setProperties({
|
|
|
|
token: null,
|
|
|
|
id: null,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|