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

Update /internal/setRules endpoint; fix ruleset file watcher #4337

Merged
merged 6 commits into from Mar 30, 2022

Conversation

tohhsinpei
Copy link
Member

Description

2 changes:

  1. Follow up to this comment in Add StorageRulesManagerRegistry to handle rules files for multiple targets #4281. This PR adds support for per-resource Storage rules files on the /internal/setRules endpoint. Note that we only allow callers to overwrite the entire rules config, not update rules for a given resource. This means we can kill the updateSourceFile endpoint on the rules manager.
  2. Fix the rules file watcher, which I broke in Add StorageRulesManager class for emulator #4245. We need to reread the source file every time the file watcher detects a change at the given path; otherwise we're just reloading the same contents as before. This was not caught by the integration test because of another bug there:
    expect(await isPermitted(opts)).to.be.false;

    Note opts does not contain ruleset, so this always returns false:
    if (!opts.ruleset) {
    EmulatorLogger.forEmulator(Emulators.STORAGE).log(
    "WARN",
    `Can not process SDK request with no loaded ruleset`
    );
    return false;
    }

@@ -103,10 +91,15 @@ class DefaultStorageRulesManager implements StorageRulesManager {
"storage",
"Change detected, updating rules for Cloud Storage..."
);
this.updateRulesSource(rulesFile);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the fix for 2)

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 Show resolved Hide resolved
src/emulator/storage/server.ts Show resolved Hide resolved
src/emulator/storage/rules/manager.ts Show resolved Hide resolved
@tohhsinpei tohhsinpei force-pushed the hsinpei/storage-emulator-multiple-targets-5 branch 2 times, most recently from ecd59d1 to 4fc31d0 Compare March 23, 2022 19:56
Copy link
Contributor

@tonyjhuang tonyjhuang left a comment

Choose a reason for hiding this comment

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

thanks for the fix!

@tohhsinpei tohhsinpei enabled auto-merge (squash) March 30, 2022 15:39
@tohhsinpei tohhsinpei merged commit 7757ea1 into master Mar 30, 2022
@tohhsinpei tohhsinpei deleted the hsinpei/storage-emulator-multiple-targets-5 branch March 30, 2022 16:14
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.

None yet

2 participants