Skip to content

Commit 9d433a6

Browse files
committed
feat: geolocation setter in sendgrid-python for GDPR compliance
1 parent 1e1299d commit 9d433a6

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

examples/dataresidency/set_region.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sendgrid
2-
import os
32

43
from sendgrid import Email, To, Content, Mail
54

sendgrid/base_interface.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import python_http_client
22

3+
region_host_dict = {'eu':'https://api.eu.sendgrid.com','global':'https://api.sendgrid.com'}
34

45
class BaseInterface(object):
56
def __init__(self, auth, host, impersonate_subuser, region='global'):
@@ -27,7 +28,7 @@ def __init__(self, auth, host, impersonate_subuser, region='global'):
2728
if host is not None and region == 'global':
2829
self.set_host(host)
2930
else:
30-
self.set_region(region)
31+
self.set_data_residency(region)
3132
self.impersonate_subuser = impersonate_subuser
3233
self.version = __version__
3334
self.useragent = 'sendgrid/{};python'.format(self.version)
@@ -69,7 +70,7 @@ def send(self, message):
6970
def set_host(self,host):
7071
self.host = host
7172

72-
def set_region(self,region):
73+
def set_data_residency(self,region):
7374
"""
7475
* Client libraries contain setters for specifying region/edge.
7576
* This allows support global and eu regions only. This set will likely expand in the future.
@@ -81,7 +82,6 @@ def set_region(self,region):
8182
:param region:
8283
:return:
8384
"""
84-
region_host_dict = {'eu':'https://api.eu.sendgrid.com','global':'https://api.sendgrid.com'}
8585
if region in region_host_dict.keys():
8686
self.host = region_host_dict[region]
8787
else:

test/unit/test_sendgrid.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ def test_host_with_no_region(self):
88

99
def test_host_with_eu_region(self):
1010
sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY')
11-
sg.set_region("eu")
11+
sg.set_data_residency("eu")
1212
self.assertEqual("https://api.eu.sendgrid.com",sg.host)
1313

1414
def test_host_with_global_region(self):
1515
sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY')
16-
sg.set_region("global")
16+
sg.set_data_residency("global")
1717
self.assertEqual("https://api.sendgrid.com",sg.host)
1818

1919
def test_host_with_host_first_eu_region_second(self):
2020
sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY')
2121
sg.set_host("https://sendgrid.com")
22-
sg.set_region("eu")
22+
sg.set_data_residency("eu")
2323
self.assertEqual("https://api.eu.sendgrid.com",sg.host)
2424

2525
def test_host_with_eu_first_host_second(self):
2626
sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY')
27-
sg.set_region("eu")
27+
sg.set_data_residency("eu")
2828
sg.set_host("https://sendgrid.com")
2929
self.assertEqual("https://sendgrid.com",sg.host)
3030

@@ -35,9 +35,9 @@ def test_host_using_constructor(self):
3535
def test_with_region_is_none(self):
3636
sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY')
3737
with self.assertRaises(ValueError):
38-
sg.set_region("")
38+
sg.set_data_residency(None)
3939

40-
def test_with_region_is_none(self):
40+
def test_with_region_is_invalid(self):
4141
sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY')
4242
with self.assertRaises(ValueError):
43-
sg.set_region("abc")
43+
sg.set_data_residency("abc")

0 commit comments

Comments
 (0)