mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-17 14:14:22 +01:00
@@ -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,
|
||||
}
|
||||
|
||||
17
src/rpc.js
17
src/rpc.js
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user