diff --git a/src/app/shared/service/cloud-provider-metadata/cloud-provider-metadata.service.ts b/src/app/shared/service/cloud-provider-metadata/cloud-provider-metadata.service.ts index f2ed30f..10832a2 100644 --- a/src/app/shared/service/cloud-provider-metadata/cloud-provider-metadata.service.ts +++ b/src/app/shared/service/cloud-provider-metadata/cloud-provider-metadata.service.ts @@ -84,17 +84,14 @@ export class CloudProviderMetadataService { public parseRcFile(rcFile: string, password: string): OpenStackCredentials { if (rcFile) { - - // update RC file with the user password and set it as current RC file // console.log("The current RC file...", rcFile); - rcFile = rcFile.replace(/#.*\n/, ''); // remove all comments - rcFile = rcFile.replace(/\becho\b.+\n/, ''); // remove all echo commands - rcFile = rcFile.replace(/\bread\b.+\n/, ''); // remove the read command - rcFile = rcFile.replace(/(\bexport OS_PASSWORD=)(.*)/, // set the password + rcFile = rcFile.replace(/#.*\n/g, ''); // remove all comments + rcFile = rcFile.replace(/\becho\b.+/g, ''); // remove all echo commands + rcFile = rcFile.replace(/\bread\b.+/g, ''); // remove the read command + rcFile = rcFile.replace(/(\bexport OS_PASSWORD=)(.*)/, // set the password "$1" + '"' + password + '"'); - // extract all the required RC file fields required to query the TSI portal let rcVersion = CloudProviderMetadataService.extractPropertyValue(rcFile, "OS_IDENTITY_API_VERSION"); let username = CloudProviderMetadataService.extractPropertyValue(rcFile, "OS_USERNAME"); @@ -124,13 +121,18 @@ export class CloudProviderMetadataService { private static extractPropertyValue(rcFile: string, propertyName: string): string { let match; let result: string = null; - let pattern = new RegExp(propertyName + "=(.+)"); + let pattern = new RegExp(propertyName + "=(.+)", 'g'); // extract property if (rcFile) { - if ((match = pattern.exec(rcFile)) !== null) { - result = match[1].replace(/\"/g, ""); - } + // search for all matches and use only the last one + do { + match = pattern.exec(rcFile); + if(match) { + // remove single and double quotes + result = match[1].replace(/['"]/g, ""); + } + }while(match); } return result; }