Skip to content

Commit

Permalink
Handle nested cloud config fields (#160)
Browse files Browse the repository at this point in the history
* build json from config map recursively

* remove console.log

---------

Co-authored-by: Philip Prinz <Philip.Prinz@sva.de>
  • Loading branch information
PhPrinz and Philip Prinz authored Mar 17, 2023
1 parent d1fb3aa commit 5b67438
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/app/data/vm-template-service-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,27 @@ export function vmServiceToJSON(vmService: VMTemplateServiceConfiguration) {
result += ', "noRewriteRootPath": ' + vmService.noRewriteRootPath;
}
}
if (vmService.cloudConfigMap) {
let cloudConfigMapString = '';
vmService.cloudConfigMap.forEach((value, key) => {
cloudConfigMapString += '"' + key + '": ' + JSON.stringify(value) + ' ';
});
result += ', "cloudConfigMap": {' + cloudConfigMapString + '}';
if (vmService.cloudConfigMap) {
result += ', "cloudConfigMap": {' + mapToJson(vmService.cloudConfigMap, '') + '}'; //Potential alternative if es2019 or higher (configurable in tsconfig, field: lib): JSON.stringify(Object.fromEntries(vmService.cloudConfigMap))
}
result += '}';
return result;
}

export function mapToJson(map: Map<string, any>, jsonString: string): string {
let isfirstElement = true
map.forEach((value, key) => {
if(!isfirstElement) {
jsonString += ','
}
if(typeof value === 'string' || Array.isArray(value)) {
jsonString += '"' + key + '": ' + JSON.stringify(value) + ' ';
} else if (value instanceof Map){
jsonString += '"' + key + '": {' + mapToJson(value, '') + '} ';
} else {
jsonString += '"' + key + '": {' + mapToJson(new Map(Object.entries(value)), '') + '} ';
}
isfirstElement = false
});
return jsonString
}

0 comments on commit 5b67438

Please sign in to comment.