Skip to content

[ts] Update network-facing libs like express (et al.), node-fetch, p-… #8312

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

Merged
merged 3 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 4 additions & 4 deletions components/ee/payment-endpoint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"@gitpod/gitpod-protocol": "0.1.5",
"@octokit/rest": "18.5.6",
"@octokit/webhooks": "9.17.0",
"body-parser": "^1.19.0",
"body-parser": "^1.19.2",
"chargebee": "^2.4.6",
"express": "^4.17.1",
"express": "^4.17.3",
"inversify": "^5.0.1",
"jsonwebtoken": "^8.5.0",
"node-fetch": "^2.6.1",
"node-fetch": "^2.6.7",
"passport": "^0.4.0",
"passport-http": "^0.3.0",
"reflect-metadata": "^0.1.13",
Expand All @@ -24,7 +24,7 @@
"@types/body-parser": "^1.16.5",
"@types/chai": "^4.2.2",
"@types/jsonwebtoken": "^8.3.2",
"@types/node-fetch": "^2.5.0",
"@types/node-fetch": "^2.6.1",
"@types/passport-http": "^0.3.0",
"chai": "^4.1.2",
"mocha": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion components/gitpod-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/react": "17.0.32",
"ajv": "^6.5.4",
"analytics-node": "^4.0.1",
"cookie": "^0.4.1",
"cookie": "^0.4.2",
"inversify": "^5.1.1",
"jaeger-client": "^3.18.1",
"js-yaml": "^3.10.0",
Expand Down
1 change: 1 addition & 0 deletions components/server/ee/src/user/eligibility-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class EligibilityService {
const logCtx = { userId: user.id };
try {
const rawResponse = await fetch("https://education.github.com/api/user", {
timeout: 5000,
headers: {
"Authorization": `token ${token}`,
"faculty-check-preview": "true"
Expand Down
7 changes: 4 additions & 3 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { AccountStatementProvider } from "../user/account-statement-provider";
import { GithubUpgradeURL, PlanCoupon } from "@gitpod/gitpod-protocol/lib/payment-protocol";
import { AssigneeIdentityIdentifier, TeamSubscription, TeamSubscriptionSlot, TeamSubscriptionSlotResolved } from "@gitpod/gitpod-protocol/lib/team-subscription-protocol";
import { Plans } from "@gitpod/gitpod-protocol/lib/plans";
import pThrottle, { ThrottledFunction } from "p-throttle";
import * as pThrottle from "p-throttle";
import { formatDate } from "@gitpod/gitpod-protocol/lib/util/date-time";
import { FindUserByIdentityStrResult } from "../../../src/user/user-service";
import { Accounting, AccountService, SubscriptionService, TeamSubscriptionService } from "@gitpod/gitpod-payment-endpoint/lib/accounting";
Expand Down Expand Up @@ -1198,7 +1198,8 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
}
}

protected readonly findAssigneeThrottled: ThrottledFunction<any[], FindUserByIdentityStrResult> = pThrottle(async (logCtx: LogContext, identityStr: string): Promise<FindUserByIdentityStrResult> => {
protected readonly findAssigneeThrottler = pThrottle({ limit: 1, interval: 1000 });
protected readonly findAssigneeThrottled: pThrottle.ThrottledFunction<any[], FindUserByIdentityStrResult> = this.findAssigneeThrottler(async (logCtx: LogContext, identityStr: string): Promise<FindUserByIdentityStrResult> => {
let assigneeInfo = undefined;
try {
assigneeInfo = await this.userService.findUserByIdentityStr(identityStr);
Expand All @@ -1209,7 +1210,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
throw new ResponseError(ErrorCodes.TEAM_SUBSCRIPTION_ASSIGNMENT_FAILED, `Gitpod user not found`, { msg: `Gitpod user not found` });
}
return assigneeInfo;
}, 1, 1000);
});

protected async findAssignee(logCtx: LogContext, identityStr: string) {
return await this.findAssigneeThrottled(logCtx, identityStr);
Expand Down
16 changes: 8 additions & 8 deletions components/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
"amqplib": "^0.8.0",
"base-64": "^1.0.0",
"bitbucket": "^2.7.0",
"body-parser": "^1.18.2",
"cookie": "^0.4.1",
"cookie-parser": "^1.4.5",
"body-parser": "^1.19.2",
"cookie": "^0.4.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.4",
"deep-equal": "^2.0.5",
"deepmerge": "^4.2.2",
"express": "^4.16.1",
"express": "^4.17.3",
"express-http-proxy": "^1.0.7",
"express-mysql-session": "^2.1.0",
"express-session": "^1.15.6",
Expand All @@ -65,16 +65,16 @@
"lodash.debounce": "^4.0.8",
"longjohn": "^0.2.12",
"minio": "^7.0.12",
"node-fetch": "^2.6.1",
"node-fetch": "^2.6.7",
"opentracing": "^0.14.4",
"p-throttle": "^3.0.0",
"p-throttle": "^4.1.1",
"passport": "^0.4.1",
"passport-dummy": "^0.0.1",
"passport-gitlab2": "5.0.0",
"passport-http": "^0.3.0",
"probot": "12.1.1",
"prom-client": "^13.2.0",
"rate-limiter-flexible": "^2.2.1",
"rate-limiter-flexible": "^2.3.6",
"reflect-metadata": "^0.1.10",
"swot-js": "^1.0.3",
"uuid": "^8.3.2",
Expand Down Expand Up @@ -103,7 +103,7 @@
"@types/minio": "^7.0.10",
"@types/mocha": "^2.2.45",
"@types/node": "^16.11.0",
"@types/node-fetch": "^2.5.12",
"@types/node-fetch": "^2.6.1",
"@types/passport": "^1.0.7",
"@types/passport-oauth2": "^1.4.11",
"@types/uuid": "^8.3.1",
Expand Down
1 change: 1 addition & 0 deletions components/server/src/auth/generic-auth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export class GenericAuthProvider implements AuthProvider {
this.readAuthUserSetup = async (accessToken: string, tokenResponse: object) => {
try {
const fetchResult = await fetch(configURL, {
timeout: 10000,
method: "POST",
headers: {
"Accept": "application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class BitbucketServerApi {
const token = (await this.tokenHelper.getTokenWithScopes(user, [])).value;
const fullUrl = `${this.baseUrl}${urlPath}`;
const response = await fetch(fullUrl, {
timeout: 10000,
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class BitbucketServerAuthProvider extends GenericAuthProvider {
protected readAuthUserSetup = async (accessToken: string, _tokenResponse: object) => {
try {
const fetchResult = await fetch(`https://${this.params.host}/plugins/servlet/applinks/whoami`, {
timeout: 10000,
headers: {
"Authorization": `Bearer ${accessToken}`,
}
Expand Down
2 changes: 2 additions & 0 deletions components/server/src/code-sync/code-sync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export class CodeSyncService {
const blobsClient = this.blobsProvider.getDefault();
const urlResponse = await util.promisify<DownloadUrlRequest, DownloadUrlResponse>(blobsClient.downloadUrl.bind(blobsClient))(request);
const response = await fetch(urlResponse.getUrl(), {
timeout: 10000,
headers: {
'content-type': contentType
}
Expand Down Expand Up @@ -241,6 +242,7 @@ export class CodeSyncService {
const url = urlResponse.getUrl();
const content = req.body as string;
const response = await fetch(url, {
timeout: 10000,
method: 'PUT',
body: content,
headers: {
Expand Down
4 changes: 3 additions & 1 deletion components/server/src/github/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class GitHubGraphQlEndpoint {
`https://github.com/raw/${org}/${name}/${commitish}/${path}` :
`https://${host}/${org}/${name}/raw/${commitish}/${path}`;
const response = await fetch(urlString, {
timeout: 15000,
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -82,6 +83,7 @@ export class GitHubGraphQlEndpoint {

async runQueryWithToken<T>(token: string, request: object): Promise<QueryResult<T>> {
const response = await fetch(this.baseURLv4, {
timeout: 15000,
method: 'POST',
body: JSON.stringify(request),
headers: {
Expand All @@ -92,7 +94,7 @@ export class GitHubGraphQlEndpoint {
if (!response.ok) {
throw Error(response.statusText);
}
const result: QueryResult<T> = await response.json();
const result = await response.json() as QueryResult<T>;
if (!result.data && result.errors) {
const error = new Error(JSON.stringify({
request,
Expand Down
3 changes: 2 additions & 1 deletion components/server/src/gitlab/gitlab-token-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class GitLabTokenValidator implements IGitTokenValidator {
query: `query {project(fullPath: "${repoFullName}") { visibility, userPermissions{ pushCode } } } `
};
const response = await fetch(`https://${host}/api/graphql`, {
timeout: 5000,
method: "POST",
body: JSON.stringify(request),
headers: {
Expand All @@ -31,7 +32,7 @@ export class GitLabTokenValidator implements IGitTokenValidator {
});
if (response.ok) {
found = true;
const json = await response.json();
const json = await response.json() as any;
const project = json.data && json.data.project;
if (project) {
isPrivateRepo = project.visibility !== "public";
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ process.on("SIGUSR1", () => {
if (!err) {
const filename = path.join(os.tmpdir(), Date.now() + '.cpuprofile');
console.log('preparing cpuprofile: ' + filename);
fs.promises.writeFile(filename, JSON.stringify(profile));
fs.promises.writeFile(filename, JSON.stringify(profile)).catch(err => console.error("error writing cpuprofile", err));
} else {
console.error('failed to cpuprofile: ', err);
}
Expand Down
5 changes: 4 additions & 1 deletion components/server/src/workspace/config-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ export class ConfigProvider {

try {
const url = `https://github.com/raw/gitpod-io/definitely-gp/master/${filePath}`;
const response = await fetch(url, { method: 'GET' });
const response = await fetch(url, {
timeout: 10000,
method: 'GET',
});
let content;
if (response.ok) {
try {
Expand Down
2 changes: 1 addition & 1 deletion components/ws-manager-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@gitpod/ws-manager": "0.1.5",
"@gitpod/ws-manager-bridge-api": "0.1.5",
"amqplib": "^0.8.0",
"express": "^4.17.1",
"express": "^4.17.3",
"inversify": "^5.0.1",
"prom-client": "^13.2.0",
"reflect-metadata": "^0.1.13"
Expand Down
Loading