Skip to content

Commit 100e66c

Browse files
committed
refactor: expand file transfer capabilities
Update Device capabilities based on the latest version of interfaces Signed-off-by: Omar <omar.brbutovic@secomind.com>
1 parent 9df1b0e commit 100e66c

48 files changed

Lines changed: 1549 additions & 537 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/config/test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ config :edgehog,
120120
:astarte_file_upload_request_module,
121121
Edgehog.Astarte.Device.FileUploadRequestMock
122122

123+
config :edgehog,
124+
:astarte_file_transfer_capabilities_module,
125+
Edgehog.Astarte.Device.FileTransferCapabilitiesMock
126+
123127
config :edgehog, :astarte_forwarder_session_module, Edgehog.Astarte.Device.ForwarderSessionMock
124128
config :edgehog, :astarte_geolocation_module, Edgehog.Astarte.Device.GeolocationMock
125129
config :edgehog, :astarte_hardware_info_module, Edgehog.Astarte.Device.HardwareInfoMock

backend/lib/edgehog/astarte/device/file_download_request/behaviour.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ defmodule Edgehog.Astarte.Device.FileDownloadRequest.Behaviour do
2929
@callback request_download(
3030
client :: AppEngine.t(),
3131
device_id :: String.t(),
32-
request_data :: RequestData.t(),
33-
device_type :: :posix | :windows
32+
request_data :: RequestData.t()
3433
) ::
3534
:ok | {:error, term()}
3635
end

backend/lib/edgehog/astarte/device/file_download_request/request_data.ex

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ defmodule Edgehog.Astarte.Device.FileDownloadRequest.RequestData do
2828
defstruct [
2929
:id,
3030
:url,
31-
:httpHeaderKey,
32-
:httpHeaderValue,
33-
:compression,
31+
:httpHeaderKeys,
32+
:httpHeaderValues,
33+
:encoding,
3434
:fileSizeBytes,
3535
:progress,
3636
:digest,
37-
:fileName,
3837
:ttlSeconds,
3938
:fileMode,
4039
:userId,
@@ -46,13 +45,12 @@ defmodule Edgehog.Astarte.Device.FileDownloadRequest.RequestData do
4645
@type t() :: %__MODULE__{
4746
id: String.t(),
4847
url: String.t(),
49-
httpHeaderKey: String.t(),
50-
httpHeaderValue: String.t(),
51-
compression: String.t(),
48+
httpHeaderKeys: [String.t()],
49+
httpHeaderValues: [String.t()],
50+
encoding: String.t(),
5251
fileSizeBytes: non_neg_integer() | nil,
5352
progress: boolean(),
5453
digest: String.t() | nil,
55-
fileName: String.t() | nil,
5654
ttlSeconds: non_neg_integer(),
5755
fileMode: non_neg_integer(),
5856
userId: integer(),

backend/lib/edgehog/astarte/device/file_download_request/request_download.ex

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,17 @@ defmodule Edgehog.Astarte.Device.FileDownloadRequest do
2828
alias Astarte.Client.AppEngine
2929
alias Edgehog.Error
3030

31-
@posix_interface "io.edgehog.devicemanager.fileTransfer.posix.ServerToDevice"
32-
@windows_interface "io.edgehog.devicemanager.fileTransfer.windows.ServerToDevice"
31+
@interface "io.edgehog.devicemanager.fileTransfer.ServerToDevice"
3332

3433
@impl Edgehog.Astarte.Device.FileDownloadRequest.Behaviour
35-
def request_download(%AppEngine{} = client, device_id, request_data, :posix) do
36-
do_request_download(client, device_id, request_data, @posix_interface)
37-
end
38-
39-
def request_download(%AppEngine{} = client, device_id, request_data, :windows) do
40-
do_request_download(client, device_id, request_data, @windows_interface)
41-
end
42-
43-
defp do_request_download(client, device_id, request_data, interface) do
34+
def request_download(%AppEngine{} = client, device_id, request_data) do
4435
client
4536
|> AppEngine.Devices.send_datastream(
4637
device_id,
47-
interface,
38+
@interface,
4839
"/request",
4940
Map.from_struct(request_data)
5041
)
51-
|> Error.maybe_match_error(device_id, interface)
42+
|> Error.maybe_match_error(device_id, @interface)
5243
end
5344
end
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#
2+
# This file is part of Edgehog.
3+
#
4+
# Copyright 2026 SECO Mind Srl
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
20+
21+
defmodule Edgehog.Astarte.Device.FileTransferCapabilities do
22+
@moduledoc false
23+
@behaviour Edgehog.Astarte.Device.FileTransferCapabilities.Behaviour
24+
25+
alias Astarte.Client.AppEngine
26+
alias Edgehog.Astarte.Device.FileTransferCapabilities
27+
28+
@type target :: :storage | :streaming | :filesystem
29+
30+
@type t :: %__MODULE__{
31+
encodings: [String.t()],
32+
unix_permissions: boolean() | nil,
33+
targets: [target()]
34+
}
35+
36+
@enforce_keys [:encodings, :unix_permissions, :targets]
37+
defstruct @enforce_keys
38+
39+
@interface "io.edgehog.devicemanager.fileTransfer.Capabilities"
40+
41+
@impl Edgehog.Astarte.Device.FileTransferCapabilities.Behaviour
42+
def get(%AppEngine{} = client, device_id) do
43+
with {:ok, %{"data" => data}} <-
44+
AppEngine.Devices.get_properties_data(client, device_id, @interface) do
45+
{:ok, parse_data(data)}
46+
end
47+
end
48+
49+
def parse_data(data) do
50+
%FileTransferCapabilities{
51+
encodings: Map.get(data, "encodings", []),
52+
unix_permissions: Map.get(data, "unixPermissions"),
53+
targets: parse_targets(Map.get(data, "targets", []))
54+
}
55+
end
56+
57+
defp parse_targets(targets) when is_list(targets) do
58+
targets
59+
|> Enum.map(&parse_target/1)
60+
|> Enum.reject(&is_nil/1)
61+
end
62+
63+
defp parse_targets(_), do: []
64+
65+
defp parse_target("storage"), do: :storage
66+
defp parse_target("streaming"), do: :streaming
67+
defp parse_target("filesystem"), do: :filesystem
68+
defp parse_target(:storage), do: :storage
69+
defp parse_target(:streaming), do: :streaming
70+
defp parse_target(:filesystem), do: :filesystem
71+
defp parse_target(_), do: nil
72+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# This file is part of Edgehog.
3+
#
4+
# Copyright 2026 SECO Mind Srl
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
20+
21+
defmodule Edgehog.Astarte.Device.FileTransferCapabilities.Behaviour do
22+
@moduledoc false
23+
24+
alias Astarte.Client.AppEngine
25+
alias Edgehog.Astarte.Device.FileTransferCapabilities
26+
27+
@callback get(client :: AppEngine.t(), device_id :: String.t()) ::
28+
{:ok, FileTransferCapabilities.t()} | {:error, term()}
29+
end

backend/lib/edgehog/astarte/device/file_upload_request/request_data.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ defmodule Edgehog.Astarte.Device.FileUploadRequest.RequestData do
2626
defstruct [
2727
:id,
2828
:url,
29-
:httpHeaderKey,
30-
:httpHeaderValue,
31-
:compression,
29+
:httpHeaderKeys,
30+
:httpHeaderValues,
31+
:encoding,
3232
:progress,
3333
:source,
3434
:sourceType
@@ -37,9 +37,9 @@ defmodule Edgehog.Astarte.Device.FileUploadRequest.RequestData do
3737
@type t() :: %__MODULE__{
3838
id: String.t(),
3939
url: String.t(),
40-
httpHeaderKey: String.t(),
41-
httpHeaderValue: String.t(),
42-
compression: String.t(),
40+
httpHeaderKeys: [String.t()],
41+
httpHeaderValues: [String.t()],
42+
encoding: String.t(),
4343
progress: boolean(),
4444
source: String.t(),
4545
sourceType: String.t()

backend/lib/edgehog/capabilities.ex

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ defmodule Edgehog.Capabilities do
133133
minor: 1
134134
}
135135
],
136-
posix_file_transfer_stream: [
136+
file_transfer_stream: [
137137
%Astarte.InterfaceID{
138-
name: "io.edgehog.devicemanager.fileTransfer.posix.ServerToDevice",
138+
name: "io.edgehog.devicemanager.fileTransfer.ServerToDevice",
139139
major: 0,
140140
minor: 1
141141
},
@@ -150,48 +150,9 @@ defmodule Edgehog.Capabilities do
150150
minor: 1
151151
}
152152
],
153-
posix_file_transfer_storage: [
153+
file_transfer_storage: [
154154
%Astarte.InterfaceID{
155-
name: "io.edgehog.devicemanager.fileTransfer.posix.ServerToDevice",
156-
major: 0,
157-
minor: 1
158-
},
159-
%Astarte.InterfaceID{
160-
name: "io.edgehog.devicemanager.fileTransfer.Progress",
161-
major: 0,
162-
minor: 1
163-
},
164-
%Astarte.InterfaceID{
165-
name: "io.edgehog.devicemanager.fileTransfer.Response",
166-
major: 0,
167-
minor: 1
168-
},
169-
%Astarte.InterfaceID{
170-
name: "io.edgehog.devicemanager.storage.File",
171-
major: 0,
172-
minor: 1
173-
}
174-
],
175-
windows_file_transfer_stream: [
176-
%Astarte.InterfaceID{
177-
name: "io.edgehog.devicemanager.fileTransfer.windows.ServerToDevice",
178-
major: 0,
179-
minor: 1
180-
},
181-
%Astarte.InterfaceID{
182-
name: "io.edgehog.devicemanager.fileTransfer.Progress",
183-
major: 0,
184-
minor: 1
185-
},
186-
%Astarte.InterfaceID{
187-
name: "io.edgehog.devicemanager.fileTransfer.Response",
188-
major: 0,
189-
minor: 1
190-
}
191-
],
192-
windows_file_transfer_storage: [
193-
%Astarte.InterfaceID{
194-
name: "io.edgehog.devicemanager.fileTransfer.windows.ServerToDevice",
155+
name: "io.edgehog.devicemanager.fileTransfer.ServerToDevice",
195156
major: 0,
196157
minor: 1
197158
},

backend/lib/edgehog/devices/device/calculations/astarte_interface_value.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of Edgehog.
33
#
4-
# Copyright 2024-2025 SECO Mind Srl
4+
# Copyright 2024-2026 SECO Mind Srl
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -97,6 +97,12 @@ defmodule Edgehog.Devices.Device.Calculations.AstarteInterfaceValue do
9797
Edgehog.Astarte.Device.HardwareInfo
9898
)
9999

100+
@file_transfer_capabilities Application.compile_env(
101+
:edgehog,
102+
:astarte_file_transfer_capabilities_module,
103+
Edgehog.Astarte.Device.FileTransferCapabilities
104+
)
105+
100106
@os_info Application.compile_env(
101107
:edgehog,
102108
:astarte_os_info_module,
@@ -135,6 +141,7 @@ defmodule Edgehog.Devices.Device.Calculations.AstarteInterfaceValue do
135141
defp value_id_to_fetch_fun(:available_device_mappings), do: &@available_device_mappings.get/2
136142
defp value_id_to_fetch_fun(:base_image_info), do: &@base_image.get/2
137143
defp value_id_to_fetch_fun(:hardware_info), do: &@hardware_info.get/2
144+
defp value_id_to_fetch_fun(:file_transfer_capabilities), do: &@file_transfer_capabilities.get/2
138145
defp value_id_to_fetch_fun(:modem_properties), do: &@cellular_connection.get_modem_properties/2
139146
defp value_id_to_fetch_fun(:modem_status), do: &@cellular_connection.get_modem_status/2
140147
defp value_id_to_fetch_fun(:os_info), do: &@os_info.get/2

backend/lib/edgehog/devices/device/device.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,11 @@ defmodule Edgehog.Devices.Device do
605605
calculation {Calculations.AstarteInterfaceValue, value_id: :hardware_info}
606606
end
607607

608+
calculate :file_transfer_capabilities, Types.FileTransferCapabilities do
609+
public? true
610+
calculation {Calculations.AstarteInterfaceValue, value_id: :file_transfer_capabilities}
611+
end
612+
608613
calculate :location, Edgehog.Geolocation.Location do
609614
description """
610615
Describes the place where the device is located.

0 commit comments

Comments
 (0)