[api] use sensor id to determine the corresponding hash key
This commit is contained in:
parent
bd6762399b
commit
b157a5dc72
|
@ -31,7 +31,7 @@ ensure_started(App) ->
|
||||||
|
|
||||||
mysql_prepare() ->
|
mysql_prepare() ->
|
||||||
mysql:prepare(permissions, <<"SELECT permissions FROM logger_tokens WHERE meter = ? AND token = ?">>),
|
mysql:prepare(permissions, <<"SELECT permissions FROM logger_tokens WHERE meter = ? AND token = ?">>),
|
||||||
mysql:prepare(device_key, <<"SELECT sha FROM logger_devices WHERE device = ?">>).
|
mysql:prepare(device_key, <<"SELECT sha FROM (logger_devices ld INNER JOIN logger_meters lm ON ld.device = lm.device) WHERE lm.meter = ?">>).
|
||||||
|
|
||||||
%% @spec start_link() -> {ok,Pid::pid()}
|
%% @spec start_link() -> {ok,Pid::pid()}
|
||||||
%% @doc Starts the app for inclusion in a supervisor tree
|
%% @doc Starts the app for inclusion in a supervisor tree
|
||||||
|
|
|
@ -90,8 +90,8 @@ is_authorized(ReqData, State) ->
|
||||||
'GET' -> is_auth_GET(ReqData, State)
|
'GET' -> is_auth_GET(ReqData, State)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
is_auth_POST(ReqData, #state{device = Device, digest = ClientDigest} = State) ->
|
is_auth_POST(ReqData, #state{rrdSensor = Sensor, digest = ClientDigest} = State) ->
|
||||||
{data, Result} = mysql:execute(pool, device_key, [Device]),
|
{data, Result} = mysql:execute(pool, device_key, [Sensor]),
|
||||||
[[Key]] = mysql:get_result_rows(Result),
|
[[Key]] = mysql:get_result_rows(Result),
|
||||||
Data = wrq:req_body(ReqData),
|
Data = wrq:req_body(ReqData),
|
||||||
<<X:160/big-unsigned-integer>> = crypto:sha_mac(Key, Data),
|
<<X:160/big-unsigned-integer>> = crypto:sha_mac(Key, Data),
|
||||||
|
|
Loading…
Reference in New Issue