consul/ui-v2/app/utils/create-fingerprinter.js
John Cowen 7044aa52c8 ui: Namespace Support (#6639)
Adds namespace support to the UI:

1. Namespace CRUD/management
2. Show Namespace in relevant areas (intentions, upstreams)
3. Main navigation bar improvements
4. Logic/integration to interact with a new `internal/acl/authorize` endpoint
2019-12-18 12:26:47 +00:00

22 lines
772 B
JavaScript

export default function(foreignKey, nspaceKey, nspaceUndefinedName, hash = JSON.stringify) {
return function(primaryKey, slugKey, foreignKeyValue) {
if (foreignKeyValue == null || foreignKeyValue.length < 1) {
throw new Error('Unable to create fingerprint, missing foreignKey value');
}
return function(item) {
if (item[slugKey] == null || item[slugKey].length < 1) {
throw new Error('Unable to create fingerprint, missing slug');
}
const nspaceValue = item[nspaceKey] || nspaceUndefinedName;
return {
...item,
...{
[nspaceKey]: nspaceValue,
[foreignKey]: foreignKeyValue,
[primaryKey]: hash([nspaceValue, foreignKeyValue, item[slugKey]]),
},
};
};
};
}