mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 13:26:07 +00:00
5fb9df1640
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
99 lines
2.6 KiB
JavaScript
99 lines
2.6 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Serializer from './application';
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/service';
|
|
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 {
|
|
primaryKey = PRIMARY_KEY;
|
|
slugKey = SLUG_KEY;
|
|
|
|
respondForQuery(respond, query) {
|
|
return super.respondForQuery(
|
|
(cb) =>
|
|
respond((headers, body) => {
|
|
// Services and proxies all come together in the same list. Here we
|
|
// map the proxies to their related services on a Service.Proxy
|
|
// property for easy access later on
|
|
return cb(headers, this._transformServicesPayload(body));
|
|
}),
|
|
query
|
|
);
|
|
}
|
|
|
|
respondForQueryRecord(respond, query) {
|
|
// Name is added here from the query, which is used to make the uid
|
|
// Datacenter gets added in the ApplicationSerializer
|
|
return super.respondForQueryRecord(
|
|
(cb) =>
|
|
respond((headers, body) => {
|
|
return cb(headers, {
|
|
Name: query.id,
|
|
Namespace: get(body, 'firstObject.Service.Namespace'),
|
|
Nodes: body,
|
|
});
|
|
}),
|
|
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;
|
|
}
|
|
}
|