Skip to content

Commit

Permalink
Report fwup version to nerves hub
Browse files Browse the repository at this point in the history
Why:

* NH needs to know the fwup version to make decisions about delta updates
* Resolves Issue nerves-hub#43

This change addresses the need by:

* Grab fwup version when creating config
* Add fwup version to config params
* Add a spec to check that fwup version key is present
  • Loading branch information
Mrjaco12 committed Aug 31, 2020
1 parent fda7d06 commit 6b77a13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/nerves_hub_link/configurator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ defmodule NervesHubLink.Configurator do
|> Keyword.put_new(:verify, :verify_peer)
|> Keyword.put_new(:server_name_indication, to_charlist(base.device_api_sni))

%{base | params: Nerves.Runtime.KV.get_all_active(), socket: socket, ssl: ssl}
params = Map.put(Nerves.Runtime.KV.get_all_active(), "nerves_fw_fwup_version", fwup_version())

%{base | params: params, socket: socket, ssl: ssl}
end

defp do_build(configurator) when is_atom(configurator) do
Expand All @@ -71,4 +73,9 @@ defmodule NervesHubLink.Configurator do
Default
end
end

defp fwup_version do
{version_string, 0} = System.cmd("fwup", ["--version"])
version_string |> String.trim()
end
end
5 changes: 5 additions & 0 deletions test/nerves_hub_link/configurator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ defmodule NervesHubLink.ConfiguratorTest do
config = NervesHubLink.Configurator.build()
assert config.socket[:transport_opts][:socket_opts] == ssl
end

test "fwup_version is included in params" do
config = NervesHubLink.Configurator.build()
assert Map.has_key?(config.params, "nerves_fw_fwup_version")
end
end

0 comments on commit 6b77a13

Please sign in to comment.