firebase-tools-with-isolate 13.29.1 → 14.10.1-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/README.md +53 -4
- package/lib/api.js +10 -2
- package/lib/appdistribution/client.js +2 -2
- package/lib/apphosting/backend.js +157 -55
- package/lib/apphosting/config.js +121 -101
- package/lib/apphosting/githubConnections.js +65 -100
- package/lib/apphosting/repo.js +22 -36
- package/lib/apphosting/rollout.js +5 -11
- package/lib/apphosting/secrets/dialogs.js +13 -11
- package/lib/apphosting/secrets/index.js +47 -5
- package/lib/apphosting/utils.js +1 -3
- package/lib/apphosting/yaml.js +35 -49
- package/lib/auth.js +23 -6
- package/lib/bin/cli.js +99 -0
- package/lib/bin/firebase.js +7 -123
- package/lib/bin/mcp.js +49 -0
- package/lib/checkValidTargetFilters.js +1 -0
- package/lib/command.js +3 -2
- package/lib/commands/appdistribution-distribute.js +1 -1
- package/lib/commands/appdistribution-groups-create.js +1 -1
- package/lib/commands/appdistribution-groups-delete.js +1 -1
- package/lib/commands/appdistribution-groups-list.js +2 -2
- package/lib/commands/appdistribution-testers-add.js +1 -1
- package/lib/commands/appdistribution-testers-list.js +3 -3
- package/lib/commands/appdistribution-testers-remove.js +1 -1
- package/lib/commands/apphosting-backends-create.js +3 -3
- package/lib/commands/apphosting-backends-delete.js +23 -27
- package/lib/commands/apphosting-backends-get.js +12 -12
- package/lib/commands/apphosting-backends-list.js +5 -5
- package/lib/commands/apphosting-builds-create.js +8 -2
- package/lib/commands/apphosting-builds-get.js +8 -1
- package/lib/commands/apphosting-rollouts-create.js +3 -3
- package/lib/commands/apphosting-rollouts-list.js +8 -2
- package/lib/commands/apphosting-secrets-access.js +1 -1
- package/lib/commands/apphosting-secrets-describe.js +2 -2
- package/lib/commands/apphosting-secrets-grantaccess.js +20 -10
- package/lib/commands/apphosting-secrets-set.js +27 -1
- package/lib/commands/apps-android-sha-create.js +1 -1
- package/lib/commands/apps-android-sha-delete.js +1 -1
- package/lib/commands/apps-android-sha-list.js +2 -2
- package/lib/commands/apps-create.js +4 -108
- package/lib/commands/apps-init.js +94 -0
- package/lib/commands/apps-list.js +1 -1
- package/lib/commands/apps-sdkconfig.js +5 -10
- package/lib/commands/auth-export.js +1 -1
- package/lib/commands/auth-import.js +1 -1
- package/lib/commands/database-import.js +4 -6
- package/lib/commands/database-instances-create.js +1 -1
- package/lib/commands/database-instances-list.js +1 -1
- package/lib/commands/database-profile.js +1 -2
- package/lib/commands/database-remove.js +4 -6
- package/lib/commands/database-set.js +6 -6
- package/lib/commands/database-settings-set.js +1 -1
- package/lib/commands/database-update.js +6 -6
- package/lib/commands/dataconnect-sdk-generate.js +5 -2
- package/lib/commands/dataconnect-services-list.js +2 -2
- package/lib/commands/dataconnect-sql-diff.js +2 -2
- package/lib/commands/dataconnect-sql-grant.js +3 -3
- package/lib/commands/dataconnect-sql-migrate.js +2 -2
- package/lib/commands/dataconnect-sql-setup.js +39 -0
- package/lib/commands/dataconnect-sql-shell.js +5 -7
- package/lib/commands/deploy.js +4 -3
- package/lib/commands/emulators-exec.js +1 -1
- package/lib/commands/emulators-start.js +4 -3
- package/lib/commands/experiments-list.js +1 -1
- package/lib/commands/ext-dev-deprecate.js +1 -0
- package/lib/commands/ext-dev-init.js +3 -12
- package/lib/commands/ext-dev-list.js +1 -1
- package/lib/commands/ext-dev-register.js +3 -5
- package/lib/commands/ext-dev-undeprecate.js +1 -2
- package/lib/commands/ext-dev-usage.js +4 -6
- package/lib/commands/ext-export.js +1 -2
- package/lib/commands/ext-install.js +3 -3
- package/lib/commands/ext-sdk-install.js +1 -0
- package/lib/commands/ext-update.js +1 -0
- package/lib/commands/firestore-backups-delete.js +3 -4
- package/lib/commands/firestore-backups-get.js +1 -1
- package/lib/commands/firestore-backups-list.js +2 -2
- package/lib/commands/firestore-backups-schedules-create.js +4 -4
- package/lib/commands/firestore-backups-schedules-delete.js +3 -4
- package/lib/commands/firestore-backups-schedules-list.js +2 -2
- package/lib/commands/firestore-backups-schedules-update.js +1 -1
- package/lib/commands/firestore-databases-create.js +6 -6
- package/lib/commands/firestore-databases-delete.js +3 -7
- package/lib/commands/firestore-databases-get.js +1 -1
- package/lib/commands/firestore-databases-list.js +1 -1
- package/lib/commands/firestore-databases-restore.js +5 -5
- package/lib/commands/firestore-databases-update.js +4 -4
- package/lib/commands/firestore-delete.js +13 -14
- package/lib/commands/firestore-indexes-list.js +4 -4
- package/lib/commands/firestore-locations.js +1 -1
- package/lib/commands/functions-artifacts-setpolicy.js +132 -0
- package/lib/commands/functions-config-export.js +6 -10
- package/lib/commands/functions-delete.js +5 -7
- package/lib/commands/functions-deletegcfartifacts.js +5 -5
- package/lib/commands/functions-list.js +24 -33
- package/lib/commands/functions-secrets-access.js +1 -1
- package/lib/commands/functions-secrets-describe.js +1 -1
- package/lib/commands/functions-secrets-destroy.js +10 -12
- package/lib/commands/functions-secrets-get.js +1 -1
- package/lib/commands/functions-secrets-prune.js +14 -15
- package/lib/commands/functions-secrets-set.js +14 -18
- package/lib/commands/hosting-channel-create.js +1 -2
- package/lib/commands/hosting-channel-delete.js +4 -4
- package/lib/commands/hosting-channel-list.js +1 -1
- package/lib/commands/hosting-channel-open.js +2 -3
- package/lib/commands/hosting-disable.js +5 -5
- package/lib/commands/hosting-sites-delete.js +4 -4
- package/lib/commands/hosting-sites-get.js +1 -1
- package/lib/commands/hosting-sites-list.js +1 -1
- package/lib/commands/index.js +7 -4
- package/lib/commands/init.js +54 -60
- package/lib/commands/internaltesting-frameworks-compose.js +1 -1
- package/lib/commands/login-use.js +2 -11
- package/lib/commands/login.js +10 -8
- package/lib/commands/logout.js +2 -3
- package/lib/commands/mcp.js +11 -0
- package/lib/commands/open.js +4 -2
- package/lib/commands/projects-create.js +1 -2
- package/lib/commands/projects-list.js +1 -1
- package/lib/commands/remoteconfig-get.js +1 -1
- package/lib/commands/remoteconfig-rollback.js +5 -5
- package/lib/commands/remoteconfig-versions-list.js +2 -2
- package/lib/commands/setup-emulators-database.js +1 -1
- package/lib/commands/setup-emulators-dataconnect.js +1 -1
- package/lib/commands/setup-emulators-firestore.js +1 -1
- package/lib/commands/setup-emulators-pubsub.js +1 -1
- package/lib/commands/setup-emulators-storage.js +1 -1
- package/lib/commands/setup-emulators-ui.js +1 -1
- package/lib/commands/use.js +115 -111
- package/lib/config.js +49 -33
- package/lib/crashlytics/buildToolsJarHelper.js +1 -1
- package/lib/crashlytics/listTopIssues.js +45 -0
- package/lib/dataconnect/build.js +61 -4
- package/lib/dataconnect/client.js +26 -17
- package/lib/dataconnect/cloudAICompanionClient.js +72 -0
- package/lib/dataconnect/dataplaneClient.js +19 -2
- package/lib/dataconnect/ensureApis.js +6 -3
- package/lib/dataconnect/fileUtils.js +39 -6
- package/lib/dataconnect/freeTrial.js +21 -9
- package/lib/dataconnect/graphqlError.js +56 -2
- package/lib/dataconnect/provisionCloudSql.js +23 -12
- package/lib/dataconnect/schemaMigration.js +46 -26
- package/lib/dataconnect/types.js +5 -1
- package/lib/defaultCredentials.js +12 -1
- package/lib/deploy/apphosting/args.js +2 -0
- package/lib/deploy/apphosting/deploy.js +77 -0
- package/lib/deploy/apphosting/index.js +9 -0
- package/lib/deploy/apphosting/prepare.js +138 -0
- package/lib/deploy/apphosting/release.js +56 -0
- package/lib/deploy/apphosting/util.js +65 -0
- package/lib/deploy/dataconnect/deploy.js +14 -7
- package/lib/deploy/dataconnect/prepare.js +3 -5
- package/lib/deploy/extensions/v2FunctionHelper.js +2 -1
- package/lib/deploy/firestore/deploy.js +50 -4
- package/lib/deploy/functions/build.js +1 -0
- package/lib/deploy/functions/checkIam.js +41 -6
- package/lib/deploy/functions/containerCleaner.js +17 -2
- package/lib/deploy/functions/ensure.js +2 -1
- package/lib/deploy/functions/params.js +10 -17
- package/lib/deploy/functions/prepare.js +51 -18
- package/lib/deploy/functions/prepareFunctionsUpload.js +9 -5
- package/lib/deploy/functions/prompts.js +24 -17
- package/lib/deploy/functions/release/fabricator.js +4 -4
- package/lib/deploy/functions/release/index.js +27 -9
- package/lib/deploy/functions/release/planner.js +1 -0
- package/lib/deploy/functions/runtimes/discovery/index.js +13 -5
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +4 -4
- package/lib/deploy/functions/runtimes/python/index.js +4 -1
- package/lib/deploy/functions/runtimes/supported/types.js +17 -11
- package/lib/deploy/functions/services/firestore.js +23 -4
- package/lib/deploy/index.js +29 -10
- package/lib/deploy/lifecycleHooks.js +6 -12
- package/lib/emulator/ExpressBasedEmulator.js +1 -1
- package/lib/emulator/apphosting/config.js +15 -14
- package/lib/emulator/apphosting/index.js +2 -0
- package/lib/emulator/apphosting/serve.js +147 -10
- package/lib/emulator/auth/cloudFunctions.js +13 -1
- package/lib/emulator/auth/operations.js +2 -1
- package/lib/emulator/auth/widget_ui.js +2 -1
- package/lib/emulator/commandUtils.js +14 -20
- package/lib/emulator/constants.js +2 -0
- package/lib/emulator/controller.js +24 -9
- package/lib/emulator/dataconnect/pgliteServer.js +136 -45
- package/lib/emulator/dataconnectEmulator.js +34 -6
- package/lib/emulator/dataconnectToolkitController.js +5 -0
- package/lib/emulator/downloadableEmulatorInfo.json +81 -0
- package/lib/emulator/downloadableEmulators.js +28 -80
- package/lib/emulator/env.js +47 -1
- package/lib/emulator/extensionsEmulator.js +5 -3
- package/lib/emulator/functionsEmulator.js +6 -26
- package/lib/emulator/hub.js +5 -4
- package/lib/emulator/hubClient.js +5 -0
- package/lib/emulator/initEmulators.js +29 -15
- package/lib/emulator/ui.js +4 -8
- package/lib/ensureApiEnabled.js +32 -1
- package/lib/experiments.js +11 -12
- package/lib/extensions/askUserForEventsConfig.js +6 -15
- package/lib/extensions/askUserForParam.js +23 -52
- package/lib/extensions/change-log.js +1 -25
- package/lib/extensions/checkProjectBilling.js +3 -9
- package/lib/extensions/diagnose.js +3 -6
- package/lib/extensions/emulator/triggerHelper.js +4 -0
- package/lib/extensions/extensionsHelper.js +25 -31
- package/lib/extensions/listExtensions.js +1 -1
- package/lib/extensions/manifest.js +3 -7
- package/lib/extensions/paramHelper.js +11 -2
- package/lib/extensions/provisioningHelper.js +1 -1
- package/lib/extensions/tos.js +4 -2
- package/lib/extensions/utils.js +1 -10
- package/lib/firebaseConfigValidate.js +7 -5
- package/lib/firestore/delete.js +5 -4
- package/lib/firestore/pretty-print.js +1 -1
- package/lib/frameworks/angular/index.js +11 -6
- package/lib/frameworks/angular/utils.js +76 -47
- package/lib/frameworks/constants.js +1 -1
- package/lib/frameworks/index.js +6 -4
- package/lib/frameworks/next/index.js +7 -4
- package/lib/frameworks/utils.js +11 -3
- package/lib/frameworks/vite/index.js +2 -3
- package/lib/fsAsync.js +9 -2
- package/lib/fsutils.js +16 -1
- package/lib/functions/artifacts.js +196 -0
- package/lib/functions/secrets.js +15 -16
- package/lib/gcp/apphosting.js +13 -1
- package/lib/gcp/artifactregistry.js +27 -2
- package/lib/gcp/auth.js +113 -1
- package/lib/gcp/cloudbilling.js +12 -1
- package/lib/gcp/cloudfunctions.js +32 -4
- package/lib/gcp/cloudfunctionsv2.js +15 -9
- package/lib/gcp/cloudscheduler.js +2 -2
- package/lib/gcp/cloudsql/cloudsqladmin.js +32 -11
- package/lib/gcp/cloudsql/connect.js +21 -14
- package/lib/gcp/cloudsql/interactive.js +1 -1
- package/lib/gcp/cloudsql/permissions.js +46 -99
- package/lib/gcp/cloudsql/permissionsSetup.js +224 -0
- package/lib/gcp/computeEngine.js +19 -2
- package/lib/gcp/devConnect.js +6 -1
- package/lib/gcp/firestore.js +55 -16
- package/lib/gcp/iam.js +1 -5
- package/lib/gcp/proto.js +4 -3
- package/lib/gcp/run.js +18 -1
- package/lib/gcp/serviceusage.js +2 -1
- package/lib/gcp/storage.js +47 -1
- package/lib/gemini/fdcExperience.js +56 -0
- package/lib/gemini/types.js +2 -0
- package/lib/hosting/api.js +4 -0
- package/lib/hosting/implicitInit.js +7 -3
- package/lib/hosting/interactive.js +2 -3
- package/lib/index.js +1 -2
- package/lib/init/features/account.js +2 -4
- package/lib/init/features/apphosting.js +75 -6
- package/lib/init/features/database.js +63 -62
- package/lib/init/features/dataconnect/index.js +131 -85
- package/lib/init/features/dataconnect/sdk.js +73 -18
- package/lib/init/features/emulators.js +29 -46
- package/lib/init/features/firestore/index.js +79 -43
- package/lib/init/features/firestore/indexes.js +30 -45
- package/lib/init/features/firestore/rules.js +36 -62
- package/lib/init/features/functions/index.js +11 -16
- package/lib/init/features/functions/javascript.js +17 -30
- package/lib/init/features/functions/npm-dependencies.js +4 -8
- package/lib/init/features/functions/python.js +1 -3
- package/lib/init/features/functions/typescript.js +25 -43
- package/lib/init/features/genkit/index.js +111 -106
- package/lib/init/features/hosting/github.js +22 -52
- package/lib/init/features/hosting/index.js +37 -57
- package/lib/init/features/index.js +10 -5
- package/lib/init/features/project.js +18 -21
- package/lib/init/features/remoteconfig.js +5 -10
- package/lib/init/features/storage.js +30 -10
- package/lib/init/index.js +79 -24
- package/lib/logger.js +76 -3
- package/lib/management/apps.js +292 -7
- package/lib/management/projects.js +100 -52
- package/lib/mcp/errors.js +20 -0
- package/lib/mcp/index.js +227 -0
- package/lib/mcp/tool.js +12 -0
- package/lib/mcp/tools/apphosting/fetch_logs.js +68 -0
- package/lib/mcp/tools/apphosting/index.js +6 -0
- package/lib/mcp/tools/apphosting/list_backends.js +51 -0
- package/lib/mcp/tools/auth/disable_user.js +30 -0
- package/lib/mcp/tools/auth/get_user.js +38 -0
- package/lib/mcp/tools/auth/index.js +15 -0
- package/lib/mcp/tools/auth/list_users.js +36 -0
- package/lib/mcp/tools/auth/set_claims.js +43 -0
- package/lib/mcp/tools/auth/set_sms_region_policy.js +36 -0
- package/lib/mcp/tools/core/consult_assistant.js +28 -0
- package/lib/mcp/tools/core/create_android_sha.js +43 -0
- package/lib/mcp/tools/core/create_app.js +90 -0
- package/lib/mcp/tools/core/create_project.js +68 -0
- package/lib/mcp/tools/core/get_admin_sdk_config.js +26 -0
- package/lib/mcp/tools/core/get_environment.js +51 -0
- package/lib/mcp/tools/core/get_project.js +22 -0
- package/lib/mcp/tools/core/get_sdk_config.js +40 -0
- package/lib/mcp/tools/core/index.js +29 -0
- package/lib/mcp/tools/core/init.js +153 -0
- package/lib/mcp/tools/core/list_apps.js +34 -0
- package/lib/mcp/tools/core/list_projects.js +45 -0
- package/lib/mcp/tools/core/update_environment.js +55 -0
- package/lib/mcp/tools/crashlytics/index.js +5 -0
- package/lib/mcp/tools/crashlytics/list_top_issues.js +39 -0
- package/lib/mcp/tools/dataconnect/converter.js +60 -0
- package/lib/mcp/tools/dataconnect/emulator.js +16 -0
- package/lib/mcp/tools/dataconnect/execute_graphql.js +48 -0
- package/lib/mcp/tools/dataconnect/execute_graphql_read.js +48 -0
- package/lib/mcp/tools/dataconnect/execute_mutation.js +62 -0
- package/lib/mcp/tools/dataconnect/execute_query.js +62 -0
- package/lib/mcp/tools/dataconnect/generate_operation.js +34 -0
- package/lib/mcp/tools/dataconnect/generate_schema.js +26 -0
- package/lib/mcp/tools/dataconnect/get_connector.js +31 -0
- package/lib/mcp/tools/dataconnect/get_schema.js +31 -0
- package/lib/mcp/tools/dataconnect/index.js +23 -0
- package/lib/mcp/tools/dataconnect/list_services.js +23 -0
- package/lib/mcp/tools/firestore/converter.js +102 -0
- package/lib/mcp/tools/firestore/delete_document.js +50 -0
- package/lib/mcp/tools/firestore/get_documents.js +58 -0
- package/lib/mcp/tools/firestore/index.js +17 -0
- package/lib/mcp/tools/firestore/list_collections.js +36 -0
- package/lib/mcp/tools/firestore/query_collection.js +132 -0
- package/lib/mcp/tools/index.js +62 -0
- package/lib/mcp/tools/messaging/index.js +5 -0
- package/lib/mcp/tools/messaging/send_message.js +42 -0
- package/lib/mcp/tools/remoteconfig/get_template.js +27 -0
- package/lib/mcp/tools/remoteconfig/index.js +7 -0
- package/lib/mcp/tools/remoteconfig/publish_template.js +34 -0
- package/lib/mcp/tools/remoteconfig/rollback_template.js +29 -0
- package/lib/mcp/tools/rules/get_rules.js +29 -0
- package/lib/mcp/tools/rules/validate_rules.js +97 -0
- package/lib/mcp/tools/storage/get_download_url.js +40 -0
- package/lib/mcp/tools/storage/get_rules.js +26 -0
- package/lib/mcp/tools/storage/index.js +11 -0
- package/lib/mcp/types.js +13 -0
- package/lib/mcp/util.js +214 -0
- package/lib/mcp/util.test.js +468 -0
- package/lib/messaging/interfaces.js +2 -0
- package/lib/messaging/sendMessage.js +48 -0
- package/lib/operation-poller.js +3 -1
- package/lib/profileReport.js +1 -1
- package/lib/prompt.js +86 -54
- package/lib/remoteconfig/publish.js +39 -0
- package/lib/requireAuth.js +2 -2
- package/lib/requireTosAcceptance.js +4 -0
- package/lib/rulesDeploy.js +10 -15
- package/lib/track.js +7 -37
- package/lib/utils.js +28 -41
- package/lib/vsCodeUtils.js +7 -3
- package/package.json +31 -15
- package/schema/connector-yaml.json +12 -0
- package/schema/dataconnect-yaml.json +5 -0
- package/schema/extension-yaml.json +17 -4
- package/schema/firebase-config.json +1117 -2121
- package/standalone/package-lock.json +1255 -992
- package/standalone/package.json +1 -1
- package/templates/dataconnect-prompts/operation-generation-cursor-windsurf-rule.txt +273 -0
- package/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt +653 -0
- package/templates/genkit/firebase.0.9.0.template +1 -1
- package/templates/genkit/firebase.1.0.0.template +71 -0
- package/templates/init/dataconnect/connector.yaml +4 -1
- package/templates/init/dataconnect/dataconnect.yaml +1 -1
- package/templates/init/dataconnect/mutations.gql +9 -26
- package/templates/init/dataconnect/queries.gql +9 -14
- package/templates/init/dataconnect/schema.gql +28 -21
- package/templates/init/firestore/firestore.rules +2 -0
- package/templates/init/functions/javascript/index.js +14 -1
- package/templates/init/functions/javascript/package.lint.json +1 -1
- package/templates/init/functions/javascript/package.nolint.json +1 -1
- package/templates/init/functions/python/_gitignore +6 -1
- package/templates/init/functions/python/main.py +8 -0
- package/templates/init/functions/typescript/index.ts +14 -1
- package/templates/init/functions/typescript/package.lint.json +2 -2
- package/templates/init/functions/typescript/package.nolint.json +3 -3
- package/lib/commands/apphosting-config-export.js +0 -28
- package/lib/commands/experimental-functions-shell.js +0 -13
- package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +0 -11
- package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +0 -58
- package/lib/emulator/dataconnect/pg-gateway/auth/index.js +0 -22
- package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +0 -124
- package/lib/emulator/dataconnect/pg-gateway/auth/password.js +0 -54
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +0 -34
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +0 -270
- package/lib/emulator/dataconnect/pg-gateway/backend-error.js +0 -75
- package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +0 -54
- package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +0 -79
- package/lib/emulator/dataconnect/pg-gateway/connection.js +0 -315
- package/lib/emulator/dataconnect/pg-gateway/connection.types.js +0 -8
- package/lib/emulator/dataconnect/pg-gateway/crypto.js +0 -40
- package/lib/emulator/dataconnect/pg-gateway/duplex.js +0 -53
- package/lib/emulator/dataconnect/pg-gateway/index.js +0 -27
- package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +0 -82
- package/lib/emulator/dataconnect/pg-gateway/message-codes.js +0 -52
- package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +0 -16
- package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +0 -35
- package/lib/emulator/dataconnect/pg-gateway/utils.js +0 -40
- package/templates/setup/web.js +0 -5
- /package/lib/{emulator/dataconnect/pg-gateway/auth/trust.js → dataconnect/cloudAICompanionTypes.js} +0 -0
|
@@ -1,89 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const error_1 = require("../../error");
|
|
10
|
-
function firebaseowner(databaseId) {
|
|
11
|
-
return `firebaseowner_${databaseId}_public`;
|
|
3
|
+
exports.defaultPermissions = exports.readerRolePermissions = exports.writerRolePermissions = exports.ownerRolePermissions = exports.firebasewriter = exports.firebasereader = exports.firebaseowner = exports.CLOUDSQL_SUPER_USER = exports.FIREBASE_SUPER_USER = exports.DEFAULT_SCHEMA = void 0;
|
|
4
|
+
exports.DEFAULT_SCHEMA = "public";
|
|
5
|
+
exports.FIREBASE_SUPER_USER = "firebasesuperuser";
|
|
6
|
+
exports.CLOUDSQL_SUPER_USER = "cloudsqlsuperuser";
|
|
7
|
+
function firebaseowner(databaseId, schema = exports.DEFAULT_SCHEMA) {
|
|
8
|
+
return `firebaseowner_${databaseId}_${schema}`;
|
|
12
9
|
}
|
|
13
10
|
exports.firebaseowner = firebaseowner;
|
|
14
|
-
function firebasereader(databaseId) {
|
|
15
|
-
return `firebasereader_${databaseId}
|
|
11
|
+
function firebasereader(databaseId, schema = exports.DEFAULT_SCHEMA) {
|
|
12
|
+
return `firebasereader_${databaseId}_${schema}`;
|
|
16
13
|
}
|
|
17
14
|
exports.firebasereader = firebasereader;
|
|
18
|
-
function firebasewriter(databaseId) {
|
|
19
|
-
return `firebasewriter_${databaseId}
|
|
15
|
+
function firebasewriter(databaseId, schema = exports.DEFAULT_SCHEMA) {
|
|
16
|
+
return `firebasewriter_${databaseId}_${schema}`;
|
|
20
17
|
}
|
|
21
18
|
exports.firebasewriter = firebasewriter;
|
|
22
|
-
exports.fdcSqlRoleMap = {
|
|
23
|
-
owner: firebaseowner,
|
|
24
|
-
writer: firebasewriter,
|
|
25
|
-
reader: firebasereader,
|
|
26
|
-
};
|
|
27
|
-
async function checkSQLRoleIsGranted(options, instanceId, databaseId, grantedRole, granteeRole) {
|
|
28
|
-
const checkCmd = `
|
|
29
|
-
DO $$
|
|
30
|
-
DECLARE
|
|
31
|
-
role_count INTEGER;
|
|
32
|
-
BEGIN
|
|
33
|
-
-- Count the number of rows matching the criteria
|
|
34
|
-
SELECT COUNT(*)
|
|
35
|
-
INTO role_count
|
|
36
|
-
FROM
|
|
37
|
-
pg_auth_members m
|
|
38
|
-
JOIN
|
|
39
|
-
pg_roles grantee ON grantee.oid = m.member
|
|
40
|
-
JOIN
|
|
41
|
-
pg_roles granted ON granted.oid = m.roleid
|
|
42
|
-
JOIN
|
|
43
|
-
pg_roles grantor ON grantor.oid = m.grantor
|
|
44
|
-
WHERE
|
|
45
|
-
granted.rolname = '${grantedRole}'
|
|
46
|
-
AND grantee.rolname = '${granteeRole}';
|
|
47
|
-
|
|
48
|
-
-- If no rows were found, raise an exception
|
|
49
|
-
IF role_count = 0 THEN
|
|
50
|
-
RAISE EXCEPTION 'Role "%", is not granted to role "%".', '${grantedRole}', '${granteeRole}';
|
|
51
|
-
END IF;
|
|
52
|
-
END $$;
|
|
53
|
-
`;
|
|
54
|
-
try {
|
|
55
|
-
await (0, connect_1.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [checkCmd], true);
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
if (e instanceof error_1.FirebaseError && e.message.includes("not granted to role")) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
logger_1.logger.error(`Role Check Failed: ${e}`);
|
|
63
|
-
throw e;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.checkSQLRoleIsGranted = checkSQLRoleIsGranted;
|
|
67
|
-
async function iamUserIsCSQLAdmin(options) {
|
|
68
|
-
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
69
|
-
const requiredPermissions = [
|
|
70
|
-
"cloudsql.instances.connect",
|
|
71
|
-
"cloudsql.instances.get",
|
|
72
|
-
"cloudsql.users.create",
|
|
73
|
-
"cloudsql.users.update",
|
|
74
|
-
];
|
|
75
|
-
try {
|
|
76
|
-
const iamResult = await (0, iam_1.testIamPermissions)(projectId, requiredPermissions);
|
|
77
|
-
return iamResult.passed;
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
logger_1.logger.debug(`[iam] error while checking permissions, command may fail: ${err}`);
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.iamUserIsCSQLAdmin = iamUserIsCSQLAdmin;
|
|
85
19
|
function ownerRolePermissions(databaseId, superuser, schema) {
|
|
86
|
-
const firebaseOwnerRole = firebaseowner(databaseId);
|
|
20
|
+
const firebaseOwnerRole = firebaseowner(databaseId, schema);
|
|
87
21
|
return [
|
|
88
22
|
`do
|
|
89
23
|
$$
|
|
@@ -102,8 +36,9 @@ function ownerRolePermissions(databaseId, superuser, schema) {
|
|
|
102
36
|
`GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseOwnerRole}"`,
|
|
103
37
|
];
|
|
104
38
|
}
|
|
39
|
+
exports.ownerRolePermissions = ownerRolePermissions;
|
|
105
40
|
function writerRolePermissions(databaseId, superuser, schema) {
|
|
106
|
-
const firebaseWriterRole = firebasewriter(databaseId);
|
|
41
|
+
const firebaseWriterRole = firebasewriter(databaseId, schema);
|
|
107
42
|
return [
|
|
108
43
|
`do
|
|
109
44
|
$$
|
|
@@ -120,15 +55,11 @@ function writerRolePermissions(databaseId, superuser, schema) {
|
|
|
120
55
|
`GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
121
56
|
`GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
122
57
|
`GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
123
|
-
`SET ROLE = '${firebaseowner(databaseId)}';`,
|
|
124
|
-
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON TABLES TO "${firebaseWriterRole}";`,
|
|
125
|
-
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT USAGE ON SEQUENCES TO "${firebaseWriterRole}";`,
|
|
126
|
-
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT EXECUTE ON FUNCTIONS TO "${firebaseWriterRole}"`,
|
|
127
|
-
`SET ROLE = cloudsqlsuperuser`,
|
|
128
58
|
];
|
|
129
59
|
}
|
|
60
|
+
exports.writerRolePermissions = writerRolePermissions;
|
|
130
61
|
function readerRolePermissions(databaseId, superuser, schema) {
|
|
131
|
-
const firebaseReaderRole = firebasereader(databaseId);
|
|
62
|
+
const firebaseReaderRole = firebasereader(databaseId, schema);
|
|
132
63
|
return [
|
|
133
64
|
`do
|
|
134
65
|
$$
|
|
@@ -145,21 +76,37 @@ function readerRolePermissions(databaseId, superuser, schema) {
|
|
|
145
76
|
`GRANT SELECT ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
146
77
|
`GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
147
78
|
`GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
148
|
-
`SET ROLE = '${firebaseowner(databaseId)}';`,
|
|
149
|
-
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT SELECT ON TABLES TO "${firebaseReaderRole}";`,
|
|
150
|
-
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT SELECT, USAGE ON SEQUENCES TO "${firebaseReaderRole}";`,
|
|
151
|
-
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT EXECUTE ON FUNCTIONS TO "${firebaseReaderRole}"`,
|
|
152
|
-
`SET ROLE = cloudsqlsuperuser`,
|
|
153
79
|
];
|
|
154
80
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
81
|
+
exports.readerRolePermissions = readerRolePermissions;
|
|
82
|
+
function defaultPermissions(databaseId, schema, ownerRole) {
|
|
83
|
+
const firebaseWriterRole = firebasewriter(databaseId, schema);
|
|
84
|
+
const firebaseReaderRole = firebasereader(databaseId, schema);
|
|
85
|
+
return [
|
|
86
|
+
`ALTER DEFAULT PRIVILEGES
|
|
87
|
+
FOR ROLE "${ownerRole}"
|
|
88
|
+
IN SCHEMA "${schema}"
|
|
89
|
+
GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON TABLES TO "${firebaseWriterRole}";`,
|
|
90
|
+
`ALTER DEFAULT PRIVILEGES
|
|
91
|
+
FOR ROLE "${ownerRole}"
|
|
92
|
+
IN SCHEMA "${schema}"
|
|
93
|
+
GRANT USAGE ON SEQUENCES TO "${firebaseWriterRole}";`,
|
|
94
|
+
`ALTER DEFAULT PRIVILEGES
|
|
95
|
+
FOR ROLE "${ownerRole}"
|
|
96
|
+
IN SCHEMA "${schema}"
|
|
97
|
+
GRANT EXECUTE ON FUNCTIONS TO "${firebaseWriterRole}";`,
|
|
98
|
+
`ALTER DEFAULT PRIVILEGES
|
|
99
|
+
FOR ROLE "${ownerRole}"
|
|
100
|
+
IN SCHEMA "${schema}"
|
|
101
|
+
GRANT SELECT ON TABLES TO "${firebaseReaderRole}";`,
|
|
102
|
+
`ALTER DEFAULT PRIVILEGES
|
|
103
|
+
FOR ROLE "${ownerRole}"
|
|
104
|
+
IN SCHEMA "${schema}"
|
|
105
|
+
GRANT USAGE ON SEQUENCES TO "${firebaseReaderRole}";`,
|
|
106
|
+
`ALTER DEFAULT PRIVILEGES
|
|
107
|
+
FOR ROLE "${ownerRole}"
|
|
108
|
+
IN SCHEMA "${schema}"
|
|
109
|
+
GRANT EXECUTE ON FUNCTIONS TO "${firebaseReaderRole}";`,
|
|
110
|
+
];
|
|
164
111
|
}
|
|
165
|
-
exports.
|
|
112
|
+
exports.defaultPermissions = defaultPermissions;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.brownfieldSqlSetup = exports.setupBrownfieldAsGreenfield = exports.getSchemaMetadata = exports.greenFieldSchemaSetup = exports.setupSQLPermissions = exports.checkSQLRoleIsGranted = exports.fdcSqlRoleMap = exports.SchemaSetupStatus = void 0;
|
|
4
|
+
const clc = require("colorette");
|
|
5
|
+
const permissions_1 = require("./permissions");
|
|
6
|
+
const cloudsqladmin_1 = require("./cloudsqladmin");
|
|
7
|
+
const connect_1 = require("./connect");
|
|
8
|
+
const logger_1 = require("../../logger");
|
|
9
|
+
const prompt_1 = require("../../prompt");
|
|
10
|
+
const error_1 = require("../../error");
|
|
11
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
12
|
+
const connect_2 = require("./connect");
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
14
|
+
const connect_3 = require("./connect");
|
|
15
|
+
const utils = require("../../utils");
|
|
16
|
+
var SchemaSetupStatus;
|
|
17
|
+
(function (SchemaSetupStatus) {
|
|
18
|
+
SchemaSetupStatus["NotSetup"] = "not-setup";
|
|
19
|
+
SchemaSetupStatus["GreenField"] = "greenfield";
|
|
20
|
+
SchemaSetupStatus["BrownField"] = "brownfield";
|
|
21
|
+
SchemaSetupStatus["NotFound"] = "not-found";
|
|
22
|
+
})(SchemaSetupStatus = exports.SchemaSetupStatus || (exports.SchemaSetupStatus = {}));
|
|
23
|
+
exports.fdcSqlRoleMap = {
|
|
24
|
+
owner: permissions_1.firebaseowner,
|
|
25
|
+
writer: permissions_1.firebasewriter,
|
|
26
|
+
reader: permissions_1.firebasereader,
|
|
27
|
+
};
|
|
28
|
+
async function checkSQLRoleIsGranted(options, instanceId, databaseId, grantedRole, granteeRole) {
|
|
29
|
+
const checkCmd = `
|
|
30
|
+
DO $$
|
|
31
|
+
DECLARE
|
|
32
|
+
role_count INTEGER;
|
|
33
|
+
BEGIN
|
|
34
|
+
-- Count the number of rows matching the criteria
|
|
35
|
+
SELECT COUNT(*)
|
|
36
|
+
INTO role_count
|
|
37
|
+
FROM
|
|
38
|
+
pg_auth_members m
|
|
39
|
+
JOIN
|
|
40
|
+
pg_roles grantee ON grantee.oid = m.member
|
|
41
|
+
JOIN
|
|
42
|
+
pg_roles granted ON granted.oid = m.roleid
|
|
43
|
+
JOIN
|
|
44
|
+
pg_roles grantor ON grantor.oid = m.grantor
|
|
45
|
+
WHERE
|
|
46
|
+
granted.rolname = '${grantedRole}'
|
|
47
|
+
AND grantee.rolname = '${granteeRole}';
|
|
48
|
+
|
|
49
|
+
-- If no rows were found, raise an exception
|
|
50
|
+
IF role_count = 0 THEN
|
|
51
|
+
RAISE EXCEPTION 'Role "%", is not granted to role "%".', '${grantedRole}', '${granteeRole}';
|
|
52
|
+
END IF;
|
|
53
|
+
END $$;
|
|
54
|
+
`;
|
|
55
|
+
try {
|
|
56
|
+
await (0, connect_2.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [checkCmd], true);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
if (e instanceof error_1.FirebaseError && e.message.includes("not granted to role")) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
logger_1.logger.error(`Role Check Failed: ${e}`);
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.checkSQLRoleIsGranted = checkSQLRoleIsGranted;
|
|
68
|
+
async function setupSQLPermissions(instanceId, databaseId, schemaInfo, options, silent = false) {
|
|
69
|
+
const logFn = silent
|
|
70
|
+
? logger_1.logger.debug
|
|
71
|
+
: (message) => {
|
|
72
|
+
return utils.logLabeledBullet("dataconnect", message);
|
|
73
|
+
};
|
|
74
|
+
const schema = schemaInfo.name;
|
|
75
|
+
logFn(`Detected schema "${schema}" setup status is ${schemaInfo.setupStatus}. Running setup...`);
|
|
76
|
+
const userIsCSQLAdmin = await (0, cloudsqladmin_1.iamUserIsCSQLAdmin)(options);
|
|
77
|
+
if (!userIsCSQLAdmin) {
|
|
78
|
+
throw new error_1.FirebaseError(`Missing required IAM permission to setup SQL schemas. SQL schema setup requires 'roles/cloudsql.admin' or an equivalent role.`);
|
|
79
|
+
}
|
|
80
|
+
await (0, connect_1.setupIAMUsers)(instanceId, databaseId, options);
|
|
81
|
+
let runGreenfieldSetup = false;
|
|
82
|
+
if (schemaInfo.setupStatus === SchemaSetupStatus.GreenField) {
|
|
83
|
+
runGreenfieldSetup = true;
|
|
84
|
+
logFn(`Database ${databaseId} has already been setup as greenfield project. Rerunning setup to repair any missing permissions.`);
|
|
85
|
+
}
|
|
86
|
+
if (schemaInfo.tables.length === 0) {
|
|
87
|
+
runGreenfieldSetup = true;
|
|
88
|
+
logFn(`Found no tables in schema "${schema}", assuming greenfield project.`);
|
|
89
|
+
}
|
|
90
|
+
if (runGreenfieldSetup) {
|
|
91
|
+
const greenfieldSetupCmds = await greenFieldSchemaSetup(instanceId, databaseId, schema, options);
|
|
92
|
+
await (0, connect_2.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, greenfieldSetupCmds, silent, true);
|
|
93
|
+
logFn(clc.green("Database setup complete."));
|
|
94
|
+
return SchemaSetupStatus.GreenField;
|
|
95
|
+
}
|
|
96
|
+
if (options.nonInteractive || options.force) {
|
|
97
|
+
throw new error_1.FirebaseError(`Schema "${schema}" isn't set up and can only be set up in interactive mode.`);
|
|
98
|
+
}
|
|
99
|
+
const currentTablesOwners = [...new Set(schemaInfo.tables.map((t) => t.owner))];
|
|
100
|
+
logFn(`We found some existing object owners [${currentTablesOwners.join(", ")}] in your cloudsql "${schema}" schema.`);
|
|
101
|
+
const shouldSetupGreenfield = await (0, prompt_1.confirm)({
|
|
102
|
+
message: clc.yellow("Would you like FDC to handle SQL migrations for you moving forward?\n" +
|
|
103
|
+
`This means we will transfer schema and tables ownership to ${(0, permissions_1.firebaseowner)(databaseId, schema)}\n` +
|
|
104
|
+
"Note: your existing migration tools/roles may lose access."),
|
|
105
|
+
default: false,
|
|
106
|
+
});
|
|
107
|
+
if (shouldSetupGreenfield) {
|
|
108
|
+
await setupBrownfieldAsGreenfield(instanceId, databaseId, schemaInfo, options, silent);
|
|
109
|
+
logger_1.logger.info(clc.green("Database setup complete."));
|
|
110
|
+
logFn(clc.yellow("IMPORTANT: please uncomment 'schemaValidation: \"COMPATIBLE\"' in your dataconnect.yaml file to avoid dropping any existing tables by mistake."));
|
|
111
|
+
return SchemaSetupStatus.GreenField;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
logFn(clc.yellow("Setting up database in brownfield mode.\n" +
|
|
115
|
+
`Note: SQL migrations can't be done through ${clc.bold("firebase dataconnect:sql:migrate")} in this mode.`));
|
|
116
|
+
await brownfieldSqlSetup(instanceId, databaseId, schemaInfo, options, silent);
|
|
117
|
+
logFn(clc.green("Brownfield database setup complete."));
|
|
118
|
+
return SchemaSetupStatus.BrownField;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.setupSQLPermissions = setupSQLPermissions;
|
|
122
|
+
async function greenFieldSchemaSetup(instanceId, databaseId, schema, options) {
|
|
123
|
+
const revokes = [];
|
|
124
|
+
if (await checkSQLRoleIsGranted(options, instanceId, databaseId, "cloudsqlsuperuser", (0, permissions_1.firebaseowner)(databaseId))) {
|
|
125
|
+
logger_1.logger.warn("Detected cloudsqlsuperuser was previously given to firebase owner, revoking to improve database security.");
|
|
126
|
+
revokes.push(`REVOKE "cloudsqlsuperuser" FROM "${(0, permissions_1.firebaseowner)(databaseId)}"`);
|
|
127
|
+
}
|
|
128
|
+
const user = (await (0, connect_2.getIAMUser)(options)).user;
|
|
129
|
+
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
130
|
+
const { user: fdcP4SAUser } = (0, connect_3.toDatabaseUser)((0, connect_3.getDataConnectP4SA)(projectNumber));
|
|
131
|
+
const sqlRoleSetupCmds = (0, lodash_1.concat)(revokes, [`CREATE SCHEMA IF NOT EXISTS "${schema}"`], (0, permissions_1.ownerRolePermissions)(databaseId, permissions_1.FIREBASE_SUPER_USER, schema), (0, permissions_1.writerRolePermissions)(databaseId, permissions_1.FIREBASE_SUPER_USER, schema), (0, permissions_1.readerRolePermissions)(databaseId, permissions_1.FIREBASE_SUPER_USER, schema), `GRANT "${(0, permissions_1.firebaseowner)(databaseId, schema)}" TO "${user}"`, `GRANT "${(0, permissions_1.firebasewriter)(databaseId, schema)}" TO "${fdcP4SAUser}"`, (0, permissions_1.defaultPermissions)(databaseId, schema, (0, permissions_1.firebaseowner)(databaseId, schema)));
|
|
132
|
+
return sqlRoleSetupCmds;
|
|
133
|
+
}
|
|
134
|
+
exports.greenFieldSchemaSetup = greenFieldSchemaSetup;
|
|
135
|
+
async function getSchemaMetadata(instanceId, databaseId, schema, options) {
|
|
136
|
+
const checkSchemaExists = await (0, connect_2.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [
|
|
137
|
+
`SELECT pg_get_userbyid(nspowner)
|
|
138
|
+
FROM pg_namespace
|
|
139
|
+
WHERE nspname = '${schema}';`,
|
|
140
|
+
], true);
|
|
141
|
+
if (!checkSchemaExists[0].rows[0]) {
|
|
142
|
+
return {
|
|
143
|
+
name: schema,
|
|
144
|
+
owner: null,
|
|
145
|
+
setupStatus: SchemaSetupStatus.NotFound,
|
|
146
|
+
tables: [],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const schemaOwner = checkSchemaExists[0].rows[0].pg_get_userbyid;
|
|
150
|
+
const cmd = `SELECT tablename, tableowner FROM pg_tables WHERE schemaname='${schema}'`;
|
|
151
|
+
const res = await (0, connect_2.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [cmd], true);
|
|
152
|
+
const tables = res[0].rows.map((row) => {
|
|
153
|
+
return {
|
|
154
|
+
name: row.tablename,
|
|
155
|
+
owner: row.tableowner,
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
const checkRoleExists = async (role) => {
|
|
159
|
+
const cmd = [`SELECT to_regrole('"${role}"') IS NOT NULL AS exists;`];
|
|
160
|
+
const result = await (0, connect_2.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, cmd, true);
|
|
161
|
+
return result[0].rows[0].exists;
|
|
162
|
+
};
|
|
163
|
+
let setupStatus;
|
|
164
|
+
if (!(await checkRoleExists((0, permissions_1.firebasewriter)(databaseId, schema)))) {
|
|
165
|
+
setupStatus = SchemaSetupStatus.NotSetup;
|
|
166
|
+
}
|
|
167
|
+
else if (tables.every((table) => table.owner === (0, permissions_1.firebaseowner)(databaseId, schema)) &&
|
|
168
|
+
schemaOwner === (0, permissions_1.firebaseowner)(databaseId, schema)) {
|
|
169
|
+
setupStatus = SchemaSetupStatus.GreenField;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
setupStatus = SchemaSetupStatus.BrownField;
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
name: schema,
|
|
176
|
+
owner: schemaOwner,
|
|
177
|
+
setupStatus,
|
|
178
|
+
tables: tables,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
exports.getSchemaMetadata = getSchemaMetadata;
|
|
182
|
+
function filterTableOwners(schemaInfo, databaseId) {
|
|
183
|
+
return [...new Set(schemaInfo.tables.map((t) => t.owner))].filter((owner) => owner !== permissions_1.CLOUDSQL_SUPER_USER && owner !== (0, permissions_1.firebaseowner)(databaseId, schemaInfo.name));
|
|
184
|
+
}
|
|
185
|
+
async function setupBrownfieldAsGreenfield(instanceId, databaseId, schemaInfo, options, silent = false) {
|
|
186
|
+
const schema = schemaInfo.name;
|
|
187
|
+
const firebaseOwnerRole = (0, permissions_1.firebaseowner)(databaseId, schema);
|
|
188
|
+
const uniqueTablesOwners = filterTableOwners(schemaInfo, databaseId);
|
|
189
|
+
const grantOwnersToSuperuserCmds = uniqueTablesOwners.map((owner) => `GRANT "${owner}" TO "${permissions_1.FIREBASE_SUPER_USER}"`);
|
|
190
|
+
const revokeOwnersFromSuperuserCmds = uniqueTablesOwners.map((owner) => `REVOKE "${owner}" FROM "${permissions_1.FIREBASE_SUPER_USER}"`);
|
|
191
|
+
const greenfieldSetupCmds = await greenFieldSchemaSetup(instanceId, databaseId, schema, options);
|
|
192
|
+
const grantCmds = uniqueTablesOwners.map((owner) => `GRANT "${(0, permissions_1.firebasewriter)(databaseId, schema)}" TO "${owner}"`);
|
|
193
|
+
const alterTableCmds = schemaInfo.tables.map((table) => `ALTER TABLE "${schema}"."${table.name}" OWNER TO "${firebaseOwnerRole}";`);
|
|
194
|
+
const setupCmds = [
|
|
195
|
+
...grantOwnersToSuperuserCmds,
|
|
196
|
+
...greenfieldSetupCmds,
|
|
197
|
+
...grantCmds,
|
|
198
|
+
...alterTableCmds,
|
|
199
|
+
...revokeOwnersFromSuperuserCmds,
|
|
200
|
+
];
|
|
201
|
+
await (0, connect_2.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, setupCmds, silent, true);
|
|
202
|
+
}
|
|
203
|
+
exports.setupBrownfieldAsGreenfield = setupBrownfieldAsGreenfield;
|
|
204
|
+
async function brownfieldSqlSetup(instanceId, databaseId, schemaInfo, options, silent = false) {
|
|
205
|
+
const schema = schemaInfo.name;
|
|
206
|
+
const uniqueTablesOwners = filterTableOwners(schemaInfo, databaseId);
|
|
207
|
+
const grantOwnersToFirebasesuperuser = uniqueTablesOwners.map((owner) => `GRANT "${owner}" TO "${permissions_1.FIREBASE_SUPER_USER}"`);
|
|
208
|
+
const revokeOwnersFromFirebasesuperuser = uniqueTablesOwners.map((owner) => `REVOKE "${owner}" FROM "${permissions_1.FIREBASE_SUPER_USER}"`);
|
|
209
|
+
const iamUser = (await (0, connect_2.getIAMUser)(options)).user;
|
|
210
|
+
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
211
|
+
const { user: fdcP4SAUser } = (0, connect_3.toDatabaseUser)((0, connect_3.getDataConnectP4SA)(projectNumber));
|
|
212
|
+
const firebaseDefaultPermissions = uniqueTablesOwners.flatMap((owner) => (0, permissions_1.defaultPermissions)(databaseId, schema, owner));
|
|
213
|
+
const brownfieldSetupCmds = [
|
|
214
|
+
...grantOwnersToFirebasesuperuser,
|
|
215
|
+
...(0, permissions_1.writerRolePermissions)(databaseId, permissions_1.FIREBASE_SUPER_USER, schema),
|
|
216
|
+
...(0, permissions_1.readerRolePermissions)(databaseId, permissions_1.FIREBASE_SUPER_USER, schema),
|
|
217
|
+
`GRANT "${(0, permissions_1.firebasewriter)(databaseId, schema)}" TO "${iamUser}"`,
|
|
218
|
+
`GRANT "${(0, permissions_1.firebasewriter)(databaseId, schema)}" TO "${fdcP4SAUser}"`,
|
|
219
|
+
...firebaseDefaultPermissions,
|
|
220
|
+
...revokeOwnersFromFirebasesuperuser,
|
|
221
|
+
];
|
|
222
|
+
await (0, connect_2.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, brownfieldSetupCmds, silent, true);
|
|
223
|
+
}
|
|
224
|
+
exports.brownfieldSqlSetup = brownfieldSqlSetup;
|
package/lib/gcp/computeEngine.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDefaultServiceAccount = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const apiv2_1 = require("../apiv2");
|
|
7
|
+
const computeClient = () => new apiv2_1.Client({ urlPrefix: (0, api_1.computeOrigin)() });
|
|
8
|
+
const defaultServiceAccountCache = {};
|
|
9
|
+
async function getDefaultServiceAccount(projectNumber) {
|
|
10
|
+
if (defaultServiceAccountCache[projectNumber]) {
|
|
11
|
+
return defaultServiceAccountCache[projectNumber];
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const res = await computeClient().get(`compute/v1/projects/${projectNumber}`);
|
|
15
|
+
defaultServiceAccountCache[projectNumber] = res.body.defaultServiceAccount;
|
|
16
|
+
return res.body.defaultServiceAccount;
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
const bestGuess = `${projectNumber}-compute@developer.gserviceaccount.com`;
|
|
20
|
+
logger_1.logger.debug(`unable to look up default compute service account. Falling back to ${bestGuess}. Error: ${JSON.stringify(err)}`);
|
|
21
|
+
return bestGuess;
|
|
22
|
+
}
|
|
6
23
|
}
|
|
7
24
|
exports.getDefaultServiceAccount = getDefaultServiceAccount;
|
package/lib/gcp/devConnect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRepoDetailsFromBackend = exports.extractGitRepositoryLinkComponents = exports.generateP4SA = exports.serviceAgentEmail = exports.sortConnectionsByCreateTime = exports.fetchGitRepositoryLinkReadToken = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.fetchGitHubInstallations = exports.listAllBranches = exports.listAllLinkableGitRepositories = exports.listAllConnections = exports.getConnection = exports.deleteConnection = exports.createConnection = exports.client = void 0;
|
|
3
|
+
exports.getRepoDetailsFromBackend = exports.extractGitRepositoryLinkComponents = exports.generateP4SA = exports.serviceAgentEmail = exports.sortConnectionsByCreateTime = exports.fetchGitRepositoryLinkReadToken = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.parseGitRepositoryLinkName = exports.fetchGitHubInstallations = exports.listAllBranches = exports.listAllLinkableGitRepositories = exports.listAllConnections = exports.getConnection = exports.deleteConnection = exports.createConnection = exports.client = void 0;
|
|
4
4
|
const apiv2_1 = require("../apiv2");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
const serviceusage_1 = require("./serviceusage");
|
|
@@ -106,6 +106,11 @@ async function fetchGitHubInstallations(projectId, location, connectionId) {
|
|
|
106
106
|
return res.body.installations;
|
|
107
107
|
}
|
|
108
108
|
exports.fetchGitHubInstallations = fetchGitHubInstallations;
|
|
109
|
+
function parseGitRepositoryLinkName(gitRepositoryLinkName) {
|
|
110
|
+
const [, projectName, , location, , connectionName, , id] = gitRepositoryLinkName.split("/");
|
|
111
|
+
return { projectName, location, connectionName, id };
|
|
112
|
+
}
|
|
113
|
+
exports.parseGitRepositoryLinkName = parseGitRepositoryLinkName;
|
|
109
114
|
async function createGitRepositoryLink(projectId, location, connectionId, gitRepositoryLinkId, cloneUri) {
|
|
110
115
|
const res = await exports.client.post(`projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}/gitRepositoryLinks`, { cloneUri }, { queryParams: { gitRepositoryLinkId } });
|
|
111
116
|
return res.body;
|
package/lib/gcp/firestore.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBackupSchedule = exports.listBackupSchedules = exports.getBackup = exports.listBackups = exports.deleteBackupSchedule = exports.deleteBackup = exports.updateBackupSchedule = exports.createBackupSchedule = exports.deleteDocuments = exports.deleteDocument = exports.listCollectionIds = exports.getDatabase = exports.DayOfWeek = void 0;
|
|
3
|
+
exports.getBackupSchedule = exports.listBackupSchedules = exports.getBackup = exports.listBackups = exports.deleteBackupSchedule = exports.deleteBackup = exports.updateBackupSchedule = exports.createBackupSchedule = exports.deleteDocuments = exports.deleteDocument = exports.queryCollection = exports.getDocuments = exports.listCollectionIds = exports.getDatabase = exports.DayOfWeek = void 0;
|
|
4
4
|
const api_1 = require("../api");
|
|
5
5
|
const apiv2_1 = require("../apiv2");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
@@ -11,11 +11,16 @@ const prodOnlyClient = new apiv2_1.Client({
|
|
|
11
11
|
apiVersion: "v1",
|
|
12
12
|
urlPrefix: (0, api_1.firestoreOrigin)(),
|
|
13
13
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
function getClient(emulatorUrl) {
|
|
15
|
+
if (emulatorUrl) {
|
|
16
|
+
return new apiv2_1.Client({
|
|
17
|
+
auth: true,
|
|
18
|
+
apiVersion: "v1",
|
|
19
|
+
urlPrefix: emulatorUrl,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return prodOnlyClient;
|
|
23
|
+
}
|
|
19
24
|
var DayOfWeek;
|
|
20
25
|
(function (DayOfWeek) {
|
|
21
26
|
DayOfWeek["MONDAY"] = "MONDAY";
|
|
@@ -26,8 +31,8 @@ var DayOfWeek;
|
|
|
26
31
|
DayOfWeek["SATURDAY"] = "SATURDAY";
|
|
27
32
|
DayOfWeek["SUNDAY"] = "SUNDAY";
|
|
28
33
|
})(DayOfWeek = exports.DayOfWeek || (exports.DayOfWeek = {}));
|
|
29
|
-
async function getDatabase(project, database,
|
|
30
|
-
const apiClient =
|
|
34
|
+
async function getDatabase(project, database, emulatorUrl) {
|
|
35
|
+
const apiClient = getClient(emulatorUrl);
|
|
31
36
|
const url = `projects/${project}/databases/${database}`;
|
|
32
37
|
try {
|
|
33
38
|
const resp = await apiClient.get(url);
|
|
@@ -39,9 +44,9 @@ async function getDatabase(project, database, allowEmulator = false) {
|
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
exports.getDatabase = getDatabase;
|
|
42
|
-
function listCollectionIds(project,
|
|
43
|
-
const apiClient =
|
|
44
|
-
const url =
|
|
47
|
+
function listCollectionIds(project, databaseId = "(default)", emulatorUrl) {
|
|
48
|
+
const apiClient = getClient(emulatorUrl);
|
|
49
|
+
const url = `projects/${project}/databases/${databaseId}/documents:listCollectionIds`;
|
|
45
50
|
const data = {
|
|
46
51
|
pageSize: 2147483647,
|
|
47
52
|
};
|
|
@@ -50,14 +55,48 @@ function listCollectionIds(project, allowEmulator = false) {
|
|
|
50
55
|
});
|
|
51
56
|
}
|
|
52
57
|
exports.listCollectionIds = listCollectionIds;
|
|
53
|
-
async function
|
|
54
|
-
const apiClient =
|
|
58
|
+
async function getDocuments(project, paths, databaseId = "(default)", emulatorUrl) {
|
|
59
|
+
const apiClient = getClient(emulatorUrl);
|
|
60
|
+
const basePath = `projects/${project}/databases/${databaseId}/documents`;
|
|
61
|
+
const url = `${basePath}:batchGet`;
|
|
62
|
+
const fullPaths = paths.map((p) => `${basePath}/${p}`);
|
|
63
|
+
const res = await apiClient.post(url, { documents: fullPaths });
|
|
64
|
+
const out = { documents: [], missing: [] };
|
|
65
|
+
res.body.map((r) => (r.missing ? out.missing.push(r.missing) : out.documents.push(r.found)));
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
exports.getDocuments = getDocuments;
|
|
69
|
+
async function queryCollection(project, structuredQuery, databaseId = "(default)", emulatorUrl) {
|
|
70
|
+
const apiClient = getClient(emulatorUrl);
|
|
71
|
+
const basePath = `projects/${project}/databases/${databaseId}/documents`;
|
|
72
|
+
const url = `${basePath}:runQuery`;
|
|
73
|
+
try {
|
|
74
|
+
const res = await apiClient.post(url, {
|
|
75
|
+
structuredQuery: structuredQuery,
|
|
76
|
+
explainOptions: { analyze: true },
|
|
77
|
+
newTransaction: { readOnly: { readTime: new Date().toISOString() } },
|
|
78
|
+
});
|
|
79
|
+
const out = { documents: [] };
|
|
80
|
+
res.body.map((r) => {
|
|
81
|
+
if (r.document) {
|
|
82
|
+
out.documents.push(r.document);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
throw JSON.stringify(err);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.queryCollection = queryCollection;
|
|
92
|
+
async function deleteDocument(doc, emulatorUrl) {
|
|
93
|
+
const apiClient = getClient(emulatorUrl);
|
|
55
94
|
return apiClient.delete(doc.name);
|
|
56
95
|
}
|
|
57
96
|
exports.deleteDocument = deleteDocument;
|
|
58
|
-
async function deleteDocuments(project, docs,
|
|
59
|
-
const apiClient =
|
|
60
|
-
const url =
|
|
97
|
+
async function deleteDocuments(project, docs, databaseId = "(default)", emulatorUrl) {
|
|
98
|
+
const apiClient = getClient(emulatorUrl);
|
|
99
|
+
const url = `projects/${project}/databases/${databaseId}/documents:commit`;
|
|
61
100
|
const writes = docs.map((doc) => {
|
|
62
101
|
return { delete: doc.name };
|
|
63
102
|
});
|
package/lib/gcp/iam.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printManualIamConfig = exports.mergeBindings = exports.testIamPermissions = exports.testResourceIamPermissions = exports.getRole = exports.listServiceAccountKeys = exports.deleteServiceAccount = exports.createServiceAccountKey = exports.getServiceAccount = exports.createServiceAccount = exports.
|
|
3
|
+
exports.printManualIamConfig = exports.mergeBindings = exports.testIamPermissions = exports.testResourceIamPermissions = exports.getRole = exports.listServiceAccountKeys = exports.deleteServiceAccount = exports.createServiceAccountKey = exports.getServiceAccount = exports.createServiceAccount = exports.getDefaultCloudBuildServiceAgent = void 0;
|
|
4
4
|
const api_1 = require("../api");
|
|
5
5
|
const logger_1 = require("../logger");
|
|
6
6
|
const apiv2_1 = require("../apiv2");
|
|
@@ -10,10 +10,6 @@ function getDefaultCloudBuildServiceAgent(projectNumber) {
|
|
|
10
10
|
return `${projectNumber}@cloudbuild.gserviceaccount.com`;
|
|
11
11
|
}
|
|
12
12
|
exports.getDefaultCloudBuildServiceAgent = getDefaultCloudBuildServiceAgent;
|
|
13
|
-
function getDefaultComputeEngineServiceAgent(projectNumber) {
|
|
14
|
-
return `${projectNumber}-compute@developer.gserviceaccount.com`;
|
|
15
|
-
}
|
|
16
|
-
exports.getDefaultComputeEngineServiceAgent = getDefaultComputeEngineServiceAgent;
|
|
17
13
|
async function createServiceAccount(projectId, accountId, description, displayName) {
|
|
18
14
|
const response = await apiClient.post(`/projects/${projectId}/serviceAccounts`, {
|
|
19
15
|
accountId,
|
package/lib/gcp/proto.js
CHANGED
|
@@ -91,18 +91,19 @@ function getInvokerMembers(invoker, projectId) {
|
|
|
91
91
|
return invoker.map((inv) => formatServiceAccount(inv, projectId));
|
|
92
92
|
}
|
|
93
93
|
exports.getInvokerMembers = getInvokerMembers;
|
|
94
|
-
function formatServiceAccount(serviceAccount, projectId) {
|
|
94
|
+
function formatServiceAccount(serviceAccount, projectId, removeTypePrefix = false) {
|
|
95
95
|
if (serviceAccount.length === 0) {
|
|
96
96
|
throw new error_1.FirebaseError("Service account cannot be an empty string");
|
|
97
97
|
}
|
|
98
98
|
if (!serviceAccount.includes("@")) {
|
|
99
99
|
throw new error_1.FirebaseError("Service account must be of the form 'service-account@' or 'service-account@{project-id}.iam.gserviceaccount.com'");
|
|
100
100
|
}
|
|
101
|
+
const prefix = removeTypePrefix ? "" : "serviceAccount:";
|
|
101
102
|
if (serviceAccount.endsWith("@")) {
|
|
102
103
|
const suffix = `${projectId}.iam.gserviceaccount.com`;
|
|
103
|
-
return
|
|
104
|
+
return `${prefix}${serviceAccount}${suffix}`;
|
|
104
105
|
}
|
|
105
|
-
return
|
|
106
|
+
return `${prefix}${serviceAccount}`;
|
|
106
107
|
}
|
|
107
108
|
exports.formatServiceAccount = formatServiceAccount;
|
|
108
109
|
function pruneUndefiends(obj) {
|
package/lib/gcp/run.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setInvokerUpdate = exports.setInvokerCreate = exports.getIamPolicy = exports.setIamPolicy = exports.replaceService = exports.serviceIsResolved = exports.updateService = exports.getService = exports.gcpIds = exports.LOCATION_LABEL = void 0;
|
|
3
|
+
exports.fetchServiceLogs = exports.setInvokerUpdate = exports.setInvokerCreate = exports.getIamPolicy = exports.setIamPolicy = exports.replaceService = exports.serviceIsResolved = exports.updateService = exports.getService = exports.gcpIds = exports.LOCATION_LABEL = void 0;
|
|
4
4
|
const apiv2_1 = require("../apiv2");
|
|
5
5
|
const error_1 = require("../error");
|
|
6
6
|
const api_1 = require("../api");
|
|
7
7
|
const proto = require("./proto");
|
|
8
8
|
const throttler_1 = require("../throttler/throttler");
|
|
9
9
|
const logger_1 = require("../logger");
|
|
10
|
+
const cloudlogging_1 = require("./cloudlogging");
|
|
10
11
|
const API_VERSION = "v1";
|
|
11
12
|
const client = new apiv2_1.Client({
|
|
12
13
|
urlPrefix: (0, api_1.runOrigin)(),
|
|
@@ -149,3 +150,19 @@ async function setInvokerUpdate(projectId, serviceName, invoker, httpClient = cl
|
|
|
149
150
|
await setIamPolicy(serviceName, policy, httpClient);
|
|
150
151
|
}
|
|
151
152
|
exports.setInvokerUpdate = setInvokerUpdate;
|
|
153
|
+
async function fetchServiceLogs(projectId, serviceId) {
|
|
154
|
+
const filter = `resource.type="cloud_run_revision" AND resource.labels.service_name="${serviceId}"`;
|
|
155
|
+
const pageSize = 100;
|
|
156
|
+
const order = "desc";
|
|
157
|
+
try {
|
|
158
|
+
const entries = await (0, cloudlogging_1.listEntries)(projectId, filter, pageSize, order);
|
|
159
|
+
return entries || [];
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
throw new error_1.FirebaseError(`Failed to fetch logs for Cloud Run service ${serviceId}`, {
|
|
163
|
+
original: err,
|
|
164
|
+
status: err?.context?.response?.statusCode,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.fetchServiceLogs = fetchServiceLogs;
|