Skip to content

Commit 7d59f43

Browse files
committed
Added actions
1 parent 9969779 commit 7d59f43

File tree

6 files changed

+227
-3
lines changed

6 files changed

+227
-3
lines changed

components/scalr/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

components/scalr/scalr.app.mjs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "scalr",
6+
propDefinitions: {
7+
accountId: {
8+
type: "string",
9+
label: "Account ID",
10+
description: "The ID of the account you wish to use.",
11+
async options() {
12+
const { data: accounts } = await this.getAccounts();
13+
return accounts.map((account) => ({
14+
label: account.attributes.name,
15+
value: account.id,
16+
}));
17+
},
18+
},
19+
},
20+
methods: {
21+
_baseUrl() {
22+
return `https://${this.$auth.domain}.scalr.io/api/iacp/v3`;
23+
},
24+
async _makeRequest(opts = {}) {
25+
const {
26+
$ = this,
27+
path,
28+
headers,
29+
...otherOpts
30+
} = opts;
31+
return axios($, {
32+
...otherOpts,
33+
url: this._baseUrl() + path,
34+
headers: {
35+
"Authorization": `Bearer ${this.$auth.api_token}`,
36+
"Content-type": "application/vnd.api+json",
37+
...headers,
38+
},
39+
});
40+
},
41+
async createWebhook({ ...args }) {
42+
return this._makeRequest({
43+
path: "/integrations/webhooks",
44+
method: "post",
45+
...args,
46+
});
47+
},
48+
async removeWebhook(webhookId) {
49+
return this._makeRequest({
50+
path: `/integrations/webhooks/${webhookId}`,
51+
method: "delete",
52+
});
53+
},
54+
async getWebhooks(args = {}) {
55+
return this._makeRequest({
56+
path: "/integrations/webhooks",
57+
...args,
58+
});
59+
},
60+
async getAccounts(args = {}) {
61+
return this._makeRequest({
62+
path: "/accounts",
63+
...args,
64+
});
65+
},
66+
async getEvents(args = {}) {
67+
return this._makeRequest({
68+
path: "/event-definitions",
69+
...args,
70+
});
71+
},
72+
},
73+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import scalr from "../../scalr.app.mjs";
2+
3+
export default {
4+
props: {
5+
scalr,
6+
db: "$.service.db",
7+
http: "$.interface.http",
8+
accountId: {
9+
propDefinition: [
10+
scalr,
11+
"accountId",
12+
],
13+
},
14+
},
15+
methods: {
16+
_getWebhookId() {
17+
return this.db.get("webhookId");
18+
},
19+
_setWebhookId(webhookId) {
20+
this.db.set("webhookId", webhookId);
21+
},
22+
getWebhookEventType() {
23+
throw new Error("getWebhookEventType is not implemented");
24+
},
25+
emitEvent(event) {
26+
throw new Error("emitEvent is not implemented", event);
27+
},
28+
},
29+
hooks: {
30+
async activate() {
31+
const { data } = await this.scalr.createWebhook({
32+
data: {
33+
"data": {
34+
"attributes": {
35+
"max-attempts": 3,
36+
"timeout": 15,
37+
"name": "Webhook Pipedream - " + new Date().toISOString(),
38+
"url": this.http.endpoint,
39+
},
40+
"relationships": {
41+
"account": {
42+
"data": {
43+
"type": "accounts",
44+
"id": this.accountId,
45+
},
46+
},
47+
"events": {
48+
"data": [
49+
{
50+
"type": "event-definitions",
51+
"id": this.getWebhookEventType(),
52+
},
53+
],
54+
},
55+
},
56+
"type": "webhook-integrations",
57+
},
58+
},
59+
});
60+
this._setWebhookId(data.id);
61+
},
62+
async deactivate() {
63+
const webhookId = this._getWebhookId();
64+
await this.scalr.removeWebhook(webhookId);
65+
},
66+
},
67+
async run(event) {
68+
await this.emitEvent(event.body);
69+
},
70+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import common from "../common/common.mjs";
2+
3+
export default {
4+
...common,
5+
name: "New Run Completed (Instant)",
6+
version: "0.0.1",
7+
key: "scalr-new-run-completed",
8+
description: "Emit new event on each new completed run.",
9+
type: "source",
10+
dedupe: "unique",
11+
hooks: {
12+
...common.hooks,
13+
},
14+
methods: {
15+
...common.methods,
16+
getWebhookEventType() {
17+
return "run:completed";
18+
},
19+
async emitEvent(data) {
20+
21+
this.$emit(data, {
22+
id: data.run.id,
23+
summary: `New run completed with ID ${data.run.id}`,
24+
ts: Date.parse(data.run["created-at"]),
25+
});
26+
},
27+
},
28+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import common from "../common/common.mjs";
2+
3+
export default {
4+
...common,
5+
name: "New Run Errored (Instant)",
6+
version: "0.0.1",
7+
key: "scalr-new-run-errored",
8+
description: "Emit new event when a new run encountered an error.",
9+
type: "source",
10+
dedupe: "unique",
11+
hooks: {
12+
...common.hooks,
13+
},
14+
methods: {
15+
...common.methods,
16+
getWebhookEventType() {
17+
return "run:errored";
18+
},
19+
async emitEvent(data) {
20+
21+
this.$emit(data, {
22+
id: data.run.id,
23+
summary: `New run completed with ID ${data.run.id}`,
24+
ts: Date.parse(data.run["created-at"]),
25+
});
26+
},
27+
},
28+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import common from "../common/common.mjs";
2+
3+
export default {
4+
...common,
5+
name: "New Run Needs Attention (Instant)",
6+
version: "0.0.1",
7+
key: "scalr-new-run-needs-attention",
8+
description: "Emit new event when a new run needs attention.",
9+
type: "source",
10+
dedupe: "unique",
11+
hooks: {
12+
...common.hooks,
13+
},
14+
methods: {
15+
...common.methods,
16+
getWebhookEventType() {
17+
return "run:needs_attention";
18+
},
19+
async emitEvent(data) {
20+
21+
this.$emit(data, {
22+
id: data.run.id,
23+
summary: `New run with ID ${data.run.id} needs attention`,
24+
ts: Date.parse(data.run["created-at"]),
25+
});
26+
},
27+
},
28+
};

0 commit comments

Comments
 (0)