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

Add ability to impersonate subuser #571

Merged
merged 1 commit into from
Aug 14, 2018
Merged

Add ability to impersonate subuser #571

merged 1 commit into from
Aug 14, 2018

Conversation

stianpr
Copy link
Contributor

@stianpr stianpr commented Jan 10, 2018

Sendgrid API has a feature allowing parent accounts to impersonate
subusers by including an HTTP header "On-Behalf-Of" in each API request.
This commit enables setting the value for impersonation when creating
the Sendgrid API Client instance, through the $options argument.

Fixes #551

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Jan 10, 2018
@SendGridDX
Copy link

SendGridDX commented Jan 10, 2018

CLA assistant check
All committers have signed the CLA.

@stianpr
Copy link
Contributor Author

stianpr commented Jan 11, 2018

Not sure why dockerfile existence test breaks? Has it been removed in the repo?

@thinkingserious
Copy link
Contributor

No worries on the failing test, we will fix that on our end.

Thanks for taking the time to submit this PR! It's currently on our backlog for review.

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Jan 11, 2018
@thinkingserious thinkingserious added difficulty: medium fix is medium in difficulty type: twilio enhancement feature request on Twilio's roadmap labels Feb 28, 2018
Copy link

@phansys phansys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status: Needs work.

lib/SendGrid.php Outdated
*/
public function __construct($apiKey, $options = array())
public function __construct($apiKey, $options = array(), $impersonateSubuser = null)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove surplus blankspace before $options.

lib/SendGrid.php Outdated
@@ -37,15 +37,20 @@ class SendGrid
*
* @param string $apiKey your SendGrid API Key.
* @param array $options an array of options, currently only "host" and "curl" are implemented.
* @param string $impersonateSubuser Support impersonation of subusers.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, update docblock according the accepted values (string|null).

lib/SendGrid.php Outdated
{
$headers = array(
'Authorization: Bearer '.$apiKey,
'User-Agent: sendgrid/' . $this->version . ';php',
'Accept: application/json'
);

if (!empty($impersonateSubuser)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use null !== $impersonateSubuser instead.

Copy link

@phansys phansys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status: Needs work.

$subuser = 'abcxyz@this.is.a.test.subuser';
$headers[] = 'On-Behalf-Of: ' . $subuser;
$sg5 = new SendGrid(self::$apiKey, [], $subuser);
$this->assertEquals($sg5->client->getHeaders(), $headers);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless assert*() methods are already misused in the existing codebase, please, pass the expectation in argument 1, then the actual value in argument 2. [ref].
Use assertSame() if possible.

@stianpr
Copy link
Contributor Author

stianpr commented Mar 22, 2018

@phansys For some reason another test started to fail because the test runner installs version 3.9.x of sendgrid/php-http-client. That version has removed $curlOptions in Client->__construct() . We should probably lock sendgrid/php-http-client to 3.7.0 in composer.json, but that doesnt fit in this path. This is a bug that should be fixed in another patch IMO. What do you think?

EDIT: Ah there is already a bug report for this in #586 . Then this patch should be complete when that issue is resolved.

@thinkingserious
Copy link
Contributor

@stianpr,

That is a valid bug, the function signature should be: https://github.com/sendgrid/php-http-client/blob/929018c62b7fcd99b3b356216ae75fff4d47b5a1/lib/Client.php#L48

I'll be fixing that shortly in a v3.9.4 patch. Thanks for the heads up!

With Best Regards,

Elmer

lib/SendGrid.php Outdated
*/
public function __construct($apiKey, $options = array())
public function __construct($apiKey, $options = array(), $impersonateSubuser = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about including this as part of the $options array?

@thinkingserious thinkingserious added status: waiting for feedback waiting for feedback from the submitter and removed status: code review request requesting a community code review or review from Twilio labels Mar 28, 2018
Sendgrid API has a feature allowing parent accounts to impersonate
subusers by including an HTTP header "On-Behalf-Of" in each API request.
This commit enables setting the value for impersonation when creating
the Sendgrid API Client instance.

Fixes #551
@stianpr
Copy link
Contributor Author

stianpr commented Aug 9, 2018

Just rebased this PR on master branch now. Would be nice to get it in soon =)

@thinkingserious thinkingserious added status: code review request requesting a community code review or review from Twilio and removed status: waiting for feedback waiting for feedback from the submitter labels Aug 13, 2018
@thinkingserious
Copy link
Contributor

Awesome, thanks @stianpr!

@thinkingserious thinkingserious merged commit 3eaddc5 into sendgrid:master Aug 14, 2018
@thinkingserious
Copy link
Contributor

Hello @stianpr,

Thanks again for the PR!

We want to show our appreciation by sending you some swag. Could you please fill out this form so we can send it to you? Thanks!

Team SendGrid DX

@stianpr
Copy link
Contributor Author

stianpr commented Aug 15, 2018

@thinkingserious Sweet. Thank you! =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: code review request requesting a community code review or review from Twilio type: twilio enhancement feature request on Twilio's roadmap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants