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.

prepare.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const _ = require("lodash");
  4. const gcp = require("../../gcp");
  5. const rulesDeploy_1 = require("../../rulesDeploy");
  6. const error_1 = require("../../error");
  7. async function default_1(context, options) {
  8. let rulesConfig = options.config.get("storage");
  9. if (!rulesConfig) {
  10. return;
  11. }
  12. const onlyTargets = new Set();
  13. let allStorage = !options.only;
  14. if (options.only) {
  15. const split = options.only.split(",");
  16. if (split.includes("storage")) {
  17. allStorage = true;
  18. }
  19. else {
  20. for (const value of split) {
  21. if (value.startsWith("storage:")) {
  22. onlyTargets.add(value.split(":")[1]);
  23. }
  24. }
  25. }
  26. }
  27. const rulesDeploy = new rulesDeploy_1.RulesDeploy(options, rulesDeploy_1.RulesetServiceType.FIREBASE_STORAGE);
  28. const rulesConfigsToDeploy = [];
  29. if (!Array.isArray(rulesConfig)) {
  30. const defaultBucket = await gcp.storage.getDefaultBucket(options.project);
  31. rulesConfig = [Object.assign(rulesConfig, { bucket: defaultBucket })];
  32. }
  33. for (const ruleConfig of rulesConfig) {
  34. const target = ruleConfig.target;
  35. if (target) {
  36. options.rc.requireTarget(context.projectId, "storage", target);
  37. }
  38. if (allStorage || onlyTargets.has(target)) {
  39. rulesDeploy.addFile(ruleConfig.rules);
  40. rulesConfigsToDeploy.push(ruleConfig);
  41. onlyTargets.delete(target);
  42. }
  43. }
  44. if (!allStorage && onlyTargets.size !== 0) {
  45. throw new error_1.FirebaseError(`Could not find rules for the following storage targets: ${[...onlyTargets].join(", ")}`);
  46. }
  47. _.set(context, "storage.rules", rulesConfig);
  48. _.set(context, "storage.rulesConfigsToDeploy", rulesConfigsToDeploy);
  49. _.set(context, "storage.rulesDeploy", rulesDeploy);
  50. await rulesDeploy.compile();
  51. }
  52. exports.default = default_1;