feat(cloud): add edge host enrollment
This commit is contained in:
@@ -28,22 +28,42 @@ class DeviceConfigStore:
|
||||
name: str | None = None,
|
||||
driver_type: str,
|
||||
connection_info: dict[str, Any],
|
||||
cloud_device_id: str | None = None,
|
||||
) -> None:
|
||||
with self._connect() as connection:
|
||||
connection.execute(
|
||||
"""
|
||||
insert or replace into device_configs (
|
||||
device_id, name, driver_type, connection_info
|
||||
) values (?, ?, ?, ?)
|
||||
insert into device_configs (
|
||||
device_id, name, driver_type, connection_info, cloud_device_id
|
||||
) values (?, ?, ?, ?, ?)
|
||||
on conflict(device_id) do update set
|
||||
name = excluded.name,
|
||||
driver_type = excluded.driver_type,
|
||||
connection_info = excluded.connection_info,
|
||||
cloud_device_id = coalesce(
|
||||
excluded.cloud_device_id,
|
||||
device_configs.cloud_device_id
|
||||
)
|
||||
""",
|
||||
(
|
||||
device_id,
|
||||
name,
|
||||
driver_type,
|
||||
json.dumps(connection_info, ensure_ascii=False),
|
||||
cloud_device_id,
|
||||
),
|
||||
)
|
||||
|
||||
def set_cloud_device_id(self, device_id: str, cloud_device_id: str) -> bool:
|
||||
if not cloud_device_id:
|
||||
raise ValueError("cloud_device_id must not be empty")
|
||||
with self._connect() as connection:
|
||||
cursor = connection.execute(
|
||||
"update device_configs set cloud_device_id = ? where device_id = ?",
|
||||
(cloud_device_id, device_id),
|
||||
)
|
||||
return cursor.rowcount > 0
|
||||
|
||||
def remove(self, device_id: str) -> None:
|
||||
with self._connect() as connection:
|
||||
connection.execute(
|
||||
@@ -93,10 +113,19 @@ class DeviceConfigStore:
|
||||
device_id text primary key,
|
||||
name text,
|
||||
driver_type text not null,
|
||||
connection_info text not null
|
||||
connection_info text not null,
|
||||
cloud_device_id text
|
||||
)
|
||||
"""
|
||||
)
|
||||
columns = {
|
||||
row["name"]
|
||||
for row in connection.execute("pragma table_info(device_configs)")
|
||||
}
|
||||
if "cloud_device_id" not in columns:
|
||||
connection.execute(
|
||||
"alter table device_configs add column cloud_device_id text"
|
||||
)
|
||||
connection.execute(
|
||||
"""
|
||||
create table if not exists settings (
|
||||
@@ -121,4 +150,5 @@ class DeviceConfigStore:
|
||||
"name": row["name"],
|
||||
"driver_type": row["driver_type"],
|
||||
"connection_info": json.loads(row["connection_info"]),
|
||||
"cloud_device_id": row["cloud_device_id"],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user