rpc-req: fix list auth

Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
dzdidi
2024-02-11 17:00:49 +00:00
parent 76dca8b5e6
commit 638d379ec9
2 changed files with 9 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
const list-remote = require('./list-remote') const listRemote = require('./list-remote')
module.exports = { module.exports = {
list-remote, listRemote,
} }

View File

@@ -3,8 +3,8 @@ const ProtomuxRPC = require('protomux-rpc')
const Hyperswarm = require('hyperswarm') const Hyperswarm = require('hyperswarm')
const crypto = require('hypercore-crypto') const crypto = require('hypercore-crypto')
const home = require('./home') const home = require('../home')
const auth = require('./auth') const auth = require('../auth')
module.exports = async function listRemote (url) { module.exports = async function listRemote (url) {
const matches = url.match(/pear:\/\/([a-f0-9]{64})/) const matches = url.match(/pear:\/\/([a-f0-9]{64})/)
@@ -29,13 +29,14 @@ module.exports = async function listRemote (url) {
const rpc = new ProtomuxRPC(socket) const rpc = new ProtomuxRPC(socket)
let payload = { body: { url, method: 'get-repos' } } 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') { if (process.env.GIT_PEAR_AUTH && process.env.GIT_PEAR_AUTH !== 'native') {
payload.header = await auth.getToken(payload.body) payload.header = await auth.getToken(payload.body)
console.debug('Retreiving data using authenticated access')
} else {
console.debug('Retreiving data using un-authenticated access')
} }
console.log()
const reposRes = await rpc.request('get-repos', Buffer.from(JSON.stringify(payload))) const reposRes = await rpc.request('get-repos', Buffer.from(JSON.stringify(payload)))
const repositories = JSON.parse(reposRes.toString()) const repositories = JSON.parse(reposRes.toString())