Skip to content
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

Enable to use aws es with iam auth #98

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

yukato
Copy link

@yukato yukato commented Jul 26, 2016

  • PSR-2 code formatted, php syntax to >=5.4
  • Enable to use Amazon Elasticsearch Service with IAM auth

I wanted to use Amazon Elasticsearch Service. (Amazon ES)
https://aws.amazon.com/elasticsearch-service/

When use Amazon ES, I also want to use IAM auth, and with elasticsearch-php library, I wanted to set aws authed handler.
https://github.com/elastic/elasticsearch-php

@bathan
Copy link

bathan commented Sep 27, 2016

I could really use this. Any chance that it will be included in the project?

@pulkitjalan
Copy link

This would be very useful, any updated on this?

@yukato
Copy link
Author

yukato commented Oct 13, 2016

thanx @bathan , @pulkitjalan , and sorry for my late reply...
to be included to this project, first, i need to pass tests...
i'll try ;)

but if this code helps you, i'm happy :)

@timgws
Copy link
Member

timgws commented Oct 13, 2016

This will get included when the composer.json file is updated correctly, and when the test suite successfully runs so the project does not break for people already using the project.

---- On Tue, 27 Sep 2016 23:00:12 +1000 [email protected] wrote ----

I could really use this. Any chance that it will be included in the project?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@yukato
Copy link
Author

yukato commented Oct 14, 2016

@timgws Thanx for your comment! :)
I fixed the code, and now passed test.
Please check.

@yukato yukato force-pushed the enable-to-use-aws-es-with-iam-auth branch from 97090db to 7709f6b Compare October 14, 2016 03:07
@yukato
Copy link
Author

yukato commented Oct 14, 2016

also rebased for cleaning up code. ;)

@yukato
Copy link
Author

yukato commented Oct 14, 2016

@bathan @pulkitjalan
I fixed code, stay tuned ;)

@pulkitjalan
Copy link

@yukato Awesome, thanks!

@timgws
Copy link
Member

timgws commented Oct 14, 2016

Hi @yukato!

Sorry for my poor timing on the comment yesterday, I sent the reply to the email just moments after I saw your email :)

Thanks for your work here. This is really starting to look good.

The only thing now is that ElasticquentClientTrait should be changed so that it does not have a hard dependancy on AWS.

The way that I suggest doing this is maybe making a new class (ElasticSearchClientFactory?)

The factory's purpose is that it will build either an instance of the ElasticSearch PHP API using either \Elasticsearch\ClientBuilder or \Elasticsearch\Client, depending on the API version installed, this Factory can then pull in another class that will be used only if IAM is going to be used as specified in the config.

@yukato
Copy link
Author

yukato commented Oct 14, 2016

@timgws Thanks for your comment :)
I fixed code, you mean like this...?

@yukato
Copy link
Author

yukato commented Oct 18, 2016

@timgws Do i misunderstand your suggestion? feel free to comment to me, i'll do my best ;)

@timgws
Copy link
Member

timgws commented Oct 18, 2016

@yukato, re: factory, I was thinking something along the lines of this: https://github.com/domnikl/DesignPatternsPHP/tree/master/Creational/SimpleFactory

The factory class would contain a method that would detect wether the config was for Amazon or not, if it was for Amazon, a class would be created that would create an Elastic instance for use with the Amazon SDK.

Another method would create an instance without using the Amazon SDK.

This way, for users that are not using Amazon, they do not need to install the Amazon SDK.

Currently, if I wanted to remove the Amazon dependancy from my app using your PR, then I would end up with a broken application that did not work.

@yukato yukato force-pushed the enable-to-use-aws-es-with-iam-auth branch 2 times, most recently from 5e58de2 to 63f8e6d Compare October 18, 2016 05:53
@yukato yukato force-pushed the enable-to-use-aws-es-with-iam-auth branch from 63f8e6d to 96e65e7 Compare October 18, 2016 06:08
@yukato
Copy link
Author

yukato commented Oct 18, 2016

Hi @timgws , thank you for your reply ;)
I already added ElasticSearchClientFactory class, and i think it would detect wether the config was for Amazon or not.
And also, i think it would create instance with/without Amazon SDK according to the config file.

And yes, my composer.json file was not good...
I moved aws-sdk-php dependencies to suggest section, and also added class exists check logic to getAwsESHandler function on ElasticSearchClientFactory class.
96e65e7

Can you please check again? :)

@yukato
Copy link
Author

yukato commented Oct 26, 2016

@timgws if i need to improve code more, feel free to tell me. :)
i'll do my best!

@timgws
Copy link
Member

timgws commented Oct 27, 2016

@yukato, your work on 7a7ecf8 is almost half way to being awesome! (:

If you have a look at the Design Pattern code again that I linked you before (https://github.com/domnikl/DesignPatternsPHP/tree/master/Creational/SimpleFactory) look at the class SimpleFactory.

What would happen is you would have two new classes under SimpleFactory.

eg, AwsClient and ElasticsearchClient.

SimpleFactory would determine if it should create a new instance AwsClient depending on wether or not AWS-specific config is set (or a new instance of ElasticsearchClient if it isn't).

https://github.com/yukato/Elasticquent/blob/7a7ecf8b012e6d0613dbc181928f5380e8908b1c/src/ElasticSearchClientFactory.php#L30-L50

This way, when you call getClient(), you will call it on either AwsClient or ElasticsearchClient. Only AwsClient would use Aws\Credentials\Credentials;, which means you only need to have the AWS SDK installed if you are going to be having AWS config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants