-
Notifications
You must be signed in to change notification settings - Fork 261
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
feat: added data residency for eu and global regions #469
Conversation
base_interface.go
Outdated
func setDataResidency(options options) (string, error) { | ||
currentHost := options.Host | ||
defaultHost := allowedRegionsHostMap["global"] | ||
if currentHost != defaultHost { // for testing, the hostname can be different |
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.
What do you mean hostname can be different? For example if its api.sendgrid.com
by default and I am calling setDataResidency('eu'), shouldn't the hostname change ?
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.
In the test cases, we set the URL of the fakeServer as the hostname (something like 127.0.0.1:5000) In that case if we return the default host (api.sendgrid.com) the test would fail. That's why I added this check.
examples/dataresidency/setRegion.go
Outdated
// SetDataResidency : Set region for sendgrid. | ||
func SetDataResidencyGlobal() { | ||
message := buildHelloEmail() | ||
request := buildSendgridObj("global") |
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 we call setDataResidency() method on the request object too? Right now, I guess the only way to set it is via the constructor, no?
LGTM |
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.
CR
base_interface.go
Outdated
@@ -55,6 +61,38 @@ func requestNew(options options) rest.Request { | |||
} | |||
} | |||
|
|||
func ExtractEndpoint(link string) (string, error) { |
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.
is there any reason to export this outside of the sendgrid
package? If not, we should make it private
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.
caling this exportPath
seems more appropriate too
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.
yeah we do not need to export it outside, making it private.
base_interface.go
Outdated
|
||
func SetDataResidency(request rest.Request, region string) (rest.Request, error) { | ||
regionalHost, isPresent := allowedRegionsHostMap[region] | ||
if isPresent { |
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.
it's generally better to wrap the !ok
in the if
block since it's a shorter path. You'll be able to avoid the nested if
blocks and makes the code more readable. So something like
regionalHost, ok := allowedRegionsHostMap[region]
if !ok {
return error
}
do other stuff here
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.
Yeah that makes sense. Will correct it
sendgrid_test.go
Outdated
@@ -81,6 +81,53 @@ func TestGetRequestSubuser(t *testing.T) { | |||
ShouldHaveHeaders(&request, t) | |||
} | |||
|
|||
func Test_test_set_residency_eu(t *testing.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.
we should try to follow the Go
convention of naming test functions and proper casing. You can refer to the other existing tests for example, but generally, it should be Test<FunctionNameBeingTested>
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, will correct the casing and naming of the test cases
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 think for different scenarios in a single function to be tested, we can add them with an underscore like the test cases like TestRequestRetry_rateLimit and TestRequestRetry_rateLimit_noHeader.
Similarly, I think we can also have test cases named - TestSetDataResidency_eu and TestSetDataResidency_global. Will that be okay?
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.
CR 2
return request, nil | ||
} | ||
|
||
func SetDataResidency(request rest.Request, region string) (rest.Request, error) { |
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.
we should add comments to document what these function does, especially how it manipulates the host
field
return parsedURL.Path, nil | ||
} | ||
|
||
func SetHost(request rest.Request, host string) (rest.Request, error) { |
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.
public functions should be documented
* feat: added data residency for eu and global regions * feat: added data residency for eu and global regions * fix: added setters for host and data residency * chore: corrected the naming of test cases * chore: added inline documentation for SetDataResidency and SetHost * chore: added comment for SetDataResidency
Fixes
Added region field in sendgrid options. The default region is "global" and the default host is "api.sendgrid.com". When the region is set to "eu", the host should change to "api.eu.sendgrid.com".
Checklist
If you have questions, please file a support ticket.