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

Implement getBackend. #8200

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
50 changes: 49 additions & 1 deletion src/apphosting/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { addServiceAccountToRoles } from "../gcp/resourceManager";
import * as iam from "../gcp/iam";
import { FirebaseError, getErrStatus, getError } from "../error";
import { promptOnce } from "../prompt";
import { promptOnce, confirm } from "../prompt";
import { DEFAULT_LOCATION } from "./constants";
import { ensure } from "../ensureApiEnabled";
import * as deploymentTool from "../deploymentTool";
Expand Down Expand Up @@ -48,7 +48,7 @@
// SSL.
const maybeNodeError = err as { cause: { code: string }; code: string };
if (
/HANDSHAKE_FAILURE/.test(maybeNodeError?.cause?.code) ||

Check warning on line 51 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Use `String#includes()` method with a string instead
"EPROTO" === maybeNodeError?.code
) {
return false;
Expand Down Expand Up @@ -263,10 +263,10 @@
async function promptNewBackendId(
projectId: string,
location: string,
prompt: any,

Check warning on line 266 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
): Promise<string> {
while (true) {

Check warning on line 268 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected constant condition
const backendId = await promptOnce(prompt);

Check warning on line 269 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `QuestionsThatReturnAString<Answers>`
try {
await apphosting.getBackend(projectId, location, backendId);
} catch (err: unknown) {
Expand Down Expand Up @@ -443,7 +443,7 @@
let { unreachable, backends } = await apphosting.listBackends(projectId, "-");
if (unreachable && unreachable.length !== 0) {
logWarning(
`The following locations are currently unreachable: ${unreachable}.\n` +

Check warning on line 446 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "string[]" of template literal expression
"If your backend is in one of these regions, please try again later.",
);
}
Expand All @@ -466,11 +466,59 @@
backends.forEach((backend) =>
backendsByLocation.set(apphosting.parseBackendName(backend.name).location, backend),
);
const location = await promptOnce({

Check warning on line 469 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
name: "location",
type: "list",
message: locationDisambugationPrompt,
choices: [...backendsByLocation.keys()],
});
return backendsByLocation.get(location)!;

Check warning on line 475 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion

Check warning on line 475 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string`
}

/**
* Fetches a backend from the server. If there are multiple backends with the name, it will fetch the first
* in the list and warn the user that there are other backends with the same name that need to be deleted. If
* the force option is specified nad multiple backends have the same name, it throws an error.
*/
export async function getBackend(
projectId: string,
backendId: string,
force?: boolean,
): Promise<apphosting.Backend> {
// TODO: call apphosting.getBackend() once all duplicate named backends have been deleted.
let { unreachable, backends } = await apphosting.listBackends(projectId, "-");
backends = backends.filter(
(backend) => apphosting.parseBackendName(backend.name).id === backendId,
);
if (backends.length > 0) {
if (backends.length > 1) {
logWarning(
`You have multiple backends with the same ${backendId} ID. This is no longer supported. ` +
"Please delete and recreate any backends that share an ID with another backend."

Check failure on line 497 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `"Please·delete·and·recreate·any·backends·that·share·an·ID·with·another·backend."` with `··"Please·delete·and·recreate·any·backends·that·share·an·ID·with·another·backend.",`

Check failure on line 497 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `"Please·delete·and·recreate·any·backends·that·share·an·ID·with·another·backend."` with `··"Please·delete·and·recreate·any·backends·that·share·an·ID·with·another·backend.",`

Check failure on line 497 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `"Please·delete·and·recreate·any·backends·that·share·an·ID·with·another·backend."` with `··"Please·delete·and·recreate·any·backends·that·share·an·ID·with·another·backend.",`

Check failure on line 497 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `"Please·delete·and·recreate·any·backends·that·share·an·ID·with·another·backend."` with `··"Please·delete·and·recreate·any·backends·that·share·an·ID·with·another·backend.",`
);
if (force) {
throw new FirebaseError(

Check failure on line 500 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `⏎··········`Force·cannot·be·used·when·multiple·backends·share·the·same·ID`,⏎········` with ``Force·cannot·be·used·when·multiple·backends·share·the·same·ID``

Check failure on line 500 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `⏎··········`Force·cannot·be·used·when·multiple·backends·share·the·same·ID`,⏎········` with ``Force·cannot·be·used·when·multiple·backends·share·the·same·ID``

Check failure on line 500 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `⏎··········`Force·cannot·be·used·when·multiple·backends·share·the·same·ID`,⏎········` with ``Force·cannot·be·used·when·multiple·backends·share·the·same·ID``

Check failure on line 500 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `⏎··········`Force·cannot·be·used·when·multiple·backends·share·the·same·ID`,⏎········` with ``Force·cannot·be·used·when·multiple·backends·share·the·same·ID``
`Force cannot be used when multiple backends share the same ID`,
);
}
const options = { force: force, nonInteractive: false };
const confirmed = await confirm({
...options,

Check failure on line 506 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `↹` with `········`

Check failure on line 506 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `↹` with `········`

Check failure on line 506 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `↹` with `········`

Check failure on line 506 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `↹` with `········`
message: `Using backend ${backends[0].name} continue?`,

Check failure on line 507 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `↹` with `········`

Check failure on line 507 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `↹` with `········`

Check failure on line 507 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `↹` with `········`

Check failure on line 507 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `↹` with `········`
});
if (!confirmed) {
throw new FirebaseError("Command aborted.");

Check failure on line 510 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `↹` with `········`

Check failure on line 510 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `↹` with `········`

Check failure on line 510 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `↹` with `········`

Check failure on line 510 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `↹` with `········`
}
}
return backends[0];
}
if (unreachable && unreachable.length !== 0) {
logWarning(
`Backends with the following primary regions are unreachable: ${unreachable}.\n` +

Check warning on line 517 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "string[]" of template literal expression
"If your backend is in one of these regions, please try again later."

Check failure on line 518 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `↹"If·your·backend·is·in·one·of·these·regions,·please·try·again·later."` with `········"If·your·backend·is·in·one·of·these·regions,·please·try·again·later.",`

Check failure on line 518 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `↹"If·your·backend·is·in·one·of·these·regions,·please·try·again·later."` with `········"If·your·backend·is·in·one·of·these·regions,·please·try·again·later.",`

Check failure on line 518 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `↹"If·your·backend·is·in·one·of·these·regions,·please·try·again·later."` with `········"If·your·backend·is·in·one·of·these·regions,·please·try·again·later.",`

Check failure on line 518 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `↹"If·your·backend·is·in·one·of·these·regions,·please·try·again·later."` with `········"If·your·backend·is·in·one·of·these·regions,·please·try·again·later.",`
);
};

Check failure on line 520 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Delete `;`

Check failure on line 520 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Delete `;`

Check failure on line 520 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Delete `;`

Check failure on line 520 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Delete `;`
throw new FirebaseError(

Check failure on line 521 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `⏎····`No·backend·named·${backendId}·found.`,⏎··` with ``No·backend·named·${backendId}·found.``

Check failure on line 521 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `⏎····`No·backend·named·${backendId}·found.`,⏎··` with ``No·backend·named·${backendId}·found.``

Check failure on line 521 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `⏎····`No·backend·named·${backendId}·found.`,⏎··` with ``No·backend·named·${backendId}·found.``

Check failure on line 521 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Replace `⏎····`No·backend·named·${backendId}·found.`,⏎··` with ``No·backend·named·${backendId}·found.``
`No backend named ${backendId} found.`,
);
}
Loading