From 4ef1ad74c4f32fab8d2424f097b0fa35647f5648 Mon Sep 17 00:00:00 2001 From: dzdidi Date: Mon, 12 Feb 2024 15:15:09 +0000 Subject: [PATCH] debugs Signed-off-by: dzdidi --- src/cli.js | 29 ++++++++++------ src/rpc-handlers/index.js | 2 -- src/rpc-requests/acl-remote.js | 61 ++++++++++++++++++++++++++++++++++ src/rpc-requests/bpr-remote.js | 61 ---------------------------------- src/rpc-requests/index.js | 4 +-- src/rpc.js | 2 +- 6 files changed, 83 insertions(+), 76 deletions(-) delete mode 100644 src/rpc-requests/bpr-remote.js diff --git a/src/cli.js b/src/cli.js index 5a0f95f..401c240 100755 --- a/src/cli.js +++ b/src/cli.js @@ -12,7 +12,7 @@ const home = require('./home') const acl = require('./acl') const git = require('./git') -const { listRemote, bpr } = require('./rpc-requests') +const { listRemote, aclRemote } = require('./rpc-requests') const pkg = require('../package.json') program @@ -94,11 +94,11 @@ program 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 (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('Protected Branch(s):', '\t', repoACL.protectedBranches.join(', ')) @@ -108,17 +108,22 @@ program return } - if (options.user) { - if (p.startsWith('pear://') || n.startsWith('pear://')) { - // XXX + if (p.startsWith('pear://')) { + 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) } else { localACL(a, n, p, options) } } else if (options.branch) { - if (p.startsWith('pear://') || n.startsWith('pear://')) { - // XXX + if (p.startsWith('pear://')) { + 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) } else { localBranchProtectionRules(a, n, p, options) @@ -305,7 +310,7 @@ function localACL(a, u, p, options) { async function remoteBranchProtectionRules(a, b, p, options) { 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(', ')) } -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)) } @@ -358,5 +366,6 @@ async function getLocalACL(p) { } async function getRemoteACL(p) { + console.log('getting remote acl') } program.parse() diff --git a/src/rpc-handlers/index.js b/src/rpc-handlers/index.js index bf2cd87..4027ecb 100644 --- a/src/rpc-handlers/index.js +++ b/src/rpc-handlers/index.js @@ -1,9 +1,7 @@ const git = require('./git') const acl = require('./acl') -const bpr = require('./bpr') module.exports = { git, acl, - bpr, } diff --git a/src/rpc-requests/acl-remote.js b/src/rpc-requests/acl-remote.js index e69de29..6d5dbaf 100644 --- a/src/rpc-requests/acl-remote.js +++ b/src/rpc-requests/acl-remote.js @@ -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, +} diff --git a/src/rpc-requests/bpr-remote.js b/src/rpc-requests/bpr-remote.js deleted file mode 100644 index f1ffdd5..0000000 --- a/src/rpc-requests/bpr-remote.js +++ /dev/null @@ -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, -} diff --git a/src/rpc-requests/index.js b/src/rpc-requests/index.js index 785437d..01e7653 100644 --- a/src/rpc-requests/index.js +++ b/src/rpc-requests/index.js @@ -1,7 +1,7 @@ const listRemote = require('./list-remote') -const bpr = require('./bpr-remote') +const aclRemote = require('./acl-remote') module.exports = { listRemote, - bpr, + aclRemote, } diff --git a/src/rpc.js b/src/rpc.js index 6e03cfd..6241255 100755 --- a/src/rpc.js +++ b/src/rpc.js @@ -3,7 +3,7 @@ const SecretStream = require('@hyperswarm/secret-stream') const { spawn } = require('child_process') const home = require('./home') const auth = require('./auth') -const { git, acl, bpr } = require('./rpc-handlers') +const { git, acl } = require('./rpc-handlers') module.exports = class RPC { constructor (announcedRefs, repositories, drives) {