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
|
|
|
*/
|
|
|
|
|
2018-10-26 16:36:15 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
2021-02-23 08:56:42 +00:00
|
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
2022-10-11 09:17:19 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2021-02-23 08:56:42 +00:00
|
|
|
|
2018-10-26 16:36:15 +00:00
|
|
|
const modelName = 'service';
|
2021-02-23 08:56:42 +00:00
|
|
|
export default class ServiceService extends RepositoryService {
|
2022-10-11 09:17:19 +00:00
|
|
|
@service store;
|
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
getModelName() {
|
2018-10-26 16:36:15 +00:00
|
|
|
return modelName;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/services')
|
2021-02-23 08:56:42 +00:00
|
|
|
async findAllByDatacenter() {
|
2021-09-15 18:50:11 +00:00
|
|
|
return super.findAll(...arguments);
|
2021-02-23 08:56:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 09:17:19 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/services/:peer/:peerId')
|
|
|
|
async findAllImportedServices(params, configuration) {
|
|
|
|
// remember peer.id so that we can add it to to the service later on to setup relationship
|
|
|
|
const { peerId } = params;
|
|
|
|
|
|
|
|
// don't send peerId with query
|
|
|
|
delete params.peerId;
|
|
|
|
|
|
|
|
// assign the peer as a belongs-to. we don't have access to any information
|
|
|
|
// we could use to do this in the serializer so we need to do it manually here
|
|
|
|
return super.findAll(params, configuration).then((services) => {
|
|
|
|
const peer = this.store.peekRecord('peer', peerId);
|
|
|
|
services.forEach((service) => (service.peer = peer));
|
|
|
|
return services;
|
|
|
|
});
|
2022-10-10 07:50:00 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/gateways/for-service/:gateway')
|
2021-02-23 08:56:42 +00:00
|
|
|
findGatewayBySlug(params, configuration = {}) {
|
2020-05-29 15:07:36 +00:00
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
2021-02-23 08:56:42 +00:00
|
|
|
params.index = configuration.cursor;
|
|
|
|
params.uri = configuration.uri;
|
2020-05-29 15:07:36 +00:00
|
|
|
}
|
2021-02-23 08:56:42 +00:00
|
|
|
return this.store.query(this.getModelName(), params);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|