Mc User
Mc User

Reputation: 33

Can i access the firebase realtime database security rules via REST?

I'm looking to set up emulated testing of my security rules, and currently the docs recommend loading your rules into a file and then reading that file into the emulator.

const rules = fs.readFileSync("database.rules.json", "utf8");

What I'd rather do is load in the latest security rules from my project, so that I know that any changes I make to it can be tested instantly and are working properly.

Is it possible to access the security rules via REST?

Upvotes: 0

Views: 220

Answers (2)

Doug Stevenson
Doug Stevenson

Reputation: 317828

I will point out: that's not really the way that the emulator was designed to work. The idea is that you're supposed to test your rules locally before you deploy them, so you don't break your app in production. Once deployed, it makes more sense to test your rules by issuing queries against your actual database.

That said, if this is really what you want to access your rules remotely, there is a REST API for that, and you're free use whatever nodejs HTTP library to load them into your test harness.

Upvotes: 1

Frank van Puffelen
Frank van Puffelen

Reputation: 600006

According to the reference documentation you can retrieve security rules via a REST GET call. From there:

curl 'https://[PROJECT_ID].firebaseio/.settings/rules.json?auth=FIREBASE_SECRET'
curl -X PUT -d '{ "rules": { ".read": true } }' 'https://[PROJECT_ID].firebaseio/.settings/rules.json?auth=FIREBASE_SECRET'

Upvotes: 1

Related Questions