Repository navigation
fix issue where storage init does not get rules from console - #9809
Conversation
Summary of ChangesHello @aalej, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where firebase init storage would not fetch existing rules from the console, instead always creating a default rules file. The changes correctly implement fetching rules for the project's default storage bucket and using them if they exist. This is achieved by modifying getLatestRulesetName to accept a resource name, and adding new logic in the storage initialization feature to perform the fetch. The tests have also been updated to cover this new behavior.
My main feedback is to improve the error handling around fetching the rules. Currently, any failure during the fetch process will cause the init command to crash. I've suggested a change to catch these errors and gracefully fall back to the default rules, which will provide a better user experience.
| if (setup.projectId) { | ||
| const downloadedRules = await getRulesFromConsole(setup.projectId); | ||
| if (downloadedRules) { | ||
| info.rules = downloadedRules; | ||
| logger.info(`Downloaded the existing Storage Security Rules from the Firebase console`); | ||
| } | ||
| } |
There was a problem hiding this comment.
The call to getRulesFromConsole can reject for various reasons (e.g., network issues, permissions, or if the ruleset on the backend is in an unexpected state). If it rejects, it will crash the firebase init process, providing a poor user experience. It would be more robust to wrap this call in a try...catch block. If fetching the rules fails, you can log the error for debugging purposes and gracefully fall back to using the default rules template. This ensures the init process can continue successfully even if existing rules can't be retrieved.
| if (setup.projectId) { | |
| const downloadedRules = await getRulesFromConsole(setup.projectId); | |
| if (downloadedRules) { | |
| info.rules = downloadedRules; | |
| logger.info(`Downloaded the existing Storage Security Rules from the Firebase console`); | |
| } | |
| } | |
| if (setup.projectId) { | |
| try { | |
| const downloadedRules = await getRulesFromConsole(setup.projectId); | |
| if (downloadedRules) { | |
| info.rules = downloadedRules; | |
| logger.info(`Downloaded the existing Storage Security Rules from the Firebase console`); | |
| } | |
| } catch (e: any) { | |
| logger.debug("Could not retrieve storage rules, falling back to default rules.", e); | |
| // We can ignore this error and fall back to the default rules. | |
| } | |
| } |
There was a problem hiding this comment.
we might actually want to crash in these scenarios?
For example, if a user already has an existing local config but they want to get the rules from the Storage console, they run firebase init storage. In this scenario, if we default back to the default rules template, we would overwrite their existing one with a default rules template.
There was a problem hiding this comment.
Agree, i think this is fine as is. Swallowing this error is a bit aggressive.
Description
Fixes #8170
Scenarios Tested
firebase init storage --project demo-projectcreates astorage.rulesfile like(uses the default rules template):firebase init storage --project amalej-8170creates astorage.rulesfile like(downloads the rules from storage):Sample Commands