@@ -18,6 +18,7 @@ define(['knockout', 'utils/observable-properties', 'js-yaml', 'utils/validation-
18
18
*/
19
19
return function ( name ) {
20
20
const ID = '[A-Za-z0-9_.-]*' ;
21
+ const PROPERTY_PATTERN = new RegExp ( `@@PROP:(@@ENV:(?<envvar>${ ID } )@@)?(?<name>${ ID } )@@` , 'g' ) ;
21
22
const SECRET_PATTERN = new RegExp ( `@@SECRET:(@@ENV:(?<envvar>${ ID } )@@)?(?<name>${ ID } ):(?<field>${ ID } )@@` , 'g' ) ;
22
23
function WdtModel ( ) {
23
24
const defaultDomainName = 'base_domain' ;
@@ -102,6 +103,40 @@ define(['knockout', 'utils/observable-properties', 'js-yaml', 'utils/validation-
102
103
}
103
104
} ;
104
105
106
+ this . getModelPropertiesReferenceCounts = ( ) => {
107
+ const propertiesMap = new Map ( ) ;
108
+
109
+ [ ...this . modelContent ( ) . matchAll ( PROPERTY_PATTERN ) ] . forEach ( matches => {
110
+ const propertyName = matches . groups . name ;
111
+ const propertyEnvVar = matches . groups . envvar ;
112
+
113
+ // While this key is never used outside this function, we need the key to
114
+ // match the resolved property name. For example, if the DOMAIN_UID is mydomain,
115
+ // the following two fields should refer to the same property:
116
+ //
117
+ // field1: '@@PROP:@@ENV:DOMAIN_UID@@-value@@'
118
+ // field2: '@@PROP:mydomain-value@@'
119
+ //
120
+ let propertyKey = propertyName ;
121
+ if ( propertyEnvVar ) {
122
+ propertyKey = propertyName . startsWith ( '-' ) ? `${ propertyEnvVar } ${ propertyName } ` : `${ propertyEnvVar } -${ propertyName } ` ;
123
+ }
124
+
125
+ let propertyData ;
126
+ if ( propertiesMap . has ( propertyKey ) ) {
127
+ propertyData = propertiesMap . get ( propertyKey ) ;
128
+ propertyData . referenceCount ++ ;
129
+ } else {
130
+ propertyData = { name : propertyName , referenceCount : 1 } ;
131
+ if ( propertyEnvVar ) {
132
+ propertyData . envVar = propertyEnvVar ;
133
+ }
134
+ }
135
+ propertiesMap . set ( propertyKey , propertyData ) ;
136
+ } ) ;
137
+ return [ ...propertiesMap . values ( ) ] ;
138
+ }
139
+
105
140
// Placeholder for when multiple model files are supported so that the domain page can reliably get all
106
141
// secrets in the models.
107
142
//
0 commit comments