Skip to content

Commit

Permalink
custom app name support (#35)
Browse files Browse the repository at this point in the history
Co-authored-by: Harry Pierson <harrypierson@outlook.com>
  • Loading branch information
devhawk and Harry Pierson authored May 15, 2024
1 parent b83346a commit 4a6fb1d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
"title": "Launch DBOS Dashboard",
"category": "DBOS",
"icon": "$(server)"
},
{
"command": "dbos-ttdbg.set-app-name",
"title": "Set Application Name",
"category": "DBOS"
}
],
"configuration": {
Expand Down
15 changes: 12 additions & 3 deletions src/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface DbosDebugConfig {
export async function getDebugConfigFromDbosCloud(app: string | DbosCloudApp, credentials: DbosCloudCredentials): Promise<Omit<DbosDebugConfig, 'password'> | undefined> {
if (!validateCredentials(credentials)) { return undefined; }

if (typeof app === 'string') {
if (typeof app === 'string') {
const $app = await getApp(app, credentials);
if (isUnauthorized($app)) { return undefined; }
app = $app;
Expand Down Expand Up @@ -73,9 +73,10 @@ function databaseSecretKey(db: Pick<DbosDebugConfig, 'user' | 'host' | 'port' |
}

const databaseSetKey = `dbos-ttdbg:databases`;
const appNameKey = `dbos-ttdbg:app-name`;

export class Configuration {
constructor(private readonly secrets: vscode.SecretStorage) { }
constructor(private readonly secrets: vscode.SecretStorage, private readonly workspaceState: vscode.Memento) { }

async getStoredCloudCredentials(domain?: string | DbosCloudDomain): Promise<DbosCloudCredentials | undefined> {
const { cloudDomain } = getCloudDomain(domain);
Expand Down Expand Up @@ -117,7 +118,7 @@ export class Configuration {
const cloudConfig = await vscode.window.withProgress(
{ location: vscode.ProgressLocation.Window },
async (): Promise<Omit<DbosDebugConfig, 'password'> | undefined> => {
const packageName = await getPackageName(folder);
const packageName = this.getAppName() ?? await getPackageName(folder);
if (!packageName) { return undefined; }

const cloudConfig = await getDebugConfigFromDbosCloud(packageName, credentials);
Expand Down Expand Up @@ -197,6 +198,14 @@ export class Configuration {
}
await this.secrets.delete(databaseSetKey);
}

async setAppName(appName?: string) {
await this.workspaceState.update(appNameKey, appName);
}

getAppName() {
return this.workspaceState.get<string>(appNameKey);
}
}

async function getPackageName(folder: vscode.WorkspaceFolder): Promise<string | undefined> {
Expand Down
3 changes: 3 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { startDebuggingFromCodeLens } from './startDebuggingFromCodeLens';
import { startDebuggingFromUri } from './startDebuggingFromUri';
import { getUpdateDebugProxyCommand } from './updateDebugProxy';
import { getRefreshDomainCommand } from './refreshDomain';
import { setApplicationName } from './setAppName';

export const cloudLoginCommandName = "dbos-ttdbg.cloud-login";
export const deleteAppDatabasePasswordCommandName = "dbos-ttdbg.delete-app-db-password";
Expand All @@ -24,6 +25,7 @@ export const launchDashboardCommandName = "dbos-ttdbg.launch-dashboard";
export const launchDebugProxyCommandName = "dbos-ttdbg.launch-debug-proxy";
export const pickWorkflowIdCommandName = "dbos-ttdbg.pick-workflow-id";
export const refreshDomainCommandName = "dbos-ttdbg.refresh-domain";
export const setApplicationNameCommandName = "dbos-ttdbg.set-app-name";
export const shutdownDebugProxyCommandName = "dbos-ttdbg.shutdown-debug-proxy";
export const startDebuggingCodeLensCommandName = "dbos-ttdbg.start-debugging-code-lens";
export const startDebuggingUriCommandName = "dbos-ttdbg.start-debugging-uri";
Expand All @@ -40,6 +42,7 @@ export function registerCommands(cloudStorage: CloudStorage, storageUri: vscode.
vscode.commands.registerCommand(launchDebugProxyCommandName, getLaunchDebugProxyCommand(storageUri)),
vscode.commands.registerCommand(pickWorkflowIdCommandName, pickWorkflowId),
vscode.commands.registerCommand(refreshDomainCommandName, getRefreshDomainCommand(refresh)),
vscode.commands.registerCommand(setApplicationNameCommandName, setApplicationName),
vscode.commands.registerCommand(shutdownDebugProxyCommandName, shutdownDebugProxy),
vscode.commands.registerCommand(startDebuggingCodeLensCommandName, startDebuggingFromCodeLens),
vscode.commands.registerCommand(startDebuggingUriCommandName, startDebuggingFromUri),
Expand Down
33 changes: 33 additions & 0 deletions src/commands/setAppName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as vscode from 'vscode';
import { config } from '../extension';

export async function setApplicationName() {

const currentAppName = config.getAppName();

const deleteCurrentNameButton = { iconPath: new vscode.ThemeIcon("trash"), tooltip: "Clear app name"};

const inputBox = vscode.window.createInputBox();
inputBox.title = "Set DBOS Cloud app name";
inputBox.prompt = "Enter custom package name. Leave blank to use name from package.json";
inputBox.value = currentAppName ?? "";
inputBox.buttons = currentAppName ? [deleteCurrentNameButton] : [];
inputBox.onDidAccept(async () => {
if (inputBox.validationMessage) { return; }
if (inputBox.value === currentAppName) { return; }
if (inputBox.value === "") { return; }
await config.setAppName(inputBox.value);
inputBox.hide();
});
inputBox.onDidTriggerButton(async (btn) => {
if (btn === deleteCurrentNameButton) {
await config.setAppName(undefined);
}
inputBox.hide();
});
inputBox.onDidChangeValue(value => {
const regex = /^[a-z0-9-~][a-z0-9-._~]*$/;
inputBox.validationMessage = regex.test(value) ? "" : "Invalid app name";
});
inputBox.show();
}
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function activate(context: vscode.ExtensionContext) {
logger = createLogger(transport);
context.subscriptions.push({ dispose() { logger.close(); transport.close(); } });

config = new Configuration(context.secrets);
config = new Configuration(context.secrets, context.workspaceState);

const cloudStorage = new S3CloudStorage();
context.subscriptions.push(cloudStorage);
Expand Down

0 comments on commit 4a6fb1d

Please sign in to comment.