Skip to content

Commit ddb406c

Browse files
author
r
committed
Support single tenant instances
1 parent 1516fb7 commit ddb406c

File tree

6 files changed

+60
-8
lines changed

6 files changed

+60
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ The ZeroPath Security extension integrates the [ZeroPath](https://zeropath.com)
7878
- Navigate to Settings → API Tokens
7979
- Create a new API token if you don't have one
8080
- Click "Configure Credentials" in the VS Code sidebar
81+
- (Optional) Enter a custom ZeroPath instance URL if using an enterprise deployment
8182
- Enter your Client ID and Client Secret
8283
- Select your version control system (GitHub, GitLab, Bitbucket, or Generic)
8384

@@ -185,7 +186,7 @@ The extension automatically detects your Git repository and connects it to your
185186
The extension can be configured through VS Code settings:
186187

187188
- `zeropath.vcs` - Primary VCS provider (github/gitlab/bitbucket/generic)
188-
- `zeropath.apiBaseUrl` - API base URL (default: https://zeropath.com)
189+
- `zeropath.apiBaseUrl` - API base URL (default: https://zeropath.com, can be configured during credential setup)
189190
- `zeropath.organizationId` - Organization ID (auto-detected from token)
190191
- `zeropath.defaultScanType` - Default scan type filter (FullScan/PrScan)
191192

media/sidebar-backup.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let filteredIssues = [];
88
let selectedScanId = null;
99
let expandedIssueId = null;
1010
let searchTerm = '';
11+
let baseUrl = 'https://zeropath.com'; // Default to zeropath.com
1112

1213
// Send ready message when DOM is loaded
1314
document.addEventListener('DOMContentLoaded', () => {
@@ -21,6 +22,12 @@ window.addEventListener('message', event => {
2122
console.log('Received message:', message);
2223

2324
switch (message.type) {
25+
case 'config':
26+
if (message.baseUrl) {
27+
baseUrl = message.baseUrl;
28+
console.log('Base URL set to:', baseUrl);
29+
}
30+
break;
2431
case 'loading':
2532
setLoading(message.loading);
2633
break;
@@ -243,7 +250,9 @@ function renderIssues(issues, scanId) {
243250

244251
// Dashboard link
245252
if (issue.id) {
246-
const dashboardUrl = 'https://zeropath.com/app/issues/' + issue.id;
253+
// Ensure baseUrl doesn't end with a slash
254+
const cleanBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
255+
const dashboardUrl = cleanBaseUrl + '/app/issues/' + issue.id;
247256
expandedContent += '<div style="margin-bottom: 10px;">';
248257
expandedContent += '<button data-url="' + escapeHtml(dashboardUrl) + '" style="background: var(--vscode-button-secondaryBackground); color: var(--vscode-button-secondaryForeground);">🔗 View in Dashboard</button>';
249258
expandedContent += '</div>';

media/sidebar.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let filteredIssues = [];
88
let selectedScanId = null;
99
let expandedIssueId = null;
1010
let searchTerm = '';
11+
let baseUrl = 'https://zeropath.com'; // Default to zeropath.com
1112

1213
// Store patch data in memory instead of encoding it
1314
const patchDataStore = new Map();
@@ -24,6 +25,12 @@ window.addEventListener('message', event => {
2425
console.log('Received message:', message);
2526

2627
switch (message.type) {
28+
case 'config':
29+
if (message.baseUrl) {
30+
baseUrl = message.baseUrl;
31+
console.log('Base URL set to:', baseUrl);
32+
}
33+
break;
2734
case 'loading':
2835
setLoading(message.loading);
2936
break;
@@ -306,7 +313,9 @@ function renderIssues(issues, scanId) {
306313
dashboardLink.onclick = (e) => {
307314
e.preventDefault();
308315
e.stopPropagation();
309-
openExternal('https://zeropath.com/app/issues/' + issue.id);
316+
// Ensure baseUrl doesn't end with a slash
317+
const cleanBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
318+
openExternal(cleanBaseUrl + '/app/issues/' + issue.id);
310319
};
311320
dashboardLinkDiv.appendChild(dashboardLink);
312321
expandedDiv.appendChild(dashboardLinkDiv);

src/extension.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ export function activate(context: vscode.ExtensionContext) {
4343
if (replace !== 'Yes') { return; }
4444
}
4545

46-
// Show a more informative message
47-
vscode.window.showInformationMessage('Configure Zeropath Security credentials. You can get your API tokens from https://zeropath.com');
48-
4946
const stored = await promptAndStoreCredentials(context.secrets);
5047
if (stored) {
5148
// Clear cache when new credentials are saved
@@ -67,7 +64,9 @@ export function activate(context: vscode.ExtensionContext) {
6764
const config = vscode.workspace.getConfiguration('zeropath');
6865
await config.update('vcs', vcsPick.value, vscode.ConfigurationTarget.Global);
6966
}
70-
vscode.window.showInformationMessage('Zeropath credentials saved successfully! You can now use the "View Scans & Issues" button to browse scans.');
67+
const currentConfig = vscode.workspace.getConfiguration('zeropath');
68+
const baseUrl = currentConfig.get<string>('apiBaseUrl', 'https://zeropath.com');
69+
vscode.window.showInformationMessage(`Zeropath credentials saved successfully! Using instance: ${baseUrl}. You can now use the "View Scans & Issues" button to browse scans.`);
7170

7271
// Credentials saved successfully
7372
}

src/sidebar.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ export class ZeropathSidebarProvider implements vscode.WebviewViewProvider {
8282
switch (message.type) {
8383
case 'ready':
8484
console.log('Zeropath: Webview ready message received');
85+
86+
// Send configuration including base URL
87+
const config = vscode.workspace.getConfiguration('zeropath');
88+
const baseUrl = config.get<string>('apiBaseUrl', 'https://zeropath.com');
89+
this.postMessage({ type: 'config', baseUrl: baseUrl });
90+
8591
// Check if we should auto-load scans
8692
if (this._shouldLoadScansOnReady) {
8793
console.log('Zeropath: Auto-loading scans on ready');

src/zeropathApi.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,37 @@ export async function getConfiguredCredentials(secretStorage: vscode.SecretStora
173173
}
174174

175175
export async function promptAndStoreCredentials(secretStorage: vscode.SecretStorage): Promise<ZeropathCredentials | undefined> {
176+
const config = vscode.workspace.getConfiguration('zeropath');
177+
const currentBaseUrl = config.get<string>('apiBaseUrl', 'https://zeropath.com');
178+
179+
// First, ask for the base URL
180+
const baseUrlInput = await vscode.window.showInputBox({
181+
prompt: 'Enter ZeroPath Instance URL (press Enter for default)',
182+
value: currentBaseUrl,
183+
placeHolder: 'https://zeropath.com',
184+
ignoreFocusOut: true,
185+
validateInput: (value) => {
186+
if (value && !value.startsWith('http://') && !value.startsWith('https://')) {
187+
return 'URL must start with http:// or https://';
188+
}
189+
return undefined;
190+
}
191+
});
192+
193+
// If user cancels, return undefined
194+
if (baseUrlInput === undefined) { return undefined; }
195+
196+
// Use the input value or default to zeropath.com
197+
const baseUrl = baseUrlInput.trim() || 'https://zeropath.com';
198+
199+
// Save the base URL to configuration
200+
if (baseUrl !== currentBaseUrl) {
201+
await config.update('apiBaseUrl', baseUrl, vscode.ConfigurationTarget.Global);
202+
}
203+
176204
const clientId = await vscode.window.showInputBox({
177205
prompt: 'Enter Zeropath API Token Id',
178-
placeHolder: 'Your API Token ID from https://zeropath.com',
206+
placeHolder: `Your API Token ID from ${baseUrl}`,
179207
ignoreFocusOut: true,
180208
password: false,
181209
validateInput: (value) => {

0 commit comments

Comments
 (0)