dummy acl

Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
dzdidi
2024-01-25 21:39:59 +00:00
parent 9d66b66221
commit 781ddb65db
2 changed files with 17 additions and 5 deletions

View File

@@ -30,6 +30,10 @@ function isShared (name) {
return fs.existsSync(`${APP_HOME}/${name}/.git-daemon-export-ok`)
}
function getACL (name) {
return fs.readFileSync(`${APP_HOME}/${name}/.git-daemon-export-ok`).toString().split('\n').filter(Boolean)
}
function list (sharedOnly) {
const repos = fs.readdirSync(APP_HOME)
if (!sharedOnly) return repos.filter(r => !r.startsWith('.') && isInitialized(r))
@@ -125,4 +129,5 @@ module.exports = {
isDaemonRunning,
removeDaemonPid,
shareWith,
getACL,
}

View File

@@ -101,17 +101,24 @@ module.exports = class RPC {
async parseReq(req) {
let payload
let request = JSON.parse(req.toString())
const result = {
repoName: request.body.url?.split('/')?.pop(),
branch: request.body.data?.split('#')[0],
url: request.body.url
}
if (process.env.GIT_PEAR_AUTH) {
payload = await acl.getId({
...request.body,
payload: request.header
})
// read .git-daemon-export-ok
// check if payload.userId is presenet there
const aclList = home.getACL(result.repoName)
if (!aclList.includes(payload.userId)) {
throw new Error(`You are not allowed to access this repo: ${payload.userId}`)
}
}
return {
repoName: request.body.url?.split('/')?.pop(),
branch: request.body.data?.split('#')[0],
url: request.body.url
}
return result
}
}