firebase-tools-with-isolate 13.15.0-0 → 13.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api.js +3 -1
- package/lib/apiv2.js +10 -3
- package/lib/appdistribution/client.js +62 -8
- package/lib/appdistribution/distribution.js +1 -1
- package/lib/apphosting/backend.js +299 -0
- package/lib/apphosting/config.js +31 -8
- package/lib/apphosting/githubConnections.js +70 -22
- package/lib/apphosting/index.js +3 -312
- package/lib/apphosting/rollout.js +138 -0
- package/lib/apphosting/secrets/index.js +70 -5
- package/lib/apphosting/utils.js +41 -0
- package/lib/apphosting/yaml.js +82 -0
- package/lib/archiveDirectory.js +1 -1
- package/lib/auth.js +31 -5
- package/lib/bin/firebase.js +2 -2
- package/lib/command.js +18 -4
- package/lib/commands/appdistribution-distribute.js +4 -4
- package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
- package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
- package/lib/commands/appdistribution-groups-list.js +55 -0
- package/lib/commands/appdistribution-testers-list.js +52 -0
- package/lib/commands/appdistribution-testers-remove.js +1 -1
- package/lib/commands/apphosting-backends-create.js +4 -4
- package/lib/commands/apphosting-backends-delete.js +7 -15
- package/lib/commands/apphosting-backends-get.js +1 -1
- package/lib/commands/apphosting-config-export.js +51 -0
- package/lib/commands/apphosting-repos-create.js +23 -0
- package/lib/commands/apphosting-rollouts-create.js +14 -15
- package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
- package/lib/commands/database-import.js +4 -2
- package/lib/commands/database-push.js +4 -2
- package/lib/commands/database-set.js +4 -2
- package/lib/commands/database-settings-get.js +1 -1
- package/lib/commands/database-settings-set.js +1 -1
- package/lib/commands/dataconnect-sdk-generate.js +4 -1
- package/lib/commands/dataconnect-services-list.js +4 -3
- package/lib/commands/dataconnect-sql-diff.js +1 -1
- package/lib/commands/dataconnect-sql-grant.js +37 -0
- package/lib/commands/dataconnect-sql-migrate.js +1 -1
- package/lib/commands/dataconnect-sql-shell.js +115 -0
- package/lib/commands/deploy.js +5 -1
- package/lib/commands/emulators-start.js +4 -1
- package/lib/commands/ext-dev-init.js +2 -2
- package/lib/commands/ext-dev-list.js +1 -1
- package/lib/commands/ext-dev-register.js +2 -2
- package/lib/commands/ext-dev-upload.js +2 -2
- package/lib/commands/ext-dev-usage.js +2 -2
- package/lib/commands/ext-info.js +3 -1
- package/lib/commands/ext-install.js +2 -2
- package/lib/commands/ext-sdk-install.js +88 -0
- package/lib/commands/ext.js +1 -0
- package/lib/commands/firestore-databases-restore.js +39 -1
- package/lib/commands/functions-secrets-access.js +2 -4
- package/lib/commands/index.js +15 -2
- package/lib/commands/init.js +25 -15
- package/lib/commands/setup-emulators-dataconnect.js +0 -13
- package/lib/commands/use.js +1 -1
- package/lib/config.js +14 -4
- package/lib/crashlytics/buildToolsJarHelper.js +2 -2
- package/lib/dataconnect/client.js +3 -2
- package/lib/dataconnect/dataplaneClient.js +12 -9
- package/lib/dataconnect/ensureApis.js +6 -1
- package/lib/dataconnect/fileUtils.js +29 -12
- package/lib/dataconnect/freeTrial.js +45 -9
- package/lib/dataconnect/load.js +3 -1
- package/lib/dataconnect/provisionCloudSql.js +41 -24
- package/lib/dataconnect/schemaMigration.js +215 -74
- package/lib/dataconnect/types.js +4 -1
- package/lib/dataconnect/webhook.js +32 -0
- package/lib/deploy/dataconnect/deploy.js +18 -15
- package/lib/deploy/dataconnect/prepare.js +41 -0
- package/lib/deploy/dataconnect/release.js +16 -7
- package/lib/deploy/extensions/deploy.js +3 -1
- package/lib/deploy/extensions/deploymentSummary.js +7 -3
- package/lib/deploy/extensions/planner.js +95 -5
- package/lib/deploy/extensions/prepare.js +89 -42
- package/lib/deploy/extensions/release.js +17 -10
- package/lib/deploy/extensions/tasks.js +32 -21
- package/lib/deploy/firestore/prepare.js +9 -0
- package/lib/deploy/firestore/release.js +3 -6
- package/lib/deploy/functions/build.js +5 -5
- package/lib/deploy/functions/checkIam.js +7 -2
- package/lib/deploy/functions/deploy.js +12 -12
- package/lib/deploy/functions/ensure.js +11 -3
- package/lib/deploy/functions/params.js +5 -3
- package/lib/deploy/functions/prepare.js +18 -3
- package/lib/deploy/functions/release/index.js +4 -0
- package/lib/deploy/functions/release/planner.js +2 -1
- package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
- package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +46 -0
- package/lib/deploy/functions/runtimes/node/index.js +5 -0
- package/lib/deploy/functions/services/auth.js +34 -3
- package/lib/deploy/functions/services/index.js +2 -0
- package/lib/deploy/index.js +8 -5
- package/lib/deploy/lifecycleHooks.js +2 -1
- package/lib/emulator/apphosting/config.js +27 -0
- package/lib/emulator/apphosting/index.js +38 -0
- package/lib/emulator/apphosting/serve.js +50 -0
- package/lib/emulator/apphosting/utils.js +18 -0
- package/lib/emulator/auth/handlers.js +27 -0
- package/lib/emulator/auth/operations.js +41 -2
- package/lib/emulator/auth/state.js +2 -1
- package/lib/emulator/commandUtils.js +8 -3
- package/lib/emulator/constants.js +11 -1
- package/lib/emulator/controller.js +59 -6
- package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
- package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
- package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
- package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
- package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
- package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
- package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
- package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
- package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
- package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
- package/lib/emulator/dataconnect/pgliteServer.js +95 -0
- package/lib/emulator/dataconnectEmulator.js +58 -75
- package/lib/emulator/dataconnectToolkitController.js +44 -0
- package/lib/emulator/downloadableEmulators.js +30 -19
- package/lib/emulator/emulatorLogger.js +3 -0
- package/lib/emulator/env.js +3 -0
- package/lib/emulator/eventarcEmulator.js +1 -1
- package/lib/emulator/extensionsEmulator.js +38 -6
- package/lib/emulator/functionsEmulator.js +115 -42
- package/lib/emulator/functionsEmulatorShared.js +18 -1
- package/lib/emulator/functionsRuntimeWorker.js +2 -1
- package/lib/emulator/hub.js +13 -9
- package/lib/emulator/hubExport.js +10 -3
- package/lib/emulator/loggingEmulator.js +2 -2
- package/lib/emulator/portUtils.js +11 -11
- package/lib/emulator/registry.js +2 -0
- package/lib/emulator/storage/persistence.js +2 -2
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/emulator/taskQueue.js +348 -0
- package/lib/emulator/tasksEmulator.js +240 -0
- package/lib/emulator/types.js +6 -0
- package/lib/emulator/ui.js +51 -25
- package/lib/error.js +31 -1
- package/lib/experiments.js +5 -0
- package/lib/extensions/askUserForEventsConfig.js +18 -8
- package/lib/extensions/askUserForParam.js +2 -1
- package/lib/extensions/displayExtensionInfo.js +5 -5
- package/lib/extensions/emulator/triggerHelper.js +1 -1
- package/lib/extensions/extensionsApi.js +15 -11
- package/lib/extensions/extensionsHelper.js +39 -8
- package/lib/extensions/localHelper.js +32 -1
- package/lib/extensions/refs.js +26 -11
- package/lib/extensions/runtimes/common.js +215 -0
- package/lib/extensions/runtimes/node.js +401 -0
- package/lib/extensions/types.js +67 -1
- package/lib/extensions/warnings.js +5 -2
- package/lib/firestore/api.js +2 -1
- package/lib/firestore/checkDatabaseType.js +10 -3
- package/lib/firestore/delete.js +11 -0
- package/lib/firestore/options.js +7 -0
- package/lib/frameworks/angular/index.js +15 -3
- package/lib/frameworks/constants.js +2 -2
- package/lib/frameworks/flutter/index.js +6 -6
- package/lib/frameworks/flutter/utils.js +34 -1
- package/lib/frameworks/next/constants.js +1 -1
- package/lib/frameworks/next/index.js +45 -17
- package/lib/frameworks/next/utils.js +57 -4
- package/lib/frameworks/vite/index.js +2 -2
- package/lib/fsutils.js +13 -1
- package/lib/functions/constants.js +4 -0
- package/lib/functions/events/v1.js +9 -2
- package/lib/gcp/apphosting.js +1 -1
- package/lib/gcp/cloudmonitoring.js +3 -3
- package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
- package/lib/gcp/cloudsql/connect.js +49 -37
- package/lib/gcp/cloudsql/interactive.js +49 -0
- package/lib/gcp/cloudsql/permissions.js +165 -0
- package/lib/gcp/devConnect.js +38 -1
- package/lib/gcp/firestore.js +5 -1
- package/lib/gcp/secretManager.js +12 -5
- package/lib/getProjectNumber.js +1 -1
- package/lib/init/features/apphosting.js +15 -0
- package/lib/init/features/dataconnect/index.js +166 -121
- package/lib/init/features/dataconnect/sdk.js +90 -81
- package/lib/init/features/emulators.js +2 -15
- package/lib/init/features/firestore/index.js +20 -1
- package/lib/init/features/firestore/indexes.js +4 -4
- package/lib/init/features/genkit/index.js +444 -0
- package/lib/init/features/hosting/index.js +2 -2
- package/lib/init/features/index.js +1 -1
- package/lib/init/features/project.js +6 -6
- package/lib/init/features/storage.js +0 -2
- package/lib/init/index.js +1 -0
- package/lib/init/spawn.js +23 -2
- package/lib/logger.js +2 -2
- package/lib/management/projects.js +24 -4
- package/lib/projectUtils.js +1 -1
- package/lib/prompt.js +22 -1
- package/lib/rc.js +1 -8
- package/lib/requireAuth.js +19 -5
- package/lib/requireDatabaseInstance.js +1 -1
- package/lib/requirePermissions.js +1 -1
- package/lib/responseToError.js +5 -2
- package/lib/rulesDeploy.js +1 -1
- package/lib/templates.js +2 -2
- package/lib/utils.js +16 -11
- package/lib/vsCodeUtils.js +8 -0
- package/package.json +8 -7
- package/schema/connector-yaml.json +57 -17
- package/schema/firebase-config.json +36 -0
- package/templates/extensions/javascript/package.lint.json +2 -2
- package/templates/extensions/javascript/package.nolint.json +2 -2
- package/templates/extensions/typescript/package.lint.json +2 -2
- package/templates/extensions/typescript/package.nolint.json +2 -2
- package/templates/genkit/firebase.0.9.0.template +57 -0
- package/templates/init/apphosting/apphosting.yaml +23 -0
- package/templates/init/dataconnect/connector.yaml +4 -3
- package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
- package/templates/init/dataconnect/dataconnect.yaml +6 -6
- package/templates/init/dataconnect/mutations.gql +44 -29
- package/templates/init/dataconnect/queries.gql +65 -38
- package/templates/init/dataconnect/schema.gql +38 -21
- package/templates/init/functions/javascript/package.lint.json +2 -2
- package/templates/init/functions/javascript/package.nolint.json +2 -2
- package/templates/init/functions/typescript/package.lint.json +2 -2
- package/templates/init/functions/typescript/package.nolint.json +2 -2
- package/lib/ensureCloudResourceLocation.js +0 -12
- package/lib/init/features/genkit.js +0 -53
|
@@ -619,6 +619,7 @@ function resetPassword(state, reqBody) {
|
|
|
619
619
|
kind: "identitytoolkit#ResetPasswordResponse",
|
|
620
620
|
requestType: oob.requestType,
|
|
621
621
|
email: oob.requestType === "EMAIL_SIGNIN" ? undefined : oob.email,
|
|
622
|
+
newEmail: oob.newEmail,
|
|
622
623
|
};
|
|
623
624
|
}
|
|
624
625
|
exports.resetPassword = resetPassword;
|
|
@@ -632,6 +633,7 @@ function sendOobCode(state, reqBody, ctx) {
|
|
|
632
633
|
(0, errors_1.assert)((0, utils_1.parseAbsoluteUri)(reqBody.continueUrl), "INVALID_CONTINUE_URI : ((expected an absolute URI with valid scheme and host))");
|
|
633
634
|
}
|
|
634
635
|
let email;
|
|
636
|
+
let newEmail;
|
|
635
637
|
let mode;
|
|
636
638
|
switch (reqBody.requestType) {
|
|
637
639
|
case "EMAIL_SIGNIN":
|
|
@@ -667,6 +669,24 @@ function sendOobCode(state, reqBody, ctx) {
|
|
|
667
669
|
email = user.email;
|
|
668
670
|
}
|
|
669
671
|
break;
|
|
672
|
+
case "VERIFY_AND_CHANGE_EMAIL":
|
|
673
|
+
mode = "verifyAndChangeEmail";
|
|
674
|
+
(0, errors_1.assert)(reqBody.newEmail, "MISSING_NEW_EMAIL");
|
|
675
|
+
newEmail = (0, utils_1.canonicalizeEmailAddress)(reqBody.newEmail);
|
|
676
|
+
if (reqBody.returnOobLink && !reqBody.idToken) {
|
|
677
|
+
(0, errors_1.assert)(reqBody.email, "MISSING_EMAIL");
|
|
678
|
+
email = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
|
|
679
|
+
const maybeUser = state.getUserByEmail(email);
|
|
680
|
+
(0, errors_1.assert)(maybeUser, "USER_NOT_FOUND");
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
(0, errors_1.assert)(reqBody.idToken, "MISSING_ID_TOKEN");
|
|
684
|
+
const user = parseIdToken(state, reqBody.idToken).user;
|
|
685
|
+
(0, errors_1.assert)(user.email, "MISSING_EMAIL");
|
|
686
|
+
email = user.email;
|
|
687
|
+
}
|
|
688
|
+
(0, errors_1.assert)(!state.getUserByEmail(newEmail), "EMAIL_EXISTS");
|
|
689
|
+
break;
|
|
670
690
|
default:
|
|
671
691
|
throw new errors_1.NotImplementedError(reqBody.requestType);
|
|
672
692
|
}
|
|
@@ -678,6 +698,7 @@ function sendOobCode(state, reqBody, ctx) {
|
|
|
678
698
|
requestType: reqBody.requestType,
|
|
679
699
|
mode,
|
|
680
700
|
continueUrl: reqBody.continueUrl,
|
|
701
|
+
newEmail,
|
|
681
702
|
});
|
|
682
703
|
if (reqBody.returnOobLink) {
|
|
683
704
|
return {
|
|
@@ -746,6 +767,7 @@ function setAccountInfoImpl(state, reqBody, { privileged = false, emulatorUrl =
|
|
|
746
767
|
let user;
|
|
747
768
|
let signInProvider;
|
|
748
769
|
let isEmailUpdate = false;
|
|
770
|
+
let newEmail;
|
|
749
771
|
if (reqBody.oobCode) {
|
|
750
772
|
const oob = state.validateOobCode(reqBody.oobCode);
|
|
751
773
|
(0, errors_1.assert)(oob, "INVALID_OOB_CODE");
|
|
@@ -762,6 +784,19 @@ function setAccountInfoImpl(state, reqBody, { privileged = false, emulatorUrl =
|
|
|
762
784
|
}
|
|
763
785
|
break;
|
|
764
786
|
}
|
|
787
|
+
case "VERIFY_AND_CHANGE_EMAIL":
|
|
788
|
+
state.deleteOobCode(reqBody.oobCode);
|
|
789
|
+
const maybeUser = state.getUserByEmail(oob.email);
|
|
790
|
+
(0, errors_1.assert)(maybeUser, "INVALID_OOB_CODE");
|
|
791
|
+
(0, errors_1.assert)(oob.newEmail, "INVALID_OOB_CODE");
|
|
792
|
+
(0, errors_1.assert)(!state.getUserByEmail(oob.newEmail), "EMAIL_EXISTS");
|
|
793
|
+
user = maybeUser;
|
|
794
|
+
if (oob.newEmail !== user.email) {
|
|
795
|
+
updates.email = oob.newEmail;
|
|
796
|
+
updates.emailVerified = true;
|
|
797
|
+
newEmail = oob.newEmail;
|
|
798
|
+
}
|
|
799
|
+
break;
|
|
765
800
|
case "RECOVER_EMAIL": {
|
|
766
801
|
state.deleteOobCode(reqBody.oobCode);
|
|
767
802
|
const maybeUser = state.getUserByInitialEmail(oob.email);
|
|
@@ -791,7 +826,7 @@ function setAccountInfoImpl(state, reqBody, { privileged = false, emulatorUrl =
|
|
|
791
826
|
}
|
|
792
827
|
if (reqBody.email) {
|
|
793
828
|
(0, errors_1.assert)((0, utils_1.isValidEmailAddress)(reqBody.email), "INVALID_EMAIL");
|
|
794
|
-
|
|
829
|
+
newEmail = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
|
|
795
830
|
if (newEmail !== user.email) {
|
|
796
831
|
(0, errors_1.assert)(!state.getUserByEmail(newEmail), "EMAIL_EXISTS");
|
|
797
832
|
updates.email = newEmail;
|
|
@@ -889,6 +924,7 @@ function setAccountInfoImpl(state, reqBody, { privileged = false, emulatorUrl =
|
|
|
889
924
|
email: user.email,
|
|
890
925
|
displayName: user.displayName,
|
|
891
926
|
photoUrl: user.photoUrl,
|
|
927
|
+
newEmail,
|
|
892
928
|
passwordHash: user.passwordHash,
|
|
893
929
|
...(updates.validSince && signInProvider ? issueTokens(state, user, signInProvider) : {}),
|
|
894
930
|
});
|
|
@@ -902,7 +938,7 @@ function sendOobForEmailReset(state, initialEmail, url) {
|
|
|
902
938
|
logOobMessage(oobRecord);
|
|
903
939
|
}
|
|
904
940
|
function createOobRecord(state, email, url, params) {
|
|
905
|
-
const oobRecord = state.createOob(email, params.requestType, (oobCode) => {
|
|
941
|
+
const oobRecord = state.createOob(email, params.newEmail, params.requestType, (oobCode) => {
|
|
906
942
|
url.pathname = "/emulator/action";
|
|
907
943
|
url.searchParams.set("mode", params.mode);
|
|
908
944
|
url.searchParams.set("lang", "en");
|
|
@@ -932,6 +968,9 @@ function logOobMessage(oobRecord) {
|
|
|
932
968
|
case "VERIFY_EMAIL":
|
|
933
969
|
maybeMessage = `To verify the email address ${email}, follow this link: ${oobLink}`;
|
|
934
970
|
break;
|
|
971
|
+
case "VERIFY_AND_CHANGE_EMAIL":
|
|
972
|
+
maybeMessage = `To verify and change the email address from ${email} to ${oobRecord.newEmail}, follow this link: ${oobLink}`;
|
|
973
|
+
break;
|
|
935
974
|
case "RECOVER_EMAIL":
|
|
936
975
|
maybeMessage = `To reset your email address to ${email}, follow this link: ${oobLink}`;
|
|
937
976
|
break;
|
|
@@ -294,11 +294,12 @@ class ProjectState {
|
|
|
294
294
|
secondFactor: record.secondFactor,
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
|
-
createOob(email, requestType, generateLink) {
|
|
297
|
+
createOob(email, newEmail, requestType, generateLink) {
|
|
298
298
|
const oobCode = (0, utils_1.randomBase64UrlStr)(54);
|
|
299
299
|
const oobLink = generateLink(oobCode);
|
|
300
300
|
const oob = {
|
|
301
301
|
email,
|
|
302
|
+
newEmail,
|
|
302
303
|
requestType,
|
|
303
304
|
oobCode,
|
|
304
305
|
oobLink,
|
|
@@ -20,6 +20,7 @@ const fsutils = require("../fsutils");
|
|
|
20
20
|
const Table = require("cli-table");
|
|
21
21
|
const track_1 = require("../track");
|
|
22
22
|
const env_1 = require("./env");
|
|
23
|
+
const webhook_1 = require("../dataconnect/webhook");
|
|
23
24
|
exports.FLAG_ONLY = "--only <emulators>";
|
|
24
25
|
exports.DESC_ONLY = "only specific emulators. " +
|
|
25
26
|
"This is a comma separated list of emulator names. " +
|
|
@@ -292,13 +293,17 @@ async function emulatorExec(script, options) {
|
|
|
292
293
|
extraEnv[constants_1.Constants.FIREBASE_GA_SESSION] = JSON.stringify(session);
|
|
293
294
|
}
|
|
294
295
|
let exitCode = 0;
|
|
295
|
-
let deprecationNotices;
|
|
296
|
+
let deprecationNotices = [];
|
|
296
297
|
try {
|
|
297
298
|
const showUI = !!options.ui;
|
|
298
299
|
({ deprecationNotices } = await controller.startAll(options, showUI, true));
|
|
300
|
+
await (0, webhook_1.sendVSCodeMessage)({ message: webhook_1.VSCODE_MESSAGE.EMULATORS_STARTED });
|
|
299
301
|
exitCode = await runScript(script, extraEnv);
|
|
300
302
|
await controller.onExit(options);
|
|
301
303
|
}
|
|
304
|
+
catch {
|
|
305
|
+
await (0, webhook_1.sendVSCodeMessage)({ message: webhook_1.VSCODE_MESSAGE.EMULATORS_START_ERRORED });
|
|
306
|
+
}
|
|
302
307
|
finally {
|
|
303
308
|
await controller.cleanShutdown();
|
|
304
309
|
}
|
|
@@ -379,5 +384,5 @@ async function checkJavaMajorVersion() {
|
|
|
379
384
|
}
|
|
380
385
|
exports.checkJavaMajorVersion = checkJavaMajorVersion;
|
|
381
386
|
exports.MIN_SUPPORTED_JAVA_MAJOR_VERSION = 11;
|
|
382
|
-
exports.JAVA_DEPRECATION_WARNING = "firebase-tools no longer supports Java
|
|
383
|
-
"Please
|
|
387
|
+
exports.JAVA_DEPRECATION_WARNING = "firebase-tools no longer supports Java versions before 11. " +
|
|
388
|
+
"Please install a JDK at version 11 or above to get a compatible runtime.";
|
|
@@ -8,6 +8,7 @@ exports.DEFAULT_PORTS = {
|
|
|
8
8
|
hosting: 5000,
|
|
9
9
|
functions: 5001,
|
|
10
10
|
extensions: 5001,
|
|
11
|
+
apphosting: 5002,
|
|
11
12
|
firestore: 8080,
|
|
12
13
|
pubsub: 8085,
|
|
13
14
|
database: 9000,
|
|
@@ -15,12 +16,14 @@ exports.DEFAULT_PORTS = {
|
|
|
15
16
|
storage: 9199,
|
|
16
17
|
eventarc: 9299,
|
|
17
18
|
dataconnect: 9399,
|
|
19
|
+
tasks: 9499,
|
|
18
20
|
};
|
|
19
21
|
exports.FIND_AVAILBLE_PORT_BY_DEFAULT = {
|
|
20
22
|
ui: true,
|
|
21
23
|
hub: true,
|
|
22
24
|
logging: true,
|
|
23
25
|
hosting: true,
|
|
26
|
+
apphosting: true,
|
|
24
27
|
functions: false,
|
|
25
28
|
firestore: false,
|
|
26
29
|
database: false,
|
|
@@ -29,13 +32,15 @@ exports.FIND_AVAILBLE_PORT_BY_DEFAULT = {
|
|
|
29
32
|
storage: false,
|
|
30
33
|
extensions: false,
|
|
31
34
|
eventarc: true,
|
|
32
|
-
dataconnect:
|
|
35
|
+
dataconnect: false,
|
|
36
|
+
tasks: true,
|
|
33
37
|
};
|
|
34
38
|
exports.EMULATOR_DESCRIPTION = {
|
|
35
39
|
ui: "Emulator UI",
|
|
36
40
|
hub: "emulator hub",
|
|
37
41
|
logging: "Logging Emulator",
|
|
38
42
|
hosting: "Hosting Emulator",
|
|
43
|
+
apphosting: "App Hosting Emulator",
|
|
39
44
|
functions: "Functions Emulator",
|
|
40
45
|
firestore: "Firestore Emulator",
|
|
41
46
|
database: "Database Emulator",
|
|
@@ -45,6 +50,7 @@ exports.EMULATOR_DESCRIPTION = {
|
|
|
45
50
|
extensions: "Extensions Emulator",
|
|
46
51
|
eventarc: "Eventarc Emulator",
|
|
47
52
|
dataconnect: "Data Connect Emulator",
|
|
53
|
+
tasks: "Cloud Tasks Emulator",
|
|
48
54
|
};
|
|
49
55
|
exports.DEFAULT_HOST = "localhost";
|
|
50
56
|
class Constants {
|
|
@@ -70,6 +76,8 @@ class Constants {
|
|
|
70
76
|
return "test lab";
|
|
71
77
|
case this.SERVICE_EVENTARC:
|
|
72
78
|
return "eventarc";
|
|
79
|
+
case this.SERVICE_CLOUD_TASKS:
|
|
80
|
+
return "tasks";
|
|
73
81
|
default:
|
|
74
82
|
return service;
|
|
75
83
|
}
|
|
@@ -100,12 +108,14 @@ Constants.FIREBASE_STORAGE_EMULATOR_HOST = "FIREBASE_STORAGE_EMULATOR_HOST";
|
|
|
100
108
|
Constants.CLOUD_STORAGE_EMULATOR_HOST = "STORAGE_EMULATOR_HOST";
|
|
101
109
|
Constants.PUBSUB_EMULATOR_HOST = "PUBSUB_EMULATOR_HOST";
|
|
102
110
|
Constants.CLOUD_EVENTARC_EMULATOR_HOST = "CLOUD_EVENTARC_EMULATOR_HOST";
|
|
111
|
+
Constants.CLOUD_TASKS_EMULATOR_HOST = "CLOUD_TASKS_EMULATOR_HOST";
|
|
103
112
|
Constants.FIREBASE_EMULATOR_HUB = "FIREBASE_EMULATOR_HUB";
|
|
104
113
|
Constants.FIREBASE_GA_SESSION = "FIREBASE_GA_SESSION";
|
|
105
114
|
Constants.SERVICE_FIRESTORE = "firestore.googleapis.com";
|
|
106
115
|
Constants.SERVICE_REALTIME_DATABASE = "firebaseio.com";
|
|
107
116
|
Constants.SERVICE_PUBSUB = "pubsub.googleapis.com";
|
|
108
117
|
Constants.SERVICE_EVENTARC = "eventarc.googleapis.com";
|
|
118
|
+
Constants.SERVICE_CLOUD_TASKS = "cloudtasks.googleapis.com";
|
|
109
119
|
Constants.SERVICE_FIREALERTS = "firebasealerts.googleapis.com";
|
|
110
120
|
Constants.SERVICE_ANALYTICS = "app-measurement.com";
|
|
111
121
|
Constants.SERVICE_AUTH = "firebaseauth.googleapis.com";
|
|
@@ -44,6 +44,10 @@ const hostingEmulator_1 = require("./hostingEmulator");
|
|
|
44
44
|
const pubsubEmulator_1 = require("./pubsubEmulator");
|
|
45
45
|
const storage_1 = require("./storage");
|
|
46
46
|
const fileUtils_1 = require("../dataconnect/fileUtils");
|
|
47
|
+
const tasksEmulator_1 = require("./tasksEmulator");
|
|
48
|
+
const apphosting_1 = require("./apphosting");
|
|
49
|
+
const webhook_1 = require("../dataconnect/webhook");
|
|
50
|
+
const api_1 = require("../api");
|
|
47
51
|
const START_LOGGING_EMULATOR = utils.envOverride("START_LOGGING_EMULATOR", "false", (val) => val === "true");
|
|
48
52
|
async function exportOnExit(options) {
|
|
49
53
|
const exportOnExitDir = options.exportOnExit;
|
|
@@ -67,6 +71,7 @@ exports.onExit = onExit;
|
|
|
67
71
|
async function cleanShutdown() {
|
|
68
72
|
emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.HUB).logLabeled("BULLET", "emulators", "Shutting down emulators.");
|
|
69
73
|
await registry_1.EmulatorRegistry.stopAll();
|
|
74
|
+
await (0, webhook_1.sendVSCodeMessage)({ message: webhook_1.VSCODE_MESSAGE.EMULATORS_SHUTDOWN });
|
|
70
75
|
}
|
|
71
76
|
exports.cleanShutdown = cleanShutdown;
|
|
72
77
|
function filterEmulatorTargets(options) {
|
|
@@ -75,6 +80,9 @@ function filterEmulatorTargets(options) {
|
|
|
75
80
|
targets = targets.filter((e) => {
|
|
76
81
|
return options.config.has(e) || options.config.has(`emulators.${e}`);
|
|
77
82
|
});
|
|
83
|
+
if (targets.includes(types_1.Emulators.FUNCTIONS) && !targets.includes(types_1.Emulators.EXTENSIONS)) {
|
|
84
|
+
targets.push(types_1.Emulators.EXTENSIONS);
|
|
85
|
+
}
|
|
78
86
|
const onlyOptions = options.only;
|
|
79
87
|
if (onlyOptions) {
|
|
80
88
|
const only = onlyOptions.split(",").map((o) => {
|
|
@@ -199,11 +207,21 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
199
207
|
const emulatableBackends = [];
|
|
200
208
|
let extensionEmulator = undefined;
|
|
201
209
|
if (shouldStart(options, types_1.Emulators.EXTENSIONS)) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
210
|
+
let projectNumber = constants_1.Constants.FAKE_PROJECT_NUMBER;
|
|
211
|
+
if (!isDemoProject) {
|
|
212
|
+
try {
|
|
213
|
+
projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.EXTENSIONS).logLabeled("ERROR", types_1.Emulators.EXTENSIONS, `Unable to look up project number for ${options.project}.\n` +
|
|
217
|
+
" If this is a real project, ensure that you are logged in and have access to it.\n" +
|
|
218
|
+
" If this is a fake project, please use a project ID starting with 'demo-' to skip production calls.\n" +
|
|
219
|
+
" Continuing with a fake project number - secrets and other features that require production access may behave unexpectedly.");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
205
222
|
const aliases = (0, projectUtils_1.getAliases)(options, projectId);
|
|
206
223
|
extensionEmulator = new extensionsEmulator_1.ExtensionsEmulator({
|
|
224
|
+
options,
|
|
207
225
|
projectId,
|
|
208
226
|
projectDir: options.config.projectDir,
|
|
209
227
|
projectNumber,
|
|
@@ -211,7 +229,7 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
211
229
|
extensions: options.config.get("extensions"),
|
|
212
230
|
});
|
|
213
231
|
const extensionsBackends = await extensionEmulator.getExtensionBackends();
|
|
214
|
-
const filteredExtensionsBackends = extensionEmulator.filterUnemulatedTriggers(
|
|
232
|
+
const filteredExtensionsBackends = extensionEmulator.filterUnemulatedTriggers(extensionsBackends);
|
|
215
233
|
emulatableBackends.push(...filteredExtensionsBackends);
|
|
216
234
|
(0, track_1.trackGA4)("extensions_emulated", {
|
|
217
235
|
number_of_extensions_emulated: filteredExtensionsBackends.length,
|
|
@@ -222,10 +240,12 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
222
240
|
if (emulatableBackends.length) {
|
|
223
241
|
listenConfig[types_1.Emulators.FUNCTIONS] = getListenConfig(options, types_1.Emulators.FUNCTIONS);
|
|
224
242
|
listenConfig[types_1.Emulators.EVENTARC] = getListenConfig(options, types_1.Emulators.EVENTARC);
|
|
243
|
+
listenConfig[types_1.Emulators.TASKS] = getListenConfig(options, types_1.Emulators.TASKS);
|
|
225
244
|
}
|
|
226
245
|
for (const emulator of types_1.ALL_EMULATORS) {
|
|
227
246
|
if (emulator === types_1.Emulators.FUNCTIONS ||
|
|
228
247
|
emulator === types_1.Emulators.EVENTARC ||
|
|
248
|
+
emulator === types_1.Emulators.TASKS ||
|
|
229
249
|
emulator === types_1.Emulators.EXTENSIONS ||
|
|
230
250
|
(emulator === types_1.Emulators.UI && !showUI)) {
|
|
231
251
|
continue;
|
|
@@ -243,6 +263,14 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
243
263
|
portFixed: !!wsPortConfig,
|
|
244
264
|
};
|
|
245
265
|
}
|
|
266
|
+
if (emulator === types_1.Emulators.DATACONNECT && !(0, api_1.dataConnectLocalConnString)()) {
|
|
267
|
+
const pglitePortConfig = options.config.src.emulators?.dataconnect?.postgresPort;
|
|
268
|
+
listenConfig["dataconnect.postgres"] = {
|
|
269
|
+
host: config.host,
|
|
270
|
+
port: pglitePortConfig || 5432,
|
|
271
|
+
portFixed: !!pglitePortConfig,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
246
274
|
}
|
|
247
275
|
}
|
|
248
276
|
let listenForEmulator = await (0, portUtils_1.resolveHostAndAssignPorts)(listenConfig);
|
|
@@ -330,11 +358,12 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
330
358
|
await startEmulator(extensionEmulator);
|
|
331
359
|
}
|
|
332
360
|
if (emulatableBackends.length) {
|
|
333
|
-
if (!listenForEmulator.functions || !listenForEmulator.eventarc) {
|
|
361
|
+
if (!listenForEmulator.functions || !listenForEmulator.eventarc || !listenForEmulator.tasks) {
|
|
334
362
|
listenForEmulator = await (0, portUtils_1.resolveHostAndAssignPorts)({
|
|
335
363
|
...listenForEmulator,
|
|
336
364
|
functions: listenForEmulator.functions ?? getListenConfig(options, types_1.Emulators.FUNCTIONS),
|
|
337
365
|
eventarc: listenForEmulator.eventarc ?? getListenConfig(options, types_1.Emulators.EVENTARC),
|
|
366
|
+
tasks: listenForEmulator.eventarc ?? getListenConfig(options, types_1.Emulators.TASKS),
|
|
338
367
|
});
|
|
339
368
|
hubLogger.log("DEBUG", "late-assigned ports for functions and eventarc emulators", {
|
|
340
369
|
user: listenForEmulator,
|
|
@@ -364,6 +393,7 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
364
393
|
debugPort: inspectFunctions,
|
|
365
394
|
verbosity: options.logVerbosity,
|
|
366
395
|
projectAlias: options.projectAlias,
|
|
396
|
+
extensionsEmulator: extensionEmulator,
|
|
367
397
|
});
|
|
368
398
|
await startEmulator(functionsEmulator);
|
|
369
399
|
const eventarcAddr = legacyGetFirstAddr(types_1.Emulators.EVENTARC);
|
|
@@ -372,6 +402,12 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
372
402
|
port: eventarcAddr.port,
|
|
373
403
|
});
|
|
374
404
|
await startEmulator(eventarcEmulator);
|
|
405
|
+
const tasksAddr = legacyGetFirstAddr(types_1.Emulators.TASKS);
|
|
406
|
+
const tasksEmulator = new tasksEmulator_1.TasksEmulator({
|
|
407
|
+
host: tasksAddr.host,
|
|
408
|
+
port: tasksAddr.port,
|
|
409
|
+
});
|
|
410
|
+
await startEmulator(tasksEmulator);
|
|
375
411
|
}
|
|
376
412
|
if (listenForEmulator.firestore) {
|
|
377
413
|
const firestoreLogger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.FIRESTORE);
|
|
@@ -538,6 +574,10 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
538
574
|
configDir,
|
|
539
575
|
rc: options.rc,
|
|
540
576
|
config: options.config,
|
|
577
|
+
autoconnectToPostgres: true,
|
|
578
|
+
postgresListen: listenForEmulator["dataconnect.postgres"],
|
|
579
|
+
enable_output_generated_sdk: true,
|
|
580
|
+
enable_output_schema_extensions: true,
|
|
541
581
|
});
|
|
542
582
|
await startEmulator(dataConnectEmulator);
|
|
543
583
|
}
|
|
@@ -566,6 +606,20 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
566
606
|
});
|
|
567
607
|
await startEmulator(hostingEmulator);
|
|
568
608
|
}
|
|
609
|
+
if (experiments.isEnabled("emulatorapphosting")) {
|
|
610
|
+
const apphostingConfig = options.config.src.emulators?.[types_1.Emulators.APPHOSTING];
|
|
611
|
+
if (listenForEmulator.apphosting) {
|
|
612
|
+
const apphostingAddr = legacyGetFirstAddr(types_1.Emulators.APPHOSTING);
|
|
613
|
+
const apphostingEmulator = new apphosting_1.AppHostingEmulator({
|
|
614
|
+
host: apphostingAddr.host,
|
|
615
|
+
port: apphostingAddr.port,
|
|
616
|
+
startCommandOverride: apphostingConfig?.startCommandOverride,
|
|
617
|
+
rootDirectory: apphostingConfig?.rootDirectory,
|
|
618
|
+
options,
|
|
619
|
+
});
|
|
620
|
+
await startEmulator(apphostingEmulator);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
569
623
|
if (listenForEmulator.logging) {
|
|
570
624
|
const loggingAddr = legacyGetFirstAddr(types_1.Emulators.LOGGING);
|
|
571
625
|
const loggingEmulator = new loggingEmulator_1.LoggingEmulator({
|
|
@@ -582,7 +636,6 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
582
636
|
if (listenForEmulator.ui) {
|
|
583
637
|
const ui = new ui_1.EmulatorUI({
|
|
584
638
|
projectId: projectId,
|
|
585
|
-
auto_download: true,
|
|
586
639
|
listen: listenForEmulator[types_1.Emulators.UI],
|
|
587
640
|
});
|
|
588
641
|
await startEmulator(ui);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseAuthFlow = void 0;
|
|
4
|
+
class BaseAuthFlow {
|
|
5
|
+
constructor(params) {
|
|
6
|
+
this.reader = params.reader;
|
|
7
|
+
this.writer = params.writer;
|
|
8
|
+
this.connectionState = params.connectionState;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.BaseAuthFlow = BaseAuthFlow;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CertAuthFlow = void 0;
|
|
4
|
+
const backend_error_1 = require("../backend-error");
|
|
5
|
+
const base_auth_flow_1 = require("./base-auth-flow");
|
|
6
|
+
const connection_1 = require("../connection");
|
|
7
|
+
class CertAuthFlow extends base_auth_flow_1.BaseAuthFlow {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super(params);
|
|
10
|
+
this.completed = false;
|
|
11
|
+
this.auth = {
|
|
12
|
+
...params.auth,
|
|
13
|
+
validateCredentials: params.auth.validateCredentials ??
|
|
14
|
+
(async ({ username, certificate }) => {
|
|
15
|
+
return certificate.subject.CN === username;
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
this.username = params.username;
|
|
19
|
+
}
|
|
20
|
+
async *handleClientMessage(message) {
|
|
21
|
+
if (false) {
|
|
22
|
+
yield (0, backend_error_1.createBackendErrorMessage)({
|
|
23
|
+
severity: 'FATAL',
|
|
24
|
+
code: '08000',
|
|
25
|
+
message: `ssl connection required when auth mode is 'certificate'`,
|
|
26
|
+
});
|
|
27
|
+
yield connection_1.closeSignal;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (false) {
|
|
31
|
+
yield (0, backend_error_1.createBackendErrorMessage)({
|
|
32
|
+
severity: 'FATAL',
|
|
33
|
+
code: '08000',
|
|
34
|
+
message: 'client certificate is invalid',
|
|
35
|
+
});
|
|
36
|
+
yield connection_1.closeSignal;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const isValid = false;
|
|
40
|
+
if (!isValid) {
|
|
41
|
+
yield (0, backend_error_1.createBackendErrorMessage)({
|
|
42
|
+
severity: 'FATAL',
|
|
43
|
+
code: '08000',
|
|
44
|
+
message: 'client certificate is invalid',
|
|
45
|
+
});
|
|
46
|
+
yield connection_1.closeSignal;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.completed = true;
|
|
50
|
+
}
|
|
51
|
+
createInitialAuthMessage() {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
get isCompleted() {
|
|
55
|
+
return this.completed;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.CertAuthFlow = CertAuthFlow;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthFlow = void 0;
|
|
4
|
+
const cert_1 = require("./cert");
|
|
5
|
+
const md5_1 = require("./md5");
|
|
6
|
+
const password_1 = require("./password");
|
|
7
|
+
const scram_sha_256_1 = require("./sasl/scram-sha-256");
|
|
8
|
+
function createAuthFlow(options) {
|
|
9
|
+
switch (options.auth.method) {
|
|
10
|
+
case 'password':
|
|
11
|
+
return new password_1.PasswordAuthFlow({ ...options, auth: options.auth });
|
|
12
|
+
case 'md5':
|
|
13
|
+
return new md5_1.Md5AuthFlow({ ...options, auth: options.auth });
|
|
14
|
+
case 'scram-sha-256':
|
|
15
|
+
return new scram_sha_256_1.ScramSha256AuthFlow({ ...options, auth: options.auth });
|
|
16
|
+
case 'cert':
|
|
17
|
+
return new cert_1.CertAuthFlow({ ...options, auth: options.auth });
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Unsupported auth method: ${options.auth.method}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.createAuthFlow = createAuthFlow;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateBinaryLike = exports.encodeHex = exports.concat = exports.createPreHashedPassword = exports.generateMd5Salt = exports.md5 = exports.hashPreHashedPassword = exports.Md5AuthFlow = void 0;
|
|
4
|
+
const backend_error_1 = require("../backend-error");
|
|
5
|
+
const connection_1 = require("../connection");
|
|
6
|
+
const message_codes_1 = require("../message-codes");
|
|
7
|
+
const base_auth_flow_1 = require("./base-auth-flow");
|
|
8
|
+
class Md5AuthFlow extends base_auth_flow_1.BaseAuthFlow {
|
|
9
|
+
constructor(params) {
|
|
10
|
+
super(params);
|
|
11
|
+
this.completed = false;
|
|
12
|
+
this.auth = {
|
|
13
|
+
...params.auth,
|
|
14
|
+
validateCredentials: params.auth.validateCredentials ??
|
|
15
|
+
(async ({ preHashedPassword, hashedPassword, salt }) => {
|
|
16
|
+
const expectedHashedPassword = await hashPreHashedPassword(preHashedPassword, salt);
|
|
17
|
+
return hashedPassword === expectedHashedPassword;
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
this.username = params.username;
|
|
21
|
+
this.salt = generateMd5Salt();
|
|
22
|
+
}
|
|
23
|
+
async *handleClientMessage(message) {
|
|
24
|
+
const length = this.reader.int32();
|
|
25
|
+
const hashedPassword = this.reader.cstring();
|
|
26
|
+
const preHashedPassword = await this.auth.getPreHashedPassword({
|
|
27
|
+
username: this.username,
|
|
28
|
+
}, this.connectionState);
|
|
29
|
+
const isValid = await this.auth.validateCredentials({
|
|
30
|
+
username: this.username,
|
|
31
|
+
hashedPassword,
|
|
32
|
+
preHashedPassword,
|
|
33
|
+
salt: this.salt,
|
|
34
|
+
}, this.connectionState);
|
|
35
|
+
if (!isValid) {
|
|
36
|
+
yield (0, backend_error_1.createBackendErrorMessage)({
|
|
37
|
+
severity: 'FATAL',
|
|
38
|
+
code: '28P01',
|
|
39
|
+
message: `password authentication failed for user "${this.username}"`,
|
|
40
|
+
});
|
|
41
|
+
yield connection_1.closeSignal;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.completed = true;
|
|
45
|
+
}
|
|
46
|
+
createInitialAuthMessage() {
|
|
47
|
+
return this.createAuthenticationMD5Password();
|
|
48
|
+
}
|
|
49
|
+
get isCompleted() {
|
|
50
|
+
return this.completed;
|
|
51
|
+
}
|
|
52
|
+
createAuthenticationMD5Password() {
|
|
53
|
+
this.writer.addInt32(5);
|
|
54
|
+
this.writer.add(Buffer.from(this.salt));
|
|
55
|
+
return this.writer.flush(message_codes_1.BackendMessageCode.AuthenticationResponse);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.Md5AuthFlow = Md5AuthFlow;
|
|
59
|
+
async function hashPreHashedPassword(preHashedPassword, salt) {
|
|
60
|
+
const hash = await md5(concat([
|
|
61
|
+
new TextEncoder().encode(preHashedPassword),
|
|
62
|
+
salt instanceof ArrayBuffer
|
|
63
|
+
? new Uint8Array(salt)
|
|
64
|
+
: new Uint8Array(salt.buffer, salt.byteOffset, salt.byteLength),
|
|
65
|
+
]));
|
|
66
|
+
return `md5${hash}`;
|
|
67
|
+
}
|
|
68
|
+
exports.hashPreHashedPassword = hashPreHashedPassword;
|
|
69
|
+
async function md5(value) {
|
|
70
|
+
const hash = await crypto.subtle.digest('MD5', typeof value === 'string' ? new TextEncoder().encode(value) : value);
|
|
71
|
+
return encodeHex(hash);
|
|
72
|
+
}
|
|
73
|
+
exports.md5 = md5;
|
|
74
|
+
function generateMd5Salt() {
|
|
75
|
+
const salt = new Uint8Array(4);
|
|
76
|
+
crypto.getRandomValues(salt);
|
|
77
|
+
return salt;
|
|
78
|
+
}
|
|
79
|
+
exports.generateMd5Salt = generateMd5Salt;
|
|
80
|
+
async function createPreHashedPassword(username, password) {
|
|
81
|
+
return await md5(`${password}${username}`);
|
|
82
|
+
}
|
|
83
|
+
exports.createPreHashedPassword = createPreHashedPassword;
|
|
84
|
+
function concat(buffers) {
|
|
85
|
+
let length = 0;
|
|
86
|
+
for (const buffer of buffers) {
|
|
87
|
+
length += buffer.length;
|
|
88
|
+
}
|
|
89
|
+
const output = new Uint8Array(length);
|
|
90
|
+
let index = 0;
|
|
91
|
+
for (const buffer of buffers) {
|
|
92
|
+
output.set(buffer, index);
|
|
93
|
+
index += buffer.length;
|
|
94
|
+
}
|
|
95
|
+
return output;
|
|
96
|
+
}
|
|
97
|
+
exports.concat = concat;
|
|
98
|
+
const hexTable = new TextEncoder().encode("0123456789abcdef");
|
|
99
|
+
const textEncoder = new TextEncoder();
|
|
100
|
+
const textDecoder = new TextDecoder();
|
|
101
|
+
function encodeHex(src) {
|
|
102
|
+
const u8 = validateBinaryLike(src);
|
|
103
|
+
const dst = new Uint8Array(u8.length * 2);
|
|
104
|
+
for (let i = 0; i < u8.length; i++) {
|
|
105
|
+
const v = u8[i];
|
|
106
|
+
dst[i * 2] = hexTable[v >> 4];
|
|
107
|
+
dst[i * 2 + 1] = hexTable[v & 0x0f];
|
|
108
|
+
}
|
|
109
|
+
return textDecoder.decode(dst);
|
|
110
|
+
}
|
|
111
|
+
exports.encodeHex = encodeHex;
|
|
112
|
+
function validateBinaryLike(source) {
|
|
113
|
+
if (typeof source === "string") {
|
|
114
|
+
return textEncoder.encode(source);
|
|
115
|
+
}
|
|
116
|
+
else if (source instanceof Uint8Array) {
|
|
117
|
+
return source;
|
|
118
|
+
}
|
|
119
|
+
else if (source instanceof ArrayBuffer) {
|
|
120
|
+
return new Uint8Array(source);
|
|
121
|
+
}
|
|
122
|
+
throw new TypeError(`Cannot validate the input as it must be a Uint8Array, a string, or an ArrayBuffer`);
|
|
123
|
+
}
|
|
124
|
+
exports.validateBinaryLike = validateBinaryLike;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PasswordAuthFlow = void 0;
|
|
4
|
+
const backend_error_1 = require("../backend-error");
|
|
5
|
+
const connection_1 = require("../connection");
|
|
6
|
+
const message_codes_1 = require("../message-codes");
|
|
7
|
+
const base_auth_flow_1 = require("./base-auth-flow");
|
|
8
|
+
class PasswordAuthFlow extends base_auth_flow_1.BaseAuthFlow {
|
|
9
|
+
constructor(params) {
|
|
10
|
+
super(params);
|
|
11
|
+
this.completed = false;
|
|
12
|
+
this.auth = {
|
|
13
|
+
...params.auth,
|
|
14
|
+
validateCredentials: params.auth.validateCredentials ??
|
|
15
|
+
(async ({ password, clearTextPassword }) => {
|
|
16
|
+
return password === clearTextPassword;
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
this.username = params.username;
|
|
20
|
+
}
|
|
21
|
+
async *handleClientMessage(message) {
|
|
22
|
+
const length = this.reader.int32();
|
|
23
|
+
const password = this.reader.cstring();
|
|
24
|
+
const clearTextPassword = await this.auth.getClearTextPassword({
|
|
25
|
+
username: this.username,
|
|
26
|
+
}, this.connectionState);
|
|
27
|
+
const isValid = await this.auth.validateCredentials({
|
|
28
|
+
username: this.username,
|
|
29
|
+
password,
|
|
30
|
+
clearTextPassword,
|
|
31
|
+
}, this.connectionState);
|
|
32
|
+
if (!isValid) {
|
|
33
|
+
yield (0, backend_error_1.createBackendErrorMessage)({
|
|
34
|
+
severity: 'FATAL',
|
|
35
|
+
code: '28P01',
|
|
36
|
+
message: `password authentication failed for user "${this.username}"`,
|
|
37
|
+
});
|
|
38
|
+
yield connection_1.closeSignal;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.completed = true;
|
|
42
|
+
}
|
|
43
|
+
createInitialAuthMessage() {
|
|
44
|
+
return this.createAuthenticationCleartextPassword();
|
|
45
|
+
}
|
|
46
|
+
get isCompleted() {
|
|
47
|
+
return this.completed;
|
|
48
|
+
}
|
|
49
|
+
createAuthenticationCleartextPassword() {
|
|
50
|
+
this.writer.addInt32(3);
|
|
51
|
+
return this.writer.flush(message_codes_1.BackendMessageCode.AuthenticationResponse);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.PasswordAuthFlow = PasswordAuthFlow;
|