2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2019-02-21 13:10:53 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
import { PRIMARY_KEY } from 'consul-ui/models/proxy';
|
2019-03-22 17:24:40 +00:00
|
|
|
import { get, set } from '@ember/object';
|
2021-02-23 08:56:42 +00:00
|
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
|
|
|
|
2019-02-21 13:10:53 +00:00
|
|
|
const modelName = 'proxy';
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class ProxyService extends RepositoryService {
|
|
|
|
getModelName() {
|
2019-02-21 13:10:53 +00:00
|
|
|
return modelName;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getPrimaryKey() {
|
2019-02-21 13:10:53 +00:00
|
|
|
return PRIMARY_KEY;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/proxies/for-service/:id')
|
2021-02-23 08:56:42 +00:00
|
|
|
findAllBySlug(params, configuration = {}) {
|
2019-02-21 13:10:53 +00:00
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
2021-02-23 08:56:42 +00:00
|
|
|
params.index = configuration.cursor;
|
|
|
|
params.uri = configuration.uri;
|
2019-02-21 13:10:53 +00:00
|
|
|
}
|
2022-09-15 08:43:17 +00:00
|
|
|
return this.store.query(this.getModelName(), params).then((items) => {
|
|
|
|
items.forEach((item) => {
|
2020-08-26 14:24:30 +00:00
|
|
|
// swap out the id for the services id
|
|
|
|
// so we can then assign the proxy to it if it exists
|
|
|
|
const id = JSON.parse(item.uid);
|
|
|
|
id.pop();
|
|
|
|
id.push(item.ServiceProxy.DestinationServiceID);
|
|
|
|
const service = this.store.peekRecord('service-instance', JSON.stringify(id));
|
|
|
|
if (service) {
|
|
|
|
set(service, 'ProxyInstance', item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return items;
|
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/proxy-instance/:serviceId/:node/:id')
|
2022-01-07 19:16:21 +00:00
|
|
|
async findInstanceBySlug(params, configuration) {
|
|
|
|
const items = await this.findAllBySlug(params, configuration);
|
|
|
|
|
|
|
|
let res = {};
|
|
|
|
if (get(items, 'length') > 0) {
|
|
|
|
let instance = items
|
|
|
|
.filterBy('ServiceProxy.DestinationServiceID', params.serviceId)
|
|
|
|
.findBy('NodeName', params.node);
|
|
|
|
if (instance) {
|
|
|
|
res = instance;
|
|
|
|
} else {
|
|
|
|
instance = items.findBy('ServiceProxy.DestinationServiceName', params.id);
|
2019-03-07 10:51:39 +00:00
|
|
|
if (instance) {
|
2019-03-22 17:24:40 +00:00
|
|
|
res = instance;
|
2019-02-21 13:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-07 19:16:21 +00:00
|
|
|
}
|
|
|
|
set(res, 'meta', get(items, 'meta'));
|
|
|
|
return res;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|