add external-services method to peer repo
This commit is contained in:
parent
d33b5c7bd3
commit
961d0179c7
|
@ -1,6 +1,10 @@
|
||||||
import Serializer from './application';
|
import Serializer from './application';
|
||||||
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/service';
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/service';
|
||||||
import { get } from '@ember/object';
|
import { get } from '@ember/object';
|
||||||
|
import {
|
||||||
|
HEADERS_NAMESPACE as HTTP_HEADERS_NAMESPACE,
|
||||||
|
HEADERS_PARTITION as HTTP_HEADERS_PARTITION,
|
||||||
|
} from 'consul-ui/utils/http/consul';
|
||||||
|
|
||||||
export default class ServiceSerializer extends Serializer {
|
export default class ServiceSerializer extends Serializer {
|
||||||
primaryKey = PRIMARY_KEY;
|
primaryKey = PRIMARY_KEY;
|
||||||
|
@ -13,31 +17,7 @@ export default class ServiceSerializer extends Serializer {
|
||||||
// Services and proxies all come together in the same list. Here we
|
// Services and proxies all come together in the same list. Here we
|
||||||
// map the proxies to their related services on a Service.Proxy
|
// map the proxies to their related services on a Service.Proxy
|
||||||
// property for easy access later on
|
// property for easy access later on
|
||||||
const services = {};
|
return cb(headers, this._transformServicesPayload(body));
|
||||||
body
|
|
||||||
.filter(function (item) {
|
|
||||||
return item.Kind !== 'connect-proxy';
|
|
||||||
})
|
|
||||||
.forEach((item) => {
|
|
||||||
services[item.Name] = item;
|
|
||||||
});
|
|
||||||
body
|
|
||||||
.filter(function (item) {
|
|
||||||
return item.Kind === 'connect-proxy';
|
|
||||||
})
|
|
||||||
.forEach((item) => {
|
|
||||||
// Iterating to cover the usecase of a proxy being used by more
|
|
||||||
// than one service
|
|
||||||
if (item.ProxyFor) {
|
|
||||||
item.ProxyFor.forEach((service) => {
|
|
||||||
if (typeof services[service] !== 'undefined') {
|
|
||||||
services[service].Proxy = item;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return cb(headers, body);
|
|
||||||
}),
|
}),
|
||||||
query
|
query
|
||||||
);
|
);
|
||||||
|
@ -58,4 +38,56 @@ export default class ServiceSerializer extends Serializer {
|
||||||
query
|
query
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createJSONApiDocumentFromServicesPayload(headers, responseBody, dc) {
|
||||||
|
const { primaryKey, slugKey, fingerprint } = this;
|
||||||
|
|
||||||
|
const transformedBody = this._transformServicesPayload(responseBody);
|
||||||
|
const attributes = transformedBody.map(
|
||||||
|
fingerprint(
|
||||||
|
primaryKey,
|
||||||
|
slugKey,
|
||||||
|
dc,
|
||||||
|
headers[HTTP_HEADERS_NAMESPACE],
|
||||||
|
headers[HTTP_HEADERS_PARTITION]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: attributes.map((attr) => {
|
||||||
|
return {
|
||||||
|
id: attr.uid,
|
||||||
|
type: 'service',
|
||||||
|
attributes: attr,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
_transformServicesPayload(body) {
|
||||||
|
const services = {};
|
||||||
|
body
|
||||||
|
.filter(function (item) {
|
||||||
|
return item.Kind !== 'connect-proxy';
|
||||||
|
})
|
||||||
|
.forEach((item) => {
|
||||||
|
services[item.Name] = item;
|
||||||
|
});
|
||||||
|
body
|
||||||
|
.filter(function (item) {
|
||||||
|
return item.Kind === 'connect-proxy';
|
||||||
|
})
|
||||||
|
.forEach((item) => {
|
||||||
|
// Iterating to cover the usecase of a proxy being used by more
|
||||||
|
// than one service
|
||||||
|
if (item.ProxyFor) {
|
||||||
|
item.ProxyFor.forEach((service) => {
|
||||||
|
if (typeof services[service] !== 'undefined') {
|
||||||
|
services[service].Proxy = item;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return body;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import RepositoryService from 'consul-ui/services/repository';
|
import RepositoryService from 'consul-ui/services/repository';
|
||||||
import dataSource from 'consul-ui/decorators/data-source';
|
import dataSource from 'consul-ui/decorators/data-source';
|
||||||
|
import { inject as service } from '@ember/service';
|
||||||
|
|
||||||
function normalizePeerPayload(peerPayload, dc, partition) {
|
function normalizePeerPayload(peerPayload, dc, partition) {
|
||||||
const {
|
const {
|
||||||
|
@ -18,10 +19,31 @@ function normalizePeerPayload(peerPayload, dc, partition) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export default class PeerService extends RepositoryService {
|
export default class PeerService extends RepositoryService {
|
||||||
|
@service store;
|
||||||
|
|
||||||
getModelName() {
|
getModelName() {
|
||||||
return 'peer';
|
return 'peer';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@dataSource('/:partition/:ns/:ds/exported-services/:name')
|
||||||
|
async fetchExportedServices({ dc, ns, partition, name }, configuration, request) {
|
||||||
|
return (
|
||||||
|
await request`
|
||||||
|
GET /v1/internal/ui/exported-services
|
||||||
|
|
||||||
|
${{
|
||||||
|
peer: name,
|
||||||
|
}}
|
||||||
|
`
|
||||||
|
)((headers, body, cache) => {
|
||||||
|
const serviceSerializer = this.store.serializerFor('service');
|
||||||
|
|
||||||
|
return this.store.push(
|
||||||
|
serviceSerializer.createJSONApiDocumentFromServicesPayload(headers, body, dc)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@dataSource('/:partition/:ns/:dc/peering/token-for/:name')
|
@dataSource('/:partition/:ns/:dc/peering/token-for/:name')
|
||||||
async fetchToken({ dc, ns, partition, name }, configuration, request) {
|
async fetchToken({ dc, ns, partition, name }, configuration, request) {
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue