From a2a8d4835cbfa01fda4d5ad591af7f9471679374 Mon Sep 17 00:00:00 2001 From: helamanl0424 Date: Thu, 14 Mar 2024 16:26:09 -0600 Subject: [PATCH] Add two functions: grantAgentAccess() and removeAgentAccess() These two functions can grant/remove a resource access to a specific agent(webID) --- pods.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pods.ts b/pods.ts index 45c49e0..fe7bcdc 100644 --- a/pods.ts +++ b/pods.ts @@ -384,6 +384,39 @@ const removeFolder = krl.Action(["containerURL"], async function(containerURL : this.log.debug('Container deleted successfully!\n'); }); +const grantAgentAccess = krl.Action(["resourceURL", "webID"], async function(resourceURL : string, webID : string) { + universalAccess.setAgentAccess( + resourceURL, // resource + webID, // agent + // sample: {"read":false,"write":false,"append":false,"controlRead":false,"controlWrite":false} + { read: true, write: false }, + { fetch: authFetch } // fetch function from authenticated session + ).then((agentAccess) => { + this.log.debug(`For resource::: ${resourceURL}`); + if (agentAccess === null) { + this.log.debug(`Could not load ${webID}'s access details.`); + } else { + this.log.debug(`${webID}'s Access:: ${JSON.stringify(agentAccess)}`); + } + }); +}); + +const removeAgentAccess = krl.Action(["resourceURL", "webID"], async function(resourceURL : string, webID : string) { + universalAccess.setAgentAccess( + resourceURL, // resource + webID, // agent + { read: false, write: false }, + { fetch: authFetch } // fetch function from authenticated session + ).then((agentAccess) => { + this.log.debug(`For resource::: ${resourceURL}`); + if (agentAccess === null) { + this.log.debug(`Could not load ${webID}'s access details.`); + } else { + this.log.debug(`${webID}'s Access:: ${JSON.stringify(agentAccess)}`); + } + }); +}); + const grantAccess = krl.Action(["resourceURL"], async function(resourceUrl: string) { universalAccess.setPublicAccess( resourceUrl, // Resource @@ -438,6 +471,8 @@ const pods: krl.Module = { setTokenURL: setTokenURL, authenticate: authenticate, + grantAgentAccess: grantAgentAccess, + removeAgentAccess: removeAgentAccess, grantAccess: grantAccess, removeAccess: removeAccess, }