2020-06-10 15:07:06 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { get, set } from '@ember/object';
|
2019-12-17 19:27:28 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
|
|
|
|
const modelName = 'discovery-chain';
|
2020-06-10 15:07:06 +00:00
|
|
|
const ERROR_MESH_DISABLED = 'Connect must be enabled in order to use this endpoint';
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class DiscoveryChainService extends RepositoryService {
|
|
|
|
@service('repository/dc')
|
|
|
|
dcs;
|
|
|
|
|
|
|
|
getModelName() {
|
2019-12-17 19:27:28 +00:00
|
|
|
return modelName;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
findBySlug(slug, dc, nspace, configuration = {}) {
|
2020-06-10 15:07:06 +00:00
|
|
|
const datacenter = this.dcs.peekOne(dc);
|
|
|
|
if (datacenter !== null && !get(datacenter, 'MeshEnabled')) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
2020-11-09 09:25:35 +00:00
|
|
|
return super.findBySlug(...arguments).catch(e => {
|
2020-06-10 15:07:06 +00:00
|
|
|
const code = get(e, 'errors.firstObject.status');
|
2021-02-19 16:42:16 +00:00
|
|
|
const body = (get(e, 'errors.firstObject.detail') || '').trim();
|
2020-06-10 15:07:06 +00:00
|
|
|
switch (code) {
|
|
|
|
case '500':
|
2020-07-16 17:27:34 +00:00
|
|
|
if (datacenter !== null && body.endsWith(ERROR_MESH_DISABLED)) {
|
2020-06-10 15:07:06 +00:00
|
|
|
set(datacenter, 'MeshEnabled', false);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
default:
|
2020-07-01 09:21:15 +00:00
|
|
|
throw e;
|
2020-06-10 15:07:06 +00:00
|
|
|
}
|
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|