advanced acl: draft

Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
dzdidi
2024-01-26 15:02:37 +00:00
parent 70b3a6c585
commit 0911049fa5
2 changed files with 24 additions and 14 deletions

View File

@@ -21,6 +21,19 @@ function shareWith (userId, branch = '*', permissions = 'rw') {
if (permissions.split('').some(p => !['r', 'w'].includes(p))) { if (permissions.split('').some(p => !['r', 'w'].includes(p))) {
throw new Error('Permissions must be r, w or rw') throw new Error('Permissions must be r, w or rw')
} }
// TODO: read file
// generate new conent
// merge with old file
// store file
//
// EXAMPLE:
// {
// protectedBranches: ['master'],
// ACL: {
// '<userId>': { '<branch name | *>': 'r|w|rw' },
// '*': { '*': 'r' }
// }
// }
fs.appendFileSync(`${APP_HOME}/.git-daemon-export-ok`, `${userId}\t${branch}\t${permissions}\n`) fs.appendFileSync(`${APP_HOME}/.git-daemon-export-ok`, `${userId}\t${branch}\t${permissions}\n`)
} }
@@ -41,9 +54,11 @@ function getACL (name) {
const res = {} const res = {}
for (const entry of entries) { for (const entry of entries) {
const [userId, branch, permissions] = entry.split('\t') const [userId, branch, permissions] = entry.split('\t')
res[userId] = { branch, permissions } if (!res[userId]) res[userId] = []
res[userId].push({ branch, permissions })
} }
return res return res
// TODO: have protected branch setting - the ACL must be assigned explicitly
} }
function list (sharedOnly) { function list (sharedOnly) {

View File

@@ -98,7 +98,7 @@ module.exports = class RPC {
}) })
} }
async parseReq(req) { async parseReq(req, access, branch = '*') {
let payload let payload
let request = JSON.parse(req.toString()) let request = JSON.parse(req.toString())
const result = { const result = {
@@ -106,17 +106,12 @@ module.exports = class RPC {
branch: request.body.data?.split('#')[0], branch: request.body.data?.split('#')[0],
url: request.body.url url: request.body.url
} }
if (process.env.GIT_PEAR_AUTH) { if (!process.env.GIT_PEAR_AUTH) return result
if (!request.header) throw new Error('You are not allowed to access this repo') if (!request.header) throw new Error('You are not allowed to access this repo')
payload = await acl.getId({ ...request.body, payload: request.header }) payload = await acl.getId({ ...request.body, payload: request.header })
const aclList = home.getACL(result.repoName) const aclList = home.getACL(result.repoName)
// TODO: read specific permissions for the user const userACL = aclList[payload.userId]
if (!Object.keys(aclList).includes(payload.userId)) { if (!userACL) throw new Error('You are not allowed to access this repo')
throw new Error('You are not allowed to access this repo')
}
}
return result if (result.branch !== 'master'
}
}