No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

storage.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ensureStorageTriggerRegion = exports.obtainStorageBindings = void 0;
  4. const storage = require("../../../gcp/storage");
  5. const logger_1 = require("../../../logger");
  6. const error_1 = require("../../../error");
  7. const location_1 = require("../../../gcp/location");
  8. const PUBSUB_PUBLISHER_ROLE = "roles/pubsub.publisher";
  9. async function obtainStorageBindings(projectNumber) {
  10. const storageResponse = await storage.getServiceAccount(projectNumber);
  11. const storageServiceAgent = `serviceAccount:${storageResponse.email_address}`;
  12. const pubsubPublisherBinding = {
  13. role: PUBSUB_PUBLISHER_ROLE,
  14. members: [storageServiceAgent],
  15. };
  16. return [pubsubPublisherBinding];
  17. }
  18. exports.obtainStorageBindings = obtainStorageBindings;
  19. async function ensureStorageTriggerRegion(endpoint) {
  20. var _a;
  21. const { eventTrigger } = endpoint;
  22. if (!eventTrigger.region) {
  23. logger_1.logger.debug("Looking up bucket region for the storage event trigger");
  24. if (!((_a = eventTrigger.eventFilters) === null || _a === void 0 ? void 0 : _a.bucket)) {
  25. throw new error_1.FirebaseError("Error: storage event trigger is missing bucket filter: " +
  26. JSON.stringify(eventTrigger, null, 2));
  27. }
  28. logger_1.logger.debug(`Looking up bucket region for the storage event trigger on bucket ${eventTrigger.eventFilters.bucket}`);
  29. try {
  30. const bucket = await storage.getBucket(eventTrigger.eventFilters.bucket);
  31. eventTrigger.region = bucket.location.toLowerCase();
  32. logger_1.logger.debug("Setting the event trigger region to", eventTrigger.region, ".");
  33. }
  34. catch (err) {
  35. throw new error_1.FirebaseError("Can't find the storage bucket region", { original: err });
  36. }
  37. }
  38. if (endpoint.region !== eventTrigger.region &&
  39. eventTrigger.region !== "us-central1" &&
  40. !(0, location_1.regionInLocation)(endpoint.region, eventTrigger.region)) {
  41. throw new error_1.FirebaseError(`A function in region ${endpoint.region} cannot listen to a bucket in region ${eventTrigger.region}`);
  42. }
  43. }
  44. exports.ensureStorageTriggerRegion = ensureStorageTriggerRegion;