|
1 |
| -# Sendgrid event target for Knative Eventing |
2 |
| - |
3 |
| -This event target integrates with Sendgrid, using received Cloud Event messages to create E-mail messages. |
4 |
| - |
5 |
| -## Contents |
6 |
| - |
7 |
| -- [Sendgrid event target for Knative Eventing](#sendgrid-event-target-for-knative-eventing) |
8 |
| - - [Contents](#contents) |
9 |
| - - [Prerequisites](#prerequisites) |
10 |
| - - [Controller Deployment](#controller-deployment) |
11 |
| - - [From code](#from-code) |
12 |
| - - [Deploy From Image](#deploy-from-image) |
13 |
| - - [If you are not a ko user or just do not want to build and deploy from source you can also follow these steps to use one of our published images to deploy.](#if-you-are-not-a-ko-user-or-just-do-not-want-to-build-and-deploy-from-source-you-can-also-follow-these-steps-to-use-one-of-our-published-images-to-deploy) |
14 |
| - - [Creating a Sendgrid Target adapter.](#creating-a-sendgrid-target-adapter) |
15 |
| - - [Once the Sendgrid Target Controller has been deployed, and all other needed assets are present, we can create integrations by adding SendgridTargets objects.](#once-the-sendgrid-target-controller-has-been-deployed-and-all-other-needed-assets-are-present-we-can-create-integrations-by-adding-sendgridtargets-objects) |
16 |
| - - [Status](#status) |
17 |
| - - [Sendgrid Target as an event Sink](#sendgrid-target-as-an-event-sink) |
18 |
| - - [Once deployed, Sendgrid Target Adapters are addressable. This means you can use it as a Sink for Knative components! Below you can find an example.](#once-deployed-sendgrid-target-adapters-are-addressable-this-means-you-can-use-it-as-a-sink-for-knative-components-below-you-can-find-an-example) |
19 |
| - - [Talking to the Sendgrid Target](#talking-to-the-sendgrid-target) |
| 1 | +# Event Target for SendGrid |
20 | 2 |
|
21 |
| -## Prerequisites |
22 |
| - |
23 |
| -A Sendgrid account is required to run this target: |
24 |
| - |
25 |
| -* Register a Sendgrid account |
26 |
| -* Retrieve from Sendgrid an API token |
27 |
| - |
28 |
| - |
29 |
| -## Controller Deployment |
30 |
| - |
31 |
| -### From code |
32 |
| - |
33 |
| -You can use the [ko](https://github.com/google/ko) tool to compile and deploy from source |
34 |
| -by executing the following command from the root directory of the Sendgrid target folder. |
35 |
| - |
36 |
| -```console |
37 |
| -ko apply -f ./config |
38 |
| -``` |
39 |
| - |
40 |
| -OR |
41 |
| - |
42 |
| -### Deploy From Image |
43 |
| - |
44 |
| -##### If you are not a ko user or just do not want to build and deploy from source you can also follow these steps to use one of our published images to deploy. |
45 |
| - |
46 |
| -1. Navigate to the [config/](https://github.com/triggermesh/knative-targets/tree/Sendgrid-merge-fix/sendgrid/config) folder and open the '500-controller.yaml' file for editing. |
47 |
| - |
48 |
| -2. Replace line #37: |
49 |
| -``` |
50 |
| -image: ko://github.com/triggermesh/knative-targets/sendgrid/cmd/controller |
51 |
| -``` |
52 |
| -With: |
53 |
| -``` |
54 |
| -tmjeff/sendgridcontroller:latest |
55 |
| -``` |
| 3 | +This event target receives [CloudEvents][ce] and utilizes [SendGrid][sg] to enable the creation and delivery of Email messages via event-data and event-occurrence, respectively. |
56 | 4 |
|
57 |
| -3. Replace line #55 |
58 |
| -``` |
59 |
| -value: ko://github.com/triggermesh/knative-targets/sendgrid/cmd/adapter |
60 |
| -``` |
61 |
| -With: |
62 |
| -``` |
63 |
| -tmjeff/sendgridadapter:latest |
64 |
| -``` |
65 |
| - |
66 |
| -4. Now we can build and deploy by moving up one directory to the [sendgrid/](https://github.com/triggermesh/knative-targets/tree/Sendgrid-merge-fix/sendgrid) folder and executing the following: |
67 |
| - |
68 |
| -```shell |
69 |
| -kubectl apply -f config/ |
70 |
| -``` |
71 |
| - |
72 |
| - |
73 |
| -## Creating a Sendgrid Target adapter. |
74 |
| - |
75 |
| -##### Once the Sendgrid Target Controller has been deployed, and all other needed assets are present, we can create integrations by adding SendgridTargets objects. |
| 5 | +## Prerequisites |
76 | 6 |
|
77 |
| -1. Start by navigating to the [samples/](https://github.com/triggermesh/knative-targets/tree/Sendgrid-merge-fix/sendgrid/samples) folder, open the file named '100-secret.yaml', and update the 'apiKey' value with a valid Sendgrid API Key. |
| 7 | +* Register a [SendGrid account][sgSU] |
| 8 | +* Retrieve a [SendGrid API token][api] |
78 | 9 |
|
79 |
| -2. Next move on to the '200-target.yaml' file in the same folder. Here was can imput some *optional* default values. If you do not require default values and want to pass these values dynamically via parameters in the CE body, you may omit some or all of these by deleteing the lines and leaving only the 'apiKey' portion. |
| 10 | +## Deploying an Instance of the Target |
80 | 11 |
|
81 |
| - * A list of (optional) supported spec options: defaultFromEmail, defaultToEmail, defaultToName, defaultFromName, defaultMessage |
| 12 | +Open the Bridge creation screen and add a target of type `SendGrid`. |
82 | 13 |
|
83 |
| -3. Last file in the folder is ' 300-trigger.yaml' Here you can make modifications or leave it as is to subscribe to the default broker in the namespace you deploy. |
| 14 | + |
84 | 15 |
|
| 16 | +In the Target creation form, provide a name for the event Target, and add the following information: |
85 | 17 |
|
86 |
| -### Status |
| 18 | +* **Default sender name**: Define a default 'name' to be assigned in the `From:` section of the email to be created, if the received event does not contain a **FromName** property. |
| 19 | +* **Default sender email**: Define a default email address to be assigned in the `From:` section of the email to be created, if the received event does not contain a **FromEmail** property. |
| 20 | +* **Default recipient name**: Define a default name to be assigned in the `To:` section of the email to be created, if the received event does not contain a **FromEmail** property. |
| 21 | +* **Default recipient email**: Define a default 'email address' to be assigned in the `To:` section of the email to be created, if the received event does not contain a **ToEmail** property. |
| 22 | +* **Default subject**: Define a default subject to be assigned to the outgoing email to be created, if the received event does not contain a **subject** property. |
| 23 | +* **API Secret**: Reference to a [TriggerMesh secret][tm-secret] containing an [API token][api] for authenticating requests |
87 | 24 |
|
88 |
| -* The SendgridTarget requires only one Secret, the APIKey, to be provided. |
| 25 | +**Note:** If there is not a default value specified for all of the optional fields, the event received by that deployment *MUST* contain all of the information noted in the [Event Types](#event-types), save **Message**, or the Target **will** **fail** |
89 | 26 |
|
90 |
| -* Once its presences is confirmed, the Sendgrid Target Controller will create a Knative Service for the Adapter. |
| 27 | + |
91 | 28 |
|
92 |
| -* A Status summary is added to the SendgridTarget object informing of the all conditions that the target needs. |
| 29 | +After clicking the `Save` button, the console will self-navigate to the Bridge editor. Proceed by adding the remaining components to the Bridge. |
93 | 30 |
|
94 |
| -* When ready the `status.address.url` will point to the internal point where Cloud Events should be sent. |
| 31 | +After submitting the bridge, and allowing some configuration time, a green checkmark on the main _Bridges_ page indicates that the bridge with a SendGrid event Target was successfully created. |
95 | 32 |
|
96 |
| -### Sendgrid Target as an event Sink |
| 33 | + |
97 | 34 |
|
98 |
| -#### Once deployed, Sendgrid Target Adapters are addressable. This means you can use it as a Sink for Knative components! Below you can find an example. |
| 35 | +For more information about using SendGrid, please refer to the [SendGrid documentation][docs]. |
99 | 36 |
|
100 |
| -* The included example trigger ['300-trigger.yaml'](https://github.com/triggermesh/knative-targets/blob/Sendgrid-merge-fix/sendgrid/samples/300-trigger.yaml) Is as follows. |
| 37 | +### Event Types |
101 | 38 |
|
102 |
| -```yaml |
103 |
| -apiVersion: eventing.knative.dev/v1beta1 |
104 |
| -kind: Trigger |
105 |
| -metadata: |
106 |
| - name: sendgrid-sample-trigger |
107 |
| -spec: |
108 |
| - broker: default |
109 |
| - subscriber: |
110 |
| - ref: |
111 |
| - apiVersion: targets.triggermesh.io/v1alpha1 |
112 |
| - kind: SendgridTarget |
113 |
| - name: triggermesh-email |
114 |
| -``` |
| 39 | +Depending on how the target is to be used, defaults can be configured for all available parameters and the Target can accept arbitrary events. Or none of the defaults can be set and these parameters can be passed in at runtime via the event payload. |
115 | 40 |
|
116 |
| -* Once this, along with the other aformentioned requirements, have been deployed. It is now possible to implement something like the [awskinesis-sinkbinding.yaml](https://github.com/triggermesh/aws-event-sources/blob/master/config/samples/awskinesis-sinkbinding.yaml) example from the [aws-event-sources](https://github.com/triggermesh/aws-event-sources). |
| 41 | +The SendGrid event Target accepts a [JSON][ce-jsonformat] payload with the following properties that will overwrite their respective `spec` parameters. |
117 | 42 |
|
118 |
| -* By replacing the section starting at line [#18](https://github.com/triggermesh/aws-event-sources/blob/93df64d5b298cc73acfb93f835646cc1d06429c4/config/samples/awskinesis-sinkbinding.yaml#L18) with: |
| 43 | +| Name | Type | Comment | Required |
| 44 | +|---|---|---|---| |
| 45 | +| **FromName** | string | Sender's name |false | |
| 46 | +| **FromEmail** | string | Sender's email | false | |
| 47 | +| **ToName** | string | Recipient's name | false | |
| 48 | +| **ToEmail** | string | Recipient's email | false | |
| 49 | +| **Message** | string | Contents of the message body | false | |
| 50 | +| **Subject** | string | Assigns a subject to the email | false | |
119 | 51 |
|
120 |
| -``` |
121 |
| - sink: |
122 |
| - ref: |
123 |
| - apiVersion: targets.triggermesh.io/v1alpha1 |
124 |
| - kind: ConfluentTarget |
125 |
| - name: triggermesh-confluent |
126 |
| -``` |
| 52 | +When a **Message** property is **not** present, the entire cloud event is passed into the email `body` by default. |
127 | 53 |
|
128 |
| -* You can now deploy this .yaml file. This will complete the setup of the sinkbinding! |
| 54 | +**Note:** If there is not a default value specified for all of the optional fields, the event received by that deployment *MUST* contain all of the information noted in the [Event Types](#event-types), save **Message**, or the Target **will** **fail** |
129 | 55 |
|
130 |
| -*****Please note that to deploy the [awskinesis-sinkbinding.yaml](https://github.com/triggermesh/aws-event-sources/blob/master/config/samples/awskinesis-sinkbinding.yaml) example there are other resources that need to be deployed. Please see the [DEVELOPMENT.md](https://github.com/triggermesh/aws-event-sources/blob/master/DEVELOPMENT.md) doc hosted there for full details***** |
| 56 | +### Example |
131 | 57 |
|
| 58 | +An example email sent from the Sendgrid Target with the **Message** parameter omitted will look as follows: |
132 | 59 |
|
133 |
| -### Talking to the Sendgrid Target |
134 |
| -
|
135 |
| -* Depending on how you want to use the target. You can set up defaults for all the avalible paraments and pass absolutely nothing to have a static message sent to a defined user. Or you can pass in key:value params to dynamically set all of the variables. |
136 |
| -
|
137 |
| -An example of a Cloudevent being passed via a Curl command: |
| 60 | +```email |
| 61 | + |
| 62 | + |
| 63 | +date: Sep 12, 2020, 12:41 AM |
| 64 | +subject: Hello World |
138 | 65 |
|
| 66 | +Validation: valid Context Attributes, specversion: 1.0 type: dev.knative.samples.helloworld source: dev.knative.samples/helloworldsource id: 536808d3-88be-4077-9d7a-a3f162705f79 time: 2020-09-12T04:41:00.000610299Z datacontenttype: application/json Extensions, knativearrivaltime: 2020-09-12T04:41:00.006331845Z knativehistory: default-kne-trigger-kn-channel.midimansland.svc.cluster.local Data, { "event":"data"} |
139 | 67 | ```
|
140 |
| -curl -v "10.152.183.229" \ |
141 |
| - -X POST \ |
142 |
| - -H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \ |
143 |
| - -H "Ce-Specversion: 1.0" \ |
144 |
| - -H "Ce-Type: dev.knative.samples.helloworld" \ |
145 |
| - -H "Ce-Source: dev.knative.samples/helloworldsource" \ |
146 |
| - -H "Content-Type: application/json" \ |
147 |
| - -d '{"FromEmail":"[email protected].","ToEmail":"[email protected]", \ |
148 |
| - "FromName":"SendgridTarget","ToName":"endUser","Message":"hello"}' |
149 |
| -``` |
150 |
| - |
151 |
| -A list of possible keys: |
152 |
| -- message |
153 |
| -- fromname |
154 |
| -- fromemail |
155 |
| -- toname |
156 |
| -- toemail |
157 | 68 |
|
158 |
| -**If the "Message" key:value is omited. The body of the email will contain the entire cloud event** |
| 69 | +[sgSU]:https://signup.sendgrid.com/ |
| 70 | +[sg]:https://sendgrid.com/ |
| 71 | +[api]:https://sendgrid.com/docs/ui/account-and-settings/api-keys/ |
159 | 72 |
|
| 73 | +[ce]: https://cloudevents.io/ |
| 74 | +[ce-jsonformat]: https://github.com/cloudevents/spec/blob/v1.0/json-format.md |
| 75 | +[tm-secret]:https://docs.triggermesh.io/guides/secrets/ |
| 76 | +[docs]: https://sendgrid.com/docs/ |
0 commit comments