Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StorageRulesManagerRegistry to handle rules files for multiple targets #4281

Merged
merged 18 commits into from Mar 16, 2022

Conversation

tohhsinpei
Copy link
Member

Description

Fixes #3390. Following up to #4263, this PR adds a StorageRulesManager that will live inside the Storage Emulator. The interface is implemented by:

  • StorageRulesManagerImplementation, which keeps track of rules for a single resource
  • StorageRulesManagerRegistry, which maps resource to StorageRulesManagerImplementation

In the server, all calls to the validator will pass along the resource aka bucket id in order to determine which ruleset to use.

@tohhsinpei tohhsinpei force-pushed the hsinpei/storage-emulator-multiple-targets-3 branch from 40af2f8 to aa0ebeb Compare March 9, 2022 20:51
@tohhsinpei tohhsinpei force-pushed the hsinpei/storage-emulator-multiple-targets-3 branch 3 times, most recently from 789252a to 4b45374 Compare March 9, 2022 22:29
return this._rulesManager.getRuleset(resource);
}

async setRules(rules: RulesType, resource: string): Promise<StorageRulesIssues> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have a pattern of accessing StorageEmulator internals from within server.ts so I'm not sure we need to wrap the rules manager's interface here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can expose the rules manager instead for the sake of consistency. Curious, is there any benefit to exposing the internals?

src/emulator/storage/index.ts Outdated Show resolved Hide resolved
src/emulator/storage/index.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
@tohhsinpei tohhsinpei requested a review from sam-gc March 10, 2022 22:55
@tohhsinpei tohhsinpei force-pushed the hsinpei/storage-emulator-multiple-targets-3 branch from 0f00d1a to 9ab16db Compare March 10, 2022 23:01
@tohhsinpei tohhsinpei force-pushed the hsinpei/storage-emulator-multiple-targets-3 branch from 9ab16db to 015a865 Compare March 10, 2022 23:14
src/emulator/storage/index.ts Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/fsutils.ts Outdated Show resolved Hide resolved
src/emulator/storage/index.ts Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Outdated Show resolved Hide resolved
src/test/emulators/storage/rules/manager.spec.ts Outdated Show resolved Hide resolved
@tohhsinpei tohhsinpei force-pushed the hsinpei/storage-emulator-multiple-targets-3 branch from 8e24f4c to 4575d14 Compare March 15, 2022 20:14
@tohhsinpei tohhsinpei force-pushed the hsinpei/storage-emulator-multiple-targets-3 branch from 4575d14 to 9eaf5c4 Compare March 15, 2022 20:15
Copy link
Contributor

@sam-gc sam-gc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript LGTM

@@ -0,0 +1 @@
- Adds support for configuration with multiple storage targets (#4281).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should coordinate with @puf to get the public docs updated once this is released :) https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some docs, somewhat hidden away...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, the emulator-specific docs don't seem to mention this: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration

But it's okay that we don't reiterate everything since it's already in the CLI documentation

src/emulator/storage/rules/config.ts Outdated Show resolved Hide resolved
* Updates the source file and, correspondingly, the file watcher and ruleset for the resource.
* Returns an array of errors and/or warnings that arise from loading the ruleset.
*/
updateSourceFile(rules: SourceFile, resource: string): Promise<StorageRulesIssues>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, we may want to remove this method as we don't need to support modifying currently running StorageRulesManagers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, will do in follow up PR.

src/test/emulators/storage/rules/config.spec.ts Outdated Show resolved Hide resolved
src/test/emulators/storage/rules/config.spec.ts Outdated Show resolved Hide resolved
src/test/emulators/storage/rules/manager.spec.ts Outdated Show resolved Hide resolved
src/test/emulators/storage/rules/manager.spec.ts Outdated Show resolved Hide resolved
src/test/emulators/storage/rules/manager.spec.ts Outdated Show resolved Hide resolved
@tohhsinpei tohhsinpei force-pushed the hsinpei/storage-emulator-multiple-targets-3 branch 2 times, most recently from bce98a8 to 4f53ed4 Compare March 16, 2022 19:59
@tohhsinpei tohhsinpei force-pushed the hsinpei/storage-emulator-multiple-targets-3 branch from 4f53ed4 to 0c8c165 Compare March 16, 2022 20:01
@@ -0,0 +1 @@
- Adds support for configuration with multiple storage targets (#4281).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, the emulator-specific docs don't seem to mention this: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration

But it's okay that we don't reiterate everything since it's already in the CLI documentation

@tohhsinpei tohhsinpei merged commit c69b437 into master Mar 16, 2022
@tohhsinpei tohhsinpei deleted the hsinpei/storage-emulator-multiple-targets-3 branch March 16, 2022 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Storage emulator does not accept multiple storage targets configuration
3 participants