Fix open notebook bug (#10930)

* Fix open notebook bug

* cleanup

* clean up spaces
This commit is contained in:
Charles Gagnon
2020-06-16 13:06:44 -07:00
committed by GitHub
parent 381a747b62
commit 94bc0d9559
9 changed files with 213 additions and 169 deletions

View File

@@ -8,6 +8,7 @@ import * as fs from 'fs-extra';
import * as nls from 'vscode-nls';
import * as vscode from 'vscode';
import * as azdata from 'azdata';
import * as crypto from 'crypto';
import { notebookLanguages } from './constants';
const localize = nls.loadMessageBundle();
@@ -300,3 +301,19 @@ function decorate(decorator: (fn: Function, key: string) => Function): Function
export function getDropdownValue(dropdown: azdata.DropDownComponent): string {
return (typeof dropdown.value === 'string') ? dropdown.value : dropdown.value.name;
}
/**
* Creates a random token per https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback.
* Defaults to 24 bytes, which creates a 48-char hex string
*/
export async function getRandomToken(size: number = 24): Promise<string> {
return new Promise((resolve, reject) => {
crypto.randomBytes(size, (err, buffer) => {
if (err) {
reject(err);
}
let token = buffer.toString('hex');
resolve(token);
});
});
}