Skip to content

Commit 42afae1

Browse files
committed
solving issues to succedd in the integration tests
1 parent f9e4016 commit 42afae1

File tree

2 files changed

+41
-53
lines changed

2 files changed

+41
-53
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@
5757
"publishConfig": {
5858
"registry": "https://npm.pkg.github.com"
5959
}
60-
}
60+
}

src/main/CxAuth.ts

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export class CxAuth {
1414
clientId: string = "";
1515
clientSecret: string = "";
1616
apiKey: string = "";
17-
commands: string[] = [];
1817
pathToExecutable: string;
1918
tenant: string;
2019

@@ -56,7 +55,7 @@ export class CxAuth {
5655
}
5756

5857
initializeCommands(formatRequired: boolean): string[] {
59-
let list: string[] = [];
58+
const list: string[] = [];
6059
if (this.clientId) {
6160
list.push("--client-id");
6261
list.push(this.clientId);
@@ -80,69 +79,64 @@ export class CxAuth {
8079
if (formatRequired) {
8180
list.push("--format");
8281
list.push("json");
83-
list.push("-v");
8482
}
8583
return list;
8684
}
8785

8886
async scanCreate(params: ParamTypeMap): Promise<CxCommandOutput> {
89-
this.commands = this.initializeCommands(true);
90-
this.commands.push("scan");
91-
this.commands.push("create");
87+
const commands: string[] = ["scan", "create"];
88+
commands.push(...this.initializeCommands(true));
9289
params.forEach((value: string, key: CxParamType) => {
9390
if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value) {
94-
this.commands.push("--" + key.toString().replace(/_/g, "-").toLowerCase());
95-
this.commands.push(value);
91+
commands.push("--" + key.toString().replace(/_/g, "-").toLowerCase());
92+
commands.push(value);
9693
} else if (key.length === 1 && value) {
97-
this.commands.push("-" + key.toString().replace(/_/g, "-").toLowerCase());
98-
this.commands.push(value);
94+
commands.push("-" + key.toString().replace(/_/g, "-").toLowerCase());
95+
commands.push(value);
9996
} else if (key === CxParamType.ADDITIONAL_PARAMETERS) {
10097
let paramList = value.match(/(?:[^\s"]+|"[^"]*")+/g);
10198
console.log("Additional parameters refined: " + paramList)
10299
if (paramList) {
103100
paramList.forEach((element) => {
104-
this.commands.push(element);
101+
commands.push(element);
105102
});
106103
}
107104
}
108105
});
109106

110-
let exec = new ExecutionService();
111-
return await exec.executeCommands(this.pathToExecutable, this.commands);
107+
const exec = new ExecutionService();
108+
return await exec.executeCommands(this.pathToExecutable, commands);
112109
}
113110

114111
async authValidate(): Promise<CxCommandOutput> {
115-
this.commands = this.initializeCommands(false);
116-
this.commands.push("auth");
117-
this.commands.push("validate");
112+
const commands: string[] = ["auth", "validate"];
113+
commands.push(...this.initializeCommands(false));
118114
let exec = new ExecutionService();
119-
return await exec.executeCommands(this.pathToExecutable, this.commands);
115+
return await exec.executeCommands(this.pathToExecutable, commands);
120116
}
121117

122118
async scanShow(id: string): Promise<CxCommandOutput> {
123-
this.commands = this.initializeCommands(true);
124-
this.commands.push("scan");
125-
this.commands.push("show");
126-
this.commands.push("--scan-id");
127-
this.commands.push(id);
128-
let exec = new ExecutionService();
129-
return await exec.executeCommands(this.pathToExecutable, this.commands);
119+
const commands: string[] = ["scan", "show", "--scan-id", id];
120+
commands.push(...this.initializeCommands(true));
121+
122+
const exec = new ExecutionService();
123+
return await exec.executeCommands(this.pathToExecutable, commands);
130124
}
131125

132126
async scanList(): Promise<CxCommandOutput> {
133-
this.commands = this.initializeCommands(true);
134-
this.commands.push("scan");
135-
this.commands.push("list");
136-
let exec = new ExecutionService();
137-
return await exec.executeCommands(this.pathToExecutable, this.commands);
127+
const commands: string[] = ["scan", "list"];
128+
commands.push(...this.initializeCommands(true));
129+
130+
const exec = new ExecutionService();
131+
return await exec.executeCommands(this.pathToExecutable, commands);
138132
}
139133

140134
async projectList(): Promise<CxCommandOutput> {
141-
this.commands = this.initializeCommands(true);
142-
this.commands.push("project");
143-
this.commands.push("list");
144-
let exec = new ExecutionService();
145-
return await exec.executeCommands(this.pathToExecutable, this.commands);
135+
const commands: string[] = ["project", "list"];
136+
commands.push(...this.initializeCommands(true));
137+
138+
const exec = new ExecutionService();
139+
return await exec.executeCommands(this.pathToExecutable, commands);
146140
}
147141

148142
async getResultsList(scanId: string) {
@@ -154,43 +148,37 @@ export class CxAuth {
154148
}
155149

156150
async getResults(scanId: string, resultType:string, outputFileName: string, outputFilePath: string) {
157-
this.commands = this.createResultCommand(scanId, resultType, outputFileName, outputFilePath)
151+
const commands = this.createResultCommand(scanId, resultType, outputFileName, outputFilePath)
158152

159153
const exec = new ExecutionService();
160-
return await exec.executeCommands(this.pathToExecutable, this.commands);
154+
return await exec.executeCommands(this.pathToExecutable, commands);
161155
}
162156

163157
async executeResultsCommands(scanId: string, resultType: string, fileExtension: string): Promise<string> {
164158
const fileName = new Date().getTime().toString();
165-
this.commands = this.createResultCommand(scanId, resultType, fileName, os.tmpdir())
159+
const commands = this.createResultCommand(scanId, resultType, fileName, os.tmpdir())
166160

167161
const exec = new ExecutionService();
168-
await exec.executeResultsCommands(this.pathToExecutable, this.commands)
162+
await exec.executeResultsCommands(this.pathToExecutable, commands)
169163

170164
const filePath = path.join(os.tmpdir(), fileName + fileExtension)
171165

172166
return fs.readFileSync(filePath,'utf8');
173167
}
174168

175169
createResultCommand(scanId: string, reportFormat: string, outputFileName: string, outputPath: string): string[] {
176-
const resultCommands = this.initializeCommands(false);
177-
resultCommands.push("result");
178-
resultCommands.push("--scan-id");
179-
resultCommands.push(scanId);
180-
resultCommands.push("--report-format");
181-
resultCommands.push(reportFormat);
170+
const commands: string[] = ["result", "--scan-id", scanId, "--report-format", reportFormat];
182171

183172
if (outputFileName) {
184-
resultCommands.push("--output-name")
185-
resultCommands.push(outputFileName)
173+
commands.push("--output-name")
174+
commands.push(outputFileName)
186175
}
187176
if (outputPath) {
188-
resultCommands.push("--output-path")
189-
resultCommands.push(outputPath)
177+
commands.push("--output-path")
178+
commands.push(outputPath)
190179
}
180+
commands.push(...this.initializeCommands(false));
191181

192-
return resultCommands;
182+
return commands;
193183
}
194-
}
195-
196-
184+
}

0 commit comments

Comments
 (0)