diff --git a/courier/http_channel.go b/courier/http_channel.go index e9015dca13fd..13e0a5792623 100644 --- a/courier/http_channel.go +++ b/courier/http_channel.go @@ -47,12 +47,12 @@ func (c *httpChannel) ID() string { } type httpDataModel struct { - Recipient string - Subject string - Body string - TemplateType template.TemplateType - TemplateData Template - MessageType string + Recipient string `json:"recipient"` + Subject string `json:"subject"` + Body string `json:"body"` + TemplateType template.TemplateType `json:"template_type"` + TemplateData Template `json:"template_data"` + MessageType string `json:"message_type"` } func (c *httpChannel) Dispatch(ctx context.Context, msg Message) (err error) { diff --git a/courier/http_test.go b/courier/http_test.go index 4f21e467653b..f6327bdafc4e 100644 --- a/courier/http_test.go +++ b/courier/http_test.go @@ -30,17 +30,17 @@ func TestQueueHTTPEmail(t *testing.T) { ctx := context.Background() type sendEmailRequestBody struct { - IdentityID string - IdentityEmail string - Recipient string - TemplateType string - To string - RecoveryCode string - RecoveryURL string - VerificationURL string - VerificationCode string - Body string - Subject string + IdentityID string `json:"identity_id"` + IdentityEmail string `json:"identity_email"` + Recipient string `json:"recipient"` + TemplateType string `json:"template_type"` + To string `json:"to"` + RecoveryCode string `json:"recovery_code"` + RecoveryURL string `json:"recovery_url"` + VerificationURL string `json:"verification_url"` + VerificationCode string `json:"verification_code"` + Body string `json:"body"` + Subject string `json:"subject"` } expectedEmail := []*email.TestStubModel{ @@ -112,7 +112,7 @@ func TestQueueHTTPEmail(t *testing.T) { if len(actual) == len(expectedEmail) { return nil } - return errors.New("capacity not reached") + return errors.Errorf("capacity not reached: %d of %d", len(actual), len(expectedEmail)) })) for i, message := range actual { diff --git a/courier/stub/request.config.mailer.jsonnet b/courier/stub/request.config.mailer.jsonnet index 903aff05f541..fba51d68f8a2 100644 --- a/courier/stub/request.config.mailer.jsonnet +++ b/courier/stub/request.config.mailer.jsonnet @@ -1,11 +1,11 @@ function(ctx) { - recipient: ctx.Recipient, - template_type: ctx.TemplateType, - to: if "TemplateData" in ctx && "To" in ctx.TemplateData then ctx.TemplateData.To else null, - recovery_code: if "TemplateData" in ctx && "RecoveryCode" in ctx.TemplateData then ctx.TemplateData.RecoveryCode else null, - recovery_url: if "TemplateData" in ctx && "RecoveryURL" in ctx.TemplateData then ctx.TemplateData.RecoveryURL else null, - verification_url: if "TemplateData" in ctx && "VerificationURL" in ctx.TemplateData then ctx.TemplateData.VerificationURL else null, - verification_code: if "TemplateData" in ctx && "VerificationCode" in ctx.TemplateData then ctx.TemplateData.VerificationCode else null, - subject: if "TemplateData" in ctx && "Subject" in ctx.TemplateData then ctx.TemplateData.Subject else null, - body: if "TemplateData" in ctx && "Body" in ctx.TemplateData then ctx.TemplateData.Body else null + recipient: ctx.recipient, + template_type: ctx.template_type, + to: if "template_data" in ctx && "to" in ctx.template_data then ctx.template_data.to else null, + recovery_code: if "template_data" in ctx && "recovery_code" in ctx.template_data then ctx.template_data.recovery_code else null, + recovery_url: if "template_data" in ctx && "recovery_url" in ctx.template_data then ctx.template_data.recovery_url else null, + verification_url: if "template_data" in ctx && "verification_url" in ctx.template_data then ctx.template_data.verification_url else null, + verification_code: if "template_data" in ctx && "verification_code" in ctx.template_data then ctx.template_data.verification_code else null, + subject: if "template_data" in ctx && "subject" in ctx.template_data then ctx.template_data.subject else null, + body: if "template_data" in ctx && "body" in ctx.template_data then ctx.template_data.body else null } diff --git a/courier/stub/request.config.twilio.jsonnet b/courier/stub/request.config.twilio.jsonnet index f3a99db694e5..b8497666a227 100644 --- a/courier/stub/request.config.twilio.jsonnet +++ b/courier/stub/request.config.twilio.jsonnet @@ -1,5 +1,5 @@ function(ctx) { from: "Kratos Test", - to: ctx.Recipient, - body: ctx.Body + to: ctx.recipient, + body: ctx.body } diff --git a/courier/template/email/login_code_valid.go b/courier/template/email/login_code_valid.go index 1b3b55d4807c..ea1dde008728 100644 --- a/courier/template/email/login_code_valid.go +++ b/courier/template/email/login_code_valid.go @@ -18,9 +18,9 @@ type ( model *LoginCodeValidModel } LoginCodeValidModel struct { - To string - LoginCode string - Identity map[string]interface{} + To string `json:"to"` + LoginCode string `json:"login_code"` + Identity map[string]interface{} `json:"identity"` } ) diff --git a/courier/template/email/recovery_code_invalid.go b/courier/template/email/recovery_code_invalid.go index 4914b75c7024..2ac8022bf2d0 100644 --- a/courier/template/email/recovery_code_invalid.go +++ b/courier/template/email/recovery_code_invalid.go @@ -18,7 +18,7 @@ type ( model *RecoveryCodeInvalidModel } RecoveryCodeInvalidModel struct { - To string + To string `json:"to"` } ) diff --git a/courier/template/email/recovery_code_valid.go b/courier/template/email/recovery_code_valid.go index dce31b72e2fa..e386de93d984 100644 --- a/courier/template/email/recovery_code_valid.go +++ b/courier/template/email/recovery_code_valid.go @@ -18,9 +18,9 @@ type ( model *RecoveryCodeValidModel } RecoveryCodeValidModel struct { - To string - RecoveryCode string - Identity map[string]interface{} + To string `json:"to"` + RecoveryCode string `json:"recovery_code"` + Identity map[string]interface{} `json:"identity"` } ) diff --git a/courier/template/email/recovery_invalid.go b/courier/template/email/recovery_invalid.go index dbc8992d5593..4d19808206f5 100644 --- a/courier/template/email/recovery_invalid.go +++ b/courier/template/email/recovery_invalid.go @@ -18,7 +18,7 @@ type ( m *RecoveryInvalidModel } RecoveryInvalidModel struct { - To string + To string `json:"to"` } ) diff --git a/courier/template/email/recovery_valid.go b/courier/template/email/recovery_valid.go index 532d8d1bc4e6..0a9e01e35919 100644 --- a/courier/template/email/recovery_valid.go +++ b/courier/template/email/recovery_valid.go @@ -18,9 +18,9 @@ type ( m *RecoveryValidModel } RecoveryValidModel struct { - To string - RecoveryURL string - Identity map[string]interface{} + To string `json:"to"` + RecoveryURL string `json:"recovery_url"` + Identity map[string]interface{} `json:"identity"` } ) diff --git a/courier/template/email/registration_code_valid.go b/courier/template/email/registration_code_valid.go index f984ffaeb6c6..1c48b89f80c4 100644 --- a/courier/template/email/registration_code_valid.go +++ b/courier/template/email/registration_code_valid.go @@ -18,9 +18,9 @@ type ( model *RegistrationCodeValidModel } RegistrationCodeValidModel struct { - To string - Traits map[string]interface{} - RegistrationCode string + To string `json:"to"` + Traits map[string]interface{} `json:"traits"` + RegistrationCode string `json:"registration_code"` } ) diff --git a/courier/template/email/stub.go b/courier/template/email/stub.go index 57b66e06e4aa..9493ca967a08 100644 --- a/courier/template/email/stub.go +++ b/courier/template/email/stub.go @@ -18,9 +18,9 @@ type ( m *TestStubModel } TestStubModel struct { - To string - Subject string - Body string + To string `json:"to"` + Subject string `json:"subject"` + Body string `json:"body"` } ) diff --git a/courier/template/email/verification_code_invalid.go b/courier/template/email/verification_code_invalid.go index fa76441b3434..491997a50ec3 100644 --- a/courier/template/email/verification_code_invalid.go +++ b/courier/template/email/verification_code_invalid.go @@ -18,7 +18,7 @@ type ( m *VerificationCodeInvalidModel } VerificationCodeInvalidModel struct { - To string + To string `json:"to"` } ) diff --git a/courier/template/email/verification_code_valid.go b/courier/template/email/verification_code_valid.go index e23f48f70b5a..3f6ccb966ed9 100644 --- a/courier/template/email/verification_code_valid.go +++ b/courier/template/email/verification_code_valid.go @@ -18,10 +18,10 @@ type ( m *VerificationCodeValidModel } VerificationCodeValidModel struct { - To string - VerificationURL string - VerificationCode string - Identity map[string]interface{} + To string `json:"to"` + VerificationURL string `json:"verification_url"` + VerificationCode string `json:"verification_code"` + Identity map[string]interface{} `json:"identity"` } ) diff --git a/courier/template/email/verification_invalid.go b/courier/template/email/verification_invalid.go index 5f6623f04352..dc2e050a585e 100644 --- a/courier/template/email/verification_invalid.go +++ b/courier/template/email/verification_invalid.go @@ -18,7 +18,7 @@ type ( m *VerificationInvalidModel } VerificationInvalidModel struct { - To string + To string `json:"to"` } ) diff --git a/courier/template/email/verification_valid.go b/courier/template/email/verification_valid.go index 723ea618e071..9c088d144735 100644 --- a/courier/template/email/verification_valid.go +++ b/courier/template/email/verification_valid.go @@ -18,9 +18,9 @@ type ( m *VerificationValidModel } VerificationValidModel struct { - To string - VerificationURL string - Identity map[string]interface{} + To string `json:"to"` + VerificationURL string `json:"verification_url"` + Identity map[string]interface{} `json:"identity"` } ) diff --git a/courier/template/sms/login_code_valid.go b/courier/template/sms/login_code_valid.go index 194e113e6c6b..2f56aee885a7 100644 --- a/courier/template/sms/login_code_valid.go +++ b/courier/template/sms/login_code_valid.go @@ -17,9 +17,9 @@ type ( model *LoginCodeValidModel } LoginCodeValidModel struct { - To string - LoginCode string - Identity map[string]interface{} + To string `json:"to"` + LoginCode string `json:"login_code"` + Identity map[string]interface{} `json:"identity"` } ) diff --git a/courier/template/sms/stub.go b/courier/template/sms/stub.go index 0d68db1b209b..b75f541e462e 100644 --- a/courier/template/sms/stub.go +++ b/courier/template/sms/stub.go @@ -18,9 +18,9 @@ type ( } TestStubModel struct { - To string - Body string - Identity map[string]interface{} + To string `json:"to"` + Body string `json:"body"` + Identity map[string]interface{} `json:"identity"` } ) diff --git a/courier/template/sms/verification_code.go b/courier/template/sms/verification_code.go index f4ab6fc23359..a4d19e3d4a7d 100644 --- a/courier/template/sms/verification_code.go +++ b/courier/template/sms/verification_code.go @@ -18,9 +18,9 @@ type ( } VerificationCodeValidModel struct { - To string - VerificationCode string - Identity map[string]interface{} + To string `json:"to"` + VerificationCode string `json:"verification_code"` + Identity map[string]interface{} `json:"identity"` } ) diff --git a/embedx/config.schema.json b/embedx/config.schema.json index 930e7b34e95c..a836c21a7af5 100644 --- a/embedx/config.schema.json +++ b/embedx/config.schema.json @@ -150,7 +150,7 @@ "format": "uri", "pattern": "^(http|https|file|base64)://", "description": "URI pointing to the jsonnet template used for payload generation. Only used for those HTTP methods, which support HTTP body payloads", - "default": "base64://ZnVuY3Rpb24oY3R4KSB7CiAgcmVjaXBpZW50OiBjdHguUmVjaXBpZW50LAogIHRlbXBsYXRlX3R5cGU6IGN0eC5UZW1wbGF0ZVR5cGUsCiAgdG86IGlmICJUZW1wbGF0ZURhdGEiIGluIGN0eCAmJiAiVG8iIGluIGN0eC5UZW1wbGF0ZURhdGEgdGhlbiBjdHguVGVtcGxhdGVEYXRhLlRvIGVsc2UgbnVsbCwKICByZWNvdmVyeV9jb2RlOiBpZiAi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LnRlbXBsYXRlX2RhdGEgdGhlbiBjdHgudGVtcGxhdGVfZGF0YS5yZWNvdmVyeV9jb2RlIGVsc2UgbnVsbCwKICByZWNvdmVyeV91cmw6IGlmICJ0ZW1wbGF0ZV9kYXRhIiBpbiBjdHggJiYgInJlY292ZXJ5X3VybCIgaW4gY3R4LnRlbXBsYXRlX2RhdGEgdGhlbiBjdHgudGVtcGxhdGVfZGF0YS5yZWNvdmVyeV91cmwgZWxzZSBudWxsLAogIHZlcmlmaWNhdGlvbl91cmw6IGlmICJ0ZW1wbGF0ZV9kYXRhIiBpbiBjdHggJiYgInZlcmlmaWNhdGlvbl91cmwiIGluIGN0eC50ZW1wbGF0ZV9kYXRhIHRoZW4gY3R4LnRlbXBsYXRlX2RhdGEudmVyaWZpY2F0aW9uX3VybCBlbHNlIG51bGwsCiAgdmVyaWZpY2F0aW9uX2NvZGU6IGlmICJ0ZW1wbGF0ZV9kYXRhIiBpbiBjdHggJiYgInZlcmlmaWNhdGlvbl9jb2RlIiBpbiBjdHgudGVtcGxhdGVfZGF0YSB0aGVuIGN0eC50ZW1wbGF0ZV9kYXRhLnZlcmlmaWNhdGlvbl9jb2RlIGVsc2UgbnVsbCwKICBzdWJqZWN0OiBjdHguc3ViamVjdCwKICBib2R5OiBjdHguYm9keQp9Cg==", "examples": [ "file:///path/to/body.jsonnet", "file://./body.jsonnet", diff --git a/internal/client-go/go.sum b/internal/client-go/go.sum index c966c8ddfd0d..6cc3f5911d11 100644 --- a/internal/client-go/go.sum +++ b/internal/client-go/go.sum @@ -4,6 +4,7 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/request/builder_test.go b/request/builder_test.go index 8269b5133346..3b443dd2ce29 100644 --- a/request/builder_test.go +++ b/request/builder_test.go @@ -22,9 +22,9 @@ import ( ) type testRequestBody struct { - To string - From string - Body string + To string `json:"to"` + From string `json:"from"` + Body string `json:"body"` } //go:embed stub/test_body.jsonnet @@ -53,7 +53,7 @@ func TestBuildRequest(t *testing.T) { From: "+12288534869", Body: "test-sms-body", }, - expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+12288534869\",\n \"To\": \"+15056445993\"\n}\n", + expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+12288534869\",\n \"to\": \"+15056445993\"\n}\n", rawConfig: `{ "url": "https://test.kratos.ory.sh/my_endpoint1", "method": "POST", @@ -70,7 +70,7 @@ func TestBuildRequest(t *testing.T) { From: "+12288534869", Body: "test-sms-body", }, - expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+12288534869\",\n \"To\": \"+15056445993\"\n}\n", + expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+12288534869\",\n \"to\": \"+15056445993\"\n}\n", rawConfig: `{ "url": "https://test.kratos.ory.sh/my_endpoint1", "method": "POST", @@ -87,7 +87,7 @@ func TestBuildRequest(t *testing.T) { From: "+12288534869", Body: "test-sms-body", }, - expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+12288534869\",\n \"To\": \"+15056445993\"\n}\n", + expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+12288534869\",\n \"to\": \"+15056445993\"\n}\n", rawConfig: fmt.Sprintf( `{ "url": "https://test.kratos.ory.sh/my_endpoint1", @@ -108,7 +108,7 @@ func TestBuildRequest(t *testing.T) { From: "+15822228108", Body: "test-sms-body", }, - expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+15822228108\",\n \"To\": \"+12127110378\"\n}\n", + expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+15822228108\",\n \"to\": \"+12127110378\"\n}\n", rawConfig: `{ "url": "https://test.kratos.ory.sh/my_endpoint2", "method": "POST", @@ -129,7 +129,7 @@ func TestBuildRequest(t *testing.T) { From: "+13104661805", Body: "test-sms-body", }, - expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+13104661805\",\n \"To\": \"+14134242223\"\n}\n", + expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+13104661805\",\n \"to\": \"+14134242223\"\n}\n", rawConfig: `{ "url": "https://test.kratos.ory.sh/my_endpoint3", "method": "GET", @@ -171,7 +171,7 @@ func TestBuildRequest(t *testing.T) { From: "+14253787846", Body: "test-sms-body", }, - expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+14253787846\",\n \"To\": \"+12235499085\"\n}\n", + expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+14253787846\",\n \"to\": \"+12235499085\"\n}\n", rawConfig: `{ "url": "https://test.kratos.ory.sh/my_endpoint5", "method": "DELETE", @@ -198,7 +198,7 @@ func TestBuildRequest(t *testing.T) { From: "+13104661805", Body: "test-sms-body", }, - expectedBody: "Body=test-sms-body&From=%2B13104661805&To=%2B14134242223", + expectedBody: "body=test-sms-body&from=%2B13104661805&to=%2B14134242223", rawConfig: `{ "url": "https://test.kratos.ory.sh/my_endpoint6", "method": "POST", @@ -228,7 +228,7 @@ func TestBuildRequest(t *testing.T) { From: "+13104661805", Body: "test-sms-body", }, - expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+13104661805\",\n \"To\": \"+14134242223\"\n}\n", + expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+13104661805\",\n \"to\": \"+14134242223\"\n}\n", rawConfig: `{ "url": "https://test.kratos.ory.sh/my_endpoint7", "method": "POST", diff --git a/request/stub/test_body.jsonnet b/request/stub/test_body.jsonnet index 03edc83a65e2..63f5ec813f26 100644 --- a/request/stub/test_body.jsonnet +++ b/request/stub/test_body.jsonnet @@ -1,5 +1,5 @@ function(ctx) { - From: ctx.From, - To: ctx.To, - Body: ctx.Body, + from: ctx.from, + to: ctx.to, + body: ctx.body, }