diff options
author | 2020-10-05 10:23:48 +0200 | |
---|---|---|
committer | 2020-10-05 10:23:48 +0200 | |
commit | 178dbc0bcb8b3b685a9f1c45eb4d21d062c8ee86 (patch) | |
tree | fa644d71bdc7337f19be6789d0666d7e7a8f91d4 /cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory | |
parent | 133afdcc3d4580cb61e1a2134e0ab617c3901eb0 (diff) |
in Jinja Template support the parsing of parent variable in dictionary mapping file
Issue-ID: CCSDK-2866
Signed-off-by: Ahmedeldeeb50 <ahmed.eldeeb.ext@orange.com>
Change-Id: Ib3d4f70cd1728e34b8db362dcb1435ea5386cade
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory')
4 files changed, 54 insertions, 5 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts index 11d1ad7f0..6ecee9070 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts @@ -4,18 +4,30 @@ export class JinjaYMLParser implements Parser { variables: Set<string> = new Set(); getVariables(fileContent: string): string[] { if (fileContent.includes('{{')) { - const xmlSplit = fileContent.split(new RegExp('[{]+[ ]*.[V-v]alues.')); + // '[{]+[ ]*.[V-v]alues.' old regex + const xmlSplit = fileContent.split(new RegExp('[{]+[ ]*.')); for (const val of xmlSplit) { const res = val.substring(0, val.indexOf('}}')); if (res && res.length > 0) { - this.variables.add(res.trim()); + console.log(res); + if (res.includes('Value')) { + this.variables.add(this.extractValues(res.trim())); + } else { + this.variables.add(this.extractParent(res.trim()).toLowerCase()); + } } - } } return [...this.variables]; } + extractValues(value) { + return value.split('Values.')[1]; + } + extractParent(value): string { + return value.split('.')[0]; + } + } /* diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts index aab37c722..3a1880c99 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts @@ -72,7 +72,7 @@ fdescribe('ImportsTabComponent', () => { const parser = parserFactory.getParser(fileContent, FileExtension.Jinja); const res = parser.getVariables(fileContent); console.log(res); - expect(res.length).toEqual(2); + expect(res.length).toEqual(4); expect(res[0]).toEqual('vpg_name_0'); expect(res[1]).toEqual('vnf_name'); @@ -115,4 +115,39 @@ fdescribe('ImportsTabComponent', () => { }); + + + + + + it('Test Velocity YML Parser', () => { + const fileContent = `apiVersion: v1 + kind: Service + metadata: + name: {{ .Values.vpg_name_0 }}-ssh + labels: + vnf-name: {{ .Values.vnf_name }} + vf-module-name: {{ .Values.vpg_name_0 }} + release: {{ .Release.Name }} + chart: {{ .Chart.Name }} + spec: + type: NodePort + ports: + port: 22 + nodePort: \${vpg-management-port} + selector: + vf-module-name: {{ .Values.vpg_name_0 }} + release: {{ .Release.Name }} + chart: {{ .Chart.Name }}`; + + const parser = parserFactory.getParser(fileContent, FileExtension.Velocity); + const res = parser.getVariables(fileContent); + console.log(res); + expect(res.length).toEqual(1); + expect(res[0]).toEqual('vpg-management-port'); + + }); + + + }); diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts index a5c92e441..b64afeed0 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts @@ -23,6 +23,7 @@ export class ParserFactory { } else if (this.isASCII(fileContent)) { parser = new ASCIIParser(); } else { + console.log('Velocity YML parser....'); parser = new VtlYMLParser(); } @@ -35,6 +36,7 @@ export class ParserFactory { } else if (this.isASCII(fileContent)) { parser = new ASCIIParser(); } else { + console.log('Jinja YML parser....'); parser = new JinjaYMLParser(); } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts index 4b7d22762..6c3a0e0fd 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts @@ -7,7 +7,7 @@ export class VtlYMLParser implements Parser { const xmlSplit = fileContent.split('${'); for (const val of xmlSplit) { const res = val.substring(0, val.indexOf('}')); - if (res && res.length > 0) { + if (res && res.length > 0 && !res.includes('{')) { this.variables.add(res); } |