Skip to content

Commit

Permalink
Treat the device serial as a string to support device 0000
Browse files Browse the repository at this point in the history
  • Loading branch information
sylane committed Oct 8, 2024
1 parent 0b2e9b6 commit 234a709
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/rebar3_grisp_io_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ update_package(RState, Token, PackageName, PackagePath, Force) ->
-spec deploy_update(RState, Token, PackageName, Device) -> Res when
RState :: rebar_state:t(),
Token :: rebar3_grisp_io_config:clear_token(),
PackageName :: string(),
Device :: integer(),
PackageName :: binary(),
Device :: binary(),
Res :: ok | no_return().
deploy_update(RState, Token, PackageName, Device) ->
BaseUrl = base_url(RState),
URI = list_to_binary("/grisp-manager/api/deploy-update/" ++ PackageName),
QS = <<"device=", (integer_to_binary(Device))/binary>>,
URI = <<"/grisp-manager/api/deploy-update/", PackageName/binary>>,
QS = <<"device=", Device/binary>>,
Url = hackney_url:make_url(BaseUrl, URI, QS),
Headers = [{<<"authorization">>, bearer_token(Token)},
{<<"content-type">>, <<"application/json">>},
Expand Down
20 changes: 15 additions & 5 deletions src/rebar3_grisp_io_deploy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,21 @@ do(RState) ->
{Args, _} = rebar_state:command_parsed_args(RState),
RelNameArg = proplists:get_value(relname, Args, undefined),
RelVsnArg = proplists:get_value(relvsn, Args, undefined),
Device = try_get_device_serial(Args),
Device = try try_get_device_serial(Args) of
DeviceStr ->
_ = list_to_integer(DeviceStr),
list_to_binary(DeviceStr)
catch
exit:badarg ->
throw(invalid_device_serial_number)
end,

{RelName, RelVsn}
= rebar3_grisp_util:select_release(RState, RelNameArg, RelVsnArg),
CurrentRelease = binary_to_list(
rebar3_grisp_util:update_file_name(RState, RelName, RelVsn)),
PackageName = proplists:get_value(package, Args, CurrentRelease),
PackageName = list_to_binary(
proplists:get_value(package, Args, CurrentRelease)),

Config = rebar3_grisp_io_config:read_config(RState),
EncryptedToken = maps:get(encrypted_token, Config),
Expand All @@ -60,14 +68,16 @@ do(RState) ->

rebar3_grisp_io_api:deploy_update(RState, Token, PackageName, Device),

success("Deployement request for package " ++ PackageName
++ " on device #" ++ integer_to_list(Device)),
success("Deployement request for package ~s on device #~s",
[PackageName, Device]),

{ok, RState}
catch
throw:no_device_serial_number ->
abort("Error: The serial number of the target device is missing." ++
" Specify it with -d or --device");
throw:invalid_device_serial_number ->
abort("Error: The serial number of the target device is invalid.");
throw:wrong_local_password ->
abort("Wrong local password. Try again");
throw:wrong_credentials ->
Expand All @@ -91,7 +101,7 @@ options() -> [
"Specify the name for the release to deploy"},
{relvsn, $v, "relvsn", string,
"Specify the version of the release to deploy"},
{device, $d, "device", integer, "The serial number of the GRiSP board"},
{device, $d, "device", string, "The serial number of the GRiSP board"},
{package, $p, "package", string,
"The name of the package that will be deployed"}
].
Expand Down
2 changes: 1 addition & 1 deletion test/rebar3_grisp_io_deploy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ setup_meck_io() ->
ct:fail(Msg)
end
end),
ok = meck:expect(rebar3_grisp_io_io, success, 1, fun (_) -> ok end).
ok = meck:expect(rebar3_grisp_io_io, success, 2, fun (_, _) -> ok end).

setup_meck_gio_utils() ->
ok = meck:new(rebar3_grisp_io_utils, [no_link, passthrough]),
Expand Down

0 comments on commit 234a709

Please sign in to comment.