MrBrightside
MrBrightside

Reputation: 2669

Firebase Storage security rules: duration.value parameter

I'm trying to secure my Firebase Storage files based on time access, let's say only allowing files to be read up to a specific time after they were uploaded.

This specific time is stored into a custom property 'expiration' field in the file metadata when it is uploaded by the user.

My problem is that I'm trying to use this value as a parameter into the duration.value(int magnitude, string units) function like so:

request.time < resource.timeCreated + duration.value(resource.metadata.expiration, "m");

But the 'duration' function only seems to accept constant values into the magnitude parameter and not dynamic values.

Anyone out there that has tried this too?

Thanks

Upvotes: 1

Views: 398

Answers (1)

Mike McDonald
Mike McDonald

Reputation: 15963

Good question, sorry you're having trouble :(

Yes, these functions do take dynamic values--the issue here is that the type is wrong, and thus the function is failing.

All custom metadata (as "expiration" is), is returned as a string, while duration.value() takes an int and a string, as you correctly pointed out.

The simple (though as of yet undocumented) way of doing this, is to cast the string value to an int, using the int() method:

request.time < resource.timeCreated + duration.value(int(resource.metadata.expiration), "m");

Upvotes: 2

Related Questions