2018-09-25 16:28:26 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Component from '@ember/component';
|
2018-04-03 14:16:57 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
|
|
|
import { underscore } from 'vault/helpers/underscore';
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
export default Component.extend({
|
|
|
|
store: service(),
|
|
|
|
flashMessages: service(),
|
|
|
|
router: service(),
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
// Public API - either 'entity' or 'group'
|
|
|
|
// this will determine which adapter is used to make the lookup call
|
|
|
|
type: 'entity',
|
|
|
|
|
|
|
|
param: 'alias name',
|
|
|
|
paramValue: null,
|
|
|
|
aliasMountAccessor: null,
|
|
|
|
|
|
|
|
authMethods: null,
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
2018-09-25 16:28:26 +00:00
|
|
|
this.get('store')
|
|
|
|
.findAll('auth-method')
|
|
|
|
.then(methods => {
|
|
|
|
this.set('authMethods', methods);
|
|
|
|
this.set('aliasMountAccessor', methods.get('firstObject.accessor'));
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
adapter() {
|
|
|
|
let type = this.get('type');
|
|
|
|
let store = this.get('store');
|
|
|
|
return store.adapterFor(`identity/${type}`);
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
let { param, paramValue, aliasMountAccessor } = this.getProperties(
|
|
|
|
'param',
|
|
|
|
'paramValue',
|
|
|
|
'aliasMountAccessor'
|
|
|
|
);
|
|
|
|
let data = {};
|
|
|
|
|
|
|
|
data[underscore([param])] = paramValue;
|
|
|
|
if (param === 'alias name') {
|
|
|
|
data.alias_mount_accessor = aliasMountAccessor;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
|
|
|
lookup: task(function*() {
|
|
|
|
let flash = this.get('flashMessages');
|
|
|
|
let type = this.get('type');
|
|
|
|
let store = this.get('store');
|
|
|
|
let { param, paramValue } = this.getProperties('param', 'paramValue');
|
|
|
|
let response;
|
|
|
|
try {
|
|
|
|
response = yield this.adapter().lookup(store, this.data());
|
|
|
|
} catch (err) {
|
|
|
|
flash.danger(
|
|
|
|
`We encountered an error attempting the ${type} lookup: ${err.message || err.errors.join('')}.`
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (response) {
|
2018-09-25 16:28:26 +00:00
|
|
|
return this.get('router').transitionTo('vault.cluster.access.identity.show', response.id, 'details');
|
2018-04-03 14:16:57 +00:00
|
|
|
} else {
|
|
|
|
flash.danger(`We were unable to find an identity ${type} with a "${param}" of "${paramValue}".`);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
});
|