2020-10-01 08:33:22 +00:00
|
|
|
import Route from 'consul-ui/routing/route';
|
2019-02-21 13:10:53 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { hash } from 'rsvp';
|
|
|
|
import { get } from '@ember/object';
|
|
|
|
|
|
|
|
export default Route.extend({
|
2020-07-17 13:42:45 +00:00
|
|
|
data: service('data-source/service'),
|
2019-02-21 13:10:53 +00:00
|
|
|
model: function(params) {
|
|
|
|
const dc = this.modelFor('dc').dc.Name;
|
2020-07-17 13:42:45 +00:00
|
|
|
const nspace = this.modelFor('nspace').nspace.substr(1) || 'default';
|
2019-02-21 13:10:53 +00:00
|
|
|
return hash({
|
2020-06-17 09:25:54 +00:00
|
|
|
dc: dc,
|
2020-07-17 13:42:45 +00:00
|
|
|
nspace: nspace,
|
|
|
|
item: this.data.source(
|
|
|
|
uri => uri`/${nspace}/${dc}/service-instance/${params.id}/${params.node}/${params.name}`
|
|
|
|
),
|
2019-12-17 18:47:37 +00:00
|
|
|
}).then(model => {
|
2019-03-22 17:24:40 +00:00
|
|
|
// this will not be run in a blocking loop, but this is ok as
|
|
|
|
// its highly unlikely that a service will suddenly change to being a
|
|
|
|
// connect-proxy or vice versa so leave as is for now
|
2019-02-21 13:10:53 +00:00
|
|
|
return hash({
|
2020-07-17 13:42:45 +00:00
|
|
|
...model,
|
2020-05-07 13:57:15 +00:00
|
|
|
proxyMeta:
|
2019-07-05 08:07:25 +00:00
|
|
|
// proxies and mesh-gateways can't have proxies themselves so don't even look
|
|
|
|
['connect-proxy', 'mesh-gateway'].includes(get(model.item, 'Kind'))
|
2019-03-07 10:51:39 +00:00
|
|
|
? null
|
2020-07-17 13:42:45 +00:00
|
|
|
: this.data.source(
|
|
|
|
uri =>
|
|
|
|
uri`/${nspace}/${dc}/proxy-instance/${params.id}/${params.node}/${params.name}`
|
|
|
|
),
|
2020-05-07 13:57:15 +00:00
|
|
|
}).then(model => {
|
|
|
|
if (typeof get(model, 'proxyMeta.ServiceID') === 'undefined') {
|
|
|
|
return model;
|
|
|
|
}
|
2020-07-17 13:42:45 +00:00
|
|
|
const proxy = {
|
|
|
|
id: get(model, 'proxyMeta.ServiceID'),
|
|
|
|
node: get(model, 'proxyMeta.Node'),
|
|
|
|
name: get(model, 'proxyMeta.ServiceName'),
|
|
|
|
};
|
2020-05-07 13:57:15 +00:00
|
|
|
return hash({
|
2020-07-17 13:42:45 +00:00
|
|
|
...model,
|
2020-05-07 13:57:15 +00:00
|
|
|
// Proxies have identical dc/nspace as their parent instance
|
|
|
|
// No need to use Proxy's dc/nspace response
|
2020-07-17 13:42:45 +00:00
|
|
|
proxy: this.data.source(
|
|
|
|
uri => uri`/${nspace}/${dc}/service-instance/${proxy.id}/${proxy.node}/${proxy.name}`
|
|
|
|
),
|
2020-05-07 13:57:15 +00:00
|
|
|
});
|
2019-02-21 13:10:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
setupController: function(controller, model) {
|
2020-10-01 08:33:22 +00:00
|
|
|
this._super(...arguments);
|
2019-02-21 13:10:53 +00:00
|
|
|
controller.setProperties(model);
|
|
|
|
},
|
|
|
|
});
|