Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix 1 #71

Merged
merged 15 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ jobs:
path: .
key: ${{ runner.os }}-repo-${{ steps.hash.outputs.hash }}

build:
runs-on: ubuntu-latest
needs: setup
steps:
- name: Restore repository cache
uses: actions/cache@v4
with:
path: .
key: ${{ needs.setup.outputs.package-lock-hash }}
fail-on-cache-miss: true
- name: Compile
run: npm run compile

package:
runs-on: ubuntu-latest
needs: setup
Expand Down Expand Up @@ -78,6 +65,11 @@ jobs:

- name: Package VS Code Extension
run: vsce package
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_URL: ${{ secrets.SENTRY_URL }}

- name: Upload VSIX artifact
uses: actions/upload-artifact@v4
Expand All @@ -86,6 +78,20 @@ jobs:
path: "*.vsix"
retention-days: 10

- name: Install Sentry CLI
run: npm install -g @sentry/cli

- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_URL: ${{ secrets.SENTRY_URL }}
with:
environment: review
version: vs-code-extension@${{ env.LATEST_TAG }}+${{ env.LAT_COMMIT }}-review

test:
runs-on: ubuntu-latest
needs: setup
Expand Down Expand Up @@ -120,7 +126,7 @@ jobs:

cleanup:
runs-on: ubuntu-latest
needs: [setup, build]
needs: [setup, package]
if: always()
steps:
- name: Cleanup
Expand Down
4 changes: 2 additions & 2 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ async function main() {
project: "visual-studio-code-extensions",
url: "https://sentry.debricked.com/",
release: {
name: `vs-code-extension@${process.env.LATEST_TAG || "0.0.0"}`,
dist: process.env.LATEST_TAG || "0.0.0",
name: `vs-code-extension@${process.env.LATEST_TAG || "0.0.0-dev"}${process.env.LAT_COMMIT ? `+${process.env.LAT_COMMIT}-review` : ""}`,
dist: `${process.env.LATEST_TAG || "0.0.0-dev"}${process.env.LAT_COMMIT ? `+${process.env.LAT_COMMIT}-review` : ""}`,
cleanArtifacts: true,
},
}),
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "debricked",
"description": "A fast and flexible software composition analysis VS Code Extension and CLI tool, given to you by Debricked.",
"publisher": "debricked",
"version": "0.0.0",
"version": "0.0.0-dev",
"engines": {
"vscode": "^1.90.0"
},
Expand Down Expand Up @@ -105,6 +105,12 @@
"title": "Retrieve access token",
"category": "debricked",
"icon": "$(account)"
},
{
"command": "debricked.debricked.reset",
"title": "Reset Debricked",
"category": "debricked",
"icon": "$(trash)"
}
],
"menus": {
Expand All @@ -121,12 +127,12 @@
"vscode:prepublish": "npm run package",
"compile": "npm run check-types && npm run lint && node esbuild.js",
"watch": "npm-run-all -p watch:*",
"watch:esbuild": "set NODE_ENV=development && set LATEST_TAG=0.0.0&& node esbuild.js --watch",
"watch:esbuild": "set NODE_ENV=development && set LATEST_TAG=0.0.0-dev&& node esbuild.js --watch",
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
"package": "npm run check-types && npm run lint && node esbuild.js --production",
"compile-tests": "npm run clean && tsc -p . --outDir out",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "set NODE_ENV=test && set LATEST_TAG=0.0.0&& npm run compile-tests && npm run compile",
"pretest": "set NODE_ENV=test && set LATEST_TAG=0.0.0-dev&& npm run compile-tests && npm run compile",
"check-types": "tsc --noEmit",
"lint": "eslint src --ext ts",
"lint:fix": "eslint --fix src --ext ts",
Expand All @@ -135,7 +141,7 @@
"clean-all": "rimraf out && rimraf dist && rimraf coverage && rimraf .vscode-test",
"vsce": "vsce package",
"madge": "npm run compile-tests && rimraf out\\test && madge --include-npm --image graph.svg out",
"sentry:sourcemaps": "sentry-cli --url https://sentry.debricked.com/ sourcemaps upload --org debricked --project visual-studio-code-extensions out --release [email protected]"
"sentry:sourcemaps": "sentry-cli --url https://sentry.debricked.com/ sourcemaps upload --org debricked --project visual-studio-code-extensions out --release [email protected]-dev"
},
"devDependencies": {
"@sentry/cli": "^2.36.1",
Expand Down
1 change: 1 addition & 0 deletions src/commands/debrickedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class DebrickedCommand {
this.registerCommand(context, baseSubCommands[3].command, Logger.openLogFile);
this.registerCommand(context, baseSubCommands[4].command, baseCommandService.login);
this.registerCommand(context, baseSubCommands[5].command, SentryHelper.reConfigureSentry);
this.registerCommand(context, baseSubCommands[6].command, baseCommandService.reset);
}

//Register auth sub-commands
Expand Down
6 changes: 6 additions & 0 deletions src/constants/debricked_cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export class DebrickedCommands {
cli_command: "sentry",
description: "Debricked sentry logs",
},
{
label: "Reset",
command: "debricked.debricked.reset",
cli_command: "reset",
description: "Reset Debricked",
},
],
flags: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/constants/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export enum Environment {
TEST = "test",
}

export enum TokenType {
export enum Secrets {
ACCESS = "access",
BEARER = "bearer",
}
Expand Down
4 changes: 2 additions & 2 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DebrickedCommands } from "./debricked_cli";
import { Messages } from "./messages";
import { MessageStatus, Environment, TokenType, SupportedFilesToScan } from "./enums";
import { MessageStatus, Environment, Secrets, SupportedFilesToScan } from "./enums";
import { Organization } from "./organization";
import { SecondService } from "./secondService";
import { Regex } from "./regex";
Expand All @@ -17,7 +17,7 @@ export {
PolicyRules,
PolicyTriggerEvents,
Environment,
TokenType,
Secrets,
Icons,
SupportedFilesToScan,
};
1 change: 1 addition & 0 deletions src/constants/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export class Messages {
static readonly INSTALLATION_ERROR = "Installation script execution failed.";

// Miscellaneous Messages
static readonly RESET_SUCCESS = "Successfully reset debricked.";
}
3 changes: 1 addition & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export async function activate(context: vscode.ExtensionContext) {
progress.report({ increment: progressCount });

const globalState = globalStore.getGlobalStateInstance();
// For dev - Clears the globalData - uncomment to clear the globalData
// await globalState?.clearAllGlobalData();

progress.report({
message: "Activating VS Code Extension",
increment: (progressCount += 20),
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosR
import { AuthHelper } from "./authHelper";
import { ErrorHandler } from "./errorHandler";
import { Logger } from "./loggerHelper";
import { TokenType } from "../constants";
import { Secrets } from "../constants";
import * as Sentry from "@sentry/node";

export class ApiClient {
Expand All @@ -17,7 +17,7 @@ export class ApiClient {

this.axiosInstance.interceptors.request.use(
async (config: AxiosRequestConfig): Promise<InternalAxiosRequestConfig> => {
const token = await authHelper.getToken(true, TokenType.BEARER);
const token = await authHelper.getToken(true, Secrets.BEARER);
if (token) {
config.headers = {
...config.headers,
Expand Down
16 changes: 8 additions & 8 deletions src/helpers/authHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Messages, TokenType } from "../constants/index";
import { Messages, Secrets } from "../constants/index";
import { ShowInputBoxHelper } from "./showInputBoxHelper";
import { StatusBarMessageHelper } from "./statusBarMessageHelper";
import { Logger } from "./loggerHelper";
Expand All @@ -17,7 +17,7 @@ export class AuthHelper {
* @param void
* @returns Promise<string | undefined>
*/
async getToken(useDefaultToken = true, tokenKey: TokenType): Promise<string | undefined> {
async getToken(useDefaultToken = true, tokenKey: Secrets): Promise<string | undefined> {
try {
let token: string | undefined;
const defaultToken: any = await this.globalStore.getGlobalStateInstance()?.getSecretData(tokenKey);
Expand All @@ -31,12 +31,12 @@ export class AuthHelper {
this.logger.logInfo("InputBox Opened for tokens");

token = await this.showInputBoxHelper.promptForInput({
prompt: tokenKey === TokenType.ACCESS ? Messages.ENTER_ACCESS_TOKEN : Messages.ENTER_BEARER_TOKEN,
prompt: tokenKey === Secrets.ACCESS ? Messages.ENTER_ACCESS_TOKEN : Messages.ENTER_BEARER_TOKEN,
ignoreFocusOut: true,
password: true,
title: tokenKey === TokenType.ACCESS ? Messages.ACCESS_TOKEN : Messages.BEARER_TOKEN,
title: tokenKey === Secrets.ACCESS ? Messages.ACCESS_TOKEN : Messages.BEARER_TOKEN,
placeHolder:
tokenKey === TokenType.ACCESS ? Messages.ENTER_ACCESS_TOKEN : Messages.ENTER_BEARER_TOKEN,
tokenKey === Secrets.ACCESS ? Messages.ENTER_ACCESS_TOKEN : Messages.ENTER_BEARER_TOKEN,
});

this.setToken(tokenKey, token);
Expand All @@ -49,13 +49,13 @@ export class AuthHelper {
}
}

async setToken(tokenKey: TokenType, token: string | undefined): Promise<void> {
async setToken(tokenKey: Secrets, token: string | undefined): Promise<void> {
if (token) {
await this.globalStore.getGlobalStateInstance()?.setSecretData(tokenKey, token);
const message = tokenKey === TokenType.ACCESS ? Messages.ACCESS_TOKEN_SAVED : Messages.BEARER_TOKEN_SAVED;
const message = tokenKey === Secrets.ACCESS ? Messages.ACCESS_TOKEN_SAVED : Messages.BEARER_TOKEN_SAVED;
this.statusBarMessageHelper.showInformationMessage(message);
} else {
const message = tokenKey === TokenType.ACCESS ? Messages.ACCESS_TOKEN_RQD : Messages.BEARER_TOKEN_RQD;
const message = tokenKey === Secrets.ACCESS ? Messages.ACCESS_TOKEN_RQD : Messages.BEARER_TOKEN_RQD;
throw new Error(message);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/helpers/commandHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DebrickedCommands, Messages, MessageStatus, TokenType } from "../constants/index";
import { DebrickedCommands, Messages, MessageStatus, Secrets } from "../constants/index";
import { exec } from "child_process";
import * as vscode from "vscode";
import { promisify } from "util";
Expand Down Expand Up @@ -31,7 +31,7 @@ export class Command {

if (accessTokenRequired) {
const globalFlags = DebrickedCommands.getCommandSpecificFlags("Debricked", true) || [];
const accessToken = await this.authHelper.getToken(true, TokenType.ACCESS);
const accessToken = await this.authHelper.getToken(true, Secrets.ACCESS);

if (accessToken) {
this.logger.logMessageByStatus(
Expand All @@ -56,7 +56,8 @@ export class Command {
}
span.end(new Date());
return stdout.trim();
} catch (error) {
} catch (error: any) {
this.logger.logMessageByStatus(MessageStatus.ERROR, `command error: ${error.message}`);
this.logger.logError("Error in executeAsyncCommand");
throw error;
}
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/globalState.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Secrets } from "../constants";
import * as vscode from "vscode";

export class GlobalState {
Expand Down Expand Up @@ -59,4 +60,11 @@ export class GlobalState {
public deleteSecretData(key: string): Thenable<void> {
return this.context.secrets.delete(key);
}

public async resetDebrickedData(): Promise<void> {
for (const secret in Secrets) {
this.context.secrets.delete(Secrets[secret as keyof typeof Secrets]);
}
await this.clearAllGlobalData();
}
}
4 changes: 4 additions & 0 deletions src/helpers/statusBarMessageHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class StatusBarMessageHelper {
return await vscode.window.showInformationMessage(`${Organization.nameCaps}: ` + message, ...items);
}

public async showWarningMessageWithItems(message: string, items: string[]): Promise<string | undefined> {
return await vscode.window.showWarningMessage(`${Organization.nameCaps}: ` + message, ...items);
}

public showWarningMessage(message: string): void {
vscode.window.showWarningMessage(`${Organization.nameCaps}: ` + message);
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/terminalHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DebrickedCommands, Messages, MessageStatus, Organization, TokenType } from "../constants/index";
import { DebrickedCommands, Messages, MessageStatus, Organization, Secrets } from "../constants/index";
import { AuthHelper } from "./authHelper";
import { Logger } from "./loggerHelper";

Expand All @@ -19,7 +19,7 @@ export class Terminal {
let command: string = Organization.debrickedCli;
if (accessTokenRequired) {
const flags = DebrickedCommands.getCommandSpecificFlags("Debricked") || [];
const accessToken = await this.authHelper.getToken(useDefaultAccessToken, TokenType.ACCESS);
const accessToken = await this.authHelper.getToken(useDefaultAccessToken, Secrets.ACCESS);

if (accessToken) {
this.logger.logMessageByStatus(
Expand Down
Loading