From 7b1a2208167a7334cc6ec061791ebe02c60ba2d3 Mon Sep 17 00:00:00 2001 From: James Aimonetti Date: Fri, 3 Apr 2020 18:14:24 +0000 Subject: [PATCH 1/2] [4.3] Add missing fields from resources schema Stepswitch makes use of a number of fields that aren't defined on the resources schema. Add them and use the accessor module when possible. --- applications/callflow/src/cf_exe.erl | 6 + applications/crossbar/doc/ref/resources.md | 12 ++ applications/crossbar/doc/resources.md | 12 ++ applications/crossbar/priv/api/swagger.json | 65 ++++++ .../priv/couchdb/schemas/resources.json | 65 ++++++ .../stepswitch/src/stepswitch_resources.erl | 82 ++++---- core/kazoo_documents/src/kzd_resource.erl | 49 ----- core/kazoo_documents/src/kzd_resources.erl | 197 +++++++++++++++++- .../kazoo_documents/src/kzd_resources.erl.src | 143 +++++++++++++ doc/mkdocs/mkdocs.yml | 5 + 10 files changed, 543 insertions(+), 93 deletions(-) delete mode 100644 core/kazoo_documents/src/kzd_resource.erl diff --git a/applications/callflow/src/cf_exe.erl b/applications/callflow/src/cf_exe.erl index ca5e20e7a8b..7e101b1cf66 100644 --- a/applications/callflow/src/cf_exe.erl +++ b/applications/callflow/src/cf_exe.erl @@ -535,6 +535,12 @@ handle_cast({'gen_listener', {'is_consuming', 'true'}} ) -> lager:debug("ready to recv events, launching the callflow"), {'noreply', launch_cf_module(State#state{status = 'running'})}; +handle_cast({'gen_listener', {'is_consuming', 'true'}}, State) -> + lager:info("consuming AMQP events"), + {'noreply', State}; +handle_cast({'gen_listener', {'is_consuming', 'false'}}, State) -> + lager:info("no longer consuming AMQP events"), + {'noreply', State}; handle_cast(_Msg, State) -> lager:debug("unhandled cast: ~p", [_Msg]), {'noreply', State}. diff --git a/applications/crossbar/doc/ref/resources.md b/applications/crossbar/doc/ref/resources.md index d0d7ee9fdda..06e65073358 100644 --- a/applications/crossbar/doc/ref/resources.md +++ b/applications/crossbar/doc/ref/resources.md @@ -10,6 +10,17 @@ Schema for resources Key | Description | Type | Default | Required | Support Level --- | ----------- | ---- | ------- | -------- | ------------- +`caller_id_options.type` | Caller ID type to choose | `string('internal' | 'external' | 'emergency')` | | `false` | +`caller_id_options` | Caller ID options | `object()` | | `false` | +`cid_rules.[]` | | `string()` | | `false` | +`cid_rules` | Regexps to match against caller ID | `array(string())` | | `false` | +`classifiers.emergency` | Determines if the resource represents emergency services | `boolean()` | `false` | `false` | +`classifiers.enabled` | Determines if the resource is currently enabled | `boolean()` | `true` | `false` | +`classifiers.prefix` | A string to prepend to the dialed number or capture group of the matching rule | `string(0..64)` | | `false` | +`classifiers.regex` | regexp to match against dialed number | `string()` | | `false` | +`classifiers.suffix` | A string to append to the dialed number or capture group of the matching rule | `string(0..64)` | | `false` | +`classifiers.weight_cost` | A value between 0 and 100 that determines the order of resources when multiple can be used | `integer()` | `50` | `false` | +`classifiers` | Resource classifiers to use as rules when matching against dialed numbers | `object()` | | `false` | `emergency` | Determines if the resource represents emergency services | `boolean()` | `false` | `false` | `enabled` | Determines if the resource is currently enabled | `boolean()` | `true` | `false` | `flags.[]` | | `string()` | | `false` | @@ -18,6 +29,7 @@ Key | Description | Type | Default | Required | Support Level `flat_rate_whitelist` | Regex for determining if the number is eligible for flat-rate trunking | `string()` | | `false` | `format_from_uri` | When set to true requests to this resource will have a reformatted SIP From Header | `boolean()` | | `false` | `formatters` | Schema for request formatters | `object()` | | `false` | +`from_account_realm` | When formatting SIP From on outbound requests, use the calling account's SIP realm | `boolean()` | `false` | `false` | `from_uri_realm` | When formatting SIP From on outbound requests this can be used to override the realm | `string()` | | `false` | `gateway_strategy` | The strategy of choosing gateways from list: sequential or random | `string('sequential' | 'random')` | | `false` | `gateways.[].bypass_media` | The resource gateway bypass media mode | `boolean()` | | `false` | diff --git a/applications/crossbar/doc/resources.md b/applications/crossbar/doc/resources.md index 523eb2a403b..60f4572bd12 100644 --- a/applications/crossbar/doc/resources.md +++ b/applications/crossbar/doc/resources.md @@ -28,6 +28,17 @@ Schema for resources Key | Description | Type | Default | Required | Support Level --- | ----------- | ---- | ------- | -------- | ------------- +`caller_id_options.type` | Caller ID type to choose | `string('internal' | 'external' | 'emergency')` | | `false` | +`caller_id_options` | Caller ID options | `object()` | | `false` | +`cid_rules.[]` | | `string()` | | `false` | +`cid_rules` | Regexps to match against caller ID | `array(string())` | | `false` | +`classifiers.emergency` | Determines if the resource represents emergency services | `boolean()` | `false` | `false` | +`classifiers.enabled` | Determines if the resource is currently enabled | `boolean()` | `true` | `false` | +`classifiers.prefix` | A string to prepend to the dialed number or capture group of the matching rule | `string(0..64)` | | `false` | +`classifiers.regex` | regexp to match against dialed number | `string()` | | `false` | +`classifiers.suffix` | A string to append to the dialed number or capture group of the matching rule | `string(0..64)` | | `false` | +`classifiers.weight_cost` | A value between 0 and 100 that determines the order of resources when multiple can be used | `integer()` | `50` | `false` | +`classifiers` | Resource classifiers to use as rules when matching against dialed numbers | `object()` | | `false` | `emergency` | Determines if the resource represents emergency services | `boolean()` | `false` | `false` | `enabled` | Determines if the resource is currently enabled | `boolean()` | `true` | `false` | `flags.[]` | | `string()` | | `false` | @@ -36,6 +47,7 @@ Key | Description | Type | Default | Required | Support Level `flat_rate_whitelist` | Regex for determining if the number is eligible for flat-rate trunking | `string()` | | `false` | `format_from_uri` | When set to true requests to this resource will have a reformatted SIP From Header | `boolean()` | | `false` | `formatters` | Schema for request formatters | `object()` | | `false` | +`from_account_realm` | When formatting SIP From on outbound requests, use the calling account's SIP realm | `boolean()` | `false` | `false` | `from_uri_realm` | When formatting SIP From on outbound requests this can be used to override the realm | `string()` | | `false` | `gateway_strategy` | The strategy of choosing gateways from list: sequential or random | `string('sequential' | 'random')` | | `false` | `gateways.[].bypass_media` | The resource gateway bypass media mode | `boolean()` | | `false` | diff --git a/applications/crossbar/priv/api/swagger.json b/applications/crossbar/priv/api/swagger.json index a1f9f49c961..1ab95a06afb 100644 --- a/applications/crossbar/priv/api/swagger.json +++ b/applications/crossbar/priv/api/swagger.json @@ -27879,6 +27879,66 @@ "resources": { "description": "Schema for resources", "properties": { + "caller_id_options": { + "description": "Caller ID options", + "properties": { + "type": { + "description": "Caller ID type to choose", + "enum": [ + "internal", + "external", + "emergency" + ], + "type": "string" + } + }, + "type": "object" + }, + "cid_rules": { + "description": "Regexps to match against caller ID", + "items": { + "description": "Regexp to match against caller ID", + "type": "string" + }, + "type": "array" + }, + "classifiers": { + "description": "Resource classifiers to use as rules when matching against dialed numbers", + "properties": { + "emergency": { + "default": false, + "description": "Determines if the resource represents emergency services", + "type": "boolean" + }, + "enabled": { + "default": true, + "description": "Determines if the resource is currently enabled", + "type": "boolean" + }, + "prefix": { + "description": "A string to prepend to the dialed number or capture group of the matching rule", + "maxLength": 64, + "type": "string" + }, + "regex": { + "description": "regexp to match against dialed number", + "type": "string" + }, + "suffix": { + "description": "A string to append to the dialed number or capture group of the matching rule", + "maxLength": 64, + "type": "string" + }, + "weight_cost": { + "default": 50, + "description": "A value between 0 and 100 that determines the order of resources when multiple can be used", + "maximum": 100, + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, "emergency": { "default": false, "description": "Determines if the resource represents emergency services", @@ -27913,6 +27973,11 @@ "$ref": "#/definitions/formatters", "type": "object" }, + "from_account_realm": { + "default": false, + "description": "When formatting SIP From on outbound requests, use the calling account's SIP realm", + "type": "boolean" + }, "from_uri_realm": { "description": "When formatting SIP From on outbound requests this can be used to override the realm", "type": "string" diff --git a/applications/crossbar/priv/couchdb/schemas/resources.json b/applications/crossbar/priv/couchdb/schemas/resources.json index 98b5039d2ec..a8cc7a1dfb1 100644 --- a/applications/crossbar/priv/couchdb/schemas/resources.json +++ b/applications/crossbar/priv/couchdb/schemas/resources.json @@ -3,6 +3,66 @@ "_id": "resources", "description": "Schema for resources", "properties": { + "caller_id_options": { + "description": "Caller ID options", + "properties": { + "type": { + "description": "Caller ID type to choose", + "enum": [ + "internal", + "external", + "emergency" + ], + "type": "string" + } + }, + "type": "object" + }, + "cid_rules": { + "description": "Regexps to match against caller ID", + "items": { + "description": "Regexp to match against caller ID", + "type": "string" + }, + "type": "array" + }, + "classifiers": { + "description": "Resource classifiers to use as rules when matching against dialed numbers", + "properties": { + "emergency": { + "default": false, + "description": "Determines if the resource represents emergency services", + "type": "boolean" + }, + "enabled": { + "default": true, + "description": "Determines if the resource is currently enabled", + "type": "boolean" + }, + "prefix": { + "description": "A string to prepend to the dialed number or capture group of the matching rule", + "maxLength": 64, + "type": "string" + }, + "regex": { + "description": "regexp to match against dialed number", + "type": "string" + }, + "suffix": { + "description": "A string to append to the dialed number or capture group of the matching rule", + "maxLength": 64, + "type": "string" + }, + "weight_cost": { + "default": 50, + "description": "A value between 0 and 100 that determines the order of resources when multiple can be used", + "maximum": 100, + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, "emergency": { "default": false, "description": "Determines if the resource represents emergency services", @@ -37,6 +97,11 @@ "$ref": "formatters", "type": "object" }, + "from_account_realm": { + "default": false, + "description": "When formatting SIP From on outbound requests, use the calling account's SIP realm", + "type": "boolean" + }, "from_uri_realm": { "description": "When formatting SIP From on outbound requests this can be used to override the realm", "type": "string" diff --git a/applications/stepswitch/src/stepswitch_resources.erl b/applications/stepswitch/src/stepswitch_resources.erl index 9a2396f4770..f50fc0453fb 100644 --- a/applications/stepswitch/src/stepswitch_resources.erl +++ b/applications/stepswitch/src/stepswitch_resources.erl @@ -145,7 +145,7 @@ ,fax_option :: kz_term:ne_binary() | boolean() ,codecs = [] :: kz_term:ne_binaries() ,bypass_media = 'false' :: boolean() - ,formatters :: kz_term:api_objects() + ,formatters :: kz_term:api_object() ,proxies = [] :: kz_term:proplist() ,selector_marks = [] :: [tuple()] ,privacy_method = 'undefined' :: kz_term:api_binary() @@ -906,7 +906,7 @@ fetch_global_resources() -> []; {'ok', JObjs} -> CacheProps = [{'origin', [{'db', ?KZ_OFFNET_DB, <<"resource">>}]}], - Docs = [kz_json:get_value(<<"doc">>, JObj) || JObj <- JObjs], + Docs = [kz_json:get_json_value(<<"doc">>, JObj) || JObj <- JObjs], Resources = resources_from_jobjs(Docs), kz_cache:store_local(?CACHE_NAME, 'global_resources', Resources, CacheProps), Resources @@ -972,21 +972,21 @@ build_account_dedicated_proxy(Proxy) -> %% @end %%------------------------------------------------------------------------------ --spec resources_from_jobjs(kz_json:objects()) -> resources(). +-spec resources_from_jobjs(kzd_resources:docs()) -> resources(). resources_from_jobjs(JObjs) -> resources_from_jobjs(JObjs, []). --spec resources_from_jobjs(kz_json:objects(), resources()) -> resources(). +-spec resources_from_jobjs(kzd_resources:docs(), resources()) -> resources(). resources_from_jobjs([], Resources) -> Resources; resources_from_jobjs([JObj|JObjs], Resources) -> - case kz_json:is_true(<<"enabled">>, JObj, 'true') of + case kzd_resources:enabled(JObj) of 'false' -> resources_from_jobjs(JObjs, Resources); 'true' -> resources_from_jobjs(JObjs, create_resource(JObj, Resources)) end. --spec create_resource(kz_json:object(), resources()) -> resources(). +-spec create_resource(kzd_resources:doc(), resources()) -> resources(). create_resource(JObj, Resources) -> - case kz_json:get_value(<<"classifiers">>, JObj) of + case kzd_resources:classifiers(JObj) of 'undefined' -> [resource_from_jobj(JObj) | Resources]; ResourceClassifiers -> AvailableClassifiers = kz_json:to_proplist(knm_converters:available_classifiers()), @@ -1063,21 +1063,21 @@ classifier_is_emergency(ClassifierJObj, _Classifier, DefaultEmergency) -> -type rule() :: re:mp(). -type rules() :: [rule()]. --spec resource_from_jobj(kz_json:object()) -> resource(). +-spec resource_from_jobj(kzd_resources:doc()) -> resource(). resource_from_jobj(JObj) -> Resource = #resrc{id=kz_doc:id(JObj) ,rev=kz_doc:revision(JObj) - ,name=kz_json:get_value(<<"name">>, JObj) - ,flags=kz_json:get_value(<<"flags">>, JObj, []) - ,require_flags=kz_json:is_true(<<"require_flags">>, JObj) - ,ignore_flags=kz_json:is_true(<<"ignore_flags">>, JObj) - ,format_from_uri=kz_json:is_true(<<"format_from_uri">>, JObj) - ,from_uri_realm=kz_json:get_ne_value(<<"from_uri_realm">>, JObj) - ,from_account_realm=kz_json:is_true(<<"from_account_realm">>, JObj) - ,fax_option=kz_json:is_true([<<"media">>, <<"fax_option">>], JObj) - ,raw_rules=kz_json:get_value(<<"rules">>, JObj, []) + ,name=kzd_resources:name(JObj) + ,flags=kzd_resources:flags(JObj, []) + ,require_flags=kzd_resources:require_flags(JObj, 'false') + ,ignore_flags=kzd_resources:ignore_flags(JObj, 'false') + ,format_from_uri=kzd_resources:format_from_uri(JObj, 'false') + ,from_uri_realm=kzd_resources:from_uri_realm(JObj) + ,from_account_realm=kzd_resources:from_account_realm(JObj) + ,fax_option=kzd_resources:media_fax_option(JObj) + ,raw_rules=kzd_resources:rules(JObj, []) ,rules=resource_rules(JObj) - ,cid_raw_rules=kz_json:get_value(<<"cid_rules">>, JObj, []) + ,cid_raw_rules=kzd_resources:cid_rules(JObj, []) ,cid_rules=resource_cid_rules(JObj) ,weight=resource_weight(JObj) ,grace_period=resource_grace_period(JObj) @@ -1092,39 +1092,38 @@ resource_from_jobj(JObj) -> ,privacy_hide_number=kz_privacy:should_hide_number(JObj) ,classifier=kz_json:get_ne_value(<<"classifier">>, JObj) ,classifier_enable=kz_json:is_true(<<"classifier_enable">>, JObj, 'true') - ,gateway_strategy=kz_json:get_atom_value(<<"gateway_strategy">>, JObj, 'sequential') + ,gateway_strategy=kz_term:to_atom(kzd_resources:gateway_strategy(JObj, <<"sequential">>), 'true') }, - Gateways = gateways_from_jobjs(kz_json:get_value(<<"gateways">>, JObj, []) - ,Resource - ), + Gateways = gateways_from_jobjs(kzd_resources:gateways(JObj, []), Resource), Resource#resrc{gateways=Gateways}. --spec resource_bypass_media(kz_json:object()) -> boolean(). +-spec resource_bypass_media(kzd_resources:doc()) -> boolean(). resource_bypass_media(JObj) -> Default = kapps_config:get_is_true(?SS_CONFIG_CAT, <<"default_bypass_media">>, 'false'), - kz_json:is_true([<<"media">>, <<"bypass_media">>], JObj, Default). + kzd_resources:media_bypass_media(JObj, Default). --spec resource_formatters(kz_json:object()) -> kz_term:api_objects(). +-spec resource_formatters(kzd_resources:doc()) -> kz_term:api_object(). resource_formatters(JObj) -> Default = kapps_config:get(?SS_CONFIG_CAT, <<"default_formatters">>), - kz_json:get_value(<<"formatters">>, JObj, Default). + kzd_resources:formatters(JObj, Default). --spec resource_codecs(kz_json:object()) -> kz_term:ne_binaries(). +-spec resource_codecs(kzd_resources:doc()) -> kz_term:ne_binaries(). resource_codecs(JObj) -> DefaultAudio = kapps_config:get_ne_binaries(?SS_CONFIG_CAT, <<"default_audio_codecs">>, []), DefaultVideo = kapps_config:get_ne_binaries(?SS_CONFIG_CAT, <<"default_video_codecs">>, []), - case kz_json:get_value([<<"media">>, <<"audio">>, <<"codecs">>], JObj, DefaultAudio) - ++ kz_json:get_value([<<"media">>, <<"video">>, <<"codecs">>], JObj, DefaultVideo) + case kzd_resources:media_audio_codecs(JObj, DefaultAudio) + ++ kzd_resources:media_video_codecs(JObj, DefaultVideo) of [] -> kapps_config:get_ne_binaries(?SS_CONFIG_CAT, <<"default_codecs">>, []); Codecs -> Codecs end. --spec resource_rules(kz_json:object()) -> rules(). +-spec resource_rules(kzd_resources:doc()) -> rules(). resource_rules(JObj) -> - Rules = kz_json:get_value(<<"rules">>, JObj, []), + Rules = kzd_resources:rules(JObj, []), lager:info("compiling resource rules for ~s / ~s: ~p" - ,[kz_doc:account_db(JObj, <<"offnet">>), kz_doc:id(JObj), Rules]), + ,[kz_doc:account_db(JObj, <<"offnet">>), kz_doc:id(JObj), Rules] + ), resource_rules(Rules, []). -spec resource_rules(kz_term:ne_binaries(), rules()) -> rules(). @@ -1141,28 +1140,29 @@ resource_rules([Rule|Rules], CompiledRules) -> -spec resource_cid_rules(kz_json:object()) -> rules(). resource_cid_rules(JObj) -> lager:info("compiling caller id rules for ~s / ~s" - ,[kz_doc:account_db(JObj, <<"offnet">>), kz_doc:id(JObj)]), + ,[kz_doc:account_db(JObj, <<"offnet">>), kz_doc:id(JObj)] + ), Rules = kz_json:get_value(<<"cid_rules">>, JObj, []), resource_rules(Rules, []). --spec resource_grace_period(kz_json:object() | integer()) -> 0..100. +-spec resource_grace_period(kzd_resources:doc() | integer()) -> 0..100. resource_grace_period(JObj) when not is_integer(JObj) -> - resource_grace_period(kz_json:get_integer_value(<<"grace_period">>, JObj, ?DEFAULT_WEIGHT)); + resource_grace_period(kzd_resources:grace_period(JObj, ?DEFAULT_WEIGHT)); resource_grace_period(GracePeriod) when is_integer(GracePeriod), GracePeriod > 100 -> 100; resource_grace_period(GracePeriod) when is_integer(GracePeriod), GracePeriod < 0 -> 0; resource_grace_period(GracePeriod) when is_integer(GracePeriod) -> GracePeriod. --spec resource_weight(kz_json:object() | integer()) -> integer(). +-spec resource_weight(kzd_resources:doc() | integer()) -> integer(). resource_weight(JObj) when not is_integer(JObj) -> - resource_weight(kz_json:get_integer_value(<<"weight_cost">>, JObj, ?DEFAULT_WEIGHT)); + resource_weight(kzd_resources:weight_cost(JObj, ?DEFAULT_WEIGHT)); resource_weight(W) when W > 100 -> 100; resource_weight(W) when W < 1 -> 1; resource_weight(W) -> W. -spec resource_is_emergency(kz_json:object()) -> boolean(). resource_is_emergency(JObj) -> - kz_json:is_true(<<"emergency">>, JObj) - orelse (kz_json:get_value([<<"caller_id_options">>, <<"type">>], JObj) =:= <<"emergency">>). + kzd_resources:emergency(JObj, 'false') + orelse (kzd_resources:caller_id_options_type(JObj) =:= <<"emergency">>). %%------------------------------------------------------------------------------ %% @doc @@ -1342,7 +1342,7 @@ get_resrc_codecs(#resrc{codecs=Codecs}) -> Codecs. -spec get_resrc_bypass_media(resource()) -> boolean(). get_resrc_bypass_media(#resrc{bypass_media=BypassMedia}) -> BypassMedia. --spec get_resrc_formatters(resource()) -> kz_term:api_objects(). +-spec get_resrc_formatters(resource()) -> kz_term:api_object(). get_resrc_formatters(#resrc{formatters=Formatters}) -> Formatters. -spec get_resrc_proxies(resource()) -> kz_term:proplist(). @@ -1420,7 +1420,7 @@ set_resrc_codecs(Resource, Codecs) -> Resource#resrc{codecs=Codecs}. -spec set_resrc_bypass_media(resource(), boolean()) -> resource(). set_resrc_bypass_media(Resource, BypassMedia) -> Resource#resrc{bypass_media=BypassMedia}. --spec set_resrc_formatters(resource(), kz_term:api_objects()) -> resource(). +-spec set_resrc_formatters(resource(), kz_term:api_object()) -> resource(). set_resrc_formatters(Resource, Formatters) -> Resource#resrc{formatters=Formatters}. -spec set_resrc_proxies(resource(), kz_term:proplist()) -> resource(). diff --git a/core/kazoo_documents/src/kzd_resource.erl b/core/kazoo_documents/src/kzd_resource.erl deleted file mode 100644 index 525a19d58e3..00000000000 --- a/core/kazoo_documents/src/kzd_resource.erl +++ /dev/null @@ -1,49 +0,0 @@ -%%%----------------------------------------------------------------------------- -%%% @copyright (C) 2010-2020, 2600Hz -%%% @doc -%%% @end -%%%----------------------------------------------------------------------------- --module(kzd_resource). - --export([new/0 - ,type/0, type/1 - ]). - --export([flat_rate_whitelist/1, flat_rate_whitelist/2 - ,flat_rate_blacklist/1, flat_rate_blacklist/2 - ]). - --include("kz_documents.hrl"). - --define(PVT_TYPE, <<"resource">>). --define(SCHEMA, <<"resources">>). - --type doc() :: kz_json:object(). --export_type([doc/0]). - --spec new() -> doc(). -new() -> - kz_doc:set_type(kz_json_schema:default_object(?SCHEMA), type()). - --spec type() -> kz_term:ne_binary(). -type() -> ?PVT_TYPE. - --spec type(doc()) -> kz_term:ne_binary(). -type(Doc) -> - kz_doc:type(Doc, ?PVT_TYPE). - --spec flat_rate_whitelist(doc()) -> kz_term:api_ne_binary(). -flat_rate_whitelist(Doc) -> - flat_rate_whitelist(Doc, 'undefined'). - --spec flat_rate_whitelist(doc(), Default) -> kz_term:ne_binary() | Default. -flat_rate_whitelist(Doc, Default) -> - kz_json:get_ne_binary_value(<<"flat_rate_whitelist">>, Doc, Default). - --spec flat_rate_blacklist(doc()) -> kz_term:api_ne_binary(). -flat_rate_blacklist(Doc) -> - flat_rate_blacklist(Doc, 'undefined'). - --spec flat_rate_blacklist(doc(), Default) -> kz_term:ne_binary() | Default. -flat_rate_blacklist(Doc, Default) -> - kz_json:get_ne_binary_value(<<"flat_rate_blacklist">>, Doc, Default). diff --git a/core/kazoo_documents/src/kzd_resources.erl b/core/kazoo_documents/src/kzd_resources.erl index 2808e79cac0..3be85634b9d 100644 --- a/core/kazoo_documents/src/kzd_resources.erl +++ b/core/kazoo_documents/src/kzd_resources.erl @@ -5,7 +5,19 @@ %%%----------------------------------------------------------------------------- -module(kzd_resources). --export([new/0]). +-export([new/0 + ,type/0, type/1 + ]). +-export([caller_id_options/1, caller_id_options/2, set_caller_id_options/2]). +-export([caller_id_options_type/1, caller_id_options_type/2, set_caller_id_options_type/2]). +-export([cid_rules/1, cid_rules/2, set_cid_rules/2]). +-export([classifiers/1, classifiers/2, set_classifiers/2]). +-export([classifiers_emergency/1, classifiers_emergency/2, set_classifiers_emergency/2]). +-export([classifiers_enabled/1, classifiers_enabled/2, set_classifiers_enabled/2]). +-export([classifiers_prefix/1, classifiers_prefix/2, set_classifiers_prefix/2]). +-export([classifiers_regex/1, classifiers_regex/2, set_classifiers_regex/2]). +-export([classifiers_suffix/1, classifiers_suffix/2, set_classifiers_suffix/2]). +-export([classifiers_weight_cost/1, classifiers_weight_cost/2, set_classifiers_weight_cost/2]). -export([emergency/1, emergency/2, set_emergency/2]). -export([enabled/1, enabled/2, set_enabled/2]). -export([flags/1, flags/2, set_flags/2]). @@ -13,6 +25,7 @@ -export([flat_rate_whitelist/1, flat_rate_whitelist/2, set_flat_rate_whitelist/2]). -export([format_from_uri/1, format_from_uri/2, set_format_from_uri/2]). -export([formatters/1, formatters/2, set_formatters/2]). +-export([from_account_realm/1, from_account_realm/2, set_from_account_realm/2]). -export([from_uri_realm/1, from_uri_realm/2, set_from_uri_realm/2]). -export([gateway_strategy/1, gateway_strategy/2, set_gateway_strategy/2]). -export([gateways/1, gateways/2, set_gateways/2]). @@ -24,17 +37,151 @@ -export([rules/1, rules/2, set_rules/2]). -export([weight_cost/1, weight_cost/2, set_weight_cost/2]). +-export([media_fax_option/1, media_fax_option/2 + ,media_bypass_media/1, media_bypass_media/2 + ,media_audio_codecs/1, media_audio_codecs/2 + ,media_video_codecs/1, media_video_codecs/2 + ]). -include("kz_documents.hrl"). -type doc() :: kz_json:object(). --export_type([doc/0]). +-type docs() :: [doc()]. +-export_type([doc/0, docs/0]). +-define(PVT_TYPE, <<"resource">>). -define(SCHEMA, <<"resources">>). -spec new() -> doc(). new() -> - kz_json_schema:default_object(?SCHEMA). + kz_doc:set_type(kz_json_schema:default_object(?SCHEMA), type()). + +-spec type() -> kz_term:ne_binary(). +type() -> ?PVT_TYPE. + +-spec type(doc()) -> kz_term:ne_binary(). +type(Doc) -> + kz_doc:type(Doc, ?PVT_TYPE). + +-spec caller_id_options(doc()) -> kz_term:api_object(). +caller_id_options(Doc) -> + caller_id_options(Doc, 'undefined'). + +-spec caller_id_options(doc(), Default) -> kz_json:object() | Default. +caller_id_options(Doc, Default) -> + kz_json:get_json_value([<<"caller_id_options">>], Doc, Default). + +-spec set_caller_id_options(doc(), kz_json:object()) -> doc(). +set_caller_id_options(Doc, CallerIdOptions) -> + kz_json:set_value([<<"caller_id_options">>], CallerIdOptions, Doc). + +-spec caller_id_options_type(doc()) -> kz_term:api_binary(). +caller_id_options_type(Doc) -> + caller_id_options_type(Doc, 'undefined'). + +-spec caller_id_options_type(doc(), Default) -> binary() | Default. +caller_id_options_type(Doc, Default) -> + kz_json:get_binary_value([<<"caller_id_options">>, <<"type">>], Doc, Default). + +-spec set_caller_id_options_type(doc(), binary()) -> doc(). +set_caller_id_options_type(Doc, CallerIdOptionsType) -> + kz_json:set_value([<<"caller_id_options">>, <<"type">>], CallerIdOptionsType, Doc). + +-spec cid_rules(doc()) -> kz_term:api_ne_binaries(). +cid_rules(Doc) -> + cid_rules(Doc, 'undefined'). + +-spec cid_rules(doc(), Default) -> kz_term:ne_binaries() | Default. +cid_rules(Doc, Default) -> + kz_json:get_list_value([<<"cid_rules">>], Doc, Default). + +-spec set_cid_rules(doc(), kz_term:ne_binaries()) -> doc(). +set_cid_rules(Doc, CidRules) -> + kz_json:set_value([<<"cid_rules">>], CidRules, Doc). + +-spec classifiers(doc()) -> kz_term:api_object(). +classifiers(Doc) -> + classifiers(Doc, 'undefined'). + +-spec classifiers(doc(), Default) -> kz_json:object() | Default. +classifiers(Doc, Default) -> + kz_json:get_json_value([<<"classifiers">>], Doc, Default). + +-spec set_classifiers(doc(), kz_json:object()) -> doc(). +set_classifiers(Doc, Classifiers) -> + kz_json:set_value([<<"classifiers">>], Classifiers, Doc). + +-spec classifiers_emergency(doc()) -> boolean(). +classifiers_emergency(Doc) -> + classifiers_emergency(Doc, false). + +-spec classifiers_emergency(doc(), Default) -> boolean() | Default. +classifiers_emergency(Doc, Default) -> + kz_json:get_boolean_value([<<"classifiers">>, <<"emergency">>], Doc, Default). + +-spec set_classifiers_emergency(doc(), boolean()) -> doc(). +set_classifiers_emergency(Doc, ClassifiersEmergency) -> + kz_json:set_value([<<"classifiers">>, <<"emergency">>], ClassifiersEmergency, Doc). + +-spec classifiers_enabled(doc()) -> boolean(). +classifiers_enabled(Doc) -> + classifiers_enabled(Doc, true). + +-spec classifiers_enabled(doc(), Default) -> boolean() | Default. +classifiers_enabled(Doc, Default) -> + kz_json:get_boolean_value([<<"classifiers">>, <<"enabled">>], Doc, Default). + +-spec set_classifiers_enabled(doc(), boolean()) -> doc(). +set_classifiers_enabled(Doc, ClassifiersEnabled) -> + kz_json:set_value([<<"classifiers">>, <<"enabled">>], ClassifiersEnabled, Doc). + +-spec classifiers_prefix(doc()) -> kz_term:api_binary(). +classifiers_prefix(Doc) -> + classifiers_prefix(Doc, 'undefined'). + +-spec classifiers_prefix(doc(), Default) -> binary() | Default. +classifiers_prefix(Doc, Default) -> + kz_json:get_binary_value([<<"classifiers">>, <<"prefix">>], Doc, Default). + +-spec set_classifiers_prefix(doc(), binary()) -> doc(). +set_classifiers_prefix(Doc, ClassifiersPrefix) -> + kz_json:set_value([<<"classifiers">>, <<"prefix">>], ClassifiersPrefix, Doc). + +-spec classifiers_regex(doc()) -> kz_term:api_binary(). +classifiers_regex(Doc) -> + classifiers_regex(Doc, 'undefined'). + +-spec classifiers_regex(doc(), Default) -> binary() | Default. +classifiers_regex(Doc, Default) -> + kz_json:get_binary_value([<<"classifiers">>, <<"regex">>], Doc, Default). + +-spec set_classifiers_regex(doc(), binary()) -> doc(). +set_classifiers_regex(Doc, ClassifiersRegex) -> + kz_json:set_value([<<"classifiers">>, <<"regex">>], ClassifiersRegex, Doc). + +-spec classifiers_suffix(doc()) -> kz_term:api_binary(). +classifiers_suffix(Doc) -> + classifiers_suffix(Doc, 'undefined'). + +-spec classifiers_suffix(doc(), Default) -> binary() | Default. +classifiers_suffix(Doc, Default) -> + kz_json:get_binary_value([<<"classifiers">>, <<"suffix">>], Doc, Default). + +-spec set_classifiers_suffix(doc(), binary()) -> doc(). +set_classifiers_suffix(Doc, ClassifiersSuffix) -> + kz_json:set_value([<<"classifiers">>, <<"suffix">>], ClassifiersSuffix, Doc). + +-spec classifiers_weight_cost(doc()) -> integer(). +classifiers_weight_cost(Doc) -> + classifiers_weight_cost(Doc, 50). + +-spec classifiers_weight_cost(doc(), Default) -> integer() | Default. +classifiers_weight_cost(Doc, Default) -> + kz_json:get_integer_value([<<"classifiers">>, <<"weight_cost">>], Doc, Default). + +-spec set_classifiers_weight_cost(doc(), integer()) -> doc(). +set_classifiers_weight_cost(Doc, ClassifiersWeightCost) -> + kz_json:set_value([<<"classifiers">>, <<"weight_cost">>], ClassifiersWeightCost, Doc). -spec emergency(doc()) -> boolean(). emergency(Doc) -> @@ -120,6 +267,18 @@ formatters(Doc, Default) -> set_formatters(Doc, Formatters) -> kz_json:set_value([<<"formatters">>], Formatters, Doc). +-spec from_account_realm(doc()) -> boolean(). +from_account_realm(Doc) -> + from_account_realm(Doc, 'false'). + +-spec from_account_realm(doc(), Default) -> boolean() | Default. +from_account_realm(Doc, Default) -> + kz_json:get_boolean_value([<<"from_account_realm">>], Doc, Default). + +-spec set_from_account_realm(doc(), boolean()) -> doc(). +set_from_account_realm(Doc, FromAccountRealm) -> + kz_json:set_value([<<"from_account_realm">>], FromAccountRealm, Doc). + -spec from_uri_realm(doc()) -> kz_term:api_binary(). from_uri_realm(Doc) -> from_uri_realm(Doc, 'undefined'). @@ -239,3 +398,35 @@ weight_cost(Doc, Default) -> -spec set_weight_cost(doc(), integer()) -> doc(). set_weight_cost(Doc, WeightCost) -> kz_json:set_value([<<"weight_cost">>], WeightCost, Doc). + +-spec media_fax_option(doc()) -> boolean(). +media_fax_option(Doc) -> + media_fax_option(Doc, 'false'). + +-spec media_fax_option(doc(), Default) -> boolean() | Default. +media_fax_option(Doc, Default) -> + kz_json:is_true([<<"media">>, <<"fax_option">>], Doc, Default). + +-spec media_bypass_media(doc()) -> boolean(). +media_bypass_media(Doc) -> + media_bypass_media(Doc, 'false'). + +-spec media_bypass_media(doc(), Default) -> boolean() | Default. +media_bypass_media(Doc, Default) -> + kz_json:is_true([<<"media">>, <<"bypass_media">>], Doc, Default). + +-spec media_audio_codecs(doc()) -> kz_term:api_ne_binaries(). +media_audio_codecs(Doc) -> + media_audio_codecs(Doc, 'undefined'). + +-spec media_audio_codecs(doc(), Default) -> kz_term:ne_binaries() | Default. +media_audio_codecs(Doc, Default) -> + kz_json:get_list_value([<<"media">>, <<"audio">>, <<"codecs">>], Doc, Default). + +-spec media_video_codecs(doc()) -> kz_term:api_ne_binaries(). +media_video_codecs(Doc) -> + media_video_codecs(Doc, 'undefined'). + +-spec media_video_codecs(doc(), Default) -> kz_term:ne_binaries() | Default. +media_video_codecs(Doc, Default) -> + kz_json:get_list_value([<<"media">>, <<"video">>, <<"codecs">>], Doc, Default). diff --git a/core/kazoo_documents/src/kzd_resources.erl.src b/core/kazoo_documents/src/kzd_resources.erl.src index dafb6ef20c9..5f0dc109ae5 100644 --- a/core/kazoo_documents/src/kzd_resources.erl.src +++ b/core/kazoo_documents/src/kzd_resources.erl.src @@ -6,6 +6,16 @@ -module(kzd_resources). -export([new/0]). +-export([caller_id_options/1, caller_id_options/2, set_caller_id_options/2]). +-export([caller_id_options_type/1, caller_id_options_type/2, set_caller_id_options_type/2]). +-export([cid_rules/1, cid_rules/2, set_cid_rules/2]). +-export([classifiers/1, classifiers/2, set_classifiers/2]). +-export([classifiers_emergency/1, classifiers_emergency/2, set_classifiers_emergency/2]). +-export([classifiers_enabled/1, classifiers_enabled/2, set_classifiers_enabled/2]). +-export([classifiers_prefix/1, classifiers_prefix/2, set_classifiers_prefix/2]). +-export([classifiers_regex/1, classifiers_regex/2, set_classifiers_regex/2]). +-export([classifiers_suffix/1, classifiers_suffix/2, set_classifiers_suffix/2]). +-export([classifiers_weight_cost/1, classifiers_weight_cost/2, set_classifiers_weight_cost/2]). -export([emergency/1, emergency/2, set_emergency/2]). -export([enabled/1, enabled/2, set_enabled/2]). -export([flags/1, flags/2, set_flags/2]). @@ -13,6 +23,7 @@ -export([flat_rate_whitelist/1, flat_rate_whitelist/2, set_flat_rate_whitelist/2]). -export([format_from_uri/1, format_from_uri/2, set_format_from_uri/2]). -export([formatters/1, formatters/2, set_formatters/2]). +-export([from_account_realm/1, from_account_realm/2, set_from_account_realm/2]). -export([from_uri_realm/1, from_uri_realm/2, set_from_uri_realm/2]). -export([gateway_strategy/1, gateway_strategy/2, set_gateway_strategy/2]). -export([gateways/1, gateways/2, set_gateways/2]). @@ -36,6 +47,126 @@ new() -> kz_json_schema:default_object(?SCHEMA). +-spec caller_id_options(doc()) -> kz_term:api_object(). +caller_id_options(Doc) -> + caller_id_options(Doc, 'undefined'). + +-spec caller_id_options(doc(), Default) -> kz_json:object() | Default. +caller_id_options(Doc, Default) -> + kz_json:get_json_value([<<"caller_id_options">>], Doc, Default). + +-spec set_caller_id_options(doc(), kz_json:object()) -> doc(). +set_caller_id_options(Doc, CallerIdOptions) -> + kz_json:set_value([<<"caller_id_options">>], CallerIdOptions, Doc). + +-spec caller_id_options_type(doc()) -> kz_term:api_binary(). +caller_id_options_type(Doc) -> + caller_id_options_type(Doc, 'undefined'). + +-spec caller_id_options_type(doc(), Default) -> binary() | Default. +caller_id_options_type(Doc, Default) -> + kz_json:get_binary_value([<<"caller_id_options">>, <<"type">>], Doc, Default). + +-spec set_caller_id_options_type(doc(), binary()) -> doc(). +set_caller_id_options_type(Doc, CallerIdOptionsType) -> + kz_json:set_value([<<"caller_id_options">>, <<"type">>], CallerIdOptionsType, Doc). + +-spec cid_rules(doc()) -> kz_term:api_ne_binaries(). +cid_rules(Doc) -> + cid_rules(Doc, 'undefined'). + +-spec cid_rules(doc(), Default) -> kz_term:ne_binaries() | Default. +cid_rules(Doc, Default) -> + kz_json:get_list_value([<<"cid_rules">>], Doc, Default). + +-spec set_cid_rules(doc(), kz_term:ne_binaries()) -> doc(). +set_cid_rules(Doc, CidRules) -> + kz_json:set_value([<<"cid_rules">>], CidRules, Doc). + +-spec classifiers(doc()) -> kz_term:api_object(). +classifiers(Doc) -> + classifiers(Doc, 'undefined'). + +-spec classifiers(doc(), Default) -> kz_json:object() | Default. +classifiers(Doc, Default) -> + kz_json:get_json_value([<<"classifiers">>], Doc, Default). + +-spec set_classifiers(doc(), kz_json:object()) -> doc(). +set_classifiers(Doc, Classifiers) -> + kz_json:set_value([<<"classifiers">>], Classifiers, Doc). + +-spec classifiers_emergency(doc()) -> boolean(). +classifiers_emergency(Doc) -> + classifiers_emergency(Doc, false). + +-spec classifiers_emergency(doc(), Default) -> boolean() | Default. +classifiers_emergency(Doc, Default) -> + kz_json:get_boolean_value([<<"classifiers">>, <<"emergency">>], Doc, Default). + +-spec set_classifiers_emergency(doc(), boolean()) -> doc(). +set_classifiers_emergency(Doc, ClassifiersEmergency) -> + kz_json:set_value([<<"classifiers">>, <<"emergency">>], ClassifiersEmergency, Doc). + +-spec classifiers_enabled(doc()) -> boolean(). +classifiers_enabled(Doc) -> + classifiers_enabled(Doc, true). + +-spec classifiers_enabled(doc(), Default) -> boolean() | Default. +classifiers_enabled(Doc, Default) -> + kz_json:get_boolean_value([<<"classifiers">>, <<"enabled">>], Doc, Default). + +-spec set_classifiers_enabled(doc(), boolean()) -> doc(). +set_classifiers_enabled(Doc, ClassifiersEnabled) -> + kz_json:set_value([<<"classifiers">>, <<"enabled">>], ClassifiersEnabled, Doc). + +-spec classifiers_prefix(doc()) -> kz_term:api_binary(). +classifiers_prefix(Doc) -> + classifiers_prefix(Doc, 'undefined'). + +-spec classifiers_prefix(doc(), Default) -> binary() | Default. +classifiers_prefix(Doc, Default) -> + kz_json:get_binary_value([<<"classifiers">>, <<"prefix">>], Doc, Default). + +-spec set_classifiers_prefix(doc(), binary()) -> doc(). +set_classifiers_prefix(Doc, ClassifiersPrefix) -> + kz_json:set_value([<<"classifiers">>, <<"prefix">>], ClassifiersPrefix, Doc). + +-spec classifiers_regex(doc()) -> kz_term:api_binary(). +classifiers_regex(Doc) -> + classifiers_regex(Doc, 'undefined'). + +-spec classifiers_regex(doc(), Default) -> binary() | Default. +classifiers_regex(Doc, Default) -> + kz_json:get_binary_value([<<"classifiers">>, <<"regex">>], Doc, Default). + +-spec set_classifiers_regex(doc(), binary()) -> doc(). +set_classifiers_regex(Doc, ClassifiersRegex) -> + kz_json:set_value([<<"classifiers">>, <<"regex">>], ClassifiersRegex, Doc). + +-spec classifiers_suffix(doc()) -> kz_term:api_binary(). +classifiers_suffix(Doc) -> + classifiers_suffix(Doc, 'undefined'). + +-spec classifiers_suffix(doc(), Default) -> binary() | Default. +classifiers_suffix(Doc, Default) -> + kz_json:get_binary_value([<<"classifiers">>, <<"suffix">>], Doc, Default). + +-spec set_classifiers_suffix(doc(), binary()) -> doc(). +set_classifiers_suffix(Doc, ClassifiersSuffix) -> + kz_json:set_value([<<"classifiers">>, <<"suffix">>], ClassifiersSuffix, Doc). + +-spec classifiers_weight_cost(doc()) -> integer(). +classifiers_weight_cost(Doc) -> + classifiers_weight_cost(Doc, 50). + +-spec classifiers_weight_cost(doc(), Default) -> integer() | Default. +classifiers_weight_cost(Doc, Default) -> + kz_json:get_integer_value([<<"classifiers">>, <<"weight_cost">>], Doc, Default). + +-spec set_classifiers_weight_cost(doc(), integer()) -> doc(). +set_classifiers_weight_cost(Doc, ClassifiersWeightCost) -> + kz_json:set_value([<<"classifiers">>, <<"weight_cost">>], ClassifiersWeightCost, Doc). + -spec emergency(doc()) -> boolean(). emergency(Doc) -> emergency(Doc, false). @@ -120,6 +251,18 @@ formatters(Doc, Default) -> set_formatters(Doc, Formatters) -> kz_json:set_value([<<"formatters">>], Formatters, Doc). +-spec from_account_realm(doc()) -> boolean(). +from_account_realm(Doc) -> + from_account_realm(Doc, false). + +-spec from_account_realm(doc(), Default) -> boolean() | Default. +from_account_realm(Doc, Default) -> + kz_json:get_boolean_value([<<"from_account_realm">>], Doc, Default). + +-spec set_from_account_realm(doc(), boolean()) -> doc(). +set_from_account_realm(Doc, FromAccountRealm) -> + kz_json:set_value([<<"from_account_realm">>], FromAccountRealm, Doc). + -spec from_uri_realm(doc()) -> kz_term:api_binary(). from_uri_realm(Doc) -> from_uri_realm(Doc, 'undefined'). diff --git a/doc/mkdocs/mkdocs.yml b/doc/mkdocs/mkdocs.yml index 94b92e306cf..76344b19ec8 100644 --- a/doc/mkdocs/mkdocs.yml +++ b/doc/mkdocs/mkdocs.yml @@ -67,6 +67,7 @@ pages: - 'applications/crossbar/doc/hotdesks.md' - 'applications/crossbar/doc/menus.md' - 'applications/crossbar/doc/metaflows.md' + - 'applications/crossbar/doc/mms.md' - 'applications/crossbar/doc/phone_numbers.md' - 'applications/crossbar/doc/quickcall.md' - 'applications/crossbar/doc/recordings.md' @@ -374,6 +375,8 @@ pages: - 'Kazoo IPs': - 'core/kazoo_ips/doc/README.md' - 'core/kazoo_ips/doc/maintenance.md' + - 'Kazoo IM': + - 'core/kazoo_im/doc/README.md' - 'Kazoo Media': - 'core/kazoo_media/doc/README.md' - 'Kazoo Convert': @@ -385,6 +388,8 @@ pages: - 'core/kazoo_apps/doc/kapps_notify_publisher.md' - 'Kazoo Translator': - 'core/kazoo_translator/doc/README.md' + - 'Kazoo Telemetry': + - 'core/kazoo_telemetry/doc/README.md' - 'Kazoo Number Manager': - 'core/kazoo_number_manager/doc/README.md' - 'core/kazoo_number_manager/doc/knm_voip_innovations.md' From 92e5ff3428e4103e8a6255ca574005abdd992bb8 Mon Sep 17 00:00:00 2001 From: James Aimonetti Date: Fri, 3 Apr 2020 22:08:12 +0000 Subject: [PATCH 2/2] xref --- applications/jonny5/src/j5_flat_rate.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/jonny5/src/j5_flat_rate.erl b/applications/jonny5/src/j5_flat_rate.erl index e616b0dd462..187b3c03096 100644 --- a/applications/jonny5/src/j5_flat_rate.erl +++ b/applications/jonny5/src/j5_flat_rate.erl @@ -107,8 +107,8 @@ maybe_get_resource_flat_rate(Request, 'true') -> ResourceId = j5_request:resource_id(Request), case kz_datamgr:open_cache_doc(?KZ_OFFNET_DB, ResourceId) of {'ok', JObj} -> - {kzd_resource:flat_rate_whitelist(JObj, ?WHITELIST) - ,kzd_resource:flat_rate_blacklist(JObj, ?BLACKLIST) + {kzd_resources:flat_rate_whitelist(JObj, ?WHITELIST) + ,kzd_resources:flat_rate_blacklist(JObj, ?BLACKLIST) }; {'error', _E} -> {?WHITELIST, ?BLACKLIST}