diff --git a/webui/src/js/models/wdt-model-definition.js b/webui/src/js/models/wdt-model-definition.js index ce498eb3e..6f7c4250a 100644 --- a/webui/src/js/models/wdt-model-definition.js +++ b/webui/src/js/models/wdt-model-definition.js @@ -18,6 +18,7 @@ define(['knockout', 'utils/observable-properties', 'js-yaml', 'utils/validation- */ return function (name) { const ID = '[A-Za-z0-9_.-]*'; + const PROPERTY_PATTERN = new RegExp(`@@PROP:(@@ENV:(?${ID})@@)?(?${ID})@@`, 'g'); const SECRET_PATTERN = new RegExp(`@@SECRET:(@@ENV:(?${ID})@@)?(?${ID}):(?${ID})@@`, 'g'); function WdtModel() { const defaultDomainName = 'base_domain'; @@ -102,6 +103,40 @@ define(['knockout', 'utils/observable-properties', 'js-yaml', 'utils/validation- } }; + this.getModelPropertiesReferenceCounts = () => { + const propertiesMap = new Map(); + + [...this.modelContent().matchAll(PROPERTY_PATTERN)].forEach(matches => { + const propertyName = matches.groups.name; + const propertyEnvVar = matches.groups.envvar; + + // While this key is never used outside this function, we need the key to + // match the resolved property name. For example, if the DOMAIN_UID is mydomain, + // the following two fields should refer to the same property: + // + // field1: '@@PROP:@@ENV:DOMAIN_UID@@-value@@' + // field2: '@@PROP:mydomain-value@@' + // + let propertyKey = propertyName; + if (propertyEnvVar) { + propertyKey = propertyName.startsWith('-') ? `${propertyEnvVar}${propertyName}` : `${propertyEnvVar}-${propertyName}`; + } + + let propertyData; + if (propertiesMap.has(propertyKey)) { + propertyData = propertiesMap.get(propertyKey); + propertyData.referenceCount++; + } else { + propertyData ={ name: propertyName, referenceCount: 1 }; + if (propertyEnvVar) { + propertyData.envVar = propertyEnvVar; + } + } + propertiesMap.set(propertyKey, propertyData); + }); + return [...propertiesMap.values()]; + } + // Placeholder for when multiple model files are supported so that the domain page can reliably get all // secrets in the models. //