diff --git a/openapi-plugin/src/main/java/com/xliic/openapi/graphql/GraphQlService.java b/openapi-plugin/src/main/java/com/xliic/openapi/graphql/GraphQlService.java index 0f489cbe..a60d8d31 100644 --- a/openapi-plugin/src/main/java/com/xliic/openapi/graphql/GraphQlService.java +++ b/openapi-plugin/src/main/java/com/xliic/openapi/graphql/GraphQlService.java @@ -95,31 +95,37 @@ public void reject(@NotNull String error) { } }; if (type == Credentials.Type.AnondToken) { - CliService.getInstance().downloadOrUpdateIfNecessary(project, new CliService.Callback() { - @Override - public void complete(@NotNull String cliPath) { - startAuditTask(file, new GraphQlCliTask(project, file, type, callback)); - } - @Override - public void reject(@NotNull String error) { - callback.reject(error); - } - @Override - public void cancel() { - pendingAudits.remove(file.getPath()); - MsgUtils.notifyInfo(project, "42Crunch API Security Testing Binary is required to run Audit."); - } - }, true); + runAuditCliTask(file, type, callback); } else if (type == Credentials.Type.ApiToken) { String auditRuntime = SettingsService.getInstance().getValue(Settings.Audit.AUDIT_RUNTIME); if (Objects.equals(auditRuntime, AUDIT_RUNTIME_CLI)) { - startAuditTask(file, new GraphQlCliTask(project, file, type, callback)); + runAuditCliTask(file, type, callback); } else { - startAuditTask(file, new PlatformGraphQlAuditTask(project, file, type, callback)); + // TODO: temp WA to align logic with the VSCode implementation + //startAuditTask(file, new PlatformGraphQlAuditTask(project, file, type, callback)); + runAuditCliTask(file, type, callback); } } } + private void runAuditCliTask(VirtualFile file, Credentials.Type type, GraphQlCallback callback) { + CliService.getInstance().downloadOrUpdateIfNecessary(project, new CliService.Callback() { + @Override + public void complete(@NotNull String cliPath) { + startAuditTask(file, new GraphQlCliTask(project, file, type, callback)); + } + @Override + public void reject(@NotNull String error) { + callback.reject(error); + } + @Override + public void cancel() { + pendingAudits.remove(file.getPath()); + MsgUtils.notifyInfo(project, "42Crunch API Security Testing Binary is required to run Audit."); + } + }, true); + } + private void startAuditTask(VirtualFile file, Task.Backgroundable task) { ApplicationManager.getApplication().invokeLater(() -> { AuditService.getInstance(project).cleanAuditReport(file); diff --git a/openapi-plugin/src/main/java/com/xliic/openapi/services/AuditService.java b/openapi-plugin/src/main/java/com/xliic/openapi/services/AuditService.java index 1745108a..d326dd09 100644 --- a/openapi-plugin/src/main/java/com/xliic/openapi/services/AuditService.java +++ b/openapi-plugin/src/main/java/com/xliic/openapi/services/AuditService.java @@ -438,27 +438,11 @@ public void cancel() { boolean isFullAudit = payload == null || payload.isFull(); // Paid users always run audit using the platform, free users use CLI or fallback to anond if (type == Credentials.Type.AnondToken) { - CliService.getInstance().downloadOrUpdateIfNecessary(project, new CliService.Callback() { - @Override - public void complete(@NotNull String cliPath) { - startAuditTask(file, isFullAudit ? - new AuditCliTask(project, type, file, callback) : new AuditCliTask(project, type, payload, callback)); - } - @Override - public void reject(@NotNull String error) { - callback.reject(error); - } - @Override - public void cancel() { - pendingAudits.remove(file.getPath()); - MsgUtils.notifyInfo(project, "42Crunch API Security Testing Binary is required to run Audit."); - } - }, true); + runAuditCliTask(file, payload, type, callback); } else if (type == Credentials.Type.ApiToken) { String auditRuntime = SettingsService.getInstance().getValue(Settings.Audit.AUDIT_RUNTIME); if (Objects.equals(auditRuntime, AUDIT_RUNTIME_CLI)) { - startAuditTask(file, isFullAudit ? - new AuditCliTask(project, type, file, callback) : new AuditCliTask(project, type, payload, callback)); + runAuditCliTask(file, payload, type, callback); } else { startAuditTask(file, isFullAudit ? new PlatformAuditTask(project, file, type, callback) : new PlatformAuditTask(project, payload, type, callback)); @@ -466,6 +450,26 @@ public void cancel() { } } + private void runAuditCliTask(VirtualFile file, AuditOperation payload, Credentials.Type type, Callback callback) { + CliService.getInstance().downloadOrUpdateIfNecessary(project, new CliService.Callback() { + @Override + public void complete(@NotNull String cliPath) { + boolean isFullAudit = payload == null || payload.isFull(); + startAuditTask(file, isFullAudit ? new AuditCliTask(project, type, file, callback) : + new AuditCliTask(project, type, payload, callback)); + } + @Override + public void reject(@NotNull String error) { + callback.reject(error); + } + @Override + public void cancel() { + pendingAudits.remove(file.getPath()); + MsgUtils.notifyInfo(project, "42Crunch API Security Testing Binary is required to run Audit."); + } + }, true); + } + private void startAuditTask(VirtualFile file, Task.Backgroundable task) { ApplicationManager.getApplication().invokeLater(() -> { cleanAuditReport(file);