1
>
/*---------------------------------------------------------------------------------------------
serverConnectionToken.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import * as cookie from 'cookie';
7
>
import * as fs from 'fs';
8
>
import type * as http from 'http';
9
>
import * as url from 'url';
10
>
import * as path from '../../base/common/path.js';
11
>
import { generateUuid } from '../../base/common/uuid.js';
12
>
import { connectionTokenCookieName, connectionTokenQueryName } from '../../base/common/network.js';
13
>
import { ServerParsedArgs } from './serverEnvironmentService.js';
14
>
import { Promises } from '../../base/node/pfs.js';
15
>
16
>
const connectionTokenRegex = /^[0-9A-Za-z_-]+$/;
17
>
18
>
export const enum ServerConnectionTokenType {
19
>
None,
20
>
Optional,// TODO: Remove this soon
21
>
Mandatory
22
>
}
23
>
24
>
export class NoneServerConnectionToken {
25
public readonly type = ServerConnectionTokenType.None;
27
>
public validate(connectionToken: unknown): boolean {
28
return true;
29
}
31
>
32
>
export class MandatoryServerConnectionToken {
33
>
public readonly type = ServerConnectionTokenType.Mandatory;
34
>
35
>
constructor(public readonly value: string) {
36
}
38
>
public validate(connectionToken: unknown): boolean {
39
return (connectionToken === this.value);
40
}
42
>
43
>
export type ServerConnectionToken = NoneServerConnectionToken | MandatoryServerConnectionToken;
44
>
45
>
export class ServerConnectionTokenParseError {
46
>
constructor(
47
public readonly message: string
48
) { }
50
>
51
>
export async function parseServerConnectionToken(args: ServerParsedArgs, defaultValue: () => Promise<string>): Promise<ServerConnectionToken | ServerConnectionTokenParseError> {
52
>
const withoutConnectionToken = args['without-connection-token'];
53
>
const connectionToken = args['connection-token'];
54
>
const connectionTokenFile = args['connection-token-file'];
55
>
56
>
if (withoutConnectionToken) {
57
if (typeof connectionToken !== 'undefined' || typeof connectionTokenFile !== 'undefined') {
58
return new ServerConnectionTokenParseError(`Please do not use the argument '--connection-token' or '--connection-token-file' at the same time as '--without-connection-token'.`);