Skip to content

Commit

Permalink
Moved config storage cluster_id and added cluster_id to webhooks (#5832)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonkoma authored and lazedo committed Jun 1, 2019
1 parent 75f062a commit 1ed23b6
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 10 additions & 8 deletions applications/crossbar/priv/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 1 addition & 10 deletions applications/crossbar/src/modules/phonebook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
11 changes: 1 addition & 10 deletions applications/crossbar/src/modules/provisioner_v5.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 5 additions & 3 deletions applications/webhooks/src/webhooks_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -757,3 +758,4 @@ fetch_available_events() ->
kz_cache:store_local(?CACHE_NAME, ?AVAILABLE_EVENT_KEY, Events, CacheProps),
Events
end.

17 changes: 17 additions & 0 deletions core/kazoo_documents/src/kzd_cluster.erl
Original file line number Diff line number Diff line change
@@ -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">>).

0 comments on commit 1ed23b6

Please sign in to comment.