-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
184 additions
and
8 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
components/upstash_redis/actions/list-databases/list-databases.mjs
This file contains 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,19 @@ | ||
import app from "../../upstash_redis.app.mjs"; | ||
|
||
export default { | ||
key: "upstash_redis-list-databases", | ||
name: "List Redis Databases", | ||
description: "Lists all Redis databases. [See the documentation](https://upstash.com/docs/devops/developer-api/redis/list_databases)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.app.listDatabases({ | ||
$, | ||
}); | ||
$.export("$summary", `Successfully listed \`${response.length}\` Redis database(s)`); | ||
return response; | ||
}, | ||
}; |
49 changes: 49 additions & 0 deletions
49
components/upstash_redis/actions/post-command/post-command.mjs
This file contains 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,49 @@ | ||
import utils from "../../common/utils.mjs"; | ||
import app from "../../upstash_redis.app.mjs"; | ||
|
||
export default { | ||
key: "upstash_redis-post-command", | ||
name: "Post Command", | ||
description: "Post a command to a Redis database. [See the documentation](https://upstash.com/docs/redis/features/restapi#post-command-in-body)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
command: { | ||
type: "string", | ||
label: "Command", | ||
description: "The command to post to the database.", | ||
options: [ | ||
"SET", | ||
"GET", | ||
], | ||
}, | ||
args: { | ||
type: "string[]", | ||
label: "Arguments", | ||
description: "The arguments for the command. Eg. `[\"mykey\", \"myvalue\"]`", | ||
}, | ||
}, | ||
methods: { | ||
postCommand(args = {}) { | ||
return this.app.post(args); | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
postCommand, | ||
command, | ||
args, | ||
} = this; | ||
const response = await postCommand({ | ||
$, | ||
data: [ | ||
command, | ||
...utils.parseArray(args), | ||
], | ||
}); | ||
|
||
$.export("$summary", "Successfully posted command to the database."); | ||
return response; | ||
}, | ||
}; |
This file contains 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,9 @@ | ||
const BASE_URL = "https://api.upstash.com"; | ||
const VERSION_PATH = "/v2/redis"; | ||
const HTTPS_PROTOCOL = "https://"; | ||
|
||
export default { | ||
BASE_URL, | ||
VERSION_PATH, | ||
HTTPS_PROTOCOL, | ||
}; |
This file contains 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,28 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
function parseArray(value) { | ||
try { | ||
if (!value) { | ||
return []; | ||
} | ||
|
||
if (Array.isArray(value)) { | ||
return value; | ||
} | ||
|
||
const parsedValue = JSON.parse(value); | ||
|
||
if (!Array.isArray(parsedValue)) { | ||
throw new Error("Not an array"); | ||
} | ||
|
||
return parsedValue; | ||
|
||
} catch (e) { | ||
throw new ConfigurationError("Make sure the custom expression contains a valid array object"); | ||
} | ||
} | ||
|
||
export default { | ||
parseArray, | ||
}; |
This file contains 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
This file contains 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,76 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import constants from "./common/constants.mjs"; | ||
|
||
export default { | ||
type: "app", | ||
app: "upstash_redis", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
databaseId: { | ||
type: "string", | ||
label: "Database ID", | ||
description: "The ID of the database.", | ||
async options() { | ||
const databases = await this.listDatabases(); | ||
return databases.map(({ | ||
database_id: value, database_name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
getRedisUrl() { | ||
const { upstash_redis_rest_url: url } = this.$auth; | ||
return url.startsWith(constants.HTTPS_PROTOCOL) | ||
? url | ||
: `${constants.HTTPS_PROTOCOL}${url}`; | ||
}, | ||
getUrl(path, managementApi) { | ||
return managementApi | ||
? `${constants.BASE_URL}${constants.VERSION_PATH}${path}` | ||
: this.getRedisUrl(); | ||
}, | ||
getHeaders(headers) { | ||
return { | ||
...headers, | ||
"Authorization": `Bearer ${this.$auth.uptash_redis_rest_token}`, | ||
}; | ||
}, | ||
getAuth(managementApi) { | ||
if (managementApi) { | ||
const { | ||
email: username, | ||
management_api_key: password, | ||
} = this.$auth; | ||
return { | ||
username, | ||
password, | ||
}; | ||
} | ||
}, | ||
_makeRequest({ | ||
$ = this, path, headers, managementApi, ...args | ||
} = {}) { | ||
return axios($, { | ||
...args, | ||
url: this.getUrl(path, managementApi), | ||
headers: this.getHeaders(headers), | ||
auth: this.getAuth(managementApi), | ||
}); | ||
}, | ||
post(args = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
...args, | ||
}); | ||
}, | ||
listDatabases() { | ||
return this._makeRequest({ | ||
managementApi: true, | ||
path: "/databases", | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.