-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New Components - influxdb_cloud #16469
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
components/influxdb_cloud/actions/invoke-script/invoke-script.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import influxDbCloud from "../../influxdb_cloud.app.mjs"; | ||
import { parseObjectEntries } from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "influxdb_cloud-invoke-script", | ||
name: "Invoke Script", | ||
description: "Runs a script and returns the result. [See the documentation](https://docs.influxdata.com/influxdb3/cloud-serverless/api/v2/#operation/PostScriptsIDInvoke)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
influxDbCloud, | ||
scriptId: { | ||
propDefinition: [ | ||
influxDbCloud, | ||
"scriptId", | ||
], | ||
}, | ||
params: { | ||
type: "object", | ||
label: "Params", | ||
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.", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.influxDbCloud.invokeScript({ | ||
$, | ||
scriptId: this.scriptId, | ||
data: { | ||
params: this.params | ||
? parseObjectEntries(this.params) | ||
: {}, | ||
}, | ||
}); | ||
$.export("$summary", `Successfully invoked script with ID: ${this.scriptId}`); | ||
return response; | ||
}, | ||
}; |
62 changes: 62 additions & 0 deletions
62
components/influxdb_cloud/actions/update-bucket/update-bucket.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import influxDbCloud from "../../influxdb_cloud.app.mjs"; | ||
|
||
export default { | ||
key: "influxdb_cloud-update-bucket", | ||
name: "Update Bucket", | ||
description: "Updates an existing bucket in InfluxDB Cloud. [See the documentation](https://docs.influxdata.com/influxdb3/cloud-serverless/api/v2/#operation/PatchBucketsID)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
influxDbCloud, | ||
bucketId: { | ||
propDefinition: [ | ||
influxDbCloud, | ||
"bucketId", | ||
], | ||
}, | ||
name: { | ||
type: "string", | ||
label: "Name", | ||
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.", | ||
optional: true, | ||
}, | ||
description: { | ||
type: "string", | ||
label: "Description", | ||
description: "A description of the bucket", | ||
optional: true, | ||
}, | ||
everySeconds: { | ||
type: "integer", | ||
label: "Every Seconds", | ||
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.", | ||
default: 2592000, | ||
optional: true, | ||
}, | ||
shardGroupDurationSeconds: { | ||
type: "integer", | ||
label: "Shard Group Duration Seconds", | ||
description: "The shard group duration. The duration or interval (in seconds) that each shard group covers.", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.influxDbCloud.updateBucket({ | ||
$, | ||
bucketId: this.bucketId, | ||
data: { | ||
name: this.name, | ||
description: this.description, | ||
retentionRules: [ | ||
{ | ||
everySeconds: this.everySeconds, | ||
shardGroupDurationSeconds: this.shardGroupDurationSeconds, | ||
type: "expire", | ||
}, | ||
], | ||
}, | ||
}); | ||
$.export("$summary", `Successfully updated bucket with ID: ${response.id}`); | ||
return response; | ||
}, | ||
}; |
50 changes: 50 additions & 0 deletions
50
components/influxdb_cloud/actions/write-data/write-data.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import influxDbCloud from "../../influxdb_cloud.app.mjs"; | ||
|
||
export default { | ||
key: "influxdb_cloud-write-data", | ||
name: "Write Data", | ||
description: "Write data to a specific bucket in InfluxDB Cloud. [See the documentation](https://docs.influxdata.com/influxdb3/cloud-serverless/api/v2/#operation/PostWrite)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
influxDbCloud, | ||
bucketId: { | ||
propDefinition: [ | ||
influxDbCloud, | ||
"bucketId", | ||
], | ||
}, | ||
data: { | ||
type: "string", | ||
label: "Data", | ||
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`", | ||
}, | ||
precision: { | ||
type: "string", | ||
label: "Precision", | ||
description: "The precision for unix timestamps in the line protocol batch", | ||
options: [ | ||
"ms", | ||
"s", | ||
"us", | ||
"ns", | ||
], | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.influxDbCloud.writeData({ | ||
$, | ||
params: { | ||
bucket: this.bucketId, | ||
precision: this.precision, | ||
}, | ||
data: this.data, | ||
headers: { | ||
"Content-Type": "text/plain", | ||
}, | ||
}); | ||
$.export("$summary", "Successfully wrote data to bucket"); | ||
return response; | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function optionalParseAsJSON(value) { | ||
try { | ||
return JSON.parse(value); | ||
} catch (e) { | ||
return value; | ||
} | ||
} | ||
|
||
export function parseObjectEntries(value) { | ||
const obj = typeof value === "string" | ||
? JSON.parse(value) | ||
: value; | ||
return Object.fromEntries( | ||
Object.entries(obj).map(([ | ||
key, | ||
value, | ||
]) => [ | ||
key, | ||
optionalParseAsJSON(value), | ||
]), | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,151 @@ | ||
import { axios } from "@pipedream/platform"; | ||
const LIMIT = 50; | ||
|
||
export default { | ||
type: "app", | ||
app: "influxdb_cloud", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
bucketId: { | ||
type: "string", | ||
label: "Bucket ID", | ||
description: "The identifier of a bucket", | ||
async options({ page }) { | ||
const { buckets } = await this.listBuckets({ | ||
params: { | ||
limit: LIMIT, | ||
offset: page * LIMIT, | ||
}, | ||
}); | ||
return buckets?.map(({ | ||
id: value, name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})) || []; | ||
}, | ||
}, | ||
scriptId: { | ||
type: "string", | ||
label: "Script ID", | ||
description: "The identifier of a script", | ||
async options({ page }) { | ||
const { scripts } = await this.listScripts({ | ||
params: { | ||
limit: LIMIT, | ||
offset: page * LIMIT, | ||
}, | ||
}); | ||
return scripts?.map(({ | ||
id: value, name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})) || []; | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl(version) { | ||
let { url } = this.$auth; | ||
if (version === "v2") { | ||
url += (url.endsWith("/") | ||
? "" | ||
: "/") + "api/v2"; | ||
} else { | ||
url = url.endsWith("/") | ||
? url.slice(0, -1) | ||
: url; | ||
} | ||
return url; | ||
}, | ||
_makeRequest({ | ||
$ = this, | ||
version = "v2", | ||
path, | ||
headers, | ||
...opts | ||
}) { | ||
return axios($, { | ||
url: `${this._baseUrl(version)}${path}`, | ||
headers: { | ||
"Authorization": `Token ${this.$auth.token}`, | ||
"Content-Type": "application/json", | ||
...headers, | ||
}, | ||
...opts, | ||
}); | ||
}, | ||
listBuckets(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/buckets", | ||
...opts, | ||
}); | ||
}, | ||
listScripts(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/scripts", | ||
...opts, | ||
}); | ||
}, | ||
listTasks(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/tasks", | ||
...opts, | ||
}); | ||
}, | ||
updateBucket({ | ||
bucketId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "PATCH", | ||
path: `/buckets/${bucketId}`, | ||
...opts, | ||
}); | ||
}, | ||
writeData(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/write", | ||
...opts, | ||
}); | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
invokeScript({ | ||
scriptId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: `/scripts/${scriptId}/invoke`, | ||
...opts, | ||
}); | ||
}, | ||
async *paginate({ | ||
fn, | ||
resourceKey, | ||
params, | ||
max, | ||
}) { | ||
params = { | ||
...params, | ||
limit: LIMIT, | ||
offset: 0, | ||
}; | ||
let total, count = 0; | ||
do { | ||
const response = await fn({ | ||
params, | ||
}); | ||
const results = resourceKey | ||
? response[resourceKey] | ||
: response; | ||
for (const item of results) { | ||
yield item; | ||
if (max && ++count >= max) { | ||
return; | ||
} | ||
} | ||
total = results?.length; | ||
params.offset += params.limit; | ||
} while (total); | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.