Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase token file sync #801

Merged
merged 9 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions src/authentication/authentication.api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { tabNineProcess } from "../binary/requests/requests";
import { openLogin, openLogout } from "../cloudEnvs/authentication.api";
import isCloudEnv from "../cloudEnvs/isCloudEnv";

export function callForLogin(): Promise<unknown> {
if (isCloudEnv) {
return openLogin();
}
return tabNineProcess.request({ Login: {} });
}

export async function callForLogout(): Promise<unknown> {
if (isCloudEnv) {
return openLogout();
}
return tabNineProcess.request({ Logout: {} });
}
24 changes: 24 additions & 0 deletions src/cloudEnvs/authentication.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { env, Uri } from "vscode";
import { configuration } from "../binary/requests/requests";
import { StateType } from "../globals/consts";

export async function openLogin(): Promise<void> {
return openBinaryConfig("sign_in");
}

export async function openLogout(): Promise<void> {
return openBinaryConfig("sign_out");
}

async function openBinaryConfig(url: string): Promise<void> {
const config = await configuration({ quiet: true, source: StateType.AUTH });
if (config && config.message) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with

Suggested change
if (config && config.message) {
if (config?.message) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with

Suggested change
if (config && config.message) {
if (config?.message) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amogus

const localUri = await env.asExternalUri(Uri.parse(config.message));

await env.openExternal(
localUri.with({
path: `${localUri.path}/${url}`,
})
);
}
}
2 changes: 1 addition & 1 deletion src/cloudEnvs/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as os from "os";

export const TABNINE_CONFIG_DIR = path.join(os.homedir(), ".config", "TabNine");

export const TABNINE_TOKEN_FILE_NAME = "tabnine.token";
export const TABNINE_TOKEN_FILE_NAME = ".refresh_token_v2";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with

Suggested change
export const TABNINE_TOKEN_FILE_NAME = ".refresh_token_v2";
export const TABNINE_TOKEN_FILE_NAME = ".refresh_token";


export const TABNINE_TOKEN_FILE_PATH = path.join(
TABNINE_CONFIG_DIR,
Expand Down
33 changes: 20 additions & 13 deletions src/cloudEnvs/setupCloudState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,27 @@ function persistStateToCloudEnv(context: ExtensionContext): void {
watch(consts.TABNINE_CONFIG_DIR, (event, filename) => {
switch (filename) {
case consts.TABNINE_TOKEN_FILE_NAME:
void fsPromises
.readFile(consts.TABNINE_TOKEN_FILE_PATH, "utf8")
.then((tabnineToken) =>
context.globalState.update(
consts.TABNINE_TOKEN_CONTEXT_KEY,
tabnineToken
if (event === "rename") {
void context.globalState.update(
consts.TABNINE_TOKEN_CONTEXT_KEY,
null
);
} else {
void fsPromises
.readFile(consts.TABNINE_TOKEN_FILE_PATH, "utf8")
.then((tabnineToken) =>
context.globalState.update(
consts.TABNINE_TOKEN_CONTEXT_KEY,
tabnineToken
)
)
)
.catch((e) => {
console.error(
"Error occurred while trying to persist Tabnine token",
e
);
});
.catch((e) => {
console.error(
"Error occurred while trying to persist Tabnine token",
e
);
});
}
break;
case consts.TABNINE_CONFIG_FILE_NAME:
void fsPromises
Expand Down