consul/ui/packages/consul-ui/app/utils/create-fingerprinter.js
John Cowen 76f5de1455
ui: Ensure dc selector correctly shows the currently selected dc (#11380)
* ui: Ensure dc selector correctly shows the currently selected dc

* ui: Restrict access to non-default partitions in non-primaries (#11420)

This PR restricts access via the UI to only the default partition when in a non-primary datacenter i.e. you can only have multiple (non-default) partitions in the primary datacenter.
2021-10-26 19:26:04 +01:00

44 lines
1.5 KiB
JavaScript

import { get } from '@ember/object';
export default function(foreignKey, nspaceKey, partitionKey, hash = JSON.stringify) {
return function(primaryKey, slugKey, foreignKeyValue, nspaceValue, partitionValue) {
return function(item) {
foreignKeyValue = foreignKeyValue == null ? item[foreignKey] : foreignKeyValue;
if (foreignKeyValue == null) {
throw new Error('Unable to create fingerprint, missing foreignKey value');
}
const slugKeys = slugKey.split(',');
const slugValues = slugKeys.map(function(slugKey) {
if (get(item, slugKey) == null || get(item, slugKey).length < 1) {
throw new Error('Unable to create fingerprint, missing slug');
}
return get(item, slugKey);
});
// This ensures that all data objects have a Namespace and a Partition
// value set, even in OSS.
if (typeof item[nspaceKey] === 'undefined') {
if (nspaceValue === '*') {
nspaceValue = 'default';
}
item[nspaceKey] = nspaceValue;
}
if (typeof item[partitionKey] === 'undefined') {
if (partitionValue === '*') {
partitionValue = 'default';
}
item[partitionKey] = partitionValue;
}
if (typeof item[foreignKey] === 'undefined') {
item[foreignKey] = foreignKeyValue;
}
if (typeof item[primaryKey] === 'undefined') {
item[primaryKey] = hash(
[item[partitionKey], item[nspaceKey], foreignKeyValue].concat(slugValues)
);
}
return item;
};
};
}