diff --git a/apps/capi/src/capi_domain.erl b/apps/capi/src/capi_domain.erl index 331314c..22ab95d 100644 --- a/apps/capi/src/capi_domain.erl +++ b/apps/capi/src/capi_domain.erl @@ -1,11 +1,12 @@ -module(capi_domain). -include_lib("damsel/include/dmsl_domain_thrift.hrl"). --include_lib("damsel/include/dmsl_domain_conf_thrift.hrl"). +-include_lib("damsel/include/dmsl_domain_conf_v2_thrift.hrl"). -export([head/0]). -export([get_payment_institution/2]). -export([get_payment_institutions/1]). +-export([get_country/2]). -export([get/2]). -export([get/3]). -export([get_ext/3]). @@ -15,6 +16,8 @@ -export([extract_type/1]). -type processing_context() :: capi_handler:processing_context(). +-type country_code() :: dmsl_domain_thrift:'CountryCode'(). +-type country_object() :: dmsl_domain_thrift:'CountryObject'(). -type ref() :: dmsl_domain_thrift:'Reference'(). -type data() :: _. -type revision() :: dmt_client:version(). @@ -29,7 +32,7 @@ -spec head() -> revision(). head() -> - dmt_client:get_last_version(). + dmt_client:get_latest_version(). -spec get_payment_institution(payment_institution_ref(), processing_context()) -> {ok, payment_institution()} | {error, not_found}. @@ -46,10 +49,8 @@ get_payment_institutions(Context) -> try Opts = make_opts(Context), - #'domain_conf_VersionedObject'{ - version = Version, - object = {globals, #domain_GlobalsObject{data = Globals}} - } = dmt_client:checkout_versioned_object(latest, globals(), Opts), + {Version, #domain_GlobalsObject{data = Globals}} = + unwrap_versioned(dmt_client:checkout_object(latest, globals(), Opts)), PaymentInstitutionRefs = case Globals#domain_Globals.payment_institutions of @@ -60,9 +61,8 @@ get_payment_institutions(Context) -> PaymentInstitutions = lists:map( fun(Ref) -> - {payment_institution, Object} = dmt_client:checkout_object( - Version, {payment_institution, Ref}, Opts - ), + {_, Object} = + unwrap_versioned(dmt_client:checkout_object(Version, {payment_institution, Ref}, Opts)), Object end, PaymentInstitutionRefs @@ -70,7 +70,18 @@ get_payment_institutions(Context) -> {ok, PaymentInstitutions} catch - throw:#'domain_conf_ObjectNotFound'{} -> + throw:#domain_conf_v2_ObjectNotFound{} -> + {error, not_found} + end. + +-spec get_country(country_code(), processing_context() | undefined) -> {ok, country_object()} | {error, not_found}. +get_country(CountryCode, Context) -> + Ref = {country, #domain_CountryRef{id = CountryCode}}, + try + get(Ref, Context) + catch + error:{woody_error, {internal, result_unexpected, _}} -> + %% NOTE Object not exists if woody fails to encode country code {error, not_found} end. @@ -82,20 +93,22 @@ get(Ref, Context) -> get(Ref, Revision, Context) -> try Opts = make_opts(Context), - {_Type, Object} = dmt_client:checkout_object(Revision, Ref, Opts), + {_, Object} = unwrap_versioned(dmt_client:checkout_object(Revision, Ref, Opts)), {ok, Object} catch - throw:#'domain_conf_ObjectNotFound'{} -> + throw:#domain_conf_v2_ObjectNotFound{} -> {error, not_found} end. +%% FIXME Naming. It supposed to return unwrapped `Data` from object +%% structured as `{Type, {Tag, Ref, Data}}`. -spec get_ext(ref(), revision(), processing_context() | undefined) -> {ok, data()} | {error, not_found}. get_ext(Ref, Revision, Context) -> try Opts = make_opts(Context), - {ok, extract_data(dmt_client:checkout_object(Revision, Ref, Opts))} + {ok, extract_data(unwrap_versioned(dmt_client:checkout_object(Revision, Ref, Opts)))} catch - throw:#'domain_conf_ObjectNotFound'{} -> + throw:#domain_conf_v2_ObjectNotFound{} -> {error, not_found} end. @@ -143,7 +156,13 @@ globals() -> -spec get_objects_by_type(Type :: atom(), processing_context()) -> {ok, [dmsl_domain_thrift:'DomainObject'()]}. get_objects_by_type(Type, Context) -> Opts = make_opts(Context), - Objects = dmt_client:checkout_objects_by_type(latest, Type, Opts), + Objects = lists:map( + fun(VersionedObject) -> + {_, Object} = unwrap_versioned(VersionedObject), + Object + end, + dmt_client:checkout_objects_by_type(latest, Type, Opts) + ), {ok, Objects}. -spec make_opts(processing_context()) -> dmt_client:opts(). @@ -151,3 +170,9 @@ make_opts(#{woody_context := WoodyContext}) -> #{woody_context => WoodyContext}; make_opts(_) -> #{}. + +unwrap_versioned(#domain_conf_v2_VersionedObject{ + info = #domain_conf_v2_VersionedObjectInfo{version = Version}, + object = {_Type, Object} +}) -> + {Version, Object}. diff --git a/apps/capi/src/capi_handler_countries.erl b/apps/capi/src/capi_handler_countries.erl index 1ded40b..ffafa69 100644 --- a/apps/capi/src/capi_handler_countries.erl +++ b/apps/capi/src/capi_handler_countries.erl @@ -29,8 +29,7 @@ process_request('GetCountries', _Req, Context) -> {ok, {200, #{}, lists:map(fun decode_country_object/1, Countries)}}; process_request('GetCountryByID', Req, Context) -> CountryCode = capi_coder_utils:encode_country_code(maps:get('countryID', Req)), - Ref = {country, #domain_CountryRef{id = CountryCode}}, - case capi_domain:get(Ref, Context) of + case capi_domain:get_country(CountryCode, Context) of {ok, CountryObject} -> {ok, {200, #{}, decode_country_object(CountryObject)}}; {error, not_found} -> diff --git a/apps/capi/test/capi_ct_helper.erl b/apps/capi/test/capi_ct_helper.erl index 08dc05c..d178ec1 100644 --- a/apps/capi/test/capi_ct_helper.erl +++ b/apps/capi/test/capi_ct_helper.erl @@ -3,9 +3,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("capi_dummy_data.hrl"). -include_lib("capi_token_keeper_data.hrl"). --include_lib("damsel/include/dmsl_domain_conf_thrift.hrl"). --include_lib("damsel/include/dmsl_domain_thrift.hrl"). --include_lib("damsel/include/dmsl_base_thrift.hrl"). +-include_lib("damsel/include/dmsl_domain_conf_v2_thrift.hrl"). -export([init_suite/2]). -export([init_suite/3]). @@ -50,12 +48,44 @@ init_suite(Module, Config, CapiEnv) -> WoodyApp = start_app(woody), ServiceURLs = mock_services_( [ + { + 'RepositoryClient', + {dmsl_domain_conf_v2_thrift, 'RepositoryClient'}, + fun('CheckoutObject', {{version, ?INTEGER}, ObjectRef}) -> + case maps:get(ObjectRef, ?ALL_OBJECTS, undefined) of + undefined -> + woody_error:raise(business, #domain_conf_v2_ObjectNotFound{}); + Object -> + {ok, dmt_wrap_object(Object)} + end + end + }, { 'Repository', - {dmsl_domain_conf_thrift, 'Repository'}, + {dmsl_domain_conf_v2_thrift, 'Repository'}, fun - ('Checkout', _) -> {ok, ?SNAPSHOT}; - ('PullRange', _) -> {ok, #{}} + ('GetLatestVersion', _) -> + {ok, ?INTEGER}; + ( + 'SearchFullObjects', + {#domain_conf_v2_SearchRequestParams{ + query = ~b"*", version = ?INTEGER, limit = _, type = Type, continuation_token = _ + }} + ) -> + Result0 = lists:foldl( + fun + ({{T, _}, Object}, Acc) when T =:= Type -> + [dmt_wrap_object(Object) | Acc]; + (_, Acc) -> + Acc + end, + [], + maps:to_list(?ALL_OBJECTS) + ), + Result1 = lists:reverse(Result0), + {ok, #domain_conf_v2_SearchFullResponse{ + result = Result1, total_count = length(Result1), continuation_token = undefined + }} end } ], @@ -321,3 +351,17 @@ add_prefix(Key, Value, {Prefix, Acc}) -> get_blacklisted_keys_dir(Config) -> filename:join(?config(data_dir, Config), "blacklisted_keys"). + +dmt_wrap_object(Object) -> + #domain_conf_v2_VersionedObject{ + info = #domain_conf_v2_VersionedObjectInfo{ + version = ?INTEGER, + changed_at = genlib_rfc3339:format(genlib_time:unow(), second), + changed_by = #domain_conf_v2_Author{ + id = ?STRING, + name = ?STRING, + email = ?STRING + } + }, + object = Object + }. diff --git a/apps/capi/test/capi_dummy_data.hrl b/apps/capi/test/capi_dummy_data.hrl index e03d8c0..246eaec 100644 --- a/apps/capi/test/capi_dummy_data.hrl +++ b/apps/capi/test/capi_dummy_data.hrl @@ -5,7 +5,6 @@ -include_lib("damsel/include/dmsl_domain_thrift.hrl"). -include_lib("damsel/include/dmsl_payproc_thrift.hrl"). -include_lib("damsel/include/dmsl_webhooker_thrift.hrl"). --include_lib("damsel/include/dmsl_domain_conf_thrift.hrl"). -include_lib("damsel/include/dmsl_user_interaction_thrift.hrl"). -include_lib("magista_proto/include/magista_magista_thrift.hrl"). @@ -684,125 +683,122 @@ status_changed_at = ?TIMESTAMP }). --define(SNAPSHOT, #'domain_conf_Snapshot'{ - version = ?INTEGER, - domain = #{ - {category, #domain_CategoryRef{id = ?INTEGER}} => - {category, #domain_CategoryObject{ - ref = #domain_CategoryRef{id = ?INTEGER}, - data = #domain_Category{ - name = ?STRING, - description = ?STRING - } - }}, - {business_schedule, #domain_BusinessScheduleRef{id = ?INTEGER}} => - {business_schedule, #domain_BusinessScheduleObject{ - ref = #domain_BusinessScheduleRef{id = ?INTEGER}, - data = #domain_BusinessSchedule{ - name = ?STRING, - description = ?STRING, - schedule = #'base_Schedule'{ - year = {every, #'base_ScheduleEvery'{}}, - month = {every, #'base_ScheduleEvery'{}}, - day_of_month = {every, #'base_ScheduleEvery'{}}, - day_of_week = {every, #'base_ScheduleEvery'{}}, - hour = {every, #'base_ScheduleEvery'{}}, - minute = {every, #'base_ScheduleEvery'{}}, - second = {every, #'base_ScheduleEvery'{}} - }, - delay = #'base_TimeSpan'{} - } - }}, - {globals, #domain_GlobalsRef{}} => - {globals, #domain_GlobalsObject{ - ref = #domain_GlobalsRef{}, - data = #domain_Globals{ - external_account_set = {value, #domain_ExternalAccountSetRef{id = ?INTEGER}}, - payment_institutions = [#domain_PaymentInstitutionRef{id = ?INTEGER}] - } - }}, - {payment_institution, #domain_PaymentInstitutionRef{id = ?INTEGER}} => - {payment_institution, #domain_PaymentInstitutionObject{ - ref = #domain_PaymentInstitutionRef{id = ?INTEGER}, - data = #domain_PaymentInstitution{ - name = ?STRING, - description = ?STRING, - system_account_set = {value, #domain_SystemAccountSetRef{id = ?INTEGER}}, - default_contract_template = {value, #domain_ContractTemplateRef{id = ?INTEGER}}, - providers = {value, []}, - inspector = {value, #domain_InspectorRef{id = ?INTEGER}}, - realm = test, - residences = [rus] - } - }}, - {country, #domain_CountryRef{id = rus}} => - {country, #domain_CountryObject{ - ref = #domain_CountryRef{id = rus}, - data = #domain_Country{ - name = <<"Russia">> - } - }}, - {party_config, #domain_PartyConfigRef{id = ?STRING}} => - {party_config, #domain_PartyConfigObject{ - ref = #domain_PartyConfigRef{id = ?STRING}, - data = ?PARTY_WITH_SHOPS - }}, - {shop_config, #domain_ShopConfigRef{id = ?STRING}} => - {shop_config, #domain_ShopConfigObject{ - ref = #domain_ShopConfigRef{id = ?STRING}, - data = ?SHOP(?USD) - }}, - {country, #domain_CountryRef{id = deu}} => - {country, #domain_CountryObject{ - ref = #domain_CountryRef{id = deu}, - data = #domain_Country{ - name = <<"Germany">>, - trade_blocs = ordsets:from_list( - [#domain_TradeBlocRef{id = <<"EEA">>}] - ) - } - }}, - {trade_bloc, #domain_TradeBlocRef{id = <<"EEA">>}} => - {trade_bloc, #domain_TradeBlocObject{ - ref = #domain_TradeBlocRef{id = <<"EEA">>}, - data = #domain_TradeBloc{ - name = <<"European Economic Area">>, - description = <<"Extension of EU">> - } - }}, - - {payment_system, #domain_PaymentSystemRef{id = <<"visa">>}} => - {payment_system, #domain_PaymentSystemObject{ - ref = #domain_PaymentSystemRef{id = <<"visa">>}, - data = #domain_PaymentSystem{name = <<"Visa">>} - }}, - - {payment_system, #domain_PaymentSystemRef{id = <<"mastercard">>}} => - {payment_system, #domain_PaymentSystemObject{ - ref = #domain_PaymentSystemRef{id = <<"mastercard">>}, - data = #domain_PaymentSystem{name = <<"Mastercard">>} - }}, - - {payment_service, #domain_PaymentServiceRef{id = <<"qiwi">>}} => - {payment_service, #domain_PaymentServiceObject{ - ref = #domain_PaymentServiceRef{id = <<"qiwi">>}, - data = #domain_PaymentService{ - name = <<"Qiwi">>, - brand_name = <<"QIWI">>, - category = <<"wallets">>, - metadata = #{ - <<"test.ns">> => - {obj, #{ - <<"answer">> => {i, 42}, - <<"localization">> => - {obj, #{ - <<"ru_RU">> => {arr, [{str, <<"КИВИ Кошелёк">>}]} - }} - }} - } +-define(ALL_OBJECTS, #{ + {category, #domain_CategoryRef{id = ?INTEGER}} => + {category, #domain_CategoryObject{ + ref = #domain_CategoryRef{id = ?INTEGER}, + data = #domain_Category{ + name = ?STRING, + description = ?STRING + } + }}, + {business_schedule, #domain_BusinessScheduleRef{id = ?INTEGER}} => + {business_schedule, #domain_BusinessScheduleObject{ + ref = #domain_BusinessScheduleRef{id = ?INTEGER}, + data = #domain_BusinessSchedule{ + name = ?STRING, + description = ?STRING, + schedule = #'base_Schedule'{ + year = {every, #'base_ScheduleEvery'{}}, + month = {every, #'base_ScheduleEvery'{}}, + day_of_month = {every, #'base_ScheduleEvery'{}}, + day_of_week = {every, #'base_ScheduleEvery'{}}, + hour = {every, #'base_ScheduleEvery'{}}, + minute = {every, #'base_ScheduleEvery'{}}, + second = {every, #'base_ScheduleEvery'{}} + }, + delay = #'base_TimeSpan'{} + } + }}, + {globals, #domain_GlobalsRef{}} => + {globals, #domain_GlobalsObject{ + ref = #domain_GlobalsRef{}, + data = #domain_Globals{ + external_account_set = {value, #domain_ExternalAccountSetRef{id = ?INTEGER}}, + payment_institutions = [#domain_PaymentInstitutionRef{id = ?INTEGER}] + } + }}, + {payment_institution, #domain_PaymentInstitutionRef{id = ?INTEGER}} => + {payment_institution, #domain_PaymentInstitutionObject{ + ref = #domain_PaymentInstitutionRef{id = ?INTEGER}, + data = #domain_PaymentInstitution{ + name = ?STRING, + description = ?STRING, + system_account_set = {value, #domain_SystemAccountSetRef{id = ?INTEGER}}, + default_contract_template = {value, #domain_ContractTemplateRef{id = ?INTEGER}}, + providers = {value, []}, + inspector = {value, #domain_InspectorRef{id = ?INTEGER}}, + realm = test, + residences = [rus] + } + }}, + {country, #domain_CountryRef{id = rus}} => + {country, #domain_CountryObject{ + ref = #domain_CountryRef{id = rus}, + data = #domain_Country{ + name = <<"Russia">> + } + }}, + {party_config, #domain_PartyConfigRef{id = ?STRING}} => + {party_config, #domain_PartyConfigObject{ + ref = #domain_PartyConfigRef{id = ?STRING}, + data = ?PARTY_WITH_SHOPS + }}, + {shop_config, #domain_ShopConfigRef{id = ?STRING}} => + {shop_config, #domain_ShopConfigObject{ + ref = #domain_ShopConfigRef{id = ?STRING}, + data = ?SHOP(?USD) + }}, + {country, #domain_CountryRef{id = deu}} => + {country, #domain_CountryObject{ + ref = #domain_CountryRef{id = deu}, + data = #domain_Country{ + name = <<"Germany">>, + trade_blocs = ordsets:from_list( + [#domain_TradeBlocRef{id = <<"EEA">>}] + ) + } + }}, + {trade_bloc, #domain_TradeBlocRef{id = <<"EEA">>}} => + {trade_bloc, #domain_TradeBlocObject{ + ref = #domain_TradeBlocRef{id = <<"EEA">>}, + data = #domain_TradeBloc{ + name = <<"European Economic Area">>, + description = <<"Extension of EU">> + } + }}, + + {payment_system, #domain_PaymentSystemRef{id = <<"visa">>}} => + {payment_system, #domain_PaymentSystemObject{ + ref = #domain_PaymentSystemRef{id = <<"visa">>}, + data = #domain_PaymentSystem{name = <<"Visa">>} + }}, + + {payment_system, #domain_PaymentSystemRef{id = <<"mastercard">>}} => + {payment_system, #domain_PaymentSystemObject{ + ref = #domain_PaymentSystemRef{id = <<"mastercard">>}, + data = #domain_PaymentSystem{name = <<"Mastercard">>} + }}, + + {payment_service, #domain_PaymentServiceRef{id = <<"qiwi">>}} => + {payment_service, #domain_PaymentServiceObject{ + ref = #domain_PaymentServiceRef{id = <<"qiwi">>}, + data = #domain_PaymentService{ + name = <<"Qiwi">>, + brand_name = <<"QIWI">>, + category = <<"wallets">>, + metadata = #{ + <<"test.ns">> => + {obj, #{ + <<"answer">> => {i, 42}, + <<"localization">> => + {obj, #{ + <<"ru_RU">> => {arr, [{str, <<"КИВИ Кошелёк">>}]} + }} + }} } - }} - } + } + }} }). -define(USER_INTERACTION, diff --git a/rebar.config b/rebar.config index 5dd42cc..7c266ba 100644 --- a/rebar.config +++ b/rebar.config @@ -35,11 +35,11 @@ {genlib, {git, "https://github.com/valitydev/genlib.git", {tag, "v1.1.0"}}}, {cowboy_draining_server, {git, "https://github.com/valitydev/cowboy_draining_server.git", {branch, "master"}}}, {woody, {git, "https://github.com/valitydev/woody_erlang.git", {tag, "v1.1.0"}}}, - {woody_user_identity, {git, "https://github.com/valitydev/woody_erlang_user_identity.git", {branch, "master"}}}, - {damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}}, + {woody_user_identity, {git, "https://github.com/valitydev/woody_erlang_user_identity.git", {tag, "v1.1.0"}}}, + {damsel, {git, "https://github.com/valitydev/damsel.git", {tag, "v2.2.0"}}}, {bender_proto, {git, "https://github.com/valitydev/bender-proto.git", {branch, "master"}}}, {bender_client, {git, "https://github.com/valitydev/bender-client-erlang.git", {tag, "v1.1.0"}}}, - {dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {branch, "master"}}}, + {dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {tag, "v2.0.0"}}}, {cowboy_cors, {git, "https://github.com/valitydev/cowboy_cors.git", {branch, "master"}}}, {cowboy_access_log, {git, "https://github.com/valitydev/cowboy_access_log.git", {branch, "master"}}}, {payproc_errors, {git, "https://github.com/valitydev/payproc-errors-erlang.git", {branch, "master"}}}, @@ -90,10 +90,6 @@ {profiles, [ {prod, [ {deps, [ - %% NOTE - %% Because of a dependency conflict, prometheus libs are only included in production build for now - %% https://github.com/project-fifo/rebar3_lint/issues/42 - %% https://github.com/valitydev/hellgate/pull/2/commits/884724c1799703cee4d1033850fe32c17f986d9e {recon, "2.3.6"}, {logger_logstash_formatter, {git, "https://github.com/valitydev/logger_logstash_formatter.git", {ref, "08a66a6"}}} diff --git a/rebar.lock b/rebar.lock index ab1bf95..7b9efdb 100644 --- a/rebar.lock +++ b/rebar.lock @@ -41,11 +41,11 @@ {<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"5ca4f4a2af6bd68ba4d255889c0e2c0c1c5479a4"}}, + {ref,"ba7414811590859d058817b8f22d2e9c22f627f8"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt_client.git", - {ref,"d8a4f490d49c038d96f1cbc2a279164c6f4039f9"}}, + {ref,"fcfb028a041149caeebec8d9cef469c8cdbbc63e"}}, 0}, {<<"dmt_core">>, {git,"https://github.com/valitydev/dmt-core.git", @@ -108,7 +108,7 @@ {<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.4.1">>},1}, {<<"party_client">>, {git,"https://github.com/valitydev/party-client-erlang.git", - {ref,"a82682b6f55f41ff4962b2666bbd12cb5f1ece25"}}, + {ref,"b10b102673d899f6661e0c1a9e70f04ebddc9263"}}, 0}, {<<"payout_manager_proto">>, {git,"https://github.com/valitydev/payout-manager-proto.git", @@ -162,7 +162,7 @@ 0}, {<<"woody_user_identity">>, {git,"https://github.com/valitydev/woody_erlang_user_identity.git", - {ref,"a480762fea8d7c08f105fb39ca809482b6cb042e"}}, + {ref,"1bc1e260b8d464fe7720ca3e26f52fed363aff67"}}, 0}]}. [ {pkg_hash,[