Skip to content
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
7 changes: 5 additions & 2 deletions src/plugins/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
});

window.withProgress(

Check warning on line 57 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
{
location: ProgressLocation.Notification,
title: "Setup LocalStack",
Expand Down Expand Up @@ -126,10 +126,13 @@
message:
"Waiting for authentication response from the browser...",
});
const { authToken } = await minDelay(
const { authToken, cancelled } = await minDelay(
requestAuthentication(context, cancellationToken),
);
if (cancellationToken.isCancellationRequested) {
if (cancelled) {
void window.showWarningMessage("Authentication cancelled.");
}
if (cancelled || cancellationToken.isCancellationRequested) {
telemetry.track({
name: "auth_token_configured",
payload: {
Expand Down Expand Up @@ -186,7 +189,7 @@
"License is not valid or not assigned. Open License settings page to activate it.",
});

commands.executeCommand("localstack.openLicensePage");

Check warning on line 192 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

await activateLicenseUntilValid(
outputChannel,
Expand All @@ -211,7 +214,7 @@
}),
);

commands.executeCommand("localstack.refreshStatusBar");

Check warning on line 217 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

progress.report({
message: 'Finished configuring "localstack" AWS profiles.',
Expand All @@ -219,14 +222,14 @@
await minDelay(Promise.resolve());

/////////////////////////////////////////////////////////////////////
window

Check warning on line 225 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
.showInformationMessage("LocalStack is ready to start", {
title: "Start LocalStack",
command: "localstack.start",
})
.then((selection) => {
if (selection) {
commands.executeCommand(selection.command);

Check warning on line 232 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
});

Expand All @@ -245,14 +248,14 @@
);

if (setupStatusTracker.status() === "setup_required") {
window

Check warning on line 251 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
.showInformationMessage("Setup LocalStack to get started.", {
title: "Setup",
command: "localstack.setup",
})
.then((selected) => {
if (selected) {
commands.executeCommand(selected.command, "extension_startup");

Check warning on line 258 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
});
}
Expand Down
34 changes: 23 additions & 11 deletions src/utils/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import { assertIsError } from "./assert.ts";
export async function requestAuthentication(
context: ExtensionContext,
cancellationToken?: CancellationToken,
): Promise<{ authToken: string }> {
): Promise<
| { authToken: string; cancelled?: undefined }
| { authToken?: undefined; cancelled: true }
> {
return new Promise((resolve, reject) => {
const uriHandler = window.registerUriHandler({
handleUri: (uri: Uri) => {
Expand All @@ -34,22 +37,27 @@ export async function requestAuthentication(
if (authToken) {
resolve({ authToken });
} else {
window.showErrorMessage("No token found in URI.");
void window.showErrorMessage("No token found in URI.");
reject(new Error("No token found in URI"));
}
},
});
context.subscriptions.push(uriHandler);
cancellationToken?.onCancellationRequested(() => {
uriHandler.dispose();
reject(new Error("Authentication cancelled"));
resolve({ cancelled: true });
});

void redirectToLocalStack();
void redirectToLocalStack().then(({ cancelled }) => {
if (cancelled) {
uriHandler.dispose();
resolve({ cancelled: true });
}
});
});
}

async function redirectToLocalStack() {
async function redirectToLocalStack(): Promise<{ cancelled: boolean }> {
// You don't have to get the Uri from the `env.asExternalUri` API but it will add a query
// parameter (ex: "windowId%3D14") that will help VS Code decide which window to redirect to.
// If this query parameter isn't specified, VS Code will pick the last windows that was focused.
Expand All @@ -63,13 +71,17 @@ async function redirectToLocalStack() {
const url = new URL(process.env.LOCALSTACK_WEB_AUTH_REDIRECT!);
url.searchParams.set("windowId", redirectSearchParams.get("windowId") ?? "");

const openSuccessful = await env.openExternal(Uri.parse(url.toString()));

if (!openSuccessful) {
window.showErrorMessage(
`Open LocalStack sign-in URL in browser by entering the URL manually: ${url.toString()}`,
);
const selection = await window.showInformationMessage(
`LocalStack needs to open the browser to continue with the authentication process.`,
{ modal: true },
"Continue",
);
if (!selection) {
return { cancelled: true };
}

const openSuccessful = await env.openExternal(Uri.parse(url.toString()));
return { cancelled: !openSuccessful };
}

const LOCALSTACK_AUTH_FILENAME = `${os.homedir()}/.localstack/auth.json`;
Expand Down
Loading