Skip to content

Commit

Permalink
Add two functions: grantAgentAccess() and removeAgentAccess()
Browse files Browse the repository at this point in the history
These two functions can grant/remove a resource access to a specific agent(webID)
  • Loading branch information
helamanl0424 authored Mar 14, 2024
1 parent 7d8d25a commit a2a8d48
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -438,6 +471,8 @@ const pods: krl.Module = {
setTokenURL: setTokenURL,

authenticate: authenticate,
grantAgentAccess: grantAgentAccess,
removeAgentAccess: removeAgentAccess,
grantAccess: grantAccess,
removeAccess: removeAccess,
}
Expand Down

0 comments on commit a2a8d48

Please sign in to comment.