Merge pull request #240 from mjashanks/master

Few Bugfixes & Tidyup
This commit is contained in:
Michael Shanks 2020-05-18 16:39:27 +01:00 committed by GitHub
commit 4f0d974337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 22 deletions

View File

@ -11,9 +11,7 @@ module.exports = opts => {
const run = async opts => {
try {
opts.dir = xPlatHomeDir(opts.dir)
const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") })
console.log(bbconfig)
setup(opts)
await createAppInstance(opts)
await createEmptyAppPackage(opts)
exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`)
@ -25,6 +23,13 @@ const run = async opts => {
}
}
const setup = opts => {
opts.dir = xPlatHomeDir(opts.dir)
process.env.BUDIBASE_DIR = opts.dir
const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") })
console.log(JSON.stringify(bbconfig))
}
const createAppInstance = async opts => {
const createAppCtx = {
params: { clientId: process.env.CLIENT_ID },
@ -45,7 +50,7 @@ const createAppInstance = async opts => {
// this cannot be a top level require as it will cause
// the environment module to be loaded prematurely
const instanceController = require("@budibase/server/src/api/controllers/instance")
await instanceController.create({
const createInstCtx = {
params: {
clientId: process.env.CLIENT_ID,
applicationId: opts.applicationId,
@ -53,9 +58,11 @@ const createAppInstance = async opts => {
request: {
body: { name: `dev-${process.env.CLIENT_ID}` },
},
})
}
await instanceController.create(createInstCtx)
console.log(chalk.green(`Default Instance Created`))
console.log(JSON.stringify(createInstCtx.body))
}
const createEmptyAppPackage = async opts => {

View File

@ -1,7 +1,7 @@
const CouchDB = require("../../db")
const ClientDb = require("../../db/clientDb")
const { getPackageForBuilder } = require("../../utilities/builder")
const uuid = require("uuid")
const newid = require("../../db/newid")
const env = require("../../environment")
exports.fetch = async function(ctx) {
@ -24,7 +24,7 @@ exports.create = async function(ctx) {
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
const newApplication = {
_id: uuid.v4().replace(/-/g, ""),
_id: newid(),
type: "app",
instances: [],
userInstanceMap: {},

View File

@ -1,12 +1,12 @@
const CouchDB = require("../../db")
const client = require("../../db/clientDb")
const uuid = require("uuid")
const newid = require("../../db/newid")
const env = require("../../environment")
exports.create = async function(ctx) {
const instanceName = ctx.request.body.name
const uid = uuid.v4().replace(/-/g, "")
const instanceId = `inst_${ctx.params.applicationId.substring(0, 7)}_${uid}`
const appShortId = ctx.params.applicationId.substring(0, 7)
const instanceId = `inst_${appShortId}_${newid()}`
const { applicationId } = ctx.params
const clientId = env.CLIENT_ID
const db = new CouchDB(instanceId)

View File

@ -1,5 +1,5 @@
const CouchDB = require("../../db")
const uuid = require("uuid")
const newid = require("../../db/newid")
exports.fetch = async function(ctx) {
const db = new CouchDB(ctx.params.instanceId)
@ -15,7 +15,7 @@ exports.create = async function(ctx) {
const newModel = {
type: "model",
...ctx.request.body,
_id: uuid.v4().replace(/-/g, ""),
_id: newid(),
}
const result = await db.post(newModel)

View File

@ -1,6 +1,6 @@
const CouchDB = require("../../db")
const Ajv = require("ajv")
const uuid = require("uuid")
const newid = require("../../db/newid")
const ajv = new Ajv()
@ -9,7 +9,7 @@ exports.save = async function(ctx) {
const record = ctx.request.body
if (!record._rev && !record._id) {
record._id = uuid.v4().replace(/-/, "")
record._id = newid()
}
// validation with ajv

View File

@ -0,0 +1,5 @@
const { v4 } = require("uuid")
module.exports = function() {
return v4().replace(/-/g, "")
}

View File

@ -3,14 +3,7 @@ const STATUS_CODES = require("../utilities/statusCodes")
const env = require("../environment")
module.exports = async (ctx, next) => {
const authHeader = ctx.get("Authorization")
if (
authHeader &&
authHeader.startsWith("Basic") &&
authHeader.split(" ")[1] === env.ADMIN_SECRET
) {
ctx.isAuthenticated = true
if (ctx.path === "/_builder") {
await next()
return
}