SecurityRules class Stay organized with collections Save and categorize content based on your preferences.
The FirebaseSecurityRules service interface.
Signature:
exportdeclareclassSecurityRulesProperties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| app | App |
Methods
| Method | Modifiers | Description |
|---|---|---|
| createRuleset(file) | Creates a newRuleset from the givenRulesFile. | |
| createRulesFileFromSource(name, source) | Creates aRulesFile with the given name and source. Throws an error if any of the arguments are invalid. This is a local operation, and does not involve any network API calls. | |
| deleteRuleset(name) | Deletes theRuleset identified by the given name. The input name should be the short name string without the project ID prefix. For example, to delete theprojects/project-id/rulesets/my-ruleset, pass the short name "my-ruleset". Rejects with anot-found error if the specifiedRuleset cannot be found. | |
| getFirestoreRuleset() | Gets theRuleset currently applied to Cloud Firestore. Rejects with anot-found error if no ruleset is applied on Firestore. | |
| getRuleset(name) | Gets theRuleset identified by the given name. The input name should be the short name string without the project ID prefix. For example, to retrieve theprojects/project-id/rulesets/my-ruleset, pass the short name "my-ruleset". Rejects with anot-found error if the specifiedRuleset cannot be found. | |
| getStorageRuleset(bucket) | Gets theRuleset currently applied to a Cloud Storage bucket. Rejects with anot-found error if no ruleset is applied on the bucket. | |
| listRulesetMetadata(pageSize, nextPageToken) | Retrieves a page of ruleset metadata. | |
| releaseFirestoreRuleset(ruleset) | Applies the specifiedRuleset ruleset to Cloud Firestore. | |
| releaseFirestoreRulesetFromSource(source) | Creates a newRuleset from the given source, and applies it to Cloud Firestore. | |
| releaseStorageRuleset(ruleset, bucket) | Applies the specifiedRuleset ruleset to a Cloud Storage bucket. | |
| releaseStorageRulesetFromSource(source, bucket) | Creates a newRuleset from the given source, and applies it to a Cloud Storage bucket. |
SecurityRules.app
Signature:
readonlyapp:App;SecurityRules.createRuleset()
Creates a newRuleset from the givenRulesFile.
Signature:
createRuleset(file:RulesFile):Promise<Ruleset>;Parameters
| Parameter | Type | Description |
|---|---|---|
| file | RulesFile | Rules file to include in the newRuleset. |
Returns:
Promise<Ruleset>
A promise that fulfills with the newly createdRuleset.
SecurityRules.createRulesFileFromSource()
Creates aRulesFile with the given name and source. Throws an error if any of the arguments are invalid. This is a local operation, and does not involve any network API calls.
Signature:
createRulesFileFromSource(name:string,source:string|Buffer):RulesFile;Parameters
| Parameter | Type | Description |
|---|---|---|
| name | string | Name to assign to the rules file. This is usually a short file name that helps identify the file in a ruleset. |
| source | string | Buffer | Contents of the rules file. |
Returns:
A new rules file instance.
Example
constsource='// Some rules source';construlesFile=admin.securityRules().createRulesFileFromSource('firestore.rules',source);SecurityRules.deleteRuleset()
Deletes theRuleset identified by the given name. The input name should be the short name string without the project ID prefix. For example, to delete theprojects/project-id/rulesets/my-ruleset, pass the short name "my-ruleset". Rejects with anot-found error if the specifiedRuleset cannot be found.
Signature:
deleteRuleset(name:string):Promise<void>;Parameters
| Parameter | Type | Description |
|---|---|---|
| name | string | Name of theRuleset to delete. |
Returns:
Promise<void>
A promise that fulfills when theRuleset is deleted.
SecurityRules.getFirestoreRuleset()
Gets theRuleset currently applied to Cloud Firestore. Rejects with anot-found error if no ruleset is applied on Firestore.
Signature:
getFirestoreRuleset():Promise<Ruleset>;Returns:
Promise<Ruleset>
A promise that fulfills with the Firestore ruleset.
SecurityRules.getRuleset()
Gets theRuleset identified by the given name. The input name should be the short name string without the project ID prefix. For example, to retrieve theprojects/project-id/rulesets/my-ruleset, pass the short name "my-ruleset". Rejects with anot-found error if the specifiedRuleset cannot be found.
Signature:
getRuleset(name:string):Promise<Ruleset>;Parameters
| Parameter | Type | Description |
|---|---|---|
| name | string | Name of theRuleset to retrieve. |
Returns:
Promise<Ruleset>
A promise that fulfills with the specifiedRuleset.
SecurityRules.getStorageRuleset()
Gets theRuleset currently applied to a Cloud Storage bucket. Rejects with anot-found error if no ruleset is applied on the bucket.
Signature:
getStorageRuleset(bucket?:string):Promise<Ruleset>;Parameters
| Parameter | Type | Description |
|---|---|---|
| bucket | string | Optional name of the Cloud Storage bucket to be retrieved. If not specified, retrieves the ruleset applied on the default bucket configured viaAppOptions. |
Returns:
Promise<Ruleset>
A promise that fulfills with the Cloud Storage ruleset.
SecurityRules.listRulesetMetadata()
Retrieves a page of ruleset metadata.
Signature:
listRulesetMetadata(pageSize?:number,nextPageToken?:string):Promise<RulesetMetadataList>;Parameters
| Parameter | Type | Description |
|---|---|---|
| pageSize | number | The page size, 100 if undefined. This is also the maximum allowed limit. |
| nextPageToken | string | The next page token. If not specified, returns rulesets starting without any offset. |
Returns:
Promise<RulesetMetadataList>
A promise that fulfills with a page of rulesets.
SecurityRules.releaseFirestoreRuleset()
Applies the specifiedRuleset ruleset to Cloud Firestore.
Signature:
releaseFirestoreRuleset(ruleset:string|RulesetMetadata):Promise<void>;Parameters
| Parameter | Type | Description |
|---|---|---|
| ruleset | string |RulesetMetadata | Name of the ruleset to apply or aRulesetMetadata object containing the name. |
Returns:
Promise<void>
A promise that fulfills when the ruleset is released.
SecurityRules.releaseFirestoreRulesetFromSource()
Creates a newRuleset from the given source, and applies it to Cloud Firestore.
Signature:
releaseFirestoreRulesetFromSource(source:string|Buffer):Promise<Ruleset>;Parameters
| Parameter | Type | Description |
|---|---|---|
| source | string | Buffer | Rules source to apply. |
Returns:
Promise<Ruleset>
A promise that fulfills when the ruleset is created and released.
SecurityRules.releaseStorageRuleset()
Applies the specifiedRuleset ruleset to a Cloud Storage bucket.
Signature:
releaseStorageRuleset(ruleset:string|RulesetMetadata,bucket?:string):Promise<void>;Parameters
| Parameter | Type | Description |
|---|---|---|
| ruleset | string |RulesetMetadata | Name of the ruleset to apply or aRulesetMetadata object containing the name. |
| bucket | string | Optional name of the Cloud Storage bucket to apply the rules on. If not specified, applies the ruleset on the default bucket configured viaAppOptions. |
Returns:
Promise<void>
A promise that fulfills when the ruleset is released.
SecurityRules.releaseStorageRulesetFromSource()
Creates a newRuleset from the given source, and applies it to a Cloud Storage bucket.
Signature:
releaseStorageRulesetFromSource(source:string|Buffer,bucket?:string):Promise<Ruleset>;Parameters
| Parameter | Type | Description |
|---|---|---|
| source | string | Buffer | Rules source to apply. |
| bucket | string | Optional name of the Cloud Storage bucket to apply the rules on. If not specified, applies the ruleset on the default bucket configured viaAppOptions. |
Returns:
Promise<Ruleset>
A promise that fulfills when the ruleset is created and released.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-07-29 UTC.