2020-10-05 17:07:35 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-11-09 09:25:35 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
2020-10-05 17:07:35 +00:00
|
|
|
import { get, set } from '@ember/object';
|
2021-02-23 08:56:42 +00:00
|
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
2020-10-05 17:07:35 +00:00
|
|
|
|
|
|
|
const modelName = 'topology';
|
|
|
|
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 TopologyService extends RepositoryService {
|
|
|
|
@service('repository/dc')
|
|
|
|
dcs;
|
|
|
|
|
|
|
|
getModelName() {
|
2020-10-05 17:07:35 +00:00
|
|
|
return modelName;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/topology/:id/:kind')
|
2021-02-23 08:56:42 +00:00
|
|
|
findBySlug(params, configuration = {}) {
|
|
|
|
const datacenter = this.dcs.peekOne(params.dc);
|
2020-10-05 17:07:35 +00:00
|
|
|
if (datacenter !== null && !get(datacenter, 'MeshEnabled')) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
2020-10-09 18:39:16 +00:00
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
2021-02-23 08:56:42 +00:00
|
|
|
params.index = configuration.cursor;
|
|
|
|
params.uri = configuration.uri;
|
2020-10-09 18:39:16 +00:00
|
|
|
}
|
2022-09-15 08:43:17 +00:00
|
|
|
return this.store.queryRecord(this.getModelName(), params).catch((e) => {
|
2020-10-05 17:07:35 +00:00
|
|
|
const code = get(e, 'errors.firstObject.status');
|
2021-02-23 08:56:42 +00:00
|
|
|
const body = (get(e, 'errors.firstObject.detail') || '').trim();
|
2020-10-05 17:07:35 +00:00
|
|
|
switch (code) {
|
|
|
|
case '500':
|
|
|
|
if (datacenter !== null && body.endsWith(ERROR_MESH_DISABLED)) {
|
|
|
|
set(datacenter, 'MeshEnabled', false);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|