Skip to content
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

Update Googlesheets doc for end users #67

Merged
merged 2 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 45 additions & 48 deletions docs/targets/googlesheets.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
# Google spreadsheets Target
# Event target for Google Sheets

## Using the sink adapter
This event target receives [CloudEvents][ce] over HTTP and appends the event payload to a GoogleSheets sheet.

|ENV name |Required |Default|Description|
|-------------------------------|:---------:|-------| ----------|
|[General ENV](../README.md) | | | ENV variables that is common for every target |
|GOOGLE_CREDENTIALS_JSON | YES | | JSON string with credentials of Service Account |
|MAX_SHEET_ROW | NO | 100 | Number of rows that will be appended to sheet before creating new one|
|GOOGLE_SPREADSHEET_ID | YES | | id of Spreadsheet where cloudevent data should be saved|
## Prerequisites

- `GOOGLE_SPREADSHEET_ID` is a unique identifier that can be retrieved from the URL path or parameters:
- from path: `https://docs.google.com/spreadsheets/d/<SHEET_ID>/edit`
- from query string: `https://docs.google.com/spreadsheet/ccc?key=<SHEET_ID>`

To get `GOOGLE_CREDENTIALS` json:
1. Google API Credentials
1. GoogleSheets Sheet id
cab105 marked this conversation as resolved.
Show resolved Hide resolved

1. Head to [Google Developers Console](https://console.developers.google.com/apis/dashboard) and create a new
### Google API Credentials

1. Head to [Google Developers Console][google-dashboard] and create a new
project (or select the one you have.)
2. Under “**APIs & Services > Library**”, search for “**Sheets API**” and enable it.
3. Go to “**APIs & Services > Credentials**” and choose “**Create credentials > Service account**”. (No extra roles nor
Expand All @@ -27,51 +21,54 @@ Google Spreadsheets you want the Target to have access to. (when sharing Notific

Create a new Google Sheet and share it with the 'client_email' address found in the JSON key. (when sharing the "Send Notifications" mark should be disabled)

## Message format
### GoogleSheet ID

Navigate to the sheet that is to be used or was just created:
- from path: `https://docs.google.com/spreadsheets/d/<SHEET_ID>/edit`
- from query string: `https://docs.google.com/spreadsheet/ccc?key=<SHEET_ID>`


## Deploying an Instance of the Target

Open the Bridge creation screen and add a Target of type `GoogleSheets`.

![Adding a GoogleSheets Target](../images/googlesheets-target/create-bridge-1.png)

In the Target creation form, provide a name to the event Target, and add the following information:

* **Google Service Account Secret**: Reference to a [TriggerMesh secret][tm-secret] containing a Google API key as described in the previous section.
* **ID**: The GoogleSheets Sheet ID to send the event payload.
* **Default Prefix**: A string used during new sheet creation when the event does not provide one.

Google Spreadsheets Target expect to received Cloud Events with a JSON payload that includes these fields:
![GoogleSheets Target form](../images/googlesheets-target/create-bridge-2.png)

- `sheet_name_prefix` will be set to the prefix for individual sheets adding a suffix number.
The Target will write entries to each sheet and once `MAX_SHEET_ROW` is reached, the suffix number
will be increased, and a new sheet will be created and written to.
- `row`
After clicking the `Save` button, the console will self-navigate to the Bridge editor. Proceed by adding the remaining components to the Bridge.

```json
{
"sheet_name_prefix": "Employees",
"row": [{"column": "Name", "value": "Alex"}, {"column": "Experience", "value": "2"}, {"column": "Stack", "value": "Backend"}]
}
```
![Bridge overview](../images/googlesheets-target/create-bridge-3.png)

Example:
After submitting the bridge, and allowing some configuration time, a green check mark on the main _Bridges_ page indicates that the bridge with a GoogleSheets event Target was successfully created.

```sh
curl -v "10.1.52.153:8080" \
-X POST \
-H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
-H "Ce-Specversion: 1.0" \
-H "Ce-Type: dev.knative.helloworld" \
-H "Ce-Source: dev.knative/helloworldsource" \
-H "Content-Type: application/json" \
-d '{"sheet_name_prefix": "Employees", "row": [{"column": "Name", "value": "Alex"}, {"column": "Experience", "value": "2"}, {"column": "Stack", "value": "Backend"}]}'
```
![Bridge status](../images/bridge-status-green.png)

## Event Types

## Deploying The Google Spreadsheet Target To a Kubernetes cluster
The GoogleSheets target will accept any event type, and by default, will stringify
the [CloudEvent][ce] and save the data in a new row.

### io.triggermesh.googlesheet.append

1. In the 'samples' folder you will need to:
* Update the '100-secret.yaml' file with a valid Google JSON credential string.
* Update the '200-target.yaml' file 'googleSpreadsheetID' field with a valid Google sheet ID.
Events of this type contain nuanced data that is used to append the event data to a new row.

2. From the root of the project directory execute the following commands:
This type expects a [JSON][ce-jsonformat] payload with the following properties:

```shell
ko apply -f config/
kubectl apply -f samples/
```
| Name | Type | Comment |
|---|---|---|
| **sheet_name_prefix** | string | The prefix to be used for creating new sheets |
| **message** | string | A string to append to the sheet row |

3. If everything worked sucessfully a new namespace "triggermesh-knative-targets" should be now be created with a Googlesheets adapter and controller pod active and ready!

***Note: currently all services are deployed to the 'triggermesh-knative-targets' namespace. If you would like to deploy to another namespace the 'namespace' value in all the .yaml files found in both 'samples/' and 'config/' will need to be updated with the desired namespace***
[ce]: https://cloudevents.io/
[ce-jsonformat]: https://github.com/cloudevents/spec/blob/v1.0/json-format.md
[tm-secret]:https://docs.triggermesh.io/guides/secrets/

[google-dashboard]: https://console.developers.google.com/apis/dashboard
2 changes: 1 addition & 1 deletion docs/targets/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The following is a list of Triggermesh event destinations known as `Targets`. So
<!-- * [Confluent](./confluent.md): Forward events to Confluent Kafka. -->
* [Datadog](./datadog.md): Forward event payload to Datadog.
* [Elasticsearch](./elasticsearch.md): Send events to Elasticsarch to be indexed.
<!-- * [Googlesheets](./googlesheets.md): Send events to a GoogleSheets. -->
* [Google Sheets](./googlesheets.md): Appends events to a Google Sheet row.
* [Hasura](./hasura.md): Send GraphQL queries to Hasura.
* [Oracle](./oracle.md): Forward events to the Oracle Cloud.
* [Slack](./slack.md): Forward events to Slack as messages to deliver immediately, scheduled, or as an update to a pre-existing message.
Expand Down