Skip to content

Commit

Permalink
feat(docs): Add doc generation to element template generator (hackday…
Browse files Browse the repository at this point in the history
…s) (#3067)

* feat(docs): Enhance the element template generator with docs generation support. (Prototype)

* feat(docs): Add maven plugin support

* feat(docs): Enhance the element template generator with docs generation support. (Prototype)

* chore(example): Support an easy way of creating data examples with FEEL expression support

* chore(format): Format code

* chore(license): Add missing license headers

* chore(code): Fix interface

* chore(code): Fix test

* chore(code): Use maven project base dir.

* chore(format): Format

* chore(format): Refine secret rendering.

* chore(format): Refine secret rendering.

* chore(json): Sort json keys

* chore(format): Format code
  • Loading branch information
sbuettner authored Sep 10, 2024
1 parent 92df6e6 commit 70390e5
Show file tree
Hide file tree
Showing 38 changed files with 1,056 additions and 18 deletions.
14 changes: 14 additions & 0 deletions connectors/CONNECTOR_README_LAYOUT.peb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
![{{name}} connector icon]({{icon}})
# {{name}}

{{ description }}

{% block content %}Connector docs content{% endblock %}

{% block footer %}
| Connector Info | |
| --- | --- |
| Type | {{ type }} |
| Version | {{ version }} |
| Supported element types | {% for elementType in elementTypes %}{{ elementType }}{% endfor %} |
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@
*/
package io.camunda.connector.http.base.model;

import io.camunda.connector.generator.java.annotation.DataExample;
import java.util.Map;

public record HttpCommonResult(
int status, Map<String, Object> headers, Object body, String reason) {

public HttpCommonResult(int status, Map<String, Object> headers, Object body) {
this(status, headers, body, null);
}

@DataExample(id = "basic", feel = "= body.order.id")
public static HttpCommonResult exampleResult() {
Map<String, Object> headers = Map.of("Content-Type", "application/json");
var body = Map.of("order", Map.of("id", "123", "total", "100.00€"));
return new HttpCommonResult(200, headers, body);
}
}
44 changes: 44 additions & 0 deletions connectors/http/rest/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
![REST Outbound Connector connector icon](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgiIGhlaWdodD0iMTgiIHZpZ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Dk1OUMxMC45MjgyIDUuMjcxMTMgMTAuNDU1OCA1LjEzMTkgOS44MDkzNiA1LjEzMTlIOC4xMDg3NEw3LjQ5NzExIDguNTkyODFaIiBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4K)
# REST Outbound Connector
Invoke REST API
# Camunda HTTP JSON Connector

Find the user documentation in our [Camunda](https://docs.camunda.io/docs/components/integration-framework/connectors/out-of-the-box-connectors/rest/).
Expand Down Expand Up @@ -190,3 +193,44 @@ Additional Connector templates based on the HTTP JSON Connector:
- [Automation Anywhere Connector](../automation-anywhere)
- [Blue Prism Connector](../blue-prism)
- [UiPath Connector](../uipath)


## Properties
| Name | Type | Required | Description | Example |
| ------ | -------- | -------- | ----------- | -------------- |
| Method | Dropdown | Yes | | ```{ }``` |
| URL | String | Yes | | ```"string"``` |
## Result
The following json structure will be returned by the Connector and can be
used in the result expression.

```json
{
"body" : {
"order" : {
"id" : "123",
"total" : "100.00€"
}
},
"headers" : {
"Content-Type" : "application/json"
},
"status" : 200
}
```

The body can be accessed via FEEL:
```json
= body.order.id
```
leading to the following result
```json
"123"
```


| Connector Info | |
| --- | --- |
| Type | io.camunda:http-json:1 |
| Version | 8 |
| Supported element types | |
221 changes: 221 additions & 0 deletions connectors/http/rest/README.peb
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
{% extends "../../CONNECTOR_README_LAYOUT.peb" %}

{% block content %}
# Camunda HTTP JSON Connector

Find the user documentation in our [Camunda](https://docs.camunda.io/docs/components/integration-framework/connectors/out-of-the-box-connectors/rest/).

## Build

```bash
mvn clean package
```

## API

### Input

```json
{
"method": "post",
"url": "https://httpbin.org/anything",
"queryParameters": {
"q": "test",
"priority": 12
},
"headers": {
"User-Agent": "http-connector-demo"
},
"body": {
"customer": {
"id": 1231231,
"name": "Jane Doe",
"email": "[email protected]"
}
}
}
```

### Output

The response will contain the status code, the headers and the body of the response of the HTTP service.

```json
{
"body": {
"args": {
"priority": "12",
"q": "test"
},
"data": "{\"customer\":{\"id\":1231231.0,\"name\":\"Jane Doe\",\"email\":\"[email protected]\"}}",
"files": {},
"form": {},
"headers": {
"Accept-Encoding": "gzip",
"Content-Length": "77",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "http-connector-demo Google-HTTP-Java-Client/1.41.4 (gzip)",
"X-Amzn-Trace-Id": "Root=1-623105a8-35f88bac0c7f1dcf0d2c8aa2"
},
"json": {
"customer": {
"email": "[email protected]",
"id": 1231231.0,
"name": "Jane Doe"
}
},
"method": "POST",
"origin": "79.202.43.240",
"url": "https://httpbin.org/anything?q=test&priority=12"
},
"headers": {
"access-control-allow-credentials": "true",
"access-control-allow-origin": "*",
"connection": "keep-alive",
"content-length": 733,
"content-type": "application/json",
"date": "Tue, 15 Mar 2022 21:31:20 GMT",
"server": "gunicorn/19.9.0"
},
"status": 200
}
```

### Input (Basic)

```json
{
"method": "get",
"url": "https://httpbin.org/basic-auth/user/password",
"authentication": {
"type": "basic",
"username": "{{ "{{secrets.USERNAME}}" }}",
"password": "{{ "{{secrets.PASSWORD}}" }}"
}
}
```

### Output (Bearer Token)

```json
{
"method": "get",
"url": "https://httpbin.org/bearer",
"authentication": {
"type": "bearer",
"token": "{{ "{{secrets.TOKEN}}" }}"
}
}
```

### Input (OAuth 2.0)

```json
{
"method": "post",
"url": "https://youroauthclientdomainname.eu.auth0.com/oauth/token",
"authentication": {
"oauthTokenEndpoint":"{{ "{{secrets.OAUTH_TOKEN_ENDPOINT_KEY}}" }}",
"scopes": "read:clients read:users",
"audience":"{{ "{{secrets.AUDIENCE_KEY}}" }}",
"clientId":"{{ "{{secrets.CLIENT_ID_KEY}}" }}",
"clientSecret":"{{ "{{secrets.CLIENT_SECRET_KEY}}" }}",
"type": "oauth-client-credentials-flow",
"clientAuthentication":"{{ "{{secrets.CLIENT_AUTHENTICATION_KEY}}" }}"
}
}
```

### Output (Access Token)

```json
{
"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlUtN2N6WG1sMzljUFNfUnlQQkNMWCJ9.kjhwfjkhfejkrhfbwjkfbhetcetc",
"scope":"read:clients create:users",
"expires_in":86400,
"token_type":"Bearer"
}
```
### Error codes

The Connector will fail on any non-2XX HTTP status code in the response. This error status code will be passed on as error code, e.g. "404".

## :lock: Use proxy-mechanism

> :warning: Proxy mode is currently only supported in Camunda 8 SaaS environment.

You can configure the HTTP JSON Connector to do any outgoing HTTP call via a proxy. This proxy should be effectively also an HTTP JSON Connector
running in a different environment.

For example, you can build the following runtime architecture:

```
Camunda Process --> HTTP Connector (Proxy-mode) --> HTTP Connector --> Endpoint
[ Camunda Network, e.g. K8S ] [ Separate network, e.g. Google Function ]
```

Now, any call via the Http Connector will be just forwarded to a specified hardcoded URL. And this proxy does the real call then.
This avoids that you could reach internal endpoints in your Camunda network (e.g. the current Kubernetes cluster).

Just set the following property to enable proxy mode for the connector, e.g. in application.properties when using the Spring-based runtime:

```properties
camunda.connector.http.proxy.url=https://someUrl/
```

You can also set this via environment variables:

```
CAMUNDA_CONNECTOR_HTTP_PROXY_URL=https://someUrl/
```

If the other party requiring OAuth for authentication, you need to set the following environment property:

```shell
GOOGLE_APPLICATION_CREDENTIALS=...
```

### :lock: Test the Connector locally with Google Cloud Function as a proxy

Run the [:lock:connector-proxy-saas](https://github.com/camunda/connector-proxy-saas) project locally as described in its [:lock:README](https://github.com/camunda/connector-proxy-saas#usage).

Set the specific property or environment variable to enable proxy mode as described above.

## Element Template

This Connector is a **Protocol Connector**. It is used by multiple out-of-the-box Connector templates.

The generic HTTP JSON Connector element template can be found in
the [element-templates/http-json-connector.json](element-templates/http-json-connector.json) file.

Additional Connector templates based on the HTTP JSON Connector:
- [Automation Anywhere Connector](../automation-anywhere)
- [Blue Prism Connector](../blue-prism)
- [UiPath Connector](../uipath)


## Properties
{{ props([properties["method"],properties["url"]]) }}

## Result
The following json structure will be returned by the Connector and can be
used in the result expression.

```json
{{ exampleData["basic"].json }}

```

The body can be accessed via FEEL:
```json
{{ exampleData["basic"].feel }}

```
leading to the following result
```json
{{ exampleData["basic"].feelResultJson }}

```

{% endblock %}
2 changes: 2 additions & 0 deletions connectors/http/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ limitations under the License.</license.inlineheader>
<file>
<templateId>io.camunda.connectors.HttpJson.v2</templateId>
<templateFileName>http-json-connector.json</templateFileName>
<docTemplatePath>README.peb</docTemplatePath>
<docOutputPath>README.md</docOutputPath>
</file>
</files>
<generateHybridTemplates>true</generateHybridTemplates>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.camunda.connector.generator.java.annotation.ElementTemplate;
import io.camunda.connector.generator.java.annotation.ElementTemplate.PropertyGroup;
import io.camunda.connector.http.base.HttpService;
import io.camunda.connector.http.base.model.HttpCommonResult;
import io.camunda.connector.http.rest.model.HttpJsonRequest;

@OutboundConnector(
Expand All @@ -43,6 +44,7 @@
name = "REST Outbound Connector",
description = "Invoke REST API",
inputDataClass = HttpJsonRequest.class,
outputDataClass = HttpCommonResult.class,
version = 8,
propertyGroups = {
@PropertyGroup(id = "authentication", label = "Authentication"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.camunda.connector.jdbc.model.client.JdbcClient;
import io.camunda.connector.jdbc.model.client.JdbiJdbcClient;
import io.camunda.connector.jdbc.model.request.JdbcRequest;
import io.camunda.connector.jdbc.model.response.JdbcResponse;

@OutboundConnector(
name = "SQL Database Connector",
Expand All @@ -32,7 +33,8 @@
@ElementTemplate.PropertyGroup(id = JdbcFunction.CONNECTION_GROUP_ID, label = "Connection"),
@ElementTemplate.PropertyGroup(id = JdbcFunction.QUERY_GROUP_ID, label = "Query"),
},
inputDataClass = JdbcRequest.class)
inputDataClass = JdbcRequest.class,
outputDataClass = JdbcResponse.class)
public class JdbcFunction implements OutboundConnectorFunction {
static final String DATABASE_GROUP_ID = "database";
static final String CONNECTION_GROUP_ID = "connection";
Expand Down
Loading

0 comments on commit 70390e5

Please sign in to comment.