-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV2-3883 use external for remote setup
- Loading branch information
1 parent
0790fbb
commit 21467af
Showing
7 changed files
with
74 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { tabNineProcess } from "./requests"; | ||
|
||
export function startLoginServer(): Promise<string | null | undefined> { | ||
return tabNineProcess.request( | ||
{ | ||
StartLoginServer: {}, | ||
}, | ||
5000 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,13 @@ | ||
import { env, Uri } from "vscode"; | ||
import { URL } from "url"; | ||
import { StateType, TABNINE_URL_QUERY_PARAM } from "../globals/consts"; | ||
import createHubWebView from "../hub/createHubWebView"; | ||
import hubUri from "../hub/hubUri"; | ||
|
||
export async function openLogin(): Promise<void> { | ||
return open("https://app.tabnine.com/auth/sign-in"); | ||
} | ||
|
||
export async function openSignup(): Promise<void> { | ||
return open("https://app.tabnine.com/auth/signup"); | ||
} | ||
|
||
async function open(url: string): Promise<void> { | ||
const uri = await hubUri(StateType.AUTH); | ||
if (uri) { | ||
const callback = new URL(url); | ||
callback.searchParams.set(TABNINE_URL_QUERY_PARAM, uri.toString()); | ||
callback.searchParams.set("sync", "false"); | ||
|
||
const panel = await createHubWebView(uri); | ||
panel.reveal(); | ||
void env.openExternal(Uri.parse(callback.toString())); | ||
import { env } from "vscode"; | ||
import { asExternal } from "../utils/asExternal"; | ||
import { startLoginServer } from "../binary/requests/startLoginServer"; | ||
|
||
export async function openExternalLogin(): Promise<void> { | ||
const url = await startLoginServer(); | ||
if (!url) { | ||
return; | ||
} | ||
const remapedUrl = await asExternal(url); | ||
|
||
void env.openExternal(remapedUrl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,16 @@ | ||
import { URL } from "url"; | ||
import { Uri, env } from "vscode"; | ||
import { | ||
StateType, | ||
TABNINE_URL_QUERY_PARAM, | ||
LOCAL_ADDRESSES, | ||
} from "../globals/consts"; | ||
import { Uri } from "vscode"; | ||
import { StateType } from "../globals/consts"; | ||
import { configuration } from "../binary/requests/requests"; | ||
import { | ||
asExternalUri as asCodeServerExternalUri, | ||
isCodeServer, | ||
} from "../cloudEnvs/codeServer"; | ||
|
||
let asExternalUri = async (uri: Uri): Promise<Uri> => { | ||
if (!LOCAL_ADDRESSES.includes(new URL(uri.toString()).hostname)) return uri; | ||
if (isCodeServer) { | ||
return asCodeServerExternalUri(uri); | ||
} | ||
|
||
return env.asExternalUri(uri); | ||
}; | ||
|
||
export function setAsExternalUri(fn: typeof asExternalUri): void { | ||
asExternalUri = fn; | ||
} | ||
import { asExternal } from "../utils/asExternal"; | ||
|
||
export default async function hubUri( | ||
type: StateType, | ||
hubPath?: string | ||
path?: string | ||
): Promise<Uri | null> { | ||
const config = await configuration({ quiet: true, source: type }); | ||
if (!config?.message) { | ||
return null; | ||
} | ||
|
||
const hubUrl = new URL(config.message); | ||
|
||
const tabnineUrl = hubUrl.searchParams.get(TABNINE_URL_QUERY_PARAM); | ||
if (tabnineUrl) { | ||
hubUrl.searchParams.set( | ||
TABNINE_URL_QUERY_PARAM, | ||
(await asExternalUri(Uri.parse(tabnineUrl))).toString() | ||
); | ||
} | ||
|
||
let parsedHubUri = Uri.parse(hubUrl.toString()); | ||
|
||
if (hubPath) { | ||
parsedHubUri = Uri.joinPath(parsedHubUri, hubPath); | ||
} | ||
|
||
return asExternalUri(parsedHubUri); | ||
return asExternal(config.message, path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { URL } from "url"; | ||
import { Uri, env } from "vscode"; | ||
import { LOCAL_ADDRESSES, TABNINE_URL_QUERY_PARAM } from "../globals/consts"; | ||
import { | ||
asExternalUri as asCodeServerExternalUri, | ||
isCodeServer, | ||
} from "../cloudEnvs/codeServer"; | ||
|
||
export async function asExternalUri(uri: Uri): Promise<Uri> { | ||
if (!LOCAL_ADDRESSES.includes(new URL(uri.toString()).hostname)) return uri; | ||
if (isCodeServer) { | ||
return asCodeServerExternalUri(uri); | ||
} | ||
|
||
return env.asExternalUri(uri); | ||
} | ||
|
||
export async function asExternal(url: string, path?: string) { | ||
const serviceUrl = new URL(url); | ||
|
||
const tabnineUrl = serviceUrl.searchParams.get(TABNINE_URL_QUERY_PARAM); | ||
if (tabnineUrl) { | ||
serviceUrl.searchParams.set( | ||
TABNINE_URL_QUERY_PARAM, | ||
(await asExternalUri(Uri.parse(tabnineUrl))).toString() | ||
); | ||
} | ||
|
||
let parsedUri = Uri.parse(serviceUrl.toString()); | ||
|
||
if (path) { | ||
parsedUri = Uri.joinPath(parsedUri, path); | ||
} | ||
|
||
return asExternalUri(parsedUri); | ||
} |