Skip to content

Commit

Permalink
fix(cdp): update authentication to use the basic header (#25970)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarconLP authored Nov 4, 2024
1 parent 571add2 commit 8c1fb07
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions posthog/cdp/templates/mailjet/template_mailjet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
"secret": True,
"required": True,
}
input_secret_key = {
"key": "secret_key",
"type": "string",
"label": "Mailjet Secret Key",
"secret": True,
"required": True,
}
input_email = {
"key": "email",
"type": "string",
Expand Down Expand Up @@ -43,7 +50,7 @@
fetch(f'https://api.mailjet.com/v3/REST/contact/', {
'method': 'POST',
'headers': {
'Authorization': f'Bearer {inputs.api_key}',
'Authorization': f'Basic {base64Encode(f'{inputs.api_key}:{inputs.secret_key}')}',
'Content-Type': 'application/json'
},
'body': {
Expand All @@ -55,6 +62,7 @@
""".strip(),
inputs_schema=[
input_api_key,
input_secret_key,
input_email,
{
"key": "name",
Expand Down Expand Up @@ -95,7 +103,7 @@
fetch(f'https://api.mailjet.com/v3/REST/contact/{inputs.email}/managecontactlists', {
'method': 'POST',
'headers': {
'Authorization': f'Bearer {inputs.api_key}',
'Authorization': f'Basic {base64Encode(f'{inputs.api_key}:{inputs.secret_key}')}',
'Content-Type': 'application/json'
},
'body': {
Expand All @@ -110,6 +118,7 @@
""".strip(),
inputs_schema=[
input_api_key,
input_secret_key,
input_email,
{
"key": "contact_list_id",
Expand Down Expand Up @@ -163,7 +172,7 @@
fetch(f'https://api.mailjet.com/v3.1/send', {
'method': 'POST',
'headers': {
'Authorization': f'Bearer {inputs.api_key}',
'Authorization': f'Basic {base64Encode(f'{inputs.api_key}:{inputs.secret_key}')}',
'Content-Type': 'application/json'
},
'body': {
Expand Down Expand Up @@ -191,6 +200,7 @@
""".strip(),
inputs_schema=[
input_api_key,
input_secret_key,
{
"key": "from_email",
"type": "string",
Expand Down
6 changes: 3 additions & 3 deletions posthog/cdp/templates/mailjet/test_template_mailjet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def create_inputs(**kwargs):
inputs = {"api_key": "API_KEY", "email": "[email protected]"}
inputs = {"api_key": "API_KEY", "secret_key": "SECRET_KEY", "email": "[email protected]"}
inputs.update(kwargs)
return inputs

Expand All @@ -20,7 +20,7 @@ def test_function_works(self):
"https://api.mailjet.com/v3/REST/contact/",
{
"method": "POST",
"headers": {"Authorization": "Bearer API_KEY", "Content-Type": "application/json"},
"headers": {"Authorization": "Basic QVBJX0tFWTpTRUNSRVRfS0VZ", "Content-Type": "application/json"},
"body": {"Email": "[email protected]", "Name": "Example", "IsExcludedFromCampaigns": False},
},
)
Expand All @@ -43,7 +43,7 @@ def test_function_works(self):
"https://api.mailjet.com/v3/REST/contact/[email protected]/managecontactlists",
{
"method": "POST",
"headers": {"Authorization": "Bearer API_KEY", "Content-Type": "application/json"},
"headers": {"Authorization": "Basic QVBJX0tFWTpTRUNSRVRfS0VZ", "Content-Type": "application/json"},
"body": {"ContactsLists": [{"Action": "addnoforce", "ListID": 123}]},
},
)
Expand Down

0 comments on commit 8c1fb07

Please sign in to comment.