-
Couldn't load subscription status.
- Fork 408
Implemented the API for releasing rulesets #610
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ import { FirebaseServiceInterface, FirebaseServiceInternalsInterface } from '../ | |
| import { FirebaseApp } from '../firebase-app'; | ||
| import * as utils from '../utils/index'; | ||
| import * as validator from '../utils/validator'; | ||
| import { SecurityRulesApiClient, RulesetResponse, RulesetContent } from './security-rules-api-client'; | ||
| import { SecurityRulesApiClient, RulesetResponse, RulesetContent, Release } from './security-rules-api-client'; | ||
| import { AuthorizedHttpClient } from '../utils/api-request'; | ||
| import { FirebaseSecurityRulesError } from './security-rules-utils'; | ||
|
|
||
|
|
@@ -115,6 +115,17 @@ export class SecurityRules implements FirebaseServiceInterface { | |
| return this.getRulesetForRelease(SecurityRules.CLOUD_FIRESTORE); | ||
| } | ||
|
|
||
| /** | ||
| * Makes the specified ruleset the currently applied ruleset for Cloud Firestore. | ||
| * | ||
| * @param {string|RulesetMetadata} ruleset Name of the ruleset to release or a RulesetMetadata object containing | ||
| * the name. | ||
| * @returns {Promise<void>} A promise that fulfills when the ruleset is released. | ||
| */ | ||
| public releaseFirestoreRuleset(ruleset: string | RulesetMetadata): Promise<void> { | ||
| return this.releaseRuleset(ruleset, SecurityRules.CLOUD_FIRESTORE); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a `RulesFile` with the given name and source. Throws if any of the arguments are invalid. This is a | ||
| * local operation, and does not involve any network API calls. | ||
|
|
@@ -188,6 +199,21 @@ export class SecurityRules implements FirebaseServiceInterface { | |
| return this.getRuleset(stripProjectIdPrefix(rulesetName)); | ||
| }); | ||
| } | ||
|
|
||
| private releaseRuleset(ruleset: string | RulesetMetadata, releaseName: string): Promise<void> { | ||
| if (!validator.isNonEmptyString(ruleset) && | ||
| (!validator.isNonNullObject(ruleset) || !validator.isNonEmptyString(ruleset.name))) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's interesting that the name could come in either as a String or as part of the RulesetMetadata Object. Why did you opt for this and not the simpler signature of only passing in the name as a String, making it the caller's job to pluck out the name if it had an Object? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use the same private method for releasing storage rulesets. By doing it here we save a few lines from being duplicated. |
||
| const err = new FirebaseSecurityRulesError( | ||
| 'invalid-argument', 'ruleset must be a non-empty name or a RulesetMetadata object.'); | ||
| return Promise.reject(err); | ||
| } | ||
|
|
||
| const rulesetName = validator.isString(ruleset) ? ruleset : ruleset.name; | ||
| return this.client.updateRelease(releaseName, rulesetName) | ||
| .then(() => { | ||
| return; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| class SecurityRulesInternals implements FirebaseServiceInternalsInterface { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to expect that we won't get the
createandupdateTimes back, or you're just signaling that we don't rely on them for anything?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the same interface as an input argument when updating/patching a release. In this case I wanted the flexibility to not specify these 2 attributes. And you're right -- we also don't rely on them for anything else.