Skip to content

Commit

Permalink
squash!
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Dec 18, 2023
1 parent 4c2da0b commit 1da135e
Show file tree
Hide file tree
Showing 24 changed files with 326 additions and 313 deletions.
10 changes: 5 additions & 5 deletions Source/authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { CancellationToken } from "vscode";
import { SimpleFetch } from "./common/request";
import { IAuthenticator } from "./types";
import { generateNewApiToken, verifyApiToken } from "./jupyterHubApi";
import { IAuthenticator } from "./types";

export class Authenticator implements IAuthenticator {
constructor(private readonly fetch: SimpleFetch) {}
Expand All @@ -17,7 +17,7 @@ export class Authenticator implements IAuthenticator {
token: string;
};
},
token: CancellationToken
token: CancellationToken,
): Promise<{ token: string; tokenId: string }> {
// Possible user has entered the API token instead of the password.
if (!options.authInfo.token) {
Expand All @@ -26,7 +26,7 @@ export class Authenticator implements IAuthenticator {
options.authInfo.username,
options.authInfo.password,
this.fetch,
token
token,
);
if (isApiTokenValid) {
return { tokenId: "", token: options.authInfo.password };
Expand All @@ -38,7 +38,7 @@ export class Authenticator implements IAuthenticator {
options.authInfo.username,
options.authInfo.token,
this.fetch,
token
token,
);
if (isApiTokenValid) {
return { tokenId: "", token: options.authInfo.token };
Expand All @@ -49,7 +49,7 @@ export class Authenticator implements IAuthenticator {
options.authInfo.username,
options.authInfo.password,
this.fetch,
token
token,
);
}
}
8 changes: 4 additions & 4 deletions Source/common/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { CancellationError, CancellationToken, Disposable } from "vscode";

export async function sleep(timeout: number, token?: CancellationToken) {
let disposables: Disposable[] = [];
const disposables: Disposable[] = [];
const promise = new Promise((resolve) => {
const timer = setTimeout(resolve, timeout);
disposables.push(new Disposable(() => clearTimeout(timer)));
Expand Down Expand Up @@ -46,7 +46,7 @@ export function raceTimeout<T>(

const timer = setTimeout(
() => promiseResolve?.(resolveValue as unknown as T),
timeout
timeout,
);

return Promise.race([
Expand Down Expand Up @@ -154,8 +154,8 @@ class DeferredImpl<T> implements Deferred<T> {
private _resolve!: (value: T | PromiseLike<T>) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _reject!: (reason?: any) => void;
private _resolved: boolean = false;
private _rejected: boolean = false;
private _resolved = false;
private _rejected = false;
private _promise: Promise<T>;
private _value: T | undefined;
public get value() {
Expand Down
6 changes: 3 additions & 3 deletions Source/common/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ else if (
*/
export async function computeHash(
data: string,
algorithm: "SHA-512" | "SHA-256" | "SHA-1"
algorithm: "SHA-512" | "SHA-256" | "SHA-1",
): Promise<string> {
// Save some CPU as this is called in a number of places.
// This will not get too large, will only grow by number of files per workspace, even if user has
Expand Down Expand Up @@ -60,12 +60,12 @@ export async function computeHash(

async function computeHashInternal(
data: string,
algorithm: "SHA-512" | "SHA-256" | "SHA-1"
algorithm: "SHA-512" | "SHA-256" | "SHA-1",
): Promise<string> {
const inputBuffer = new TextEncoder().encode(data);
const hashBuffer = await cryptoProvider.subtle.digest(
{ name: algorithm },
inputBuffer
inputBuffer,
);

// Turn into hash string (got this logic from https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest)
Expand Down
28 changes: 14 additions & 14 deletions Source/common/inputCapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class WorkflowInputCapture {
buttons?: QuickInputButton[];
onDidTriggerButton?: (e: QuickInputButton) => void;
},
token: CancellationToken
token: CancellationToken,
) {
return new Promise<string | undefined>((resolve, reject) => {
const input = window.createInputBox();
Expand All @@ -56,17 +56,17 @@ export class WorkflowInputCapture {
input.onDidChangeValue(
() => (input.validationMessage = ""),
this,
this.disposables
this.disposables,
);
input.onDidTriggerButton(
(e) => options.onDidTriggerButton?.(e),
this,
this.disposables
this.disposables,
);
input.onDidHide(
() => reject(new CancellationError()),
this,
this.disposables
this.disposables,
);
input.onDidTriggerButton(
(e) => {
Expand All @@ -75,7 +75,7 @@ export class WorkflowInputCapture {
}
},
this,
this.disposables
this.disposables,
);
input.onDidAccept(
async () => {
Expand All @@ -84,7 +84,7 @@ export class WorkflowInputCapture {
// UI will be hidden upon disposing.
if (options.validateInput) {
input.validationMessage = await options.validateInput(
input.value
input.value,
);
if (input.validationMessage) {
return;
Expand All @@ -97,12 +97,12 @@ export class WorkflowInputCapture {
resolve(input.value || options.value || "");
},
this,
this.disposables
this.disposables,
);
token.onCancellationRequested(
() => reject(new CancellationError()),
this,
this.disposables
this.disposables,
);
});
}
Expand Down Expand Up @@ -131,7 +131,7 @@ export class WorkflowQuickInputCapture {
placeholder?: string;
items: QuickPickItem[];
},
token: CancellationToken
token: CancellationToken,
) {
return new Promise<QuickPickItem | undefined>((resolve, reject) => {
const input = window.createQuickPick();
Expand All @@ -144,7 +144,7 @@ export class WorkflowQuickInputCapture {
input.items = options.items;
input.show();
this.disposables.push(
input.onDidHide(() => reject(new CancellationError()))
input.onDidHide(() => reject(new CancellationError())),
);
input.onDidTriggerButton(
(e) => {
Expand All @@ -153,25 +153,25 @@ export class WorkflowQuickInputCapture {
}
},
this,
this.disposables
this.disposables,
);
input.onDidTriggerItemButton(
(e) => this._onDidTriggerItemButton.fire(e),
this,
this.disposables
this.disposables,
);
input.onDidAccept(
() =>
input.selectedItems.length
? resolve(input.selectedItems[0])
: undefined,
this,
this.disposables
this.disposables,
);
token.onCancellationRequested(
() => reject(new CancellationError()),
this,
this.disposables
this.disposables,
);
});
}
Expand Down
6 changes: 3 additions & 3 deletions Source/common/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ function isIterable<T = any>(thing: any): thing is Iterable<T> {
*/
export function dispose<T extends IDisposable>(disposable: T): T;
export function dispose<T extends IDisposable>(
disposable: T | undefined
disposable: T | undefined,
): T | undefined;
export function dispose<T extends IDisposable>(disposables: Array<T>): Array<T>;
export function dispose<T extends IDisposable>(
disposables: ReadonlyArray<T>
disposables: ReadonlyArray<T>,
): ReadonlyArray<T>;
export function dispose<T extends IDisposable>(
arg: T | Array<T> | ReadonlyArray<T> | undefined
arg: T | Array<T> | ReadonlyArray<T> | undefined,
): any {
if (isIterable(arg)) {
for (const d of arg) {
Expand Down
28 changes: 14 additions & 14 deletions Source/common/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,63 @@ import { l10n } from "vscode";
export namespace Localized {
export const OutputChannelName = l10n.t("JupyterHub");
export const ConnectingToJupyterServer = l10n.t(
"Connecting to JupyterHub Server"
"Connecting to JupyterHub Server",
);
export const startingJupyterServer = l10n.t("Starting Server");
export const KernelActionSourceTitle = l10n.t(
"Existing JupyterHub Server..."
"Existing JupyterHub Server...",
);
export const labelOfCommandToEnterUrl = l10n.t(
"Enter the URL of the running JupyterHub Server..."
"Enter the URL of the running JupyterHub Server...",
);
export const placeholderOfInputBoxToEnterUrl = l10n.t(
"Enter the URL of the running JupyterHub Server"
"Enter the URL of the running JupyterHub Server",
);
export const titleOfInputBoxToEnterUrl = l10n.t(
"Enter the URL of the running JupyterHub Server"
"Enter the URL of the running JupyterHub Server",
);
export const captureUserNameTitle = "Enter your username";
export const captureUserNamePrompt = "username";
export const capturePasswordTitle = "Enter your password or API token";
export const capturePasswordPrompt = "password or token";
export const usernamePasswordAuthFailure = l10n.t(
"Invalid username or password."
"Invalid username or password.",
);
export const jupyterSelfCertFail = (errorMessage: string) =>
l10n.t(
"The security certificate used by server {0} was not issued by a trusted certificate authority.\r\nThis may indicate an attempt to steal your information.\r\nDo you want to enable the Allow Unauthorized Remote Connection setting for this workspace to allow you to connect?",
errorMessage
errorMessage,
);
export const jupyterExpiredCertFail = (errorMessage: string) =>
l10n.t(
"The security certificate used by server {0} has expired.\r\nThis may indicate an attempt to steal your information.\r\nDo you want to enable the Allow Unauthorized Remote Connection setting for this workspace to allow you to connect?",
errorMessage
errorMessage,
);
export const jupyterSelfCertFailErrorMessageOnly = l10n.t(
"The security certificate used by server was not issued by a trusted certificate authority.\r\nThis may indicate an attempt to steal your information."
"The security certificate used by server was not issued by a trusted certificate authority.\r\nThis may indicate an attempt to steal your information.",
);
export const jupyterSelfCertExpiredErrorMessageOnly = l10n.t(
"The security certificate used by server has expired.\r\nThis may indicate an attempt to steal your information."
"The security certificate used by server has expired.\r\nThis may indicate an attempt to steal your information.",
);
export const jupyterSelfCertEnable = l10n.t("Yes, connect anyway");
export const jupyterSelfCertClose = l10n.t("No, close the connection");
export const connectToToTheJupyterServer = (url: string) =>
l10n.t("Connect to the JupyterHub server {0}", url);
export const jupyterSelectURIInvalidURI = l10n.t("Invalid URL specified");
export const invalidJupyterHubUrl = l10n.t(
"Invalid JupyterHub URL specified"
"Invalid JupyterHub URL specified",
);
export const jupyterRenameServer = l10n.t("Change server name");
export const remoteJupyterConnectionFailedWithoutServerWithError = (
errorMessage: string
errorMessage: string,
) =>
l10n.t(
"Connection failure. Verify the server is running and reachable. ({0}).",
errorMessage
errorMessage,
);
export const emptyUserNameErrorMessage = l10n.t("Username cannot be empty");
export const emptyPasswordErrorMessage = l10n.t(
"Password/API token cannot be empty"
"Password/API token cannot be empty",
);
export const authMethodApiTokenMoreInfoTooltip = l10n.t("More Info");
}
10 changes: 5 additions & 5 deletions Source/common/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT License.

import { window, workspace } from "vscode";
import { Localized } from "./localize";
import { disposableStore } from "./lifecycle";
import { Localized } from "./localize";

export const outputChannel = disposableStore.add(
window.createOutputChannel(Localized.OutputChannelName, "log")
window.createOutputChannel(Localized.OutputChannelName, "log"),
);

let loggingLevel: "error" | "debug" | "off" = workspace
Expand All @@ -28,7 +28,7 @@ disposableStore.add(
console.error(`Invalid Error Level for JupyterHub ${setting}`);
}
}
})
}),
);

export function traceError(..._args: unknown[]): void {
Expand All @@ -47,7 +47,7 @@ export function traceDebug(_message: string, ..._args: unknown[]): void {

function logMessage(level: "error" | "debug", ...data: unknown[]) {
outputChannel.appendLine(
`${getTimeForLogging()} [${level}] ${formatErrors(...data).join(" ")}`
`${getTimeForLogging()} [${level}] ${formatErrors(...data).join(" ")}`,
);
}

Expand Down Expand Up @@ -86,7 +86,7 @@ function formatErrors(...args: unknown[]) {
.filter((key) => propertiesToIgnore.indexOf(key) === -1)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.forEach((key) =>
info.push(`${key} = ${String((arg as any)[key]).trim()}`)
info.push(`${key} = ${String((arg as any)[key]).trim()}`),
);
return info
.filter((l) => l.trim().length)
Expand Down
Loading

0 comments on commit 1da135e

Please sign in to comment.