-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/amazon sns support #1149
Conversation
-module(mod_aws_sns_defaults). | ||
-author("Rafal Slota"). | ||
|
||
-behavior(mod_aws_sns). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Compiler:
Warning: behaviour mod_aws_sns undefined
f5fc1f7
to
ca6a208
Compare
-module(mod_aws_sns). | ||
-author("Rafal Slota"). | ||
|
||
-behavior(gen_mod). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Compiler:
Warning: behaviour gen_mod undefined
de7db75
to
4beb9da
Compare
apps/ejabberd/src/mod_aws_sns.erl
Outdated
%% @doc Returns AWS SNS handle base on configured AWS credentials | ||
-spec aws_handle(Host :: ejabberd:lserver()) -> erlcloud:sns_handle(). | ||
aws_handle(Host) -> | ||
AccessKeyId = [_ | _] = opt(Host, access_key_id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it checked here if the access_key_id
is a list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gen_mod
's API doesn't crash with exception when we ask for the module option that is required. This is to ensure this option is set and to crash when it doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind that check, I'll leave it here while adding a comment to make it clear :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to validate it on every push to AWS? Can we move the validation to module's start and crash when the option doesn't validate? This will get feedback to the devops that sth is misconfigured earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done.
escalus:end_per_suite(Config). | ||
|
||
init_per_group(_, Config) -> | ||
dynamic_modules:start(<<"localhost">>, mod_aws_sns, ?SNS_OPTS), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The domain in big tests shouldn't be hardcoded. This is configurable and can be read like adhoc_SUITE:58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done.
cf11ee1
to
e5b28a4
Compare
%% Tests | ||
|
||
handles_unicode_messages(Config) -> | ||
expect_message_entry(<<"message">>, <<"❤☀☆☂☻♞☯☭☢€"/utf8>>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Elvis:
Missing space right "," on line 39
%% Tests | ||
|
||
handles_unicode_messages(Config) -> | ||
expect_message_entry(<<"message">>, <<"❤☀☆☂☻♞☯☭☢€"/utf8>>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Elvis:
Missing space right "," on line 42
|
||
-define(assertReceivedMatch(Expect), ?assertReceivedMatch(Expect, 0)). | ||
|
||
-define(assertReceivedMatch(Expect, Timeout), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Elvis:
Invalid macro name assertReceivedMatch on line 36. Use UPPER_CASE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this as well.
config | ||
}). | ||
|
||
-define(assertReceivedMatch(Expect), ?assertReceivedMatch(Expect, 0)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Elvis:
Invalid macro name assertReceivedMatch on line 34. Use UPPER_CASE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can Elvis config be change to accept such macro names in tests only?
5dfb4e8
to
f2def99
Compare
ejabberd_hooks:add(user_available_hook, Host, ?MODULE, user_present, 90), | ||
ejabberd_hooks:add(unset_presence_hook, Host, ?MODULE, user_not_present, 90), | ||
|
||
application:ensure_all_started(erlcloud), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this here? Can we run erlcloud
app while starting the node?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When on start? Our reltool.config
does not start applications listed by configure script. Anyway, theres just no need for loading all those apps until this module is started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I forgot about the configure
script.
apps/ejabberd/src/mod_aws_sns.erl
Outdated
user_send_packet(From = #jid{lserver = Host}, To, Packet) -> | ||
?DEBUG("SNS Packet handle~n from ~p ~n to ~p~n packet ~p.", [From, To, Packet]), | ||
|
||
case {get_topic(Host, Packet), xml:get_subtag(Packet, <<"body">>)} of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly encourage use of exml_query
module instead of xml
. Especially in new code.
apps/ejabberd/src/mod_aws_sns.erl
Outdated
FromGUID = user_guid(Host, From), | ||
ToGUID = user_guid(Host, To), | ||
|
||
MessageBody = xml:get_tag_cdata(BodyTag), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one can also be replaced with an equivalent from exml_query
.
apps/ejabberd/src/mod_aws_sns.erl
Outdated
%% @doc Returns message type | ||
-spec message_type(Packet :: jlib:xmlel()) -> pm | muc | undefined. | ||
message_type(Packet) -> | ||
case xml:get_tag_attr_s(<<"type">>, Packet) of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another candidate to replace with exml_query
.
config | ||
}). | ||
|
||
-define(assertReceivedMatch(Expect), ?assertReceivedMatch(Expect, 0)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can Elvis config be change to accept such macro names in tests only?
|
||
-define(assertReceivedMatch(Expect), ?assertReceivedMatch(Expect, 0)). | ||
|
||
-define(assertReceivedMatch(Expect, Timeout), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this as well.
@rslota @kzemek when I'm running "big tests" I'm getting the following error: [error] <0.12290.0>@ejabberd_hooks:run1:241 {{sns_error,"InvalidClientTokenId","The security token included in the request is invalid."},[{erlcloud_sns,sns_xml_request,3,[{file,"src/erlcloud_sns.erl"},{line,649}]},{erlcloud_sns,publish,6,[{file,"src/erlcloud_sns.erl"},{line,452}]},{mod_aws_sns,user_presence_changed,2,[{file,"src/mod_aws_sns.erl"},{line,155}]},{safely,apply,3,[{file,"src/safely.erl"},{line,19}]},{ejabberd_hooks,run1,3,[{file,"src/ejabberd_hooks.erl"},{line,237}]},{ejabberd_c2s,presence_update,3,[{file,"src/ejabberd_c2s.erl"},{line,1862}]},{ejabberd_c2s,process_outgoing_stanza,2,[{file,"src/ejabberd_c2s.erl"},{line,960}]},{p1_fsm_old,handle_msg,10,[{file,"src/p1_fsm_old.erl"},{line,576}]}]}
Running hook: {user_available_hook,[{jid,<<"bOb">>,<<"localhost">>,<<"res1">>,<<"bob">>,<<"localhost">>,<<"res1">>}]}
Callback: mod_aws_sns:user_present It looks like the credentials are incorrect. |
ba74a4c
to
c71ddb2
Compare
As the publishing to Amazon SNS is synchronous, if the ercloud_sns:publish/X fails, then the whole C2S process fails. I suggest using the publish(Host, TopicARN, Content, Attributes) ->
EncodedContent = jiffy:encode(Content),
case (catch erlcloud_sns:publish(topic,
TopicARN,
unicode:characters_to_list(EncodedContent),
undefined,
maps:to_list(Attributes),
aws_handle(Host))) of
{'EXIT', Error} ->
?ERROR_MSG("Failed publishing to Amazon SNS: ~p", [Error]);
MessageId ->
MessageId
end. I believe that the end goal will be to make a pool of connections for that. How that sounds for you? |
Hooks are already ran with |
@kzemek cool. I didn't know that, thanks. |
@kzemek when I'm running the big tests I'm getting this error: === Ended at 2017-01-18 13:15:35
=== Location: [{escalus_new_assert,assert_true,84},
{escalus_story,'-drop_presences/2-lc$^0/1-0-',144},
{escalus_story,drop_presences,144},
{escalus_story,'-start_ready_clients/2-fun-0-',97},
{lists,foldl,1262},
{escalus_story,start_ready_clients,90},
{lists,flatmap,1249},
{lists,flatmap,1249}]
=== Reason: {assertion_failed,assert,is_presence,
{xmlel,<<"message">>,
[{<<"from">>,<<"bOb@localhost/res1">>},
{<<"to">>,<<"alicE@localhost/res1">>},
{<<"xml:lang">>,<<"en">>},
{<<"type">>,<<"chat">>}],
[{xmlel,<<"body">>,[],
[{xmlcdata,<<"How are you?">>}]},
{xmlel,<<"delay">>,
[{<<"xmlns">>,<<"urn:xmpp:delay">>},
{<<"from">>,<<"localhost">>},
{<<"stamp">>,
<<"2017-01-18T12:15:32.976994Z">>}],
[{xmlcdata,<<"Offline Storage">>}]}]},
"<message from='bOb@localhost/res1' to='alicE@localhost/res1' xml:lang='en' type='chat'><body>How are you?</body><delay xmlns='urn:xmpp:delay' from='localhost' stamp='2017-01-18T12:15:32.976994Z'>Offline Storage</delay></message>"}
in function escalus_new_assert:assert_true/2 (src/escalus_new_assert.erl, line 84)
in call from escalus_story:'-drop_presences/2-lc$^0/1-0-'/1 (src/escalus_story.erl, line 144)
in call from escalus_story:drop_presences/2 (src/escalus_story.erl, line 144)
in call from escalus_story:'-start_ready_clients/2-fun-0-'/3 (src/escalus_story.erl, line 97)
in call from lists:foldl/3 (lists.erl, line 1262)
in call from escalus_story:start_ready_clients/2 (src/escalus_story.erl, line 90)
in call from lists:flatmap/2 (lists.erl, line 1249)
in call from lists:flatmap/2 (lists.erl, line 1249) I'll look into it after lunch but maybe you have a clue straight away. |
And the config was:
|
86407ad
to
ce7fc5c
Compare
18046e5
to
31706ca
Compare
%% Tests | ||
|
||
handles_unicode_messages(Config) -> | ||
expect_message_entry(<<"message">>, <<"❤☀☆☂☻♞☯☭☢€"/utf8>>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Elvis:
Missing space right "," on line 42
%% Tests | ||
|
||
handles_unicode_messages(Config) -> | ||
expect_message_entry(<<"message">>, <<"❤☀☆☂☻♞☯☭☢€"/utf8>>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Elvis:
Missing space right "," on line 42
All right, I'm merging this. |
This PR introduces Amazon SNS support for message and users' presence change notifications.