1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +12:00

browse contents of s3 buckets from within budibase

This commit is contained in:
Martin McKeaveney 2020-11-26 21:23:20 +00:00
parent 9a6ac6915b
commit 6cca720117
10 changed files with 80 additions and 15 deletions

View file

@ -36,7 +36,7 @@
}
</script>
<form>
<section>
<div class="config">
<h6>Schema</h6>
{#each fields as field, idx}
@ -60,15 +60,22 @@
<div class="config">
<h6>Datasource</h6>
{#each Object.keys(table.integration) as configKey}
<Input
thin
type={configKey.type}
label={configKey}
bind:value={table.integration[configKey]} />
{#if configKey === 'query'}
<TextArea
thin
label={configKey}
bind:value={table.integration[configKey]} />
{:else}
<Input
thin
type={configKey.type}
label={configKey}
bind:value={table.integration[configKey]} />
{/if}
<Spacer small />
{/each}
</div>
</form>
</section>
<style>
.field {

View file

@ -43,7 +43,7 @@
{#each $backendUiStore.tables as table, idx}
<NavItem
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}
selected={selectedView === `all_${table._id}`}
on:click={() => selectTable(table)}>

View file

@ -79,7 +79,7 @@
bind:value={table.name}
on:input={checkValid}
{error} />
{#if table.integration}
{#if table.integration?.type}
<IntegrationConfigForm integration={table.integration} />
{/if}
<footer>

View file

@ -7,7 +7,7 @@
</script>
{#if $backendUiStore.selectedDatabase._id && selectedTable.name}
{#if selectedTable.integration}
{#if selectedTable.integration?.type}
<ExternalDataSourceTable />
{:else}
<TableDataTable />

View file

@ -190,7 +190,7 @@ exports.fetchTableRows = async function(ctx) {
const table = await db.get(ctx.params.tableId)
if (table.integration) {
if (table.integration && table.integration.type) {
const Integration = integrations[table.integration.type]
ctx.body = await new Integration(table.integration).query()
return

View file

@ -27,11 +27,11 @@ const DYNAMODB_OPTIONS = {
required: true,
},
attributeNames: {
type: "object",
type: "json",
required: true,
},
attributeValues: {
type: "object",
type: "json",
required: true,
},
}

View file

@ -11,7 +11,7 @@ const ELASTICSEARCH_OPTIONS = {
required: true,
},
query: {
type: "query",
type: "json",
required: true,
},
}

View file

@ -4,7 +4,7 @@ const mongodb = require("./mongodb")
const elasticsearch = require("./elasticsearch")
const couchdb = require("./couchdb")
// const redis = require("./redis")
// const s3 = require("./s3")
const s3 = require("./s3")
const DEFINITIONS = {
POSTGRES: postgres.schema,
@ -12,6 +12,7 @@ const DEFINITIONS = {
MONGODB: mongodb.schema,
ELASTICSEARCH: elasticsearch.schema,
COUCHDB: couchdb.schema,
S3: s3.schema,
}
const INTEGRATIONS = {
@ -20,6 +21,7 @@ const INTEGRATIONS = {
MONGODB: mongodb.integration,
ELASTICSEARCH: elasticsearch.integration,
COUCHDB: couchdb.integration,
S3: s3.integration,
}
module.exports = {

View file

@ -24,6 +24,11 @@ class MongoIntegration {
constructor(config) {
this.config = config
this.client = new MongoClient(config.connectionString)
try {
this.config.query = JSON.parse(this.config.query)
} catch (err) {
this.config.query = {}
}
}
async connect() {
@ -37,6 +42,9 @@ class MongoIntegration {
const collection = db.collection(this.config.collection)
const result = await collection.find(this.config.query).toArray()
return result
} catch (err) {
console.error("Error querying mongodb", err)
throw err
} finally {
await this.client.close()
}

View file

@ -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,
}