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

chore: Remove mail.send helpers with on-behalf-of header #436

Merged
merged 4 commits into from Sep 24, 2021

Conversation

bjohnson-va
Copy link
Contributor

The sendgrid documentation (and my own findings) say that the mail.send endpoint
does not support using the on-behalf-of header.

image
Documentation

Providing the NewSendClientSubuser in this SDK causes wasted time because it
sets the expectation that this is possible when it is not.

I also added guards to the GetRequestSubuser function to prevent people from
using it with the mail.send endpoint.

Fixes

A short description of what this PR does.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

The sendgrid documentation (and my own findings) say that the mail.send endpoint
does not support using the `on-behalf-of` header.

[Documentation](
https://docs.sendgrid.com/api-reference/how-to-use-the-sendgrid-v3-api/on-behalf-of-subuser
)

Providing the `NewSendClientSubuser` in this SDK causes wasted time because it
sets the expectation that this is possible when it is not.

I also added guards to the `GetRequestSubuser` function to prevent people from
using it with the mail.send endpoint.
@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Jul 20, 2021
sendgrid.go Outdated
@@ -21,6 +23,10 @@ func GetRequest(key, endpoint, host string) rest.Request {
// GetRequestSubuser like GetRequest but with On-Behalf of Subuser
// @return [Request] a default request object
func GetRequestSubuser(key, endpoint, host, subuser string) rest.Request {
if strings.Contains(endpoint, "v3/mail/send") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does using the on-behalf-of with this endpoint throw any error at all? I'm not too sure I like hardcoding this into the logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does not throw an error, it just silently "fails" by ignoring the header and putting the email on the subuser who owns the API key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(My primary motivation for this change was so that there would be something to test to guard against someone adding this functionality back in)

Copy link
Contributor

Choose a reason for hiding this comment

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

I am ok with getting rid of NewSendClientSubuser and updating the documentation since that's not really supported but I don't like adding this hardcoded panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@JenniferMah JenniferMah left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @bjohnson-va!

@JenniferMah JenniferMah changed the title Remove mail.send helpers with on-behalf-of header chore: Remove mail.send helpers with on-behalf-of header Sep 24, 2021
@JenniferMah JenniferMah merged commit 332b5e2 into sendgrid:main Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: code review request requesting a community code review or review from Twilio
Projects
None yet
4 participants