-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add translation function from realm to keyspace #105
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #105 +/- ##
==========================================
+ Coverage 75.08% 75.11% +0.02%
==========================================
Files 50 50
Lines 839 844 +5
==========================================
+ Hits 630 634 +4
- Misses 209 210 +1 ☔ View full report in Codecov by Sentry. |
lib/astarte_core/cql_utils.ex
Outdated
@spec get_from_realm!(any()) :: any() | ||
def get_from_realm!("") do | ||
raise "EmptyRealm" | ||
end | ||
|
||
def get_from_realm!(realm_name) when is_binary(realm_name) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go with
@spec get_from_realm!(any()) :: any() | |
def get_from_realm!("") do | |
raise "EmptyRealm" | |
end | |
def get_from_realm!(realm_name) when is_binary(realm_name) do | |
@spec realm_name_to_keyspace_name(nonempty_binary()) :: nonempty_binary() | |
def realm_name_to_keyspace_name(realm_name) do |
So that we keep consistency in naming and behavior with other functions in the module.
Another option, since the instance id will be known by the user of the library, could be
@spec realm_name_to_keyspace_name(nonempty_binary()) :: nonempty_binary()
@spec realm_name_to_keyspace_name(nonempty_binary(), nonempty_binary()) :: nonempty_binary()
def realm_name_to_keyspace_name(realm_name, astarte_instance_id \\ "default") do
#...
lib/astarte_core/cql_utils.ex
Outdated
end | ||
|
||
def get_from_realm!(realm_name) when is_binary(realm_name) do | ||
customer_keyspace = :persistent_term.get("instance_id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be either retrieved via config (see e.g. Astarte Data Access envs) or passed as an argument to the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, direct access of persistent_term or whatever env value from main application managed by Skogsra will not work, so this value needs to be passed as an argument
25f1294
to
2d7dcf6
Compare
e7a52d7
to
f75b6fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is good! Just some details in tests might be improved
test/astarte_core/cql_utils_test.exs
Outdated
assert Realm.valid_name?(CQLUtils.realm_name_to_keyspace_name("example", "atestinstance")) == | ||
true | ||
|
||
:persistent_term.erase("example") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is tasked just with the creation of the keyspace name and its storage, so the call to :persistent_term.erase/1
would be better inside the on_exit
callback.
You could also add a line with this assertion:
assert :persistent_term.get("example") = "atestinstanceexample"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also holds for the other new tests
test/astarte_core/cql_utils_test.exs
Outdated
:persistent_term.erase("example") | ||
end | ||
|
||
test "realm name gets encoded, persistent_term exists" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you want to test here is probably that the keyspace name is generated even if the realm name is longer than 47 characters, so I suggest rephrasing the test as
test "realm name gets encoded, persistent_term exists" do | |
test "realm name is > 47 characters long, persistent_term exists" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implies that the previous one must also be renamed
test "realm name is <= 47 characters long, [..]"
test/astarte_core/cql_utils_test.exs
Outdated
:persistent_term.erase("example") | ||
end | ||
|
||
test "realm name is not empty, persistent_term does not exists" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not exists?
lib/astarte_core/cql_utils.ex
Outdated
@@ -167,4 +167,35 @@ defmodule Astarte.Core.CQLUtils do | |||
|
|||
eid | |||
end | |||
|
|||
@spec realm_name_to_keyspace_name(nonempty_binary(), nonempty_binary()) :: nonempty_binary() | |||
def realm_name_to_keyspace_name(realm_name, astarte_instance_id \\ "default") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default astarte_instance_id
should be an empty string, otherwise this would be a breaking change.
lib/astarte_core/cql_utils.ex
Outdated
@spec realm_name_to_keyspace_name(nonempty_binary(), nonempty_binary()) :: nonempty_binary() | ||
def realm_name_to_keyspace_name(realm_name, astarte_instance_id \\ "default") | ||
when is_binary(realm_name) do | ||
case :persistent_term.get(realm_name, nil) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.erlang.org/doc/man/persistent_term#best-practices-for-using-persistent-terms
You should not use the bare realm as key since that might cause conflicts given that persistent terms are global. You should at least namespace it with an atom, e.g. {:astarte_realm_to_keyspace, realm_name}
lib/astarte_core/cql_utils.ex
Outdated
if String.length(astarte_instance_id <> realm_name) < 48 do | ||
keyspace_name = | ||
(astarte_instance_id <> realm_name) | ||
|> String.replace("-", "") | ||
|> String.replace("_", "") | ||
|> String.downcase() | ||
|
||
:persistent_term.put(realm_name, keyspace_name) | ||
keyspace_name | ||
else | ||
keyspace_name = | ||
Base.url_encode64(astarte_instance_id <> realm_name, padding: false) | ||
|> String.replace("-", "") | ||
|> String.replace("_", "") | ||
|> String.slice(0..47) | ||
|> String.downcase() | ||
|
||
:persistent_term.put(realm_name, keyspace_name) | ||
keyspace_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd isolate the pure function from the side effects, i.e. realm_name_to_keyspace_name/2
just transforms the realm name in a keyspace name, and then persistent_realm_name_to_keyspace_name/2
gets it from persistent term (calculating it using the previous function if not found).
This also allows you to unit test the logic of the pure function without worrying about persistent terms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(the names are a suggestion, I'm open to other proposals too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rbino the idea behind the current impl is that it's faster to retrieve an already encoded realm name from persistent_terms rather than re-encode each time it is accessed.
Probabily it's better to just rename the function in persistent_realm_name_to_keyspace_name and create a private one for the encoding? since it's useless to encode without check persistent_term first outside of this module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rbino something like this
32b2cb3
to
097d976
Compare
7940d45
to
936425d
Compare
936425d
to
bbf2731
Compare
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Currently Astarte instances are not allowd to share the same database due to a conflict in namespaces resolution (eg. two realms with same name in different astarte instances now share the same kespace, that's not good) This commit introduce univoque mapping between the pair <Astarte instance id, realm name> and keyspace name (see also astarte-platform/astarte_core#105), this way even with the same name, realms do not share the same keyspace. Also, the env var `ASTARTE_INSTANCE_ID`, defaulting to `""` has been added to maintain backward compatibility. Trivially change all queries to the database to reflect this change, both in `lib` and `tests`. Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Added a function to support new database keyspaces separation.
The function translate from a realm name to a keyspace name, derived from realm + astarte_instance_id (optional parameter).
This edit has became necessary before an extensive rewriting of the main astarte repo, in order to add the database keyspaces separation feature.
New tests have been written to cover main and side cases.
After internal discussion, this feature does not use persistent_term anymore
resolves astarte-platform/astarte#924