mirror of
https://github.com/status-im/consul.git
synced 2025-01-12 23:05:28 +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>
68 lines
2.6 KiB
JavaScript
68 lines
2.6 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { get, set } from '@ember/object';
|
|
import MultiMap from 'mnemonist/multi-map';
|
|
|
|
/**
|
|
* Checks are ember-data-model-fragments, so we can't just
|
|
* concat it, we have to loop through all the items in order to merge
|
|
* We also need to avoid repeating Node checks here as the service and the
|
|
* proxy is likely to be on the same node, without adding something extra here
|
|
* the node check will likely end up in the list twice.
|
|
*
|
|
* @param {Array} checks - Multiple lists of healthchecks to merge each one of the items in this array should be a further array of healthchecks
|
|
* @param {Boolean} exposed - Whether the checks should be marked as exposed via the proxy or not
|
|
* @param {Object} MMap - A MultiMap class. This is only exposed to allow for an easier interface but still allow an injectable MultiMap if we choose to do that during testing
|
|
* @returns {Array} - The final array of all of the healthchecks with any duplicate node checks removed, and also marked as exposed if required
|
|
*/
|
|
export default (checks = [], exposed = false, MMap = MultiMap) => {
|
|
const ids = new MMap();
|
|
const a = checks.shift();
|
|
const result = a
|
|
.map((item) => {
|
|
// its a Node check (ServiceName === ""), record this one so we
|
|
// don't end up with duplicates of it
|
|
if (item.ServiceName === '') {
|
|
ids.set(item.Node, item.CheckID);
|
|
}
|
|
return item;
|
|
})
|
|
// go through all remaining lists of checks adding each check to the
|
|
// list if its not a node check that has been already added
|
|
.concat(
|
|
checks.reduce((prev, items) => {
|
|
if (typeof items === 'undefined') {
|
|
return prev;
|
|
}
|
|
return prev.concat(
|
|
items.reduce((prev, item) => {
|
|
if (item.ServiceName === '') {
|
|
if ((ids.get(item.Node) || []).includes(item.CheckID)) {
|
|
return prev;
|
|
}
|
|
// if the node check hasn't been added yet, record this one
|
|
// so we don't end up with duplicates of it
|
|
ids.set(item.Node, item.CheckID);
|
|
}
|
|
prev.push(item);
|
|
return prev;
|
|
}, [])
|
|
);
|
|
}, [])
|
|
);
|
|
// if checks are exposed via the proxy, find the ones that are exposable
|
|
// (ones of a certain type) and set them as exposed
|
|
// TODO: consider moving this out of here so we aren't doing too much in one util
|
|
if (exposed) {
|
|
result
|
|
.filter((item) => get(item, 'Exposable'))
|
|
.forEach((item) => {
|
|
set(item, 'Exposed', exposed);
|
|
});
|
|
}
|
|
return result;
|
|
};
|