Skip to content

Commit

Permalink
Merge pull request #57 from belltoy/fix/type-spec
Browse files Browse the repository at this point in the history
Fix type spec
  • Loading branch information
zhongwencool authored Mar 23, 2023
2 parents 0cdd103 + cdda7ff commit 5919843
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 161 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ jobs:
otp-version: ${{matrix.otp}}
rebar3-version: '3.20.0'
version-type: strict
- run: rebar3 do ct -v -c, cover -v
- run: rebar3 do xref, dialyzer, gradualizer, ct -v -c, cover -v
env:
TERM: xterm-color
1 change: 1 addition & 0 deletions include/eetcd.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
-type value() :: iodata().
-type context() :: map().
-type name() :: atom() | reference().
-type new_context() :: atom() | reference() | context().
-type eetcd_error() :: timeout|{grpc_error,grpc_status()}|{gun_down,any()}|{gun_conn_error,any()}|{gun_stream_error,any()}|eetcd_conn_unavailable.
-type grpc_status() :: #{'grpc-status' => integer(), 'grpc-message' => binary()}.

Expand Down
15 changes: 15 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@
{rebar3_eetcd_plugin, "0.3.2"}
]}.

{project_plugins, [
{gradualizer, {git, "https://github.com/josefs/Gradualizer.git", {branch, "master"}}}
]}.

{gradualizer_opts, [
{include, ["include"]},

%% Use exclude_modules instead of exclude, See:
%% https://github.com/josefs/Gradualizer/issues/483
{exclude_modules, [
]},
{color, always}
]}.

{xref_checks, [
undefined_function_calls,
undefined_functions,
Expand All @@ -40,6 +54,7 @@
{xref_ignores, [
auth_pb,
gogo_pb,
health_pb,
kv_pb,
router_pb
]}.
60 changes: 30 additions & 30 deletions src/eetcd_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec auth_enable(name()|context()) ->
-spec auth_enable(new_context()) ->
{ok,router_pb:'Etcd.AuthEnableResponse'()}|{error,eetcd_error()}.
auth_enable(Context) ->
eetcd_auth_gen:auth_enable(new(Context)).
Expand All @@ -45,7 +45,7 @@ auth_enable(Context) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec auth_disable(name()|context()) ->
-spec auth_disable(new_context()) ->
{ok,router_pb:'Etcd.AuthDisableResponse'()}|{error,eetcd_error()}.
auth_disable(Context) ->
eetcd_auth_gen:auth_disable(new(Context)).
Expand All @@ -64,7 +64,7 @@ auth_disable(Context) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec user_add(name()|context(), iodata(), iodata()) ->
-spec user_add(new_context(), iodata(), iodata()) ->
{ok,router_pb:'Etcd.AuthUserAddResponse'()}|{error,eetcd_error()}.
user_add(Context, Name, Password) ->
C1 = new(Context),
Expand All @@ -86,10 +86,10 @@ user_add(Context, Name, Password) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec user_add(name()|context(), iodata()) ->
-spec user_add(new_context(), iodata()) ->
{ok,router_pb:'Etcd.AuthUserAddResponse'()}|{error,eetcd_error()}.
user_add(Context, Name) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(name, Name, C1),
C3 = maps:put(options, #{no_password => true}, C2),
eetcd_auth_gen:user_add(C3).
Expand All @@ -108,10 +108,10 @@ user_add(Context, Name) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec user_delete(name()|context(), iodata()) ->
-spec user_delete(new_context(), iodata()) ->
{ok,router_pb:'Etcd.AuthUserDeleteResponse'()}|{error,eetcd_error()}.
user_delete(Context, Name) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(name, Name, C1),
eetcd_auth_gen:user_delete(C2).

Expand All @@ -129,10 +129,10 @@ user_delete(Context, Name) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec user_change_password(name()|context(), iodata(), iodata()) ->
-spec user_change_password(new_context(), iodata(), iodata()) ->
{ok,router_pb:'Etcd.AuthUserChangePasswordResponse'()}|{error,eetcd_error()}.
user_change_password(Context, Name, Password) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(name, Name, C1),
C3 = maps:put(password, Password, C2),
eetcd_auth_gen:user_change_password(C3).
Expand All @@ -151,10 +151,10 @@ user_change_password(Context, Name, Password) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec user_grant_role(name()|context(), iodata(), iodata()) ->
-spec user_grant_role(new_context(), iodata(), iodata()) ->
{ok,router_pb:'Etcd.AuthUserGrantRoleResponse'()}|{error,eetcd_error()}.
user_grant_role(Context, User, Role) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(user, User, C1),
C3 = maps:put(role, Role, C2),
eetcd_auth_gen:user_grant_role(C3).
Expand All @@ -173,10 +173,10 @@ user_grant_role(Context, User, Role) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec user_get(name()|context(), iodata()) ->
-spec user_get(new_context(), iodata()) ->
{ok,router_pb:'Etcd.AuthUserGetResponse'()}|{error,eetcd_error()}.
user_get(Context, Name) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(name, Name, C1),
eetcd_auth_gen:user_get(C2).

Expand All @@ -194,10 +194,10 @@ user_get(Context, Name) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec user_list(name()|context()) ->
-spec user_list(new_context()) ->
{ok,router_pb:'Etcd.AuthUserListResponse'()}|{error,eetcd_error()}.
user_list(Context) ->
eetcd_auth_gen:user_list(eetcd:new(Context)).
eetcd_auth_gen:user_list(new(Context)).

%%% @doc UserRevokeRole revokes a role of a user.
%%% <dl>
Expand All @@ -213,10 +213,10 @@ user_list(Context) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec user_revoke_role(name()|context(), iodata(), iodata()) ->
-spec user_revoke_role(new_context(), iodata(), iodata()) ->
{ok,router_pb:'Etcd.AuthUserRevokeRoleResponse'()}|{error,eetcd_error()}.
user_revoke_role(Context, Name, Role) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(name, Name, C1),
C3 = maps:put(role, Role, C2),
eetcd_auth_gen:user_revoke_role(C3).
Expand All @@ -235,10 +235,10 @@ user_revoke_role(Context, Name, Role) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec role_add(name()|context(), iodata()) ->
-spec role_add(new_context(), iodata()) ->
{ok,router_pb:'Etcd.AuthRoleAddResponse'()}|{error,eetcd_error()}.
role_add(Context, Name) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(name, Name, C1),
eetcd_auth_gen:role_add(C2).

Expand All @@ -257,10 +257,10 @@ role_add(Context, Name) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec role_grant_permission(name()|context(), iodata(), iodata(), iodata(), 'READ' | 'WRITE' | 'READWRITE') ->
-spec role_grant_permission(new_context(), iodata(), iodata(), iodata(), 'READ' | 'WRITE' | 'READWRITE') ->
{ok,router_pb:'Etcd.AuthRoleGrantPermissionResponse'()}|{error,eetcd_error()}.
role_grant_permission(Context, Name, Key, RangeEnd, PermType) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(name, Name, C1),
Permission = #{key => Key, range_end => RangeEnd, permType => PermType},
C3 = maps:put(perm, Permission, C2),
Expand All @@ -280,10 +280,10 @@ role_grant_permission(Context, Name, Key, RangeEnd, PermType) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec role_get(name()|context(), iodata()) ->
-spec role_get(new_context(), iodata()) ->
{ok,router_pb:'Etcd.AuthRoleGetResponse'()}|{error,eetcd_error()}.
role_get(Context, Role) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(role, Role, C1),
eetcd_auth_gen:role_get(C2).

Expand All @@ -301,10 +301,10 @@ role_get(Context, Role) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec role_list(name()|context()) ->
-spec role_list(new_context()) ->
{ok,router_pb:'Etcd.AuthRoleListResponse'()}|{error,eetcd_error()}.
role_list(Context) ->
eetcd_auth_gen:role_list(eetcd:new(Context)).
eetcd_auth_gen:role_list(new(Context)).

%%% @doc RoleRevokePermission revokes a permission from a role.
%%% <dl>
Expand All @@ -320,10 +320,10 @@ role_list(Context) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec role_revoke_permission(name()|context(), iodata(), iodata(), iodata()) ->
-spec role_revoke_permission(new_context(), iodata(), iodata(), iodata()) ->
{ok,router_pb:'Etcd.AuthRoleRevokePermissionResponse'()}|{error,eetcd_error()}.
role_revoke_permission(Context, Role, Key, RangeEnd) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(role, Role, C1),
C3 = maps:put(key, Key, C2),
C4 = maps:put(range_end, RangeEnd, C3),
Expand All @@ -343,15 +343,15 @@ role_revoke_permission(Context, Role, Key, RangeEnd) ->
%%% </dd> </dl>
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
%%% @end
-spec role_delete(name()|context(), iodata()) ->
-spec role_delete(new_context(), iodata()) ->
{ok,router_pb:'Etcd.AuthRoleDeleteResponse'()}|{error,eetcd_error()}.
role_delete(Context, Role) ->
C1 = eetcd:new(Context),
C1 = new(Context),
C2 = maps:put(role, Role, C1),
eetcd_auth_gen:role_delete(C2).

%%% @doc Create context for request.
-spec new(atom()|reference()) -> context().
-spec new(new_context()) -> context().
new(Context) -> eetcd:new(Context).

%% @doc Timeout is an integer greater than zero which specifies how many milliseconds to wait for a reply,
Expand Down
20 changes: 10 additions & 10 deletions src/eetcd_cluster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%%% </dd> </dl>
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
%%% @end
-spec member_list(context()|name()) ->
-spec member_list(new_context()) ->
{ok,router_pb:'Etcd.MemberListResponse'()}|{error,eetcd_error()}.
member_list(Context) -> eetcd_cluster_gen:member_list(new(Context)).

Expand All @@ -41,9 +41,9 @@ member_list(Context) -> eetcd_cluster_gen:member_list(new(Context)).
%%% </dd> </dl>
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
%%% @end
-spec member_add(context()|name(), PeerURLs) ->
{ok,router_pb:'Etcd.MemberListResponse'()}
| {error, {'grpc_error', non_neg_integer(), binary()}} | {error, term()}
-spec member_add(new_context(), PeerURLs) ->
{ok,router_pb:'Etcd.MemberAddResponse'()}
| {error, eetcd:eetcd_error()}
when PeerURLs :: [iodata()].
member_add(Context, PeerAddrs) when is_list(PeerAddrs) ->
C1 = new(Context),
Expand All @@ -65,8 +65,8 @@ member_add(Context, PeerAddrs) when is_list(PeerAddrs) ->
%%% </dd> </dl>
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
%%% @end
-spec member_add_as_learner(context()|name(), PeerURLs) ->
{ok,router_pb:'Etcd.MemberListResponse'()}
-spec member_add_as_learner(new_context(), PeerURLs) ->
{ok,router_pb:'Etcd.MemberAddResponse'()}
| {error, {'grpc_error', non_neg_integer(), binary()}} | {error, term()}
when PeerURLs :: [iodata()].
member_add_as_learner(Context, PeerAddrs) when is_list(PeerAddrs) ->
Expand All @@ -89,7 +89,7 @@ member_add_as_learner(Context, PeerAddrs) when is_list(PeerAddrs) ->
%%% </dd> </dl>
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
%%% @end
-spec member_remove(context()|name(), pos_integer()) ->
-spec member_remove(new_context(), pos_integer()) ->
{ok,router_pb:'Etcd.MemberRemoveResponse'()}|{error,eetcd_error()}.
member_remove(Context, Id) when is_integer(Id) ->
C1 = new(Context),
Expand All @@ -110,7 +110,7 @@ member_remove(Context, Id) when is_integer(Id) ->
%%% </dd> </dl>
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
%%% @end
-spec member_update(context()|name(), pos_integer(), [list()]) ->
-spec member_update(new_context(), pos_integer(), [list()]) ->
{ok,router_pb:'Etcd.MemberUpdateResponse'()}|{error,eetcd_error()}.
member_update(Context, Id, PeerAddrs)
when is_integer(Id) andalso is_list(PeerAddrs) ->
Expand All @@ -133,15 +133,15 @@ member_update(Context, Id, PeerAddrs)
%%% </dd> </dl>
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
%%% @end
-spec member_promote(context()|name(), pos_integer()) ->
-spec member_promote(new_context(), pos_integer()) ->
{ok,router_pb:'Etcd.MemberPromoteResponse'()}|{error,eetcd_error()}.
member_promote(Context, Id) when is_integer(Id) ->
C1 = new(Context),
C2 = maps:put('ID', Id, C1),
eetcd_cluster_gen:member_promote(C2).

%%% @doc Create context for request.
-spec new(atom()|reference()) -> context().
-spec new(new_context()) -> context().
new(Context) -> eetcd:new(Context).

%% @doc Timeout is an integer greater than zero which specifies how many milliseconds to wait for a reply,
Expand Down
Loading

0 comments on commit 5919843

Please sign in to comment.