Skip to content

Commit 8a0c342

Browse files
committed
CM-44179 - Add proper support for disabled modules
1 parent 2d227be commit 8a0c342

File tree

14 files changed

+212
-57
lines changed

14 files changed

+212
-57
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Unreleased]
44

5+
- Add proper support for disabled modules
6+
- Fix auth required state of status bar
7+
58
## [v1.14.0]
69

710
- Add the "Ignore this violation" button for violation card of SCA

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,39 +65,39 @@
6565
"view/item/context": [
6666
{
6767
"command": "cycode.secretScanForProject",
68-
"when": "viewItem == secretScanTypeNode",
68+
"when": "viewItem == secretScanTypeNode && cycode:modules.isSecretScanningEnabled",
6969
"group": "inline"
7070
},
7171
{
7272
"command": "cycode.scaScan",
73-
"when": "viewItem == scaScanTypeNode",
73+
"when": "viewItem == scaScanTypeNode && cycode:modules.isScaScanningEnabled",
7474
"group": "inline"
7575
},
7676
{
7777
"command": "cycode.iacScanForProject",
78-
"when": "viewItem == iacScanTypeNode",
78+
"when": "viewItem == iacScanTypeNode && cycode:modules.isIacScanningEnabled",
7979
"group": "inline"
8080
},
8181
{
8282
"command": "cycode.sastScanForProject",
83-
"when": "viewItem == sastScanTypeNode",
83+
"when": "viewItem == sastScanTypeNode && cycode:modules.isSastScanningEnabled",
8484
"group": "inline"
8585
},
8686
{
8787
"command": "cycode.secretScanForProject",
88-
"when": "view == cycode.view.tree && viewItem == secretScanTypeNode"
88+
"when": "view == cycode.view.tree && viewItem == secretScanTypeNode && cycode:modules.isSecretScanningEnabled"
8989
},
9090
{
9191
"command": "cycode.scaScan",
92-
"when": "view == cycode.view.tree && viewItem == scaScanTypeNode"
92+
"when": "view == cycode.view.tree && viewItem == scaScanTypeNode && cycode:modules.isScaScanningEnabled"
9393
},
9494
{
9595
"command": "cycode.iacScanForProject",
96-
"when": "view == cycode.view.tree && viewItem == iacScanTypeNode"
96+
"when": "view == cycode.view.tree && viewItem == iacScanTypeNode && cycode:modules.isIacScanningEnabled"
9797
},
9898
{
9999
"command": "cycode.sastScanForProject",
100-
"when": "view == cycode.view.tree && viewItem == sastScanTypeNode"
100+
"when": "view == cycode.view.tree && viewItem == sastScanTypeNode && cycode:modules.isSastScanningEnabled"
101101
}
102102
]
103103
},

src/commands/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const getCommonCommand = (command: (...args: never[]) => void | Promise<v
1111
}
1212

1313
const stateService = container.resolve<IStateService>(StateServiceSymbol);
14-
if (requiredAuth && !stateService.globalState.CliAuthed) {
14+
if (requiredAuth && !stateService.tempState.CliAuthed) {
1515
vscode.window.showErrorMessage('Please authenticate with Cycode first');
1616
return;
1717
}

src/commands/run-all-scans-command.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@ import { container } from 'tsyringe';
22
import { CycodeService, ICycodeService } from '../services/cycode-service';
33
import { CliScanType } from '../cli/models/cli-scan-type';
44
import { getCommonCommand } from './common';
5+
import { IStateService } from '../services/state-service';
6+
import { StateServiceSymbol } from '../symbols';
57

68
export default getCommonCommand(async () => {
79
const cycodeService = container.resolve<ICycodeService>(CycodeService);
10+
const stateService = container.resolve<IStateService>(StateServiceSymbol);
811

912
const scanPromises = [];
10-
scanPromises.push(cycodeService.startScanForCurrentProject(CliScanType.Secret));
11-
scanPromises.push(cycodeService.startScanForCurrentProject(CliScanType.Sca));
12-
scanPromises.push(cycodeService.startScanForCurrentProject(CliScanType.Iac));
13-
scanPromises.push(cycodeService.startScanForCurrentProject(CliScanType.Sast));
13+
14+
if (stateService.tempState.IsSecretScanningEnabled) {
15+
scanPromises.push(cycodeService.startScanForCurrentProject(CliScanType.Secret));
16+
}
17+
if (stateService.tempState.IsScaScanningEnabled) {
18+
scanPromises.push(cycodeService.startScanForCurrentProject(CliScanType.Sca));
19+
}
20+
if (stateService.tempState.IsIacScanningEnabled) {
21+
scanPromises.push(cycodeService.startScanForCurrentProject(CliScanType.Iac));
22+
}
23+
if (stateService.tempState.IsSastScanningEnabled) {
24+
scanPromises.push(cycodeService.startScanForCurrentProject(CliScanType.Sast));
25+
}
26+
1427
await Promise.all(scanPromises);
1528
});

src/extension.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,19 @@ export function activate(context: vscode.ExtensionContext) {
6262
context.subscriptions.push(extensionStatusBar);
6363
// end refactor
6464

65-
if (!stateService.globalState.CliAuthed) {
66-
statusBar.showAuthIsRequired();
67-
}
68-
6965
if (config.isTheiaIde) {
7066
stateService.globalState.EnvVsCode = false;
7167
stateService.save();
7268
}
7369

7470
registerCommands(context);
75-
registerActivityBar(context);
7671
registerCodeLensProvider(context);
7772
registerCodeActionsProvider(context);
7873
registerOnDidSaveTextDocument(context);
7974
registerOnDidChangeActiveTextEditor(context);
8075

76+
stateService.tempState.ActivityBar = registerActivityBar(context);
77+
8178
// do not await because it blocks loading of the extension like views rendering
8279
void postActivate().then(() => {
8380
onProjectOpen();

src/listeners/on-did-save-text-document.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const OnDidSaveTextDocument = (document: vscode.TextDocument) => {
1818
}
1919

2020
const stateService = container.resolve<IStateService>(StateServiceSymbol);
21-
if (!stateService.globalState.CliAuthed) {
21+
if (!stateService.tempState.CliAuthed) {
2222
return;
2323
}
2424

@@ -35,16 +35,18 @@ export const OnDidSaveTextDocument = (document: vscode.TextDocument) => {
3535

3636
const cycodeService = container.resolve<ICycodeService>(CycodeService);
3737

38-
if (isSupportedPackageFile(document.fileName)) {
38+
if (stateService.tempState.IsScaScanningEnabled && isSupportedPackageFile(document.fileName)) {
3939
void cycodeService.startScan(CliScanType.Sca, [fileFsPath], false);
4040
}
4141

42-
if (isSupportedIacFile(document.fileName)) {
42+
if (stateService.tempState.IsIacScanningEnabled && isSupportedIacFile(document.fileName)) {
4343
void cycodeService.startScan(CliScanType.Iac, [fileFsPath], false);
4444
}
4545

4646
// run Secrets scan on any saved file. CLI will exclude irrelevant files
47-
void cycodeService.startScan(CliScanType.Secret, [fileFsPath], false);
47+
if (stateService.tempState.IsSecretScanningEnabled) {
48+
void cycodeService.startScan(CliScanType.Secret, [fileFsPath], false);
49+
}
4850
};
4951

5052
export const registerOnDidSaveTextDocument = (context: vscode.ExtensionContext) => {

src/listeners/on-project-open.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const onProjectOpen = () => {
1313
*/
1414

1515
const stateService = container.resolve<IStateService>(StateServiceSymbol);
16-
if (!stateService.globalState.CliAuthed) {
16+
if (!stateService.tempState.CliAuthed) {
1717
return;
1818
}
1919

src/services/cli-service.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from 'node:fs';
33
import { setSentryUser } from '../sentry';
44
import { inject, singleton } from 'tsyringe';
55
import { ExtensionServiceSymbol, LoggerServiceSymbol, ScanResultsServiceSymbol, StateServiceSymbol } from '../symbols';
6-
import { GlobalExtensionState, IStateService } from './state-service';
6+
import { GlobalExtensionState, IStateService, TemporaryExtensionState } from './state-service';
77
import { ILoggerService } from './logger-service';
88
import { CliWrapper } from '../cli/cli-wrapper';
99
import { CliResult, isCliResultError, isCliResultPanic, isCliResultSuccess } from '../cli/models/cli-result';
@@ -27,6 +27,7 @@ import { CliIgnoreType } from '../cli/models/cli-ignore-type';
2727
import { CliScanType } from '../cli/models/cli-scan-type';
2828
import { StatusResult } from '../cli/models/status-result';
2929
import { AiRemediationResult, AiRemediationResultData } from '../cli/models/ai-remediation-result';
30+
import statusBar from '../utils/status-bar';
3031

3132
export interface ICliService {
3233
getProjectRootDirectory(): string | undefined; // TODO REMOVE
@@ -47,6 +48,7 @@ export interface ICliService {
4748
@singleton()
4849
export class CliService implements ICliService {
4950
private state: GlobalExtensionState;
51+
private tempState: TemporaryExtensionState;
5052
private cli: CliWrapper;
5153

5254
constructor(@inject(StateServiceSymbol) private stateService: IStateService,
@@ -55,6 +57,7 @@ export class CliService implements ICliService {
5557
@inject(ExtensionServiceSymbol) private extensionService: IExtensionService,
5658
) {
5759
this.state = this.stateService.globalState;
60+
this.tempState = this.stateService.tempState;
5861
this.cli = new CliWrapper(this.getProjectRootDirectory());
5962
}
6063

@@ -72,7 +75,7 @@ export class CliService implements ICliService {
7275
return null;
7376
}
7477

75-
this.state.CliInstalled = false;
78+
this.tempState.CliInstalled = false;
7679
this.state.CliVer = null;
7780
this.stateService.save();
7881
}
@@ -140,15 +143,19 @@ export class CliService implements ICliService {
140143
return;
141144
}
142145

143-
this.state.CliInstalled = true;
146+
this.tempState.CliInstalled = true;
147+
this.tempState.CliAuthed = processedResult.result.isAuthenticated;
148+
this.tempState.CliStatus = processedResult.result;
149+
144150
this.state.CliVer = processedResult.result.version;
145-
this.state.CliAuthed = processedResult.result.isAuthenticated;
146-
this.state.IsAiLargeLanguageModelEnabled = processedResult.result.supportedModules.aiLargeLanguageModel;
151+
147152
this.stateService.save();
148153

149-
if (!this.state.CliAuthed) {
154+
if (!this.tempState.CliAuthed) {
155+
statusBar.showAuthIsRequired();
150156
this.showErrorNotification('You are not authenticated in Cycode. Please authenticate');
151157
} else {
158+
statusBar.showDefault();
152159
if (processedResult.result.userId && processedResult.result.tenantId) {
153160
setSentryUser(processedResult.result.userId, processedResult.result.tenantId);
154161
}
@@ -167,14 +174,14 @@ export class CliService implements ICliService {
167174
return false;
168175
}
169176

170-
this.state.CliAuthed = processedResult.result.result;
177+
this.tempState.CliAuthed = processedResult.result.result;
171178
this.stateService.save();
172179

173-
if (!this.state.CliAuthed) {
180+
if (!this.tempState.CliAuthed) {
174181
this.showErrorNotification('Authentication failed. Please try again');
175182
}
176183

177-
return this.state.CliAuthed;
184+
return this.tempState.CliAuthed;
178185
}
179186

180187
private mapIgnoreTypeToOptionName(ignoreType: CliIgnoreType): string {

0 commit comments

Comments
 (0)