browse contents of s3 buckets from within budibase
This commit is contained in:
parent
c12b59e304
commit
6518976825
|
@ -36,7 +36,7 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form>
|
<section>
|
||||||
<div class="config">
|
<div class="config">
|
||||||
<h6>Schema</h6>
|
<h6>Schema</h6>
|
||||||
{#each fields as field, idx}
|
{#each fields as field, idx}
|
||||||
|
@ -60,15 +60,22 @@
|
||||||
<div class="config">
|
<div class="config">
|
||||||
<h6>Datasource</h6>
|
<h6>Datasource</h6>
|
||||||
{#each Object.keys(table.integration) as configKey}
|
{#each Object.keys(table.integration) as configKey}
|
||||||
<Input
|
{#if configKey === 'query'}
|
||||||
thin
|
<TextArea
|
||||||
type={configKey.type}
|
thin
|
||||||
label={configKey}
|
label={configKey}
|
||||||
bind:value={table.integration[configKey]} />
|
bind:value={table.integration[configKey]} />
|
||||||
|
{:else}
|
||||||
|
<Input
|
||||||
|
thin
|
||||||
|
type={configKey.type}
|
||||||
|
label={configKey}
|
||||||
|
bind:value={table.integration[configKey]} />
|
||||||
|
{/if}
|
||||||
<Spacer small />
|
<Spacer small />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</section>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.field {
|
.field {
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
{#each $backendUiStore.tables as table, idx}
|
{#each $backendUiStore.tables as table, idx}
|
||||||
<NavItem
|
<NavItem
|
||||||
border={idx > 0}
|
border={idx > 0}
|
||||||
icon={table.integration ? 'ri-database-2-line' : 'ri-table-line'}
|
icon={table.integration?.type ? 'ri-database-2-line' : 'ri-table-line'}
|
||||||
text={table.name}
|
text={table.name}
|
||||||
selected={selectedView === `all_${table._id}`}
|
selected={selectedView === `all_${table._id}`}
|
||||||
on:click={() => selectTable(table)}>
|
on:click={() => selectTable(table)}>
|
||||||
|
|
|
@ -79,7 +79,7 @@
|
||||||
bind:value={table.name}
|
bind:value={table.name}
|
||||||
on:input={checkValid}
|
on:input={checkValid}
|
||||||
{error} />
|
{error} />
|
||||||
{#if table.integration}
|
{#if table.integration?.type}
|
||||||
<IntegrationConfigForm integration={table.integration} />
|
<IntegrationConfigForm integration={table.integration} />
|
||||||
{/if}
|
{/if}
|
||||||
<footer>
|
<footer>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $backendUiStore.selectedDatabase._id && selectedTable.name}
|
{#if $backendUiStore.selectedDatabase._id && selectedTable.name}
|
||||||
{#if selectedTable.integration}
|
{#if selectedTable.integration?.type}
|
||||||
<ExternalDataSourceTable />
|
<ExternalDataSourceTable />
|
||||||
{:else}
|
{:else}
|
||||||
<TableDataTable />
|
<TableDataTable />
|
||||||
|
|
|
@ -190,7 +190,7 @@ exports.fetchTableRows = async function(ctx) {
|
||||||
|
|
||||||
const table = await db.get(ctx.params.tableId)
|
const table = await db.get(ctx.params.tableId)
|
||||||
|
|
||||||
if (table.integration) {
|
if (table.integration && table.integration.type) {
|
||||||
const Integration = integrations[table.integration.type]
|
const Integration = integrations[table.integration.type]
|
||||||
ctx.body = await new Integration(table.integration).query()
|
ctx.body = await new Integration(table.integration).query()
|
||||||
return
|
return
|
||||||
|
|
|
@ -27,11 +27,11 @@ const DYNAMODB_OPTIONS = {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
attributeNames: {
|
attributeNames: {
|
||||||
type: "object",
|
type: "json",
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
attributeValues: {
|
attributeValues: {
|
||||||
type: "object",
|
type: "json",
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ const ELASTICSEARCH_OPTIONS = {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
query: {
|
query: {
|
||||||
type: "query",
|
type: "json",
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ const mongodb = require("./mongodb")
|
||||||
const elasticsearch = require("./elasticsearch")
|
const elasticsearch = require("./elasticsearch")
|
||||||
const couchdb = require("./couchdb")
|
const couchdb = require("./couchdb")
|
||||||
// const redis = require("./redis")
|
// const redis = require("./redis")
|
||||||
// const s3 = require("./s3")
|
const s3 = require("./s3")
|
||||||
|
|
||||||
const DEFINITIONS = {
|
const DEFINITIONS = {
|
||||||
POSTGRES: postgres.schema,
|
POSTGRES: postgres.schema,
|
||||||
|
@ -12,6 +12,7 @@ const DEFINITIONS = {
|
||||||
MONGODB: mongodb.schema,
|
MONGODB: mongodb.schema,
|
||||||
ELASTICSEARCH: elasticsearch.schema,
|
ELASTICSEARCH: elasticsearch.schema,
|
||||||
COUCHDB: couchdb.schema,
|
COUCHDB: couchdb.schema,
|
||||||
|
S3: s3.schema,
|
||||||
}
|
}
|
||||||
|
|
||||||
const INTEGRATIONS = {
|
const INTEGRATIONS = {
|
||||||
|
@ -20,6 +21,7 @@ const INTEGRATIONS = {
|
||||||
MONGODB: mongodb.integration,
|
MONGODB: mongodb.integration,
|
||||||
ELASTICSEARCH: elasticsearch.integration,
|
ELASTICSEARCH: elasticsearch.integration,
|
||||||
COUCHDB: couchdb.integration,
|
COUCHDB: couchdb.integration,
|
||||||
|
S3: s3.integration,
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -24,6 +24,11 @@ class MongoIntegration {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.config = config
|
this.config = config
|
||||||
this.client = new MongoClient(config.connectionString)
|
this.client = new MongoClient(config.connectionString)
|
||||||
|
try {
|
||||||
|
this.config.query = JSON.parse(this.config.query)
|
||||||
|
} catch (err) {
|
||||||
|
this.config.query = {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
|
@ -37,6 +42,9 @@ class MongoIntegration {
|
||||||
const collection = db.collection(this.config.collection)
|
const collection = db.collection(this.config.collection)
|
||||||
const result = await collection.find(this.config.query).toArray()
|
const result = await collection.find(this.config.query).toArray()
|
||||||
return result
|
return result
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error querying mongodb", err)
|
||||||
|
throw err
|
||||||
} finally {
|
} finally {
|
||||||
await this.client.close()
|
await this.client.close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
const AWS = require("aws-sdk")
|
||||||
|
|
||||||
|
const S3_OPTIONS = {
|
||||||
|
bucket: {
|
||||||
|
type: "string",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
region: {
|
||||||
|
type: "string",
|
||||||
|
required: true,
|
||||||
|
default: "us-east-1",
|
||||||
|
},
|
||||||
|
accessKeyId: {
|
||||||
|
type: "string",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
secretAccessKey: {
|
||||||
|
type: "secretKey",
|
||||||
|
required: true,
|
||||||
|
default: 5432,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
class S3Integration {
|
||||||
|
constructor(config) {
|
||||||
|
this.config = config
|
||||||
|
this.connect()
|
||||||
|
this.client = new AWS.S3()
|
||||||
|
}
|
||||||
|
|
||||||
|
async connect() {
|
||||||
|
AWS.config.update(this.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
async query() {
|
||||||
|
const response = await this.client
|
||||||
|
.listObjects({
|
||||||
|
Bucket: this.config.bucket,
|
||||||
|
})
|
||||||
|
.promise()
|
||||||
|
return response.Contents
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
schema: S3_OPTIONS,
|
||||||
|
integration: S3Integration,
|
||||||
|
}
|
Loading…
Reference in New Issue