TD-261: Remove user info requirement (#2)

This commit is contained in:
Alexey S 2022-04-07 12:21:18 +03:00 committed by GitHub
parent 602d4dc87b
commit 31850a63f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 117 deletions

View File

@ -16,7 +16,7 @@ services:
command: /sbin/init
party-management:
image: ghcr.io/valitydev/party-management:sha-e456e24
image: ghcr.io/valitydev/party-management:sha-76058e0
command: /opt/party-management/bin/party-management foreground
depends_on:
machinegun:

View File

@ -28,8 +28,7 @@
{deps, [
{genlib, {git, "https://github.com/valitydev/genlib.git", {branch, "master"}}},
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {branch, "master"}}},
{woody_user_identity, {git, "https://github.com/valitydev/woody_erlang_user_identity.git", {branch, "master"}}}
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {branch, "master"}}}
]}.
%% XRef checks

View File

@ -31,10 +31,6 @@
{<<"woody">>,
{git,"https://github.com/valitydev/woody_erlang.git",
{ref,"3ddacb9296691aa8ddad05498d1fd34b078eda75"}},
0},
{<<"woody_user_identity">>,
{git,"https://github.com/valitydev/woody_erlang_user_identity.git",
{ref,"a480762fea8d7c08f105fb39ca809482b6cb042e"}},
0}]}.
[
{pkg_hash,[

View File

@ -7,8 +7,7 @@
stdlib,
genlib,
damsel,
woody,
woody_user_identity
woody
]},
{env, [
{services, #{

View File

@ -4,7 +4,6 @@
-export([get_party_service/1]).
-export([get_cache_mode/1]).
-export([get_aggressive_caching_timeout/1]).
-export([get_woody_transport_opts/1]).
-export([get_woody_options/1]).
-export([get_deadline_timeout/1]).
-export([get_retries/1]).
@ -39,7 +38,6 @@
-type config_path() :: atom() | [atom() | [any()]].
-type woody_service() :: woody:service().
-type woody_options() :: woody_caching_client:options().
-type woody_transport_opts() :: woody_client_thrift_http_transport:transport_options().
%% API
@ -65,12 +63,6 @@ get_aggressive_caching_timeout(#{aggressive_caching_timeout := Timeout}) ->
get_aggressive_caching_timeout(_Client) ->
get_default([woody, aggressive_caching_time], ?DEFAULT_AGGERSSIVE_CACHING_TIMEOUT).
-spec get_woody_transport_opts(client()) -> woody_transport_opts().
get_woody_transport_opts(#{woody_transport_opts := Opts}) ->
Opts;
get_woody_transport_opts(_Client) ->
get_default([woody, transport_opts], #{}).
-spec get_woody_options(client()) -> woody_options().
get_woody_options(Client) ->
DefaultOptions = #{

View File

@ -2,26 +2,17 @@
-export([create/1]).
-export([get_woody_context/1]).
-export([set_woody_context/2]).
-export([get_user_info/1]).
-export([get_user_info/2]).
-export([set_user_info/2]).
-opaque context() :: #{
woody_context := woody_context(),
user_info => user_info()
woody_context := woody_context()
}.
-type options() :: #{
woody_context => woody_context(),
user_info => user_info()
woody_context => woody_context()
}.
-type user_info() :: woody_user_identity:user_identity().
-export_type([context/0]).
-export_type([options/0]).
-export_type([user_info/0]).
%% Internal types
@ -34,28 +25,9 @@ create(Options) ->
ensure_woody_context_exists(Options).
-spec get_woody_context(context()) -> woody_context().
get_woody_context(Context) ->
#{woody_context := WoodyContext} = ensure_user_info_set(Context),
get_woody_context(#{woody_context := WoodyContext}) ->
WoodyContext.
-spec set_woody_context(woody_context(), context()) -> context().
set_woody_context(WoodyContext, Context) ->
Context#{woody_context => WoodyContext}.
-spec get_user_info(context()) -> user_info() | undefined.
get_user_info(Context) ->
get_user_info(Context, undefined).
-spec get_user_info(context(), Default) -> user_info() | Default.
get_user_info(#{user_info := UserInfo}, _Default) ->
UserInfo;
get_user_info(#{woody_context := WoodyContext}, Default) ->
get_woody_user_info(WoodyContext, Default).
-spec set_user_info(user_info(), context()) -> context().
set_user_info(UserInfo, Context) ->
Context#{user_info => UserInfo}.
%% Internal functions
-spec ensure_woody_context_exists(options()) -> options().
@ -63,20 +35,3 @@ ensure_woody_context_exists(#{woody_context := _WoodyContext} = Options) ->
Options;
ensure_woody_context_exists(Options) ->
Options#{woody_context => woody_context:new()}.
-spec ensure_user_info_set(context()) -> context().
ensure_user_info_set(#{user_info := UserInfo, woody_context := WoodyContext} = Context) ->
NewWoodyContext = woody_user_identity:put(UserInfo, WoodyContext),
Context#{woody_context => NewWoodyContext};
ensure_user_info_set(Context) ->
Context.
-spec get_woody_user_info(woody_context(), Default) -> user_info() | Default.
get_woody_user_info(WoodyContext, Default) ->
try woody_user_identity:get(WoodyContext) of
WoodyIdentity ->
WoodyIdentity
catch
throw:{missing_required, _Key} ->
Default
end.

View File

@ -49,7 +49,6 @@
%% Domain types
-type party() :: dmsl_domain_thrift:'Party'().
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type party_params() :: dmsl_payment_processing_thrift:'PartyParams'().
-type party_revision() :: dmsl_domain_thrift:'PartyRevision'().
@ -94,7 +93,6 @@
-type revoke_reason() :: binary() | undefined.
-export_type([party/0]).
-export_type([user_info/0]).
-export_type([party_id/0]).
-export_type([party_params/0]).
-export_type([party_revision/0]).
@ -134,7 +132,6 @@
%% Error types
-type invalid_user() :: dmsl_payment_processing_thrift:'InvalidUser'().
-type party_exists() :: dmsl_payment_processing_thrift:'PartyExists'().
-type party_not_exists_yet() :: dmsl_payment_processing_thrift:'PartyNotExistsYet'().
-type party_not_found() :: dmsl_payment_processing_thrift:'PartyNotFound'().
@ -171,7 +168,7 @@
%% Internal types
-type error(Error) :: invalid_user() | party_not_found() | Error.
-type error(Error) :: party_not_found() | Error.
-type result(Success, Error) :: {ok, Success} | {error, error(Error)}.
-type void(Error) :: ok | {error, error(Error)}.
@ -185,7 +182,7 @@
%% Party API
-spec create(party_id(), party_params(), client(), context()) -> ok | {error, error(Error)} | no_return() when
Error :: invalid_user() | party_exists().
Error :: party_exists().
create(PartyId, PartyParams, Client, Context) ->
call('Create', [PartyId, PartyParams], Client, Context).
@ -415,25 +412,8 @@ get_events(PartyId, Range, Client, Context) ->
%% Internal functions
call(Function, Args, Client, Context) ->
UserInfo = party_client_context:get_user_info(Context),
valid = validate_user_info(UserInfo),
ArgsWithUserInfo = erlang:list_to_tuple([encode_user_info(UserInfo) | Args]),
ArgsWithUserInfo = erlang:list_to_tuple(with_user_info(Args)),
party_client_woody:call(Function, ArgsWithUserInfo, Client, Context).
-spec validate_user_info(party_client_context:user_info() | undefined) -> valid | no_return().
validate_user_info(undefined = UserInfo) ->
error(invalid_user_info, [UserInfo]);
validate_user_info(_UserInfo) ->
valid.
-spec encode_user_info(party_client_context:user_info()) -> user_info().
encode_user_info(#{id := Id, realm := Realm}) ->
#payproc_UserInfo{id = Id, type = encode_realm(Realm)}.
-spec encode_realm(binary()) -> dmsl_payment_processing_thrift:'UserType'().
encode_realm(<<"external">>) ->
{external_user, #payproc_ExternalUser{}};
encode_realm(<<"internal">>) ->
{internal_user, #payproc_InternalUser{}};
encode_realm(<<"service">>) ->
{service_user, #payproc_ServiceUser{}}.
with_user_info(Args) ->
[undefined | Args].

View File

@ -16,7 +16,6 @@
-export([end_per_testcase/2]).
-export([create_and_get_test/1]).
-export([user_info_using_test/1]).
-export([party_errors_test/1]).
-export([party_operations_test/1]).
-export([contract_create_and_get_test/1]).
@ -56,7 +55,6 @@ groups() ->
[
{party_management_api, [parallel], [
create_and_get_test,
user_info_using_test,
party_errors_test,
party_operations_test,
contract_create_and_get_test,
@ -136,21 +134,6 @@ create_and_get_test(C) ->
{ok, Party} = party_client_thrift:get(PartyId, Client, Context),
#domain_Party{id = PartyId, contact_info = ContactInfo} = Party.
-spec user_info_using_test(config()) -> any().
user_info_using_test(C) ->
{ok, PartyId, Client, _Context} = test_init_info(C),
UserInfo = user_info(test, service),
ContextWithoutUser = party_client:create_context(),
ContextWithUser = party_client:create_context(#{user_info => UserInfo}),
WoodyContext = woody_user_identity:put(UserInfo, woody_context:new()),
ContextWithWoody = party_client:create_context(#{woody_context => WoodyContext}),
ContactInfo = #domain_PartyContactInfo{email = PartyId},
ok = party_client_thrift:create(PartyId, make_party_params(ContactInfo), Client, ContextWithUser),
{ok, _} = (catch party_client_thrift:get(PartyId, Client, ContextWithUser)),
{ok, _} = (catch party_client_thrift:get(PartyId, Client, ContextWithWoody)),
{'EXIT', {invalid_user_info, _}} = (catch party_client_thrift:get(PartyId, Client, ContextWithoutUser)),
ok.
-spec party_errors_test(config()) -> any().
party_errors_test(C) ->
{ok, PartyId, Client, Context} = test_init_info(C),
@ -162,8 +145,6 @@ party_errors_test(C) ->
{error, #payproc_InvalidPartyRevision{}} =
party_client_thrift:checkout(PartyId, {revision, 100500}, Client, Context),
{error, #payproc_InvalidPartyStatus{}} = party_client_thrift:activate(PartyId, Client, Context),
OtherContext = party_client:create_context(#{user_info => user_info(test2, external)}),
{error, #payproc_InvalidUser{}} = party_client_thrift:get(PartyId, Client, OtherContext),
ok.
-spec party_operations_test(config()) -> any().
@ -174,8 +155,12 @@ party_operations_test(C) ->
ok = party_client_thrift:activate(PartyId, Client, Context),
ok = party_client_thrift:block(PartyId, <<"block_test">>, Client, Context),
ok = party_client_thrift:unblock(PartyId, <<"unblock_test">>, Client, Context),
OtherContext = party_client:create_context(#{user_info => user_info(test2, external)}),
{error, #payproc_InvalidUser{}} = party_client_thrift:get(PartyId, Client, OtherContext),
{ok, #{}} = party_client_thrift:get_meta(PartyId, Client, Context),
MetadataNs = <<"metadata">>,
Metadata = {str, <<"cool_stuff">>},
ok = party_client_thrift:set_metadata(PartyId, MetadataNs, Metadata, Client, Context),
{ok, Metadata} = party_client_thrift:get_metadata(PartyId, MetadataNs, Client, Context),
ok = party_client_thrift:remove_metadata(PartyId, MetadataNs, Client, Context),
ok.
-spec contract_create_and_get_test(config()) -> any().
@ -224,7 +209,10 @@ shop_operations_test(C) ->
ok = party_client_thrift:suspend_shop(PartyId, ShopId, Client, Context),
ok = party_client_thrift:activate_shop(PartyId, ShopId, Client, Context),
ok = party_client_thrift:block_shop(PartyId, ShopId, <<"block_test">>, Client, Context),
ok = party_client_thrift:unblock_shop(PartyId, ShopId, <<"unblock_test">>, Client, Context).
ok = party_client_thrift:unblock_shop(PartyId, ShopId, <<"unblock_test">>, Client, Context),
{ok, #domain_ShopAccount{settlement = AccountID}} =
party_client_thrift:get_shop_account(PartyId, ShopId, Client, Context),
{ok, _ShopAccount} = party_client_thrift:get_account_state(PartyId, AccountID, Client, Context).
-spec claim_operations_test(config()) -> any().
claim_operations_test(C) ->
@ -539,12 +527,8 @@ conf(Key, Config) ->
make_party_params(ContactInfo) ->
#payproc_PartyParams{contact_info = ContactInfo}.
-spec user_info(any(), any()) -> party_client_context:user_info().
user_info(User, Realm) ->
#{id => genlib:to_binary(User), realm => genlib:to_binary(Realm)}.
create_context() ->
party_client:create_context(#{user_info => user_info(test, service)}).
party_client:create_context().
test_init_info(C) ->
PartyId = get_test_id(C),