Skip to content

Commit

Permalink
DEV2-4252 trim trailing proxy url backslash (#1364)
Browse files Browse the repository at this point in the history
* DEV2-4252 trim trailing proxy url backslash

* run test on linux only
  • Loading branch information
dimacodota authored Nov 16, 2023
1 parent be6c0cc commit 77451b9
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 64 deletions.
89 changes: 43 additions & 46 deletions .github/workflows/continues_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,50 @@ jobs:
name: Build & Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 16.10
uses: actions/setup-node@v3
with:
node-version: '16.10'
- name: Install
run: yarn install --frozen-lockfile --ignore-optional
- name: Verify that the plugin metadta is correct
run: yarn verify-package-metadata
- name: Prettier validate
run: yarn prettier:check
- name: Lint
run: yarn lint
- name: Get Chat Version
id: get_chat_version
run: echo "version=$(cat ./.chatversion)" >> $GITHUB_ENV
- name: Checkout Chat Application Repository
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: 'codota/tabnine-chat-app'
version: 'tags/${{ env.version }}'
file: 'build.tar.gz'
token: ${{ secrets.GH_BUILDER_TOKEN }}
- name: Extract Chat App Build
run: |
mkdir -p ./chat
tar -xzvf ./build.tar.gz -C ./chat
- name: Package
run: yarn vsce:package
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 16.10
uses: actions/setup-node@v3
with:
node-version: "16.10"
- name: Install
run: yarn install --frozen-lockfile --ignore-optional
- name: Verify that the plugin metadta is correct
run: yarn verify-package-metadata
- name: Prettier validate
run: yarn prettier:check
- name: Lint
run: yarn lint
- name: Get Chat Version
id: get_chat_version
run: echo "version=$(cat ./.chatversion)" >> $GITHUB_ENV
- name: Checkout Chat Application Repository
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: "codota/tabnine-chat-app"
version: "tags/${{ env.version }}"
file: "build.tar.gz"
token: ${{ secrets.GH_BUILDER_TOKEN }}
- name: Extract Chat App Build
run: |
mkdir -p ./chat
tar -xzvf ./build.tar.gz -C ./chat
- name: Package
run: yarn vsce:package

test:
name: Test
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 16.10
uses: actions/setup-node@v3
with:
node-version: '16.10'
- name: Install
run: yarn install --frozen-lockfile --ignore-optional
- run: xvfb-run -a yarn test
if: runner.os == 'Linux'
- run: yarn test
if: runner.os != 'Linux'
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 16.10
uses: actions/setup-node@v3
with:
node-version: "16.10"
- name: Install
run: yarn install --frozen-lockfile --ignore-optional
- run: xvfb-run -a yarn test
if: runner.os == 'Linux'
- run: yarn test
if: runner.os != 'Linux'
32 changes: 20 additions & 12 deletions src/authentication/authentication.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,38 @@ import { tabNineProcess } from "../binary/requests/requests";
import { openExternalLogin } from "../cloudEnvs/openLogin";
import isCloudEnv from "../cloudEnvs/isCloudEnv";
import tabnineExtensionProperties from "../globals/tabnineExtensionProperties";
import { notifyOnError } from "../utils/notifyOnError";

export function callForLogin(): Promise<unknown> {
if (isCloudEnv || tabnineExtensionProperties.isRemote) {
return openExternalLogin();
}
return tabNineProcess.request({ Login: {} });
export async function callForLogin(): Promise<void> {
return notifyOnError(async () => {
if (isCloudEnv || tabnineExtensionProperties.isRemote) {
await openExternalLogin();
}
await tabNineProcess.request({ Login: {} });
}, "Failed to call for login");
}

export async function callForLogout(): Promise<unknown> {
return tabNineProcess.request({ Logout: {} });
return notifyOnError(
() => tabNineProcess.request({ Logout: {} }),
"Failed to call for logout"
);
}

export async function signInUsingCustomToken(
customToken: string
): Promise<unknown> {
return tabNineProcess.request({
LoginWithCustomToken: { custom_token: customToken },
});
return notifyOnError(
() => tabNineProcess.request({ SignIn: { customToken } }),
"Failed to sign in using custom token"
);
}

export async function signInUsingCustomTokenUrl(): Promise<
string | null | undefined
> {
return tabNineProcess.request({
LoginWithCustomTokenUrl: {},
});
return notifyOnError(
() => tabNineProcess.request({ SignIn: { customTokenUrl: true } }),
"Failed to sign in using custom token url"
);
}
2 changes: 1 addition & 1 deletion src/binary/Binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class Binary {
}

if (this.isBinaryDead()) {
Logger.warn("Binary died. It is being restarted.");
Logger.info("Binary died. It is being restarted.");
await this.restartChild();

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/enterprise/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const SELF_HOSTED_IGNORE_PROXY_CONFIGURATION =
export const SELF_HOSTED_IGNORE_CERTIFICATE_ERRORS_CONFIGURATION =
"tabnineSelfHostedUpdater.ignoreCertificateErrors";

export const IGNORE_PROXY_CONFIGURATION = "tabnine.useProxySupport";
export const USE_PROXY_CONFIGURATION = "tabnine.useProxySupport";

export const CA_CERTS_CONFIGURATION = "tabnine.caCerts";

Expand Down
4 changes: 2 additions & 2 deletions src/enterprise/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import tabnineExtensionProperties from "../globals/tabnineExtensionProperties";
import { host } from "../utils/utils";
import {
IGNORE_CERTIFICATE_ERRORS_CONFIGURATION,
IGNORE_PROXY_CONFIGURATION,
USE_PROXY_CONFIGURATION,
RELOAD_COMMAND,
SELF_HOSTED_IGNORE_CERTIFICATE_ERRORS_CONFIGURATION,
SELF_HOSTED_IGNORE_PROXY_CONFIGURATION,
Expand Down Expand Up @@ -230,7 +230,7 @@ async function copyConfigFromUpdater(): Promise<void> {
if (disableProxyConfig !== undefined) {
await vscode.workspace
.getConfiguration()
.update(IGNORE_PROXY_CONFIGURATION, disableProxyConfig, true);
.update(USE_PROXY_CONFIGURATION, disableProxyConfig, true);
}

const ignoreCertificateErrorsConfig = await vscode.workspace
Expand Down
4 changes: 2 additions & 2 deletions src/globals/tabnineExtensionProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getTabnineExtensionContext } from "./tabnineExtensionContext";
import {
CA_CERTS_CONFIGURATION,
IGNORE_CERTIFICATE_ERRORS_CONFIGURATION,
IGNORE_PROXY_CONFIGURATION,
USE_PROXY_CONFIGURATION,
} from "../enterprise/consts";

const TELEMETRY_CONFIG_ID = "telemetry";
Expand Down Expand Up @@ -71,7 +71,7 @@ function getContext(): TabNineExtensionProperties {
configuration.get<boolean>("tabnine.receiveBetaChannelUpdates") || false;

const useProxySupport = Boolean(
configuration.get<boolean>(IGNORE_PROXY_CONFIGURATION)
configuration.get<boolean>(USE_PROXY_CONFIGURATION)
);

const isVscodeInsiders = vscode.env.appName
Expand Down
3 changes: 3 additions & 0 deletions src/proxyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ export function getProxySettings(): string | undefined {
process.env.HTTP_PROXY ||
process.env.http_proxy;
}
if (proxy?.endsWith("/")) {
proxy = proxy.substr(0, proxy.length - 1);
}
return proxy;
}
24 changes: 24 additions & 0 deletions src/utils/notifyOnError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { window } from "vscode";
import { Logger } from "./logger";

export async function notifyOnError<T>(
action: (this: void) => Promise<T>,
message: string
): Promise<T | undefined> {
try {
return await action();
} catch (e) {
Logger.error(message, e);
void window
.showErrorMessage(
"Something went wrong, check Tabnine log output for more details",
"Show Log"
)
.then((selection) => {
if (selection === "Show Log") {
Logger.show();
}
});
return undefined;
}
}

0 comments on commit 77451b9

Please sign in to comment.