Move keyspace translations to public functions in query files#1130
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## release-1.2 #1130 +/- ##
===============================================
- Coverage 70.73% 68.78% -1.96%
===============================================
Files 176 327 +151
Lines 5184 7505 +2321
===============================================
+ Hits 3667 5162 +1495
- Misses 1517 2343 +826 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
59b4dbe to
28dca1b
Compare
| keyspace_name = | ||
| CQLUtils.realm_name_to_keyspace_name(realm_name, Config.astarte_instance_id!()) | ||
|
|
||
| with {:valid, true} <- {:valid, Realm.valid_name?(realm_name)}, |
There was a problem hiding this comment.
this makes me think: are we actually not checking for valid realm names anymore? Are we allowing the user to query on the system keyspace?
There was a problem hiding this comment.
This is actually a good point, let me fix this asap
| astarte_keyspace = Realm.keyspace_name("astarte") | ||
|
|
||
| case Queries.check_astarte_health(astarte_keyspace, :quorum) do | ||
| # TODO shall we check for an encoded astarte realm or it's fine to use the generic "astarte one"? |
There was a problem hiding this comment.
astarte is fine, as we're checking for astarte's health. Astarte is healthy even if there are no installed realms, but it needs the astarte realm to function
727eed5 to
79e5575
Compare
2ec918d to
9cc4b92
Compare
| def keyspace_name("astarte") do | ||
| CQLUtils.realm_name_to_keyspace_name("astarte", Config.astarte_instance_id!()) | ||
| end | ||
|
|
||
| def keyspace_name(realm_name) do | ||
| CQLUtils.realm_name_to_keyspace_name(realm_name, Config.astarte_instance_id!()) | ||
| keyspace = CQLUtils.realm_name_to_keyspace_name(realm_name, Config.astarte_instance_id!()) | ||
|
|
||
| with {:valid, true} <- {:valid, Realm.valid_name?(keyspace)} do | ||
| keyspace | ||
| end |
There was a problem hiding this comment.
This is a bit all over the place:
- the spec says the return type is a string, but it now is
String.t() | {:valid, false}. I suggest we either change this function to a{:ok, keyspace_name} | {:error, :invalid_realm_name}or crash instead. "astarte"is not a valid realm name, and as such you declared its own body to make sure calls to it still succeed. We do not want users querying on theastartekeyspace, I suggest we make another ad-hoc function used only for the queries actually requiring the astarte keyspace, something likeRealm.astarte_keyspace_name()
b072c43 to
8f685c2
Compare
8f685c2 to
d3ebd3d
Compare
Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
d3ebd3d to
db3982f
Compare
Fix astarte keyspace encoding, check and fix for functions that used to require a plain or encoded realm name in order to generally have:
def functions -> accepts plain realm name, encode into keyspace and then use that
defp -> accepts only keyspaces
There are actually one or two occurrences that require a rework to match the above case(s), but this would affect the entire application logic (maybe in another PR?)