forked from tsai/budibase
13 changed files with 88 additions and 67 deletions
@ -0,0 +1,22 @@ |
|||
export const buildSelfEndpoints = API => ({ |
|||
/** |
|||
* Using the logged in user, this will generate a new API key, |
|||
* assuming the user is a builder. |
|||
* @return {Promise<object>} returns the API response, including an API key. |
|||
*/ |
|||
generateAPIKey: async () => { |
|||
return await API.post({ |
|||
url: "/api/global/self/api_key", |
|||
}) |
|||
}, |
|||
|
|||
/** |
|||
* retrieves the API key for the logged in user. |
|||
* @return {Promise<object>} An object containing the user developer information. |
|||
*/ |
|||
fetchDeveloperInfo: async () => { |
|||
return await API.get({ |
|||
url: "/api/global/self/api_key", |
|||
}) |
|||
}, |
|||
}) |
|||
@ -0,0 +1,11 @@ |
|||
exports.generateAPIKey = async ctx => { |
|||
ctx.body = { |
|||
apiKey: "a175402a-89fc-11ec-a8a3-0242ac120002", |
|||
} |
|||
} |
|||
|
|||
exports.fetchAPIKey = async ctx => { |
|||
ctx.body = { |
|||
apiKey: "a175402a-89fc-11ec-a8a3-0242ac120002", |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
const Router = require("@koa/router") |
|||
const controller = require("../../controllers/global/self") |
|||
const builderOnly = require("../../../middleware/builderOnly") |
|||
|
|||
const router = Router() |
|||
|
|||
router |
|||
.post("/api/global/self/api_key", builderOnly, controller.generateAPIKey) |
|||
.get("/api/global/self/api_key", builderOnly, controller.fetchAPIKey) |
|||
|
|||
module.exports = router |
|||
@ -0,0 +1,12 @@ |
|||
const { getGlobalDB } = require("@budibase/backend-core/tenancy") |
|||
const { getGlobalUserParams } = require("@budibase/backend-core/db") |
|||
|
|||
exports.allUsers = async () => { |
|||
const db = getGlobalDB() |
|||
const response = await db.allDocs( |
|||
getGlobalUserParams(null, { |
|||
include_docs: true, |
|||
}) |
|||
) |
|||
return response.rows.map(row => row.doc) |
|||
} |
|||
Loading…
Reference in new issue