mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-17 22:24:22 +01:00
29
src/cli.js
29
src/cli.js
@@ -12,7 +12,7 @@ const home = require('./home')
|
|||||||
const acl = require('./acl')
|
const acl = require('./acl')
|
||||||
const git = require('./git')
|
const git = require('./git')
|
||||||
|
|
||||||
const { listRemote, bpr } = require('./rpc-requests')
|
const { listRemote, aclRemote } = require('./rpc-requests')
|
||||||
|
|
||||||
const pkg = require('../package.json')
|
const pkg = require('../package.json')
|
||||||
program
|
program
|
||||||
@@ -94,11 +94,11 @@ program
|
|||||||
throw new Error('Cannot perform both user and branch action at the same time')
|
throw new Error('Cannot perform both user and branch action at the same time')
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(a, n, p, options)
|
console.log("INPUT", a, n, p, options)
|
||||||
|
|
||||||
if (!options.user && !options.branch) {
|
if (!options.user && !options.branch) {
|
||||||
if (a !== 'list') throw new Error('Need either user or branch option')
|
if (a !== 'list') throw new Error('Need either user or branch option')
|
||||||
const repoACL = await getACL(p)
|
const repoACL = await retreiveACL(a, n, p)
|
||||||
|
|
||||||
console.log('Repo Visibility:', '\t', repoACL.visibility)
|
console.log('Repo Visibility:', '\t', repoACL.visibility)
|
||||||
console.log('Protected Branch(s):', '\t', repoACL.protectedBranches.join(', '))
|
console.log('Protected Branch(s):', '\t', repoACL.protectedBranches.join(', '))
|
||||||
@@ -108,17 +108,22 @@ program
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (options.user) {
|
if (options.user) {
|
||||||
if (p.startsWith('pear://') || n.startsWith('pear://')) {
|
if (p.startsWith('pear://')) {
|
||||||
// XXX
|
console.log('a', a, 'n', n, 'p', p, 'options', options)
|
||||||
|
await remoteACL(a, n, p, options)
|
||||||
|
} else if (n.startsWith('pear://')) {
|
||||||
|
console.log('a', a, 'n', n, 'p', p, 'options', options)
|
||||||
await remoteACL(a, n, p, options)
|
await remoteACL(a, n, p, options)
|
||||||
} else {
|
} else {
|
||||||
localACL(a, n, p, options)
|
localACL(a, n, p, options)
|
||||||
}
|
}
|
||||||
} else if (options.branch) {
|
} else if (options.branch) {
|
||||||
if (p.startsWith('pear://') || n.startsWith('pear://')) {
|
if (p.startsWith('pear://')) {
|
||||||
// XXX
|
console.log('a', a, 'n', n, 'p', p, 'options', options)
|
||||||
|
await remoteBranchProtectionRules(a, n, p, options)
|
||||||
|
} else if (n.startsWith('pear://')) {
|
||||||
|
console.log('a', a, 'n', n, 'p', p, 'options', options)
|
||||||
await remoteBranchProtectionRules(a, n, p, options)
|
await remoteBranchProtectionRules(a, n, p, options)
|
||||||
} else {
|
} else {
|
||||||
localBranchProtectionRules(a, n, p, options)
|
localBranchProtectionRules(a, n, p, options)
|
||||||
@@ -305,7 +310,7 @@ function localACL(a, u, p, options) {
|
|||||||
|
|
||||||
async function remoteBranchProtectionRules(a, b, p, options) {
|
async function remoteBranchProtectionRules(a, b, p, options) {
|
||||||
if (a === 'list') {
|
if (a === 'list') {
|
||||||
return await bpr.list(p)
|
return await acl.list(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,7 +344,10 @@ function logBranches(name) {
|
|||||||
console.log('Protected Branch(s):', '\t', repoACL.protectedBranches.join(', '))
|
console.log('Protected Branch(s):', '\t', repoACL.protectedBranches.join(', '))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getACL(p) {
|
async function retreiveACL(a, n, p) {
|
||||||
|
console.log('getting acl', 'a', a)
|
||||||
|
console.log('getting acl', 'n', n)
|
||||||
|
console.log('getting acl', 'p', p)
|
||||||
return (p.startsWith('pear://')) ? (await getRemoteACL(p)) : (await getLocalACL(p))
|
return (p.startsWith('pear://')) ? (await getRemoteACL(p)) : (await getLocalACL(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,5 +366,6 @@ async function getLocalACL(p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getRemoteACL(p) {
|
async function getRemoteACL(p) {
|
||||||
|
console.log('getting remote acl')
|
||||||
}
|
}
|
||||||
program.parse()
|
program.parse()
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
const git = require('./git')
|
const git = require('./git')
|
||||||
const acl = require('./acl')
|
const acl = require('./acl')
|
||||||
const bpr = require('./bpr')
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
git,
|
git,
|
||||||
acl,
|
acl,
|
||||||
bpr,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
const ProtomuxRPC = require('protomux-rpc')
|
||||||
|
|
||||||
|
const Hyperswarm = require('hyperswarm')
|
||||||
|
const crypto = require('hypercore-crypto')
|
||||||
|
|
||||||
|
const home = require('../home')
|
||||||
|
const auth = require('../auth')
|
||||||
|
|
||||||
|
async function list (url) {
|
||||||
|
const matches = url.match(/pear:\/\/([a-f0-9]{64})/)
|
||||||
|
|
||||||
|
if (!matches || matches.length < 2) {
|
||||||
|
console.error('Invalid URL')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetKey = matches[1]
|
||||||
|
console.log('Connecting to:', targetKey)
|
||||||
|
|
||||||
|
const swarmOpts = {}
|
||||||
|
if (process.env.GIT_PEAR_AUTH === 'native') {
|
||||||
|
swarmOpts.keyPair = home.getKeyPair()
|
||||||
|
}
|
||||||
|
const swarm = new Hyperswarm(swarmOpts)
|
||||||
|
|
||||||
|
swarm.join(crypto.discoveryKey(Buffer.from(targetKey, 'hex')), { server: false })
|
||||||
|
|
||||||
|
swarm.on('connection', async (socket) => {
|
||||||
|
const rpc = new ProtomuxRPC(socket)
|
||||||
|
|
||||||
|
let payload = { body: { url, method: 'get-repos' } }
|
||||||
|
if (!process.env.GIT_PEAR_AUTH) {
|
||||||
|
console.debug('Retreiving data using un-authenticated access')
|
||||||
|
} else {
|
||||||
|
console.debug('Retreiving data using authenticated access')
|
||||||
|
}
|
||||||
|
if (process.env.GIT_PEAR_AUTH && process.env.GIT_PEAR_AUTH !== 'native') {
|
||||||
|
payload.header = await auth.getToken(payload.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
const reposRes = await rpc.request('get-repos', Buffer.from(JSON.stringify(payload)))
|
||||||
|
const repositories = JSON.parse(reposRes.toString())
|
||||||
|
if (!repositories) {
|
||||||
|
console.error('Failed to retrieve repositories')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
paylod = { body: { url, method: 'get-acl' } }
|
||||||
|
if (process.env.GIT_PEAR_AUTH && process.env.GIT_PEAR_AUTH !== 'native') {
|
||||||
|
payload.header = await auth.getToken(payload.body)
|
||||||
|
}
|
||||||
|
const repoACL = await rpc.request('get-acl', Buffer.from(JSON.stringify(payload)))
|
||||||
|
console.log('REPO ACL:', JSON.parse(repoACL.toString()))
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
list,
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
const ProtomuxRPC = require('protomux-rpc')
|
|
||||||
|
|
||||||
const Hyperswarm = require('hyperswarm')
|
|
||||||
const crypto = require('hypercore-crypto')
|
|
||||||
|
|
||||||
const home = require('../home')
|
|
||||||
const auth = require('../auth')
|
|
||||||
|
|
||||||
async function list (url) {
|
|
||||||
const matches = url.match(/pear:\/\/([a-f0-9]{64})/)
|
|
||||||
|
|
||||||
if (!matches || matches.length < 2) {
|
|
||||||
console.error('Invalid URL')
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
const targetKey = matches[1]
|
|
||||||
console.log('Connecting to:', targetKey)
|
|
||||||
|
|
||||||
const swarmOpts = {}
|
|
||||||
if (process.env.GIT_PEAR_AUTH === 'native') {
|
|
||||||
swarmOpts.keyPair = home.getKeyPair()
|
|
||||||
}
|
|
||||||
const swarm = new Hyperswarm(swarmOpts)
|
|
||||||
|
|
||||||
swarm.join(crypto.discoveryKey(Buffer.from(targetKey, 'hex')), { server: false })
|
|
||||||
|
|
||||||
swarm.on('connection', async (socket) => {
|
|
||||||
const rpc = new ProtomuxRPC(socket)
|
|
||||||
|
|
||||||
let payload = { body: { url, method: 'get-repos' } }
|
|
||||||
if (!process.env.GIT_PEAR_AUTH) {
|
|
||||||
console.debug('Retreiving data using un-authenticated access')
|
|
||||||
} else {
|
|
||||||
console.debug('Retreiving data using authenticated access')
|
|
||||||
}
|
|
||||||
if (process.env.GIT_PEAR_AUTH && process.env.GIT_PEAR_AUTH !== 'native') {
|
|
||||||
payload.header = await auth.getToken(payload.body)
|
|
||||||
}
|
|
||||||
|
|
||||||
const reposRes = await rpc.request('get-repos', Buffer.from(JSON.stringify(payload)))
|
|
||||||
const repositories = JSON.parse(reposRes.toString())
|
|
||||||
if (!repositories) {
|
|
||||||
console.error('Failed to retrieve repositories')
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
paylod = { body: { url, method: 'get-bpr' } }
|
|
||||||
if (process.env.GIT_PEAR_AUTH && process.env.GIT_PEAR_AUTH !== 'native') {
|
|
||||||
payload.header = await auth.getToken(payload.body)
|
|
||||||
}
|
|
||||||
const bpr = await rpc.request('get-bpr', Buffer.from(JSON.stringify(payload)))
|
|
||||||
console.log('BPR:', JSON.parse(bpr.toString()))
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
list,
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const listRemote = require('./list-remote')
|
const listRemote = require('./list-remote')
|
||||||
const bpr = require('./bpr-remote')
|
const aclRemote = require('./acl-remote')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
listRemote,
|
listRemote,
|
||||||
bpr,
|
aclRemote,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const SecretStream = require('@hyperswarm/secret-stream')
|
|||||||
const { spawn } = require('child_process')
|
const { spawn } = require('child_process')
|
||||||
const home = require('./home')
|
const home = require('./home')
|
||||||
const auth = require('./auth')
|
const auth = require('./auth')
|
||||||
const { git, acl, bpr } = require('./rpc-handlers')
|
const { git, acl } = require('./rpc-handlers')
|
||||||
|
|
||||||
module.exports = class RPC {
|
module.exports = class RPC {
|
||||||
constructor (announcedRefs, repositories, drives) {
|
constructor (announcedRefs, repositories, drives) {
|
||||||
|
|||||||
Reference in New Issue
Block a user