okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffauffeat(api)!: migrate daemon and clients to protocol 361c43ca

main
900 B23 linesraw
1-module(albedo_oauth_test_support).
2-export([get/1, occupy/1, release/1, identity/0]).
3
4get(Url) ->
5    _ = application:ensure_all_started(inets),
6    case httpc:request(get, {binary_to_list(Url), []}, [{timeout, 5000}], [{body_format, binary}]) of
7        {ok, {{_, Status, _}, _, _}} -> Status;
8        _ -> 0
9    end.
10
11occupy(Port) ->
12    {ok, Socket} = gen_tcp:listen(Port, [{ip, {127, 0, 0, 1}}]),
13    {ok, {_, Bound}} = inet:sockname(Socket),
14    {Socket, Bound}.
15
16release({Socket, _}) -> gen_tcp:close(Socket), nil.
17
18identity() ->
19    <<Timestamp:48>> = <<(erlang:system_time(millisecond)):48>>,
20    <<RandomA:12, RandomB:62, _:6>> = crypto:strong_rand_bytes(10),
21    Hex = binary:encode_hex(<<Timestamp:48,7:4,RandomA:12,2:2,RandomB:62>>, lowercase),
22    <<A:8/binary,B:4/binary,C:4/binary,D:4/binary,E:12/binary>> = Hex,
23    <<A/binary,"-",B/binary,"-",C/binary,"-",D/binary,"-",E/binary>>.