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';
|
2019-02-21 13:10:53 +00:00
|
|
|
const modelName = 'proxy';
|
|
|
|
export default RepositoryService.extend({
|
|
|
|
getModelName: function() {
|
|
|
|
return modelName;
|
|
|
|
},
|
|
|
|
getPrimaryKey: function() {
|
|
|
|
return PRIMARY_KEY;
|
|
|
|
},
|
2019-12-17 18:47:37 +00:00
|
|
|
findAllBySlug: function(slug, dc, nspace, configuration = {}) {
|
2019-02-21 13:10:53 +00:00
|
|
|
const query = {
|
|
|
|
id: slug,
|
2019-12-17 18:47:37 +00:00
|
|
|
ns: nspace,
|
2019-02-21 13:10:53 +00:00
|
|
|
dc: dc,
|
|
|
|
};
|
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
|
|
query.index = configuration.cursor;
|
2020-07-17 13:42:45 +00:00
|
|
|
query.uri = configuration.uri;
|
2019-02-21 13:10:53 +00:00
|
|
|
}
|
2020-08-26 14:24:30 +00:00
|
|
|
return this.store.query(this.getModelName(), query).then(items => {
|
|
|
|
items.forEach(item => {
|
|
|
|
// 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;
|
|
|
|
});
|
2019-02-21 13:10:53 +00:00
|
|
|
},
|
2019-12-17 18:47:37 +00:00
|
|
|
findInstanceBySlug: function(id, node, slug, dc, nspace, configuration) {
|
|
|
|
return this.findAllBySlug(slug, dc, nspace, configuration).then(function(items) {
|
2019-03-22 17:24:40 +00:00
|
|
|
let res = {};
|
2019-02-21 13:10:53 +00:00
|
|
|
if (get(items, 'length') > 0) {
|
2019-06-20 08:37:17 +00:00
|
|
|
let instance = items.filterBy('ServiceProxy.DestinationServiceID', id).findBy('Node', node);
|
2019-03-07 10:51:39 +00:00
|
|
|
if (instance) {
|
2019-03-22 17:24:40 +00:00
|
|
|
res = instance;
|
|
|
|
} else {
|
|
|
|
instance = items.findBy('ServiceProxy.DestinationServiceName', slug);
|
|
|
|
if (instance) {
|
|
|
|
res = instance;
|
|
|
|
}
|
2019-02-21 13:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-22 17:24:40 +00:00
|
|
|
set(res, 'meta', get(items, 'meta'));
|
|
|
|
return res;
|
2019-02-21 13:10:53 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|