Split up Firebase Firestore Security Rules into separate Files? - firebase

Is there a way to split Firestore Security Rules (firestore.rules) into separate / multiple files?
I would like to do a structure like so:
index.rules // imports all the rules
users.rules
posts.rules
comments.rules
helperFunctions.rules
// ... and so on
My firestore.rules file is getting quite big and this would make working with it much, much easier.

Unfortunately, I don't think it's possible at this time out of the box. However, I'm with you 100% with this issue.
There may be a rough workaround using npm (or whatever cli tool). Following this answer, you may be able to have a head, multiple inserts, and a foot. If you're able to find all files matching a pattern, you can concat them to the head, then concat the foot, ultimately naming this file firestore.rules.

OneLunch Man's answer inspired me to sit down and write a small Node.js module that shall make live easier organizing your Firestore rules:
https://github.com/lupas/firestore-rulez
As #OneLunch Man proposed above, this combines the different files into one single firestore.rules file. Additionally, and if configured, it adds some helper functions that you don't have to define yourself.
Hope it helps someone :)
I love the simplicity of security rules, though I hope organizing them will be even easier in the near future. But I'm very sure it will, right Frank? ;-)
Btw: I'll leave the question unanswered, maybe there's even better solutions?

Related

Standardized filenames when passing folders between steps in pipeline architecture?

I am using AzureML pipelines, where the interface between pipeline steps is through a folder or file.
When I am passing data into the pipeline, I point directly to a single file. No problem at all. Very useful when passing in configuration files which all live in the same folder on my local computer.
However, when passing data between different steps of the pipeline, I can't provide the next step with a file path. All the steps get is a path to some folder that they can write to. Then that same path is passed to the next step.
The problem comes when the following step is then supposed to load something from the folder.
Which filename is it supposed to try to load?
Approaches I've considered:
Use a standardized filename for everything. Problem is that I want to be able to run the steps locally too, independant of any pipeline. This makes very for a very poor UX for that use case.
Check if the path is to a file, if it isn't, check all the files in the folder. If there is only one file, then use it. Otherwise throw an exception. This is maybe the most elegant solution from a UX perspective, but it sounds overengineered to me. We also don't structurally share any code between the steps at the moment, so either we will have repetition or we will need to find some way to share code, which is non-trivial.
Allow custom filenames to be passed in optionally, otherwise use a standard filename. This helpes with the UX, but often the filenames are supposed to be defined by the configuration files being passed in, so while we could do some bash scripting to get the filename into the command, it feels like a sub-par solution.
Ultimately it feels like none of the solutions I have come up with are any good.
It feels like we are making things more difficult for ourselves in the future if we assume some default filename. F.x. we work with multiple file types, so it would need to omit an extension.
But any way to do it without default filenames would also cause maintainence headache down the line, or incurr substantial upfront cost.
The question is am I missing something? Any potential traps, better solutions, etc. would be appreciated. It definately feels like I am somewhat under- and/or overthinking this.

Unix app to write custom syntax to can check it

well the question is, exist some app or language/etc to write a custom syntax to can check files?
You know, when we works in different places, ppl and projects every one have differents rules to how write, code style and all that things, the idea its can check all this things because at least to me normally i forgot something.
Ideally some app without a heavy GUI, thinking maybe a terminal app, or editors like gedit, avoid plis apps like Eclipse and similars.
For now i need only check simple parts, if you can recommend both a simple/limited app and a complex/full app would be great.
Obvs, if exist a simple/full app, will be better.
Thx.
If what you're looking for is a program that rewrites a source code given a specific coding style, I advise you to take a look at GNU Indent.
If you want to do more complex operations like build an AST and work on it to add things, edit, check for existing dependencies or whatever, you'll want to use a tool like Flex/Bison, Clang, Pyrser, etc.

Temporary Variables in Firebase Security rules

So I'm setting up the firebase security rules for my project and for the user to have read access to a room, we need to make sure they are part of that organization. So I have a security rule like this:
root.child('organizations').child(data.child('organization_id').val()).child('user_ids').hasChild(auth.uid)
Not only is this really ugly, there are several other rules in the same statement (separated by &&/||) which have start with root.child('organizations').child(data.child('organization_id').val()) to access data from the organization variable associated with this room.
This leads to some UGLY security rules, is there any way I can make temporary variables or something like that so I can make this a lot more readable? Thank you!
Nope. The Firebase Security rules language doesn't have support for custom variables. This indeed leads to lots of duplication between rules.
The best solution is to write your rules in a higher-level language, that compiles into Firebase Security rules. The most well-known ones are Blaze (the grand-daddy of them all), Butane (not from Firebase itself) and Bolt (new and under very active development).
Bolt for example allows you to define (global) functions, which can easily encapsulate the repeated snippet and much more.
Since June 2020 the answer is Yes, you can have local variables (answering in case it's helpful to others)
From the firebase blog linked above
Local variables have been one of the most requested features in Rules, and they're now available within functions.
In Bolt, you could write your rule like this:
type Room {
organization_id: String,
read() { isUserInOrg(this.organization_id) }
}
isUserInOrg(org_id) { root.organizations[org_id].user_ids[auth.uid] }

Tool to merge 3 CSS files

Merging huge CSS files is huge pain,
Hi i found some question asked on the same line. I tried some of the tools but they end up merging line by line rather than on the basis or CSS rules.
Now i thought i should right one good program to do following,
1. read CSS file convert in XML
2. sort it on the basis of CSS rule
Now write one more program to consume 3 XML files find different classes and merge the files nicely based on CSS rules.
How ever that turned out to be good amount of work and i hope there must be someone who must have faced this problem before me and solved it clean way.
Please add your thoughts and suggestions, I would love to know the tool for this however i would also love to know how to design/code for this kind of tool? Am i thinking on right track ?
Thanks All,
There is a free tool called CSS Merge. Have you tried it?
Since order is important in CSS, it is difficult to merge files more sensibly than simply concatenating them. Certainly, this can't be done in the general case. In a specific case you might be able to produce a tool that can do it.

Comparing and rationalizing CSS - not file or diff based

I'm in the process of taking a couple of separate asp.net applications, and combining them.
One problem is rationalizing the CSS between the two app - app1 has two css files, while app2 has about 8 of them. Much of the CSS between the two apps is the same, but there are some differences. I'm looking for a tool to compare all the elements of each app, and show what's missing, what's different, etc. Ideally the output would be 3 files: Common, app1 and app2, but I won't be that fussy if it can just show me the differences between the two apps.
Does such a tool exist?
If you hate downloading tools, there's an online version of css comparer here http://www.alanhart.co.uk/tools/compare-css.php
It provides a comparison of css class files between two files
I don't know of a stand-alone tool tailored for this specific purpose. There's a PHP class called "CSS Comparer", but I have no idea how easy it is to use. The screenshot on that page looks promising though.
Personally, I would probably just concatenate all the files together, so that you have one file for each app, and then run a diff on them. To make it even easier, you could run both files through something like CSSTidy or do some imaginative file processing with search/replace and sorting. That could get all the declarations in the same order in both files, so the diff would be clearer.
Combine all of these files into a single file and give it a run through a CSS optimizer or compressor. An optimizer should see all of your duplicate selectors and weed them out.
I'd recommend YUI's compressor, but there are plenty of web-based compressors/optimizers available, too. Here's one and another. YMMV with them, but a good Google search can turn up a bunch more.
Normally I'd recommend diff. Since you explicitly write that you are looking for something "not diff based", maybe you could describe why diff does not help you.
Then others might be able to propose something different.

Resources