Firebase rule base on path name [duplicate] - firebase

I have security rule write like this :
/databases/{database}/documents {
match /collection_COUNTRY_EN/{docId} {
allow....
}
match /collection_COUNTRY_ES/{docId} {
allow...
}
}
Where the rule are identical to all the country. Is there a way to implement regex in the match /path to have the same rule for all the collection that start with something and end with a country code ?
Or does i have to structure my data in a different way ?
Thanks for your time.

Security rules do not support regex in the path match. You can only wildcard on the full name of a path segment.
What you might want to do instead is organize all your common top-level collection into subcollections organized under a known document, and apply the same rules to each of them that way:
match /countries/data/{countryCollection}/{docId} {
allow...
}
This would apply the same permissions to all country subcollections organized under /countries/data, which can be an empty document, or even a non-existent document.

Related

Index setting path in Cosmos DB

In Cosmos DB, I have an index setting that looks like this:
"includedPaths": [
{
"path": "/PartitionKey/*"
}
]
What would be the difference if I changed the Path to only this: "/PartitionKey"?
That means indexing won't be enabled on the nested nodes in the document. The path to anything under /PartitionKey/. The character * should be used if you are planing to query on sub properties of the property for this path.
from the documentation,
the /* wildcard can be used to match any elements below the node
If you don't have nested nodes then this should be good enough. Also you need to use the ? character at the end of the index path is required to serve queries that query on this property.
/PartitionKey/?

What is GRAPHDB_CONTEXT_TEST in Graphdb?

I am trying to set a new repository in GraphDB. The npm documentation say that
GRAPHDB_CONTEXT_TEST = 'http://ont.enapso.com/repo'; where is this "http://ont.enapso.com/repo" coming from?
Also, why do we need { prefix: 'entest', iri: 'http://ont.enapso.com/test#' } ?
In the test repository, it is:
But I don't understand if the inside the quotes is just a string, or a link?
GRAPHDB_CONTEXT_TEST = 'http://ont.enapso.com/repo';
This is the global variable in which we have 'http://ont.enapso.com/repo', which is to define which named graph would be used.
{ prefix: 'entest', iri: 'http://ont.enapso.com/test#' }
These are the prefixes that we could pass in along with their IRI. They are used to perform SPARQL queries which require your prefixes.
We pass the IRI inside the quotes referred to as an internationalized resource identifier. It is used to identify uniquely.
You can also check the updated documentation of the pack available at
ENAPSO GraphDB Client
ENAPSO GraphDB Admin
Hope that answers your questions.

Error: Index not defined thrown in Firebase cURL query, even after updating database rules

I've taken a look at some of the other questions that are like mine, and they all seem to be having little to no trouble with their database rules and nested queries. As a result, I'm a little confused as to why my query isn't working out.
Just for reference, here's my query: curl 'https://----.firebaseio.com/flights.json?orderBy="classes/economy/price"&startAt=2'
Here's what the relevant database structure looks like:
My rules are:
This is the error shown:
Any help would be greatly appreciated.
You need to define indexes at the location where you run the query. Since your query runs on the flights node, you'll need an index on classes/economy/price there.
So:
{
"rules": {
"flights": {
".indexOn": "classes/economy/price"
}
}
}

Firebase authentication

I would like to be able to have my database only accessible from 3 Google domains. I can access it from one domain but when I try to add more it fails.
The rules I have tried so far:
{
"rules": {
".read": "auth.token.email.endswith('mycompany#gmail.com')"
}
}
I have tried to add an or statement into it but with the second domain I don't get authorised.
Try playing with this syntax instead:
"auth.token.email.matches(/.*#gmail.com$/)"
You can put logical operators inside as well - &&, ||.
More here and obviously here.

capturing a child value in Firebase rules

Using Firebase, it's possible to create rule expressions tp protect data but I've found it can quickly become complex.
One case I'm looking at has a rule using the children of the current node, e.g.:
data.child('value').val() === true
It's also possible to create a rule based on the contents of another node:
root.hasChild($node_variable)
What I'd like to do is to combine these two, e.g.:
root.child(data.child('value')).hasChild($node_variable)
but this hybrid approach throws an error when I publish the combined rule. Is there a way around this?
As suggested by David in the comments, the solution was
root.child(data.child('value').val()).hasChild($node_variabl‌​e)

Resources