From 024e5611d528a7268cd8000a16ee55e1fefc4d97 Mon Sep 17 00:00:00 2001 From: cyl19970726 <15258378443@163.com> Date: Sun, 26 Feb 2023 18:23:41 +0800 Subject: [PATCH] repo access control --- src/git3/index.ts | 62 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/git3/index.ts b/src/git3/index.ts index 84c8e7a..056a93f 100644 --- a/src/git3/index.ts +++ b/src/git3/index.ts @@ -179,7 +179,7 @@ create create .command("repo") - .argument("", "ex: git3.w3q/repo_name") + .argument("", "ex: git3.w3q/repo_name or hub_addr:chainid/repo_name") .description("create a new repo") .action(async (uri) => { const protocol = await parseGit3URI(uri, { ignoreProtocolHeader: true }) @@ -295,7 +295,7 @@ program }) program - .command("addContributor") + .command("addCon") .argument("", "hub_name.NS or hub_address:chain_id") .argument("", "contributor address") .description("add a manager into hub") @@ -324,7 +324,7 @@ program }) program - .command("removeContributor") + .command("removeCon") .argument("", "hub_name.NS or hub_address:chain_id") .argument("", "contributor address") .description("add a manager into hub") @@ -352,6 +352,62 @@ program console.log(explorerTxUrl(receipt.transactionHash, protocol.netConfig.explorers)) }) +// repo funcitons +let repository = program + .command("repository") + .description("repository related operations") + +repository + .command("members") + .argument("","ex: git3.w3q/repo_name or hub_addr:chainid/repo_name") + .description("get all members information of the repository") + .action(async (uri) => { + let protocol = await parseGit3URI(uri, { ignoreProtocolHeader: true, skipRepoName: true }) + let owner = await protocol.hub.repoOwner(Buffer.from(protocol.repoName)) + let contributors = await protocol.hub.repoContributors(Buffer.from(protocol.repoName)) + + console.log(`owner:${owner} \ncontributors:${contributors}`) + }) + +repository + .command("addCon") + .argument("","ex: git3.w3q/repo_name or hub_addr:chainid/repo_name") + .argument("","contributor address") + .description("add a contributor into the specified repository") + .action(async (uri,conAddr) => { + let protocol = await parseGit3URI(uri, { ignoreProtocolHeader: true, skipRepoName: true }) + let owner = await protocol.hub.repoOwner(Buffer.from(protocol.repoName)) + if (owner != protocol.wallet.address){ + let hubName = protocol.ns + ? `${protocol.nsName}.${protocol.nsDomain}` + : protocol.hubAddress + console.error(`[repo addContributor] can only be executed with the owner authority of this repository:${protocol.repoName}-hub:${hubName}`) + } + const txManager = new TxManager(protocol.hub, protocol.chainId, protocol.netConfig.txConst) + let receipt = await txManager.SendCall("addRepoContributor", [Buffer.from(protocol.repoName),conAddr]) + console.log(explorerTxUrl(receipt.transactionHash, protocol.netConfig.explorers)) + }) + +repository + .command("removeCon") + .argument("","ex: git3.w3q/repo_name or hub_addr:chainid/repo_name") + .argument("","contributor address") + .description("remove a contributor from the specified repository") + .action(async (uri,conAddr) => { + let protocol = await parseGit3URI(uri, { ignoreProtocolHeader: true, skipRepoName: true }) + let owner = await protocol.hub.repoOwner(Buffer.from(protocol.repoName)) + if (owner != protocol.wallet.address){ + let hubName = protocol.ns + ? `${protocol.nsName}.${protocol.nsDomain}` + : protocol.hubAddress + console.error(`[repository removeContributor] can only be executed with the owner authority of this repository:${protocol.repoName}-hub:${hubName}`) + } + const txManager = new TxManager(protocol.hub, protocol.chainId, protocol.netConfig.txConst) + let receipt = await txManager.SendCall("removeRepoContributor", [Buffer.from(protocol.repoName),conAddr]) + console.log(explorerTxUrl(receipt.transactionHash, protocol.netConfig.explorers)) + }) + + program .command("info") .argument("[wallet]", "wallet you want to get info", "default")