From 43789cc50fd7288afd33535492618f334c7d17b1 Mon Sep 17 00:00:00 2001 From: Luca Succi Date: Mon, 29 Jan 2024 09:13:29 +0100 Subject: [PATCH] Rebrand application as 'grisp_io' (#17) * Rebrand application as 'grisp_io' * Remove old seawater host --- .github/workflows/ct.yml | 3 +- README.md | 10 +++---- config/sys.config | 2 +- grisp/default/common/deploy/files/erl_inetrc | 1 - rebar.config | 8 +++--- ...risp_seawater.app.src => grisp_io.app.src} | 10 +++---- src/{grisp_seawater.erl => grisp_io.erl} | 2 +- ...risp_seawater_app.erl => grisp_io_app.erl} | 6 ++-- src/grisp_io_connection.erl | 10 +++---- ...water_jsonrpc.erl => grisp_io_jsonrpc.erl} | 2 +- ...risp_seawater_ntp.erl => grisp_io_ntp.erl} | 2 +- ...risp_seawater_sup.erl => grisp_io_sup.erl} | 10 +++---- ...risp_seawater_tls.erl => grisp_io_tls.erl} | 4 +-- ...{grisp_seawater_ws.erl => grisp_io_ws.erl} | 22 +++++++-------- test/jsonrpc_SUITE.erl | 28 +++++++++---------- 15 files changed, 59 insertions(+), 61 deletions(-) rename src/{grisp_seawater.app.src => grisp_io.app.src} (69%) rename src/{grisp_seawater.erl => grisp_io.erl} (94%) rename src/{grisp_seawater_app.erl => grisp_io_app.erl} (82%) rename src/{grisp_seawater_jsonrpc.erl => grisp_io_jsonrpc.erl} (99%) rename src/{grisp_seawater_ntp.erl => grisp_io_ntp.erl} (99%) rename src/{grisp_seawater_sup.erl => grisp_io_sup.erl} (82%) rename src/{grisp_seawater_tls.erl => grisp_io_tls.erl} (97%) rename src/{grisp_seawater_ws.erl => grisp_io_ws.erl} (90%) diff --git a/.github/workflows/ct.yml b/.github/workflows/ct.yml index 1be92b5..9e5f638 100644 --- a/.github/workflows/ct.yml +++ b/.github/workflows/ct.yml @@ -1,4 +1,4 @@ -name: Grisp Seawater CT +name: grisp_io CT on: push: @@ -33,4 +33,3 @@ jobs: eval `ssh-agent -s` ssh-add - <<< '${{ secrets.STRITZINGER_BOT_SSH_KEY }}' rebar3 ct - diff --git a/README.md b/README.md index eaff1e4..caaef9f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# grisp_seawater +# grisp_io -Grisp2 Seawater Client Library +GRiSP.io Client Library for GRiSP ## Application env options @@ -21,6 +21,6 @@ Allows to tweak the timeout of each API request going through the websocket. ## Basic Low Level API Usage - grisp_seawater_ws:connect(). - true = grisp_seawater_ws:is_connected(). - {ok, <>} = grisp_seawater_ws:ping(). + grisp_io_ws:connect(). + true = grisp_io_ws:is_connected(). + {ok, <>} = grisp_io_ws:ping(). diff --git a/config/sys.config b/config/sys.config index 69b4c3b..7984bf4 100644 --- a/config/sys.config +++ b/config/sys.config @@ -1,5 +1,5 @@ [ - {grisp_seawater, [ + {grisp_io, [ {device_linking_token, <<"...">>} ]} ]. diff --git a/grisp/default/common/deploy/files/erl_inetrc b/grisp/default/common/deploy/files/erl_inetrc index d29df9f..a6dd601 100644 --- a/grisp/default/common/deploy/files/erl_inetrc +++ b/grisp/default/common/deploy/files/erl_inetrc @@ -2,7 +2,6 @@ % Add hosts {host, {149,248,205,211}, ["grisp.io"]}. -{host, {46,101,169,235}, ["seawater.stritzinger.com"]}. % old {host, {212,25,1,1}, ["0.europe.pool.ntp.org"]}. % Do not monitor the hosts file diff --git a/rebar.config b/rebar.config index 5f5b557..008f503 100644 --- a/rebar.config +++ b/rebar.config @@ -9,7 +9,7 @@ {shell, [ {config, "config/sys.config"}, - {apps, [grisp_seawater]} + {apps, [grisp_io]} ]}. {plugins, [rebar3_grisp, rebar3_ex_doc]}. @@ -27,7 +27,7 @@ {relx, [ {sys_config, "config/sys.config"}, - {release, {grisp_seawater, "0.1.0"}, [grisp_seawater]} + {release, {grisp_io, "0.1.0"}, [grisp_io]} ]}. {hex, [{doc, #{provider => ex_doc}}]}. @@ -39,7 +39,7 @@ {"LICENSE", #{title => "License"}} ]}, {main, "README.md"}, - {homepage_url, "https://github.com/grisp/grisp_seawater"}, - {source_url, "https://github.com/grisp/grisp_seawater"}, + {homepage_url, "https://github.com/grisp/grisp_io"}, + {source_url, "https://github.com/grisp/grisp_io"}, {api_reference, true} ]}. diff --git a/src/grisp_seawater.app.src b/src/grisp_io.app.src similarity index 69% rename from src/grisp_seawater.app.src rename to src/grisp_io.app.src index af9ba50..a52bd85 100644 --- a/src/grisp_seawater.app.src +++ b/src/grisp_io.app.src @@ -1,8 +1,8 @@ -{application, grisp_seawater, [ - {description, "Grisp2 Seawater Client Library"}, +{application, grisp_io, [ + {description, "GRiSP.io Client Library for GRiSP"}, {vsn, "0.1.0"}, {registered, []}, - {mod, {grisp_seawater_app, []}}, + {mod, {grisp_io_app, []}}, {applications, [ kernel, inets, @@ -14,8 +14,8 @@ jsx ]}, {env, [ - {seawater_domain, "grisp.io"}, - {seawater_port, 7777}, + {domain, "grisp.io"}, + {port, 7777}, {connect, true}, % keeps a constant connection with grisp.io {ntp, false}, % if set to true, starts the NTP client {ws_requests_timeout, 5_000} diff --git a/src/grisp_seawater.erl b/src/grisp_io.erl similarity index 94% rename from src/grisp_seawater.erl rename to src/grisp_io.erl index 1e2ed07..cf654e5 100644 --- a/src/grisp_seawater.erl +++ b/src/grisp_io.erl @@ -3,7 +3,7 @@ %% @end %%%------------------------------------------------------------------- --module(grisp_seawater). +-module(grisp_io). %--- Exports ------------------------------------------------------------------- diff --git a/src/grisp_seawater_app.erl b/src/grisp_io_app.erl similarity index 82% rename from src/grisp_seawater_app.erl rename to src/grisp_io_app.erl index b2b86a4..8a3805a 100644 --- a/src/grisp_seawater_app.erl +++ b/src/grisp_io_app.erl @@ -1,9 +1,9 @@ %%%------------------------------------------------------------------- -%% @doc grisp_seawater public API +%% @doc grisp_io public API %% @end %%%------------------------------------------------------------------- --module(grisp_seawater_app). +-module(grisp_io_app). -behaviour(application). @@ -17,7 +17,7 @@ %--- Behaviour application Callback Functions ---------------------------------- start(_StartType, _StartArgs) -> - grisp_seawater_sup:start_link(). + grisp_io_sup:start_link(). stop(_State) -> ok. diff --git a/src/grisp_io_connection.erl b/src/grisp_io_connection.erl index ae8af47..e809c44 100644 --- a/src/grisp_io_connection.erl +++ b/src/grisp_io_connection.erl @@ -29,7 +29,7 @@ disconnected() -> % gen_statem CALLBACKS --------------------------------------------------------- init([]) -> - {ok, Connect} = application:get_env(grisp_seawater, connect), + {ok, Connect} = application:get_env(grisp_io, connect), NextState = case Connect of true -> waiting_ip; false -> idle @@ -65,13 +65,13 @@ handle_event(state_timeout, retry, waiting_ip, Data) -> % CONNECTING handle_event(enter, _OldState, connecting, _Data) -> - {ok, Domain} = application:get_env(grisp_seawater, seawater_domain), - {ok, Port} = application:get_env(grisp_seawater, seawater_port), + {ok, Domain} = application:get_env(grisp_io, domain), + {ok, Port} = application:get_env(grisp_io, port), ?LOG_NOTICE(#{event => connecting, domain => Domain, port => Port}), - grisp_seawater_ws:connect(Domain, Port), + grisp_io_ws:connect(Domain, Port), {keep_state_and_data, [{state_timeout, 0, retry}]}; handle_event(state_timeout, retry, connecting, Data) -> - case grisp_seawater_ws:is_connected() of + case grisp_io_ws:is_connected() of true -> ?LOG_NOTICE(#{event => connected}), {next_state, connected, Data}; diff --git a/src/grisp_seawater_jsonrpc.erl b/src/grisp_io_jsonrpc.erl similarity index 99% rename from src/grisp_seawater_jsonrpc.erl rename to src/grisp_io_jsonrpc.erl index 6dfc749..52b28b5 100644 --- a/src/grisp_seawater_jsonrpc.erl +++ b/src/grisp_io_jsonrpc.erl @@ -1,4 +1,4 @@ --module(grisp_seawater_jsonrpc). +-module(grisp_io_jsonrpc). % API -export([decode/1]). diff --git a/src/grisp_seawater_ntp.erl b/src/grisp_io_ntp.erl similarity index 99% rename from src/grisp_seawater_ntp.erl rename to src/grisp_io_ntp.erl index a6ee9e3..9bed7ce 100644 --- a/src/grisp_seawater_ntp.erl +++ b/src/grisp_io_ntp.erl @@ -1,4 +1,4 @@ --module(grisp_seawater_ntp). +-module(grisp_io_ntp). % API -export([start_link/0]). diff --git a/src/grisp_seawater_sup.erl b/src/grisp_io_sup.erl similarity index 82% rename from src/grisp_seawater_sup.erl rename to src/grisp_io_sup.erl index 5eeeac4..e99c4af 100644 --- a/src/grisp_seawater_sup.erl +++ b/src/grisp_io_sup.erl @@ -1,9 +1,9 @@ %%%------------------------------------------------------------------- -%% @doc grisp_seawater top level supervisor. +%% @doc grisp_io top level supervisor. %% @end %%%------------------------------------------------------------------- --module(grisp_seawater_sup). +-module(grisp_io_sup). -behaviour(supervisor). @@ -34,12 +34,12 @@ init([]) -> SupFlags = #{ strategy => one_for_all }, - NTP = case application:get_env(grisp_seawater, ntp) of - {ok, true} -> [worker(grisp_seawater_ntp, [])]; + NTP = case application:get_env(grisp_io, ntp) of + {ok, true} -> [worker(grisp_io_ntp, [])]; {ok, false} -> [] end, ChildSpecs = NTP ++ [ - worker(grisp_seawater_ws, []), + worker(grisp_io_ws, []), worker(grisp_io_connection, []) ], {ok, {SupFlags, ChildSpecs}}. diff --git a/src/grisp_seawater_tls.erl b/src/grisp_io_tls.erl similarity index 97% rename from src/grisp_seawater_tls.erl rename to src/grisp_io_tls.erl index a663875..28816e9 100644 --- a/src/grisp_seawater_tls.erl +++ b/src/grisp_io_tls.erl @@ -3,7 +3,7 @@ %% @end %%%------------------------------------------------------------------- --module(grisp_seawater_tls). +-module(grisp_io_tls). %--- Exports ------------------------------------------------------------------- @@ -73,7 +73,7 @@ load_cert_chain(RelPath) -> end. cert_path(RelPath) -> - PrivDir = code:priv_dir(grisp_seawater), + PrivDir = code:priv_dir(grisp_io), filename:join([PrivDir | RelPath]) ++ ".pem". decode_cert_chain(PemData) -> diff --git a/src/grisp_seawater_ws.erl b/src/grisp_io_ws.erl similarity index 90% rename from src/grisp_seawater_ws.erl rename to src/grisp_io_ws.erl index efb6daf..5442c1a 100644 --- a/src/grisp_seawater_ws.erl +++ b/src/grisp_io_ws.erl @@ -1,5 +1,5 @@ %% @doc Websocket client to connect to grisp.io --module(grisp_seawater_ws). +-module(grisp_io_ws). -export([start_link/0]). -export([connect/0]). @@ -36,8 +36,8 @@ start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). connect() -> - {ok, Domain} = application:get_env(grisp_seawater, seawater_domain), - {ok, Port} = application:get_env(grisp_seawater, seawater_port), + {ok, Domain} = application:get_env(grisp_io, domain), + {ok, Port} = application:get_env(grisp_io, port), connect(Domain, Port). connect(Server, Port) -> @@ -47,7 +47,7 @@ is_connected() -> gen_server:call(?MODULE, ?FUNCTION_NAME). link_device() -> - case application:get_env(grisp_seawater, device_linking_token) of + case application:get_env(grisp_io, device_linking_token) of undefined -> {error, token_undefined}; {ok, Token} -> link_device(Token) end. @@ -75,7 +75,7 @@ handle_call({link_device, Token}, From, S) -> {noreply, NewS}. handle_cast({connect, Server, Port}, #state{gun_pid = undefined} = S) -> - case grisp_seawater_tls:connect(Server, Port) of + case grisp_io_tls:connect(Server, Port) of {ok, GunPid} -> {noreply, #state{gun_pid = GunPid}}; Error -> @@ -101,11 +101,11 @@ handle_info({gun_response, Pid, Stream, _, Status, _Headers}, {noreply, shutdown_gun(S)}; handle_info({gun_ws, Conn, Stream, {text, JSON}}, #state{gun_pid = Conn, ws_stream = Stream}= S) -> - JSON_RPC = grisp_seawater_jsonrpc:decode(JSON), + JSON_RPC = grisp_io_jsonrpc:decode(JSON), case handle_jsonrpc(JSON_RPC, S) of {[], NewS} -> {noreply, NewS}; {Msgs, NewS} -> - Text = grisp_seawater_jsonrpc:encode(Msgs), + Text = grisp_io_jsonrpc:encode(Msgs), gun:ws_send(S#state.gun_pid, S#state.ws_stream, {text, Text}), {noreply, NewS} end; @@ -150,19 +150,19 @@ handle_rpc_messages([{error, _Code, _Msg, _Data, _ID} = E | Batch], handle_rpc_messages([{internal_error, _, _} = E | Batch], Replies, S) -> ?LOG_ERROR(#{event => internal_jsonrpc_error, message => E}), handle_rpc_messages(Batch, - [grisp_seawater_jsonrpc:format_error(E)| Replies], S). + [grisp_io_jsonrpc:format_error(E)| Replies], S). handle_request(<<"post">>, #{type := <<"flash">>} = Params, ID) -> Led = maps:get(led, Params, 1), Color = maps:get(color, Params, red), {result, flash(Led, Color), ID}; handle_request(_, _, ID) -> - grisp_seawater_jsonrpc:format_error({internal_error, method_not_found, ID}). + grisp_io_jsonrpc:format_error({internal_error, method_not_found, ID}). make_request(Caller, Method, Type, Params, #state{requests = Reqs} = State) -> ID = id(), Rpc = {request, Method, maps:put(type, Type, Params), ID}, - Msg = grisp_seawater_jsonrpc:encode(Rpc), + Msg = grisp_io_jsonrpc:encode(Rpc), gun:ws_send(State#state.gun_pid, State#state.ws_stream, {text, Msg}), TRef = erlang:start_timer(ws_request_timeout(), self(), ID), Request = {Caller, TRef}, @@ -206,5 +206,5 @@ shutdown_gun(#state{gun_pid = Pid} = State) -> State?disconnected_state. ws_request_timeout() -> - {ok, Timeout} = application:get_env(grisp_seawater, seawater_domain), + {ok, Timeout} = application:get_env(grisp_io, io_domain), Timeout. diff --git a/test/jsonrpc_SUITE.erl b/test/jsonrpc_SUITE.erl index 463c459..ac6e1db 100644 --- a/test/jsonrpc_SUITE.erl +++ b/test/jsonrpc_SUITE.erl @@ -25,8 +25,8 @@ all() -> [ positional_parameters(_) -> Term = {request, <<"subtract">>, [42,23], 1}, Json = <<"{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":[42,23]}">>, - ?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)), - Json = grisp_seawater_jsonrpc:encode(Term), + ?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)), + Json = grisp_io_jsonrpc:encode(Term), ?assert(jsonrpc_check([<<"\"id\":1">>, <<"\"method\":\"subtract\"">>, <<"\"params\":[42,23]">>], Json)). @@ -34,8 +34,8 @@ positional_parameters(_) -> named_parameters(_) -> Term = {request, <<"subtract">>, #{<<"subtrahend">> => 23, <<"minuend">> => 42}, 2}, Json = <<"{\"id\":2,\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":{\"minuend\":42,\"subtrahend\":23}}">>, - ?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)), - Json = grisp_seawater_jsonrpc:encode(Term), + ?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)), + Json = grisp_io_jsonrpc:encode(Term), ?assert(jsonrpc_check([<<"\"id\":2">>, <<"\"method\":\"subtract\"">>, <<"\"minuend\":42">>, @@ -44,16 +44,16 @@ named_parameters(_) -> notification(_) -> Term = {notification, <<"update">>, [1,2,3,4,5]}, Json = <<"{\"jsonrpc\":\"2.0\",\"method\":\"update\",\"params\":[1,2,3,4,5]}">>, - ?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)), - Json = grisp_seawater_jsonrpc:encode(Term), + ?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)), + Json = grisp_io_jsonrpc:encode(Term), ?assert(jsonrpc_check([<<"\"method\":\"update\"">>, <<"\"params\":[1,2,3,4,5]">>], Json)). invalid_json(_) -> Term = {internal_error, parse_error, null}, Json = <<"{\"jsonrpc\":\"2.0\",\"method\":\"foobar,\"params\":\"bar\",\"baz]">>, - ?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)), - JsonError = grisp_seawater_jsonrpc:encode(grisp_seawater_jsonrpc:format_error(Term)), + ?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)), + JsonError = grisp_io_jsonrpc:encode(grisp_io_jsonrpc:format_error(Term)), ?assert(jsonrpc_check([<<"\"error\":{">>, <<"\"code\":-32700">>, <<"\"message\":\"Parse error\"">>, @@ -62,8 +62,8 @@ invalid_json(_) -> invalid_request(_) -> Term = {internal_error, invalid_request, null}, Json = <<"{\"jsonrpc\":\"2.0\",\"method\":1,\"params\":\"bar\"}">>, - ?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)), - JsonError = grisp_seawater_jsonrpc:encode(grisp_seawater_jsonrpc:format_error(Term)), + ?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)), + JsonError = grisp_io_jsonrpc:encode(grisp_io_jsonrpc:format_error(Term)), ?assert(jsonrpc_check([<<"\"error\":{">>, <<"\"code\":-32600">>, <<"\"message\":\"Invalid request\"">>, @@ -73,8 +73,8 @@ batch(_) -> Term1 = {request, <<"sum">>, [1,2,4], <<"1">>}, Term2 = {internal_error, invalid_request, null}, Json = <<"[{\"jsonrpc\":\"2.0\",\"method\":\"sum\",\"params\":[1,2,4],\"id\":\"1\"},{\"foo\":\"boo\"}]">>, - ?assertMatch({batch, [Term1,Term2]}, grisp_seawater_jsonrpc:decode(Json)), - JsonError = grisp_seawater_jsonrpc:encode([Term1, grisp_seawater_jsonrpc:format_error(Term2)]), + ?assertMatch({batch, [Term1,Term2]}, grisp_io_jsonrpc:decode(Json)), + JsonError = grisp_io_jsonrpc:encode([Term1, grisp_io_jsonrpc:format_error(Term2)]), ?assert(jsonrpc_check([<<"\"id\":\"1\"">>, <<"\"method\":\"sum\"">>, <<"params\":[1,2,4]">>, @@ -86,8 +86,8 @@ batch(_) -> result(_) -> Term = {result, 7, 45}, Json = <<"{\"id\":45,\"jsonrpc\":\"2.0\",\"result\":7}">>, - ?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)), - Json = grisp_seawater_jsonrpc:encode(Term), + ?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)), + Json = grisp_io_jsonrpc:encode(Term), ?assert(jsonrpc_check([<<"\"id\":45">>, <<"\"result\":7">>], Json)).