From 1ed23b607c98b545201b114fe34f8936819ac521 Mon Sep 17 00:00:00 2001 From: yonkoma Date: Sat, 1 Jun 2019 04:07:34 -0700 Subject: [PATCH] Moved config storage cluster_id and added cluster_id to webhooks (#5832) --- .../priv/api/descriptions.system_config.json | 2 +- applications/crossbar/priv/api/swagger.json | 18 ++++++++++-------- .../couchdb/schemas/system_config.cluster.json | 12 ++++++++++++ .../system_config.crossbar.phonebook.json | 4 ---- .../schemas/system_config.provisioner.json | 4 ---- .../crossbar/src/modules/phonebook.erl | 11 +---------- .../crossbar/src/modules/provisioner_v5.erl | 11 +---------- applications/webhooks/src/webhooks_util.erl | 8 +++++--- core/kazoo_documents/src/kzd_cluster.erl | 17 +++++++++++++++++ 9 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 applications/crossbar/priv/couchdb/schemas/system_config.cluster.json create mode 100644 core/kazoo_documents/src/kzd_cluster.erl diff --git a/applications/crossbar/priv/api/descriptions.system_config.json b/applications/crossbar/priv/api/descriptions.system_config.json index 6381309e090..a51e155b11b 100644 --- a/applications/crossbar/priv/api/descriptions.system_config.json +++ b/applications/crossbar/priv/api/descriptions.system_config.json @@ -110,6 +110,7 @@ "cdr.refresh_view_timeout": "time in seconds to to trigger cdrs view refresh", "cdr.store_anonymous": "cdr store anonymous", "cdr.v3_migrate_num_months": "cdr v3 migrate num months", + "cluster.cluster_id": "provisioner cluster id", "conferences.bridge_password": "conferences bridge password", "conferences.bridge_username": "conferences bridge username", "conferences.default": "conferences default", @@ -594,7 +595,6 @@ "privacy.privacy_mode": "Default privacy mode for anonymous calls", "privacy.privacy_name": "Default Caller ID Name should be shown for anonymous calls", "privacy.privacy_number": "Default Caller ID Number should be shown for anonymous calls", - "provisioner.cluster_id": "provisioner cluster id", "provisioner.combo_keys": "provisioner combo keys", "provisioner.feature_keys": "provisioner feature keys", "provisioner.provisioning_type": "provisioner provisioning type", diff --git a/applications/crossbar/priv/api/swagger.json b/applications/crossbar/priv/api/swagger.json index 1c8e27c803e..a7815f98f77 100644 --- a/applications/crossbar/priv/api/swagger.json +++ b/applications/crossbar/priv/api/swagger.json @@ -29307,6 +29307,16 @@ }, "type": "object" }, + "system_config.cluster": { + "description": "Schema for cluster system_config", + "properties": { + "cluster_id": { + "description": "provisioner cluster id", + "type": "string" + } + }, + "type": "object" + }, "system_config.conferences": { "description": "Schema for conferences system_config", "properties": { @@ -30093,10 +30103,6 @@ "system_config.crossbar.phonebook": { "description": "Schema for crossbar.phonebook system_config", "properties": { - "cluster_id": { - "description": "the kazoo cluster_id", - "type": "string" - }, "enabled": { "default": false, "description": "phonebook integration enabled", @@ -33393,10 +33399,6 @@ "system_config.provisioner": { "description": "Schema for provisioner system_config", "properties": { - "cluster_id": { - "description": "provisioner cluster id", - "type": "string" - }, "combo_keys": { "default": { "cisco": { diff --git a/applications/crossbar/priv/couchdb/schemas/system_config.cluster.json b/applications/crossbar/priv/couchdb/schemas/system_config.cluster.json new file mode 100644 index 00000000000..04bf10457de --- /dev/null +++ b/applications/crossbar/priv/couchdb/schemas/system_config.cluster.json @@ -0,0 +1,12 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "_id": "system_config.cluster", + "description": "Schema for cluster system_config", + "properties": { + "cluster_id": { + "description": "provisioner cluster id", + "type": "string" + } + }, + "type": "object" +} diff --git a/applications/crossbar/priv/couchdb/schemas/system_config.crossbar.phonebook.json b/applications/crossbar/priv/couchdb/schemas/system_config.crossbar.phonebook.json index 0c43c810537..7b4612ebc87 100644 --- a/applications/crossbar/priv/couchdb/schemas/system_config.crossbar.phonebook.json +++ b/applications/crossbar/priv/couchdb/schemas/system_config.crossbar.phonebook.json @@ -3,10 +3,6 @@ "_id": "system_config.crossbar.phonebook", "description": "Schema for crossbar.phonebook system_config", "properties": { - "cluster_id": { - "description": "the kazoo cluster_id", - "type": "string" - }, "enabled": { "default": false, "description": "phonebook integration enabled", diff --git a/applications/crossbar/priv/couchdb/schemas/system_config.provisioner.json b/applications/crossbar/priv/couchdb/schemas/system_config.provisioner.json index b015d08dee3..b416cbec5b9 100644 --- a/applications/crossbar/priv/couchdb/schemas/system_config.provisioner.json +++ b/applications/crossbar/priv/couchdb/schemas/system_config.provisioner.json @@ -3,10 +3,6 @@ "_id": "system_config.provisioner", "description": "Schema for provisioner system_config", "properties": { - "cluster_id": { - "description": "provisioner cluster id", - "type": "string" - }, "combo_keys": { "default": { "cisco": { diff --git a/applications/crossbar/src/modules/phonebook.erl b/applications/crossbar/src/modules/phonebook.erl index c15a9707dfd..592990ecb7c 100644 --- a/applications/crossbar/src/modules/phonebook.erl +++ b/applications/crossbar/src/modules/phonebook.erl @@ -189,16 +189,7 @@ req_headers(Token) -> props:filter_undefined( [{"Content-Type", "application/json"} ,{"X-Auth-Token", kz_term:to_list(Token)} - ,{"X-Kazoo-Cluster-ID", get_cluster_id()} + ,{"X-Kazoo-Cluster-ID", kzd_cluster:id()} ,{"User-Agent", kz_term:to_list(erlang:node())} ]). --spec get_cluster_id() -> nonempty_string(). -get_cluster_id() -> - case kapps_config:get_string(?MOD_CONFIG_CAT, <<"cluster_id">>) of - 'undefined' -> - ClusterId = kz_binary:rand_hex(16), - {'ok', _JObj} = kapps_config:set_default(?MOD_CONFIG_CAT, <<"cluster_id">>, ClusterId), - kz_term:to_list(ClusterId); - ClusterId -> ClusterId - end. diff --git a/applications/crossbar/src/modules/provisioner_v5.erl b/applications/crossbar/src/modules/provisioner_v5.erl index d9c1f884fdd..f8a4d239ac2 100644 --- a/applications/crossbar/src/modules/provisioner_v5.erl +++ b/applications/crossbar/src/modules/provisioner_v5.erl @@ -719,16 +719,7 @@ req_headers(Token) -> props:filter_undefined( [{"Content-Type", "application/json"} ,{"X-Auth-Token", kz_term:to_list(Token)} - ,{"X-Kazoo-Cluster-ID", get_cluster_id()} + ,{"X-Kazoo-Cluster-ID", kzd_cluster:id()} ,{"User-Agent", kz_term:to_list(erlang:node())} ]). --spec get_cluster_id() -> nonempty_string(). -get_cluster_id() -> - case kapps_config:get_string(?MOD_CONFIG_CAT, <<"cluster_id">>) of - 'undefined' -> - ClusterId = kz_binary:rand_hex(16), - {'ok', _JObj} = kapps_config:set_default(?MOD_CONFIG_CAT, <<"cluster_id">>, ClusterId), - kz_term:to_list(ClusterId); - ClusterId -> ClusterId - end. diff --git a/applications/webhooks/src/webhooks_util.erl b/applications/webhooks/src/webhooks_util.erl index 95d23fb8938..1953646182a 100644 --- a/applications/webhooks/src/webhooks_util.erl +++ b/applications/webhooks/src/webhooks_util.erl @@ -181,11 +181,12 @@ maybe_fire_foldl(Key, Value, {_ShouldFire, JObj}) -> fire_hook(JObj, #webhook{custom_data = 'undefined' } = Hook) -> EventId = kz_binary:rand_hex(5), - do_fire(Hook, EventId, JObj); + NewJObj = kz_json:set_value(<<"cluster_id">>, kzd_cluster:id(), JObj), + do_fire(Hook, EventId, NewJObj); fire_hook(JObj, #webhook{custom_data = CustomData } = Hook) -> - EventId = kz_binary:rand_hex(5), - do_fire(Hook, EventId, kz_json:merge_jobjs(CustomData, JObj)). + NewJObj = kz_json:merge_jobjs(CustomData, JObj), + fire_hook(NewJObj, Hook#webhook{custom_data = 'undefined'}). -spec do_fire(webhook(), kz_term:ne_binary(), kz_json:object()) -> 'ok'. do_fire(#webhook{uri = ?NE_BINARY = URI @@ -757,3 +758,4 @@ fetch_available_events() -> kz_cache:store_local(?CACHE_NAME, ?AVAILABLE_EVENT_KEY, Events, CacheProps), Events end. + diff --git a/core/kazoo_documents/src/kzd_cluster.erl b/core/kazoo_documents/src/kzd_cluster.erl new file mode 100644 index 00000000000..f8f64bdca03 --- /dev/null +++ b/core/kazoo_documents/src/kzd_cluster.erl @@ -0,0 +1,17 @@ +%%%----------------------------------------------------------------------------- +%%% @copyright (C) 2019-, 2600Hz +%%% @doc Accessors for cluster document +%%% @author Kalyan Krause +%%% @end +%%%----------------------------------------------------------------------------- +-module(kzd_cluster). + +-define(MOD_CONFIG_CLUSTER, <<"cluster">>). + +-export([id/0]). + +-include("kz_documents.hrl"). + +-spec id() -> kz_term:ne_binary(). +id() -> + kapps_config:get_ne_binary(?MOD_CONFIG_CLUSTER, <<"cluster_id">>, kz_binary:rand_hex(16), <<"default">>).