Skip to content

Commit 439704b

Browse files
committed
chore: add ownership_vouchers table and device ref on all db helpers
Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
1 parent 3c77969 commit 439704b

File tree

11 files changed

+124
-11
lines changed

11 files changed

+124
-11
lines changed

apps/astarte_appengine_api/test/support/helpers/database.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ defmodule Astarte.Helpers.Database do
107107
);
108108
"""
109109

110+
@create_ownership_vouchers_table """
111+
CREATE TABLE #{Realm.keyspace_name(@test_realm)}.ownership_vouchers (
112+
id uuid,
113+
private_key blob,
114+
voucher_data blob,
115+
expiry timestamp,
116+
PRIMARY KEY (id)
117+
);
118+
"""
119+
110120
@create_devices_table """
111121
CREATE TABLE #{Realm.keyspace_name(@test_realm)}.devices (
112122
device_id uuid,
@@ -134,6 +144,7 @@ defmodule Astarte.Helpers.Database do
134144
attributes map<varchar, varchar>,
135145
groups map<text, timeuuid>,
136146
capabilities capabilities,
147+
ownership_voucher uuid,
137148
138149
PRIMARY KEY (device_id)
139150
);
@@ -433,6 +444,8 @@ defmodule Astarte.Helpers.Database do
433444
{:ok, _} ->
434445
Repo.query!(@create_capabilities_type)
435446

447+
Repo.query!(@create_ownership_vouchers_table)
448+
436449
Repo.query!(@create_devices_table)
437450

438451
Repo.query!(@create_deletion_in_progress_table)

apps/astarte_appengine_api/test/support/helpers/database_v2.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ defmodule Astarte.Helpers.DatabaseV2 do
6666
purge_properties_compression_format int
6767
);
6868
"""
69+
@create_ownership_vouchers_table """
70+
CREATE TABLE :keyspace.ownership_vouchers (
71+
id uuid,
72+
private_key blob,
73+
voucher_data blob,
74+
expiry timestamp,
75+
PRIMARY KEY (id)
76+
);
77+
"""
6978

7079
@create_devices_table """
7180
CREATE TABLE :keyspace.devices (
@@ -95,6 +104,7 @@ defmodule Astarte.Helpers.DatabaseV2 do
95104
capabilities capabilities,
96105
97106
groups map<text, timeuuid>,
107+
ownership_voucher uuid,
98108
99109
PRIMARY KEY (device_id)
100110
)
@@ -247,6 +257,7 @@ defmodule Astarte.Helpers.DatabaseV2 do
247257
realm_keyspace = Realm.keyspace_name(realm_name)
248258
execute!(realm_keyspace, @create_keyspace)
249259
execute!(realm_keyspace, @create_capabilities_type)
260+
execute!(realm_keyspace, @create_ownership_vouchers_table)
250261
execute!(realm_keyspace, @create_devices_table)
251262
execute!(realm_keyspace, @create_groups_table)
252263
execute!(realm_keyspace, @create_names_table)

apps/astarte_data_updater_plant/test/support/database_test_helper.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ defmodule Astarte.DataUpdaterPlant.DatabaseTestHelper do
5050
);
5151
"""
5252

53+
@create_ownership_vouchers_table """
54+
CREATE TABLE :keyspace.ownership_vouchers (
55+
id uuid,
56+
private_key blob,
57+
voucher_data blob,
58+
expiry timestamp,
59+
PRIMARY KEY (id)
60+
);
61+
"""
62+
5363
@create_devices_table """
5464
CREATE TABLE :keyspace.devices (
5565
device_id uuid,
@@ -77,6 +87,7 @@ defmodule Astarte.DataUpdaterPlant.DatabaseTestHelper do
7787
attributes map<varchar, varchar>,
7888
groups map<text, timeuuid>,
7989
capabilities capabilities,
90+
ownership_voucher uuid,
8091
8192
PRIMARY KEY (device_id)
8293
);
@@ -366,6 +377,7 @@ defmodule Astarte.DataUpdaterPlant.DatabaseTestHelper do
366377
case execute(keyspace_name, @create_autotestrealm) do
367378
{:ok, _} ->
368379
execute!(keyspace_name, @create_capabilities_type)
380+
execute!(keyspace_name, @create_ownership_vouchers_table)
369381
execute!(keyspace_name, @create_devices_table)
370382
execute!(keyspace_name, @create_endpoints_table)
371383

apps/astarte_data_updater_plant/test/support/helpers/database.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ defmodule Astarte.Helpers.Database do
7070
purge_properties_compression_format int
7171
);
7272
"""
73+
@create_ownership_vouchers_table """
74+
CREATE TABLE :keyspace.ownership_vouchers (
75+
id uuid,
76+
private_key blob,
77+
voucher_data blob,
78+
expiry timestamp,
79+
PRIMARY KEY (id)
80+
);
81+
"""
7382

7483
@create_devices_table """
7584
CREATE TABLE :keyspace.devices (
@@ -96,7 +105,8 @@ defmodule Astarte.Helpers.Database do
96105
last_credentials_request_ip inet,
97106
last_seen_ip inet,
98107
attributes map<varchar, varchar>,
99-
capabilities capabilities,
108+
capabilities capabilities,
109+
ownership_voucher uuid,
100110
101111
groups map<text, timeuuid>,
102112
@@ -305,6 +315,7 @@ defmodule Astarte.Helpers.Database do
305315
realm_keyspace = Realm.keyspace_name(realm_name)
306316
execute!(realm_keyspace, @create_keyspace)
307317
execute!(realm_keyspace, @create_capabilities_type)
318+
execute!(realm_keyspace, @create_ownership_vouchers_table)
308319
execute!(realm_keyspace, @create_devices_table)
309320
execute!(realm_keyspace, @create_groups_table)
310321
execute!(realm_keyspace, @create_names_table)

apps/astarte_housekeeping/test/support/helpers/database.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ defmodule Astarte.Housekeeping.Helpers.Database do
6767
purge_properties_compression_format int
6868
);
6969
"""
70+
@create_ownership_vouchers_table """
71+
CREATE TABLE :keyspace.ownership_vouchers (
72+
id uuid,
73+
private_key blob,
74+
voucher_data blob,
75+
expiry timestamp,
76+
PRIMARY KEY (id)
77+
);
78+
"""
7079

7180
@create_devices_table """
7281
CREATE TABLE :keyspace.devices (
@@ -95,6 +104,7 @@ defmodule Astarte.Housekeeping.Helpers.Database do
95104
attributes map<varchar, varchar>,
96105
groups map<text, timeuuid>,
97106
capabilities capabilities,
107+
ownership_voucher uuid,
98108
99109
PRIMARY KEY (device_id)
100110
)
@@ -325,6 +335,7 @@ defmodule Astarte.Housekeeping.Helpers.Database do
325335
realm_keyspace = Realm.keyspace_name(realm_name)
326336
execute(realm_keyspace, @create_keyspace)
327337
execute(realm_keyspace, @create_capabilities_type)
338+
execute(realm_keyspace, @create_ownership_vouchers_table)
328339
execute(realm_keyspace, @create_devices_table)
329340
execute(realm_keyspace, @create_groups_table)
330341
execute(realm_keyspace, @create_names_table)

apps/astarte_pairing/lib/astarte_pairing/fdo/voucher_manager.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defmodule Astarte.Pairing.FDO.VoucherManager do
2323
def save_voucher(realm_name, voucher_blob, pkey_blob) do
2424
with {:ok, inserted_voucher} <-
2525
Queries.create_ownership_voucher(realm_name, voucher_blob, pkey_blob),
26-
{:ok, device_guuid} <- extract_device_guuid_from_voucher_data(voucher_blob),
26+
{:ok, device_guuid } <- extract_device_guuid_from_voucher_data(voucher_blob),
2727
{:ok, _} <-
2828
Queries.update_device_registration_voucher(
2929
realm_name,
@@ -38,14 +38,14 @@ defmodule Astarte.Pairing.FDO.VoucherManager do
3838
with {:ok, cbor_data} <- clean_and_b64_decode_voucher_blob(voucher_blob),
3939
{:ok, decoded_voucher, _rest} <- cbor_data |> CBOR.decode(),
4040
{:ok, decoded_header, _rest} <- extract_and_decode_voucher_header(decoded_voucher) do
41-
device_guid_binary = device_id_from_header(decoded_header)
41+
device_guid_binary = device_id_from_header(decoded_header)
4242
{:ok, UUID.binary_to_string!(device_guid_binary)}
4343
else
4444
error ->
4545
"error extracting device guid from ownership voucher: #{inspect(error)}"
4646
|> Logger.error()
4747

48-
{:error, error}
48+
{:error, error}
4949
end
5050
end
5151

apps/astarte_pairing/test/support/helpers/database.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ defmodule Astarte.Helpers.Database do
7373
purge_properties_compression_format int
7474
);
7575
"""
76-
76+
@create_ownership_vouchers_table """
77+
CREATE TABLE :keyspace.ownership_vouchers (
78+
id uuid,
79+
private_key blob,
80+
voucher_data blob,
81+
expiry timestamp,
82+
PRIMARY KEY (id)
83+
);
84+
"""
7785
@create_devices_table """
7886
CREATE TABLE :keyspace.devices (
7987
device_id uuid,
@@ -102,6 +110,7 @@ defmodule Astarte.Helpers.Database do
102110
capabilities capabilities,
103111
104112
groups map<text, timeuuid>,
113+
ownership_voucher uuid,
105114
106115
PRIMARY KEY (device_id)
107116
)
@@ -284,6 +293,7 @@ defmodule Astarte.Helpers.Database do
284293
realm_keyspace = Realm.keyspace_name(realm_name)
285294
execute!(realm_keyspace, @create_keyspace)
286295
execute!(realm_keyspace, @create_capabilities_type)
296+
execute!(realm_keyspace, @create_ownership_vouchers_table)
287297
execute!(realm_keyspace, @create_devices_table)
288298
execute!(realm_keyspace, @create_groups_table)
289299
execute!(realm_keyspace, @create_names_table)

apps/astarte_realm_management/test/support/helpers/database.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ defmodule Astarte.Helpers.Database do
6666
purge_properties_compression_format int
6767
);
6868
"""
69-
69+
@create_ownership_vouchers_table """
70+
CREATE TABLE IF NOT EXISTS :keyspace.ownership_vouchers (
71+
id uuid,
72+
private_key blob,
73+
voucher_data blob,
74+
expiry timestamp,
75+
PRIMARY KEY (id)
76+
);
77+
"""
7078
@create_devices_table """
7179
CREATE TABLE IF NOT EXISTS :keyspace.devices (
7280
device_id uuid,
@@ -93,8 +101,8 @@ defmodule Astarte.Helpers.Database do
93101
last_seen_ip inet,
94102
attributes map<varchar, varchar>,
95103
capabilities capabilities,
96-
97104
groups map<text, timeuuid>,
105+
ownership_voucher uuid,
98106
99107
PRIMARY KEY (device_id)
100108
)
@@ -262,6 +270,7 @@ defmodule Astarte.Helpers.Database do
262270
realm_keyspace = Realm.keyspace_name(realm_name)
263271
execute!(realm_keyspace, @create_keyspace)
264272
execute!(realm_keyspace, @create_capabilities_type)
273+
execute!(realm_keyspace, @create_ownership_vouchers_table)
265274
execute!(realm_keyspace, @create_devices_table)
266275
execute!(realm_keyspace, @create_groups_table)
267276
execute!(realm_keyspace, @create_names_table)

apps/astarte_trigger_engine/test/support/helpers/database.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ defmodule Astarte.Helpers.Database do
6666
);
6767
"""
6868

69+
@create_ownership_vouchers_table """
70+
CREATE TABLE :keyspace.ownership_vouchers (
71+
id uuid,
72+
private_key blob,
73+
voucher_data blob,
74+
expiry timestamp,
75+
PRIMARY KEY (id)
76+
);
77+
"""
78+
6979
@create_devices_table """
7080
CREATE TABLE :keyspace.devices (
7181
device_id uuid,
@@ -92,8 +102,8 @@ defmodule Astarte.Helpers.Database do
92102
last_seen_ip inet,
93103
attributes map<varchar, varchar>,
94104
capabilities capabilities,
95-
96105
groups map<text, timeuuid>,
106+
ownership_voucher uuid,
97107
98108
PRIMARY KEY (device_id)
99109
)
@@ -223,6 +233,7 @@ defmodule Astarte.Helpers.Database do
223233
realm_keyspace = Realm.keyspace_name(realm_name)
224234
execute!(realm_keyspace, @create_keyspace)
225235
execute!(realm_keyspace, @create_capabilities_type)
236+
execute!(realm_keyspace, @create_ownership_vouchers_table)
226237
execute!(realm_keyspace, @create_devices_table)
227238
execute!(realm_keyspace, @create_groups_table)
228239
execute!(realm_keyspace, @create_names_table)

libs/astarte_data_access/test/support/database_test_helper.exs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
5757
);
5858
"""
5959

60+
@create_ownership_vouchers_table """
61+
CREATE TABLE :keyspace.ownership_vouchers (
62+
id uuid,
63+
private_key blob,
64+
voucher_data blob,
65+
expiry timestamp,
66+
PRIMARY KEY (id)
67+
);
68+
69+
"""
70+
6071
@create_devices_table """
6172
CREATE TABLE autotestrealm.devices (
6273
device_id uuid,
@@ -83,7 +94,8 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
8394
last_seen_ip inet,
8495
attributes map<varchar, varchar>,
8596
groups map<text, timeuuid>,
86-
97+
ownership_voucher uuid,
98+
8799
PRIMARY KEY (device_id)
88100
);
89101
"""
@@ -403,6 +415,7 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
403415
def create_test_keyspace(conn) do
404416
case Xandra.execute(conn, @create_autotestrealm) do
405417
{:ok, _} ->
418+
Xandra.execute!(conn, @create_ownership_vouchers_table)
406419
Xandra.execute!(conn, @create_devices_table)
407420
Xandra.execute!(conn, @create_names_table)
408421
Xandra.execute!(conn, @create_kv_store)

0 commit comments

Comments
 (0)