Skip to content

Commit

Permalink
release v2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kikkomep committed May 25, 2018
2 parents 097cdab + 1b65702 commit 760c794
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 760c794

Please sign in to comment.