Skip to content

Commit 6a181ef

Browse files
New Components - influxdb_cloud (#16469)
* new components * Update components/influxdb_cloud/actions/update-bucket/update-bucket.mjs Co-authored-by: Luan Cazarine <luanhc@gmail.com> --------- Co-authored-by: Luan Cazarine <luanhc@gmail.com>
1 parent 159d440 commit 6a181ef

File tree

10 files changed

+478
-5
lines changed

10 files changed

+478
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import influxDbCloud from "../../influxdb_cloud.app.mjs";
2+
import { parseObjectEntries } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "influxdb_cloud-invoke-script",
6+
name: "Invoke Script",
7+
description: "Runs a script and returns the result. [See the documentation](https://docs.influxdata.com/influxdb3/cloud-serverless/api/v2/#operation/PostScriptsIDInvoke)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
influxDbCloud,
12+
scriptId: {
13+
propDefinition: [
14+
influxDbCloud,
15+
"scriptId",
16+
],
17+
},
18+
params: {
19+
type: "object",
20+
label: "Params",
21+
description: "The script parameters. params contains key-value pairs that map values to the params.keys in a script. When you invoke a script with params, InfluxDB passes the values as invocation parameters to the script.",
22+
optional: true,
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.influxDbCloud.invokeScript({
27+
$,
28+
scriptId: this.scriptId,
29+
data: {
30+
params: this.params
31+
? parseObjectEntries(this.params)
32+
: {},
33+
},
34+
});
35+
$.export("$summary", `Successfully invoked script with ID: ${this.scriptId}`);
36+
return response;
37+
},
38+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import influxDbCloud from "../../influxdb_cloud.app.mjs";
2+
3+
export default {
4+
key: "influxdb_cloud-update-bucket",
5+
name: "Update Bucket",
6+
description: "Updates an existing bucket in InfluxDB Cloud. [See the documentation](https://docs.influxdata.com/influxdb3/cloud-serverless/api/v2/#operation/PatchBucketsID)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
influxDbCloud,
11+
bucketId: {
12+
propDefinition: [
13+
influxDbCloud,
14+
"bucketId",
15+
],
16+
},
17+
name: {
18+
type: "string",
19+
label: "Name",
20+
description: "Name of the bucket. Must contain two or more characters. Cannot start with an underscore (_). Cannot contain a double quote (\"). Note: System buckets cannot be renamed.",
21+
optional: true,
22+
},
23+
description: {
24+
type: "string",
25+
label: "Description",
26+
description: "A description of the bucket",
27+
optional: true,
28+
},
29+
everySeconds: {
30+
type: "integer",
31+
label: "Every Seconds",
32+
description: "The duration in seconds for how long data will be kept in the database. The default duration is 2592000 (30 days). 0 represents infinite retention.",
33+
default: 2592000,
34+
optional: true,
35+
},
36+
shardGroupDurationSeconds: {
37+
type: "integer",
38+
label: "Shard Group Duration Seconds",
39+
description: "The shard group duration. The duration or interval (in seconds) that each shard group covers.",
40+
optional: true,
41+
},
42+
},
43+
async run({ $ }) {
44+
const response = await this.influxDbCloud.updateBucket({
45+
$,
46+
bucketId: this.bucketId,
47+
data: {
48+
name: this.name,
49+
description: this.description,
50+
retentionRules: [
51+
{
52+
everySeconds: this.everySeconds,
53+
shardGroupDurationSeconds: this.shardGroupDurationSeconds,
54+
type: "expire",
55+
},
56+
],
57+
},
58+
});
59+
$.export("$summary", `Successfully updated bucket with ID: ${response.id}`);
60+
return response;
61+
},
62+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import influxDbCloud from "../../influxdb_cloud.app.mjs";
2+
3+
export default {
4+
key: "influxdb_cloud-write-data",
5+
name: "Write Data",
6+
description: "Write data to a specific bucket in InfluxDB Cloud. [See the documentation](https://docs.influxdata.com/influxdb3/cloud-serverless/api/v2/#operation/PostWrite)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
influxDbCloud,
11+
bucketId: {
12+
propDefinition: [
13+
influxDbCloud,
14+
"bucketId",
15+
],
16+
},
17+
data: {
18+
type: "string",
19+
label: "Data",
20+
description: "Provide data in [line protocol format](https://docs.influxdata.com/influxdb3/cloud-serverless/reference/syntax/line-protocol/). Example: `measurementName fieldKey=\"field string value\" 1795523542833000000`",
21+
},
22+
precision: {
23+
type: "string",
24+
label: "Precision",
25+
description: "The precision for unix timestamps in the line protocol batch",
26+
options: [
27+
"ms",
28+
"s",
29+
"us",
30+
"ns",
31+
],
32+
optional: true,
33+
},
34+
},
35+
async run({ $ }) {
36+
const response = await this.influxDbCloud.writeData({
37+
$,
38+
params: {
39+
bucket: this.bucketId,
40+
precision: this.precision,
41+
},
42+
data: this.data,
43+
headers: {
44+
"Content-Type": "text/plain",
45+
},
46+
});
47+
$.export("$summary", "Successfully wrote data to bucket");
48+
return response;
49+
},
50+
};
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function optionalParseAsJSON(value) {
2+
try {
3+
return JSON.parse(value);
4+
} catch (e) {
5+
return value;
6+
}
7+
}
8+
9+
export function parseObjectEntries(value) {
10+
const obj = typeof value === "string"
11+
? JSON.parse(value)
12+
: value;
13+
return Object.fromEntries(
14+
Object.entries(obj).map(([
15+
key,
16+
value,
17+
]) => [
18+
key,
19+
optionalParseAsJSON(value),
20+
]),
21+
);
22+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,151 @@
1+
import { axios } from "@pipedream/platform";
2+
const LIMIT = 50;
3+
14
export default {
25
type: "app",
36
app: "influxdb_cloud",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
bucketId: {
9+
type: "string",
10+
label: "Bucket ID",
11+
description: "The identifier of a bucket",
12+
async options({ page }) {
13+
const { buckets } = await this.listBuckets({
14+
params: {
15+
limit: LIMIT,
16+
offset: page * LIMIT,
17+
},
18+
});
19+
return buckets?.map(({
20+
id: value, name: label,
21+
}) => ({
22+
label,
23+
value,
24+
})) || [];
25+
},
26+
},
27+
scriptId: {
28+
type: "string",
29+
label: "Script ID",
30+
description: "The identifier of a script",
31+
async options({ page }) {
32+
const { scripts } = await this.listScripts({
33+
params: {
34+
limit: LIMIT,
35+
offset: page * LIMIT,
36+
},
37+
});
38+
return scripts?.map(({
39+
id: value, name: label,
40+
}) => ({
41+
label,
42+
value,
43+
})) || [];
44+
},
45+
},
46+
},
547
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
48+
_baseUrl(version) {
49+
let { url } = this.$auth;
50+
if (version === "v2") {
51+
url += (url.endsWith("/")
52+
? ""
53+
: "/") + "api/v2";
54+
} else {
55+
url = url.endsWith("/")
56+
? url.slice(0, -1)
57+
: url;
58+
}
59+
return url;
60+
},
61+
_makeRequest({
62+
$ = this,
63+
version = "v2",
64+
path,
65+
headers,
66+
...opts
67+
}) {
68+
return axios($, {
69+
url: `${this._baseUrl(version)}${path}`,
70+
headers: {
71+
"Authorization": `Token ${this.$auth.token}`,
72+
"Content-Type": "application/json",
73+
...headers,
74+
},
75+
...opts,
76+
});
77+
},
78+
listBuckets(opts = {}) {
79+
return this._makeRequest({
80+
path: "/buckets",
81+
...opts,
82+
});
83+
},
84+
listScripts(opts = {}) {
85+
return this._makeRequest({
86+
path: "/scripts",
87+
...opts,
88+
});
89+
},
90+
listTasks(opts = {}) {
91+
return this._makeRequest({
92+
path: "/tasks",
93+
...opts,
94+
});
95+
},
96+
updateBucket({
97+
bucketId, ...opts
98+
}) {
99+
return this._makeRequest({
100+
method: "PATCH",
101+
path: `/buckets/${bucketId}`,
102+
...opts,
103+
});
104+
},
105+
writeData(opts = {}) {
106+
return this._makeRequest({
107+
method: "POST",
108+
path: "/write",
109+
...opts,
110+
});
111+
},
112+
invokeScript({
113+
scriptId, ...opts
114+
}) {
115+
return this._makeRequest({
116+
method: "POST",
117+
path: `/scripts/${scriptId}/invoke`,
118+
...opts,
119+
});
120+
},
121+
async *paginate({
122+
fn,
123+
resourceKey,
124+
params,
125+
max,
126+
}) {
127+
params = {
128+
...params,
129+
limit: LIMIT,
130+
offset: 0,
131+
};
132+
let total, count = 0;
133+
do {
134+
const response = await fn({
135+
params,
136+
});
137+
const results = resourceKey
138+
? response[resourceKey]
139+
: response;
140+
for (const item of results) {
141+
yield item;
142+
if (max && ++count >= max) {
143+
return;
144+
}
145+
}
146+
total = results?.length;
147+
params.offset += params.limit;
148+
} while (total);
9149
},
10150
},
11151
};

components/influxdb_cloud/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/influxdb_cloud",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "Pipedream influxdb_cloud Components",
55
"main": "influxdb_cloud.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)