Skip to content

Commit

Permalink
Integrate grant/removePublicAccess() to one function and clean up unn…
Browse files Browse the repository at this point in the history
…ecessary comments
  • Loading branch information
helamanl0424 authored Apr 11, 2024
1 parent 5b66256 commit ba20d7f
Showing 1 changed file with 7 additions and 34 deletions.
41 changes: 7 additions & 34 deletions pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const getStorage = krl.Function([], async function() : Promise<string | undefine
return this.rsCtx.getEnt(STORAGE_ENT_NAME);
});
const setStorage = krl.Action(["new_URL"], async function(new_URL : string | undefined) {
//new_URL = standardizeURL(new_URL);
this.rsCtx.putEnt(STORAGE_ENT_NAME, new_URL);
});
const getClientID = krl.Function([], async function() : Promise<string | undefined> {
Expand Down Expand Up @@ -262,16 +261,8 @@ const store = krl.Action(["originURL", "destinationURL", "doAutoAuth"],
}
}

//Used to check file size prior to loading a file into memory
//Considered unnecessary
/*const size = getFileSize(fileURL);
if (await size / (1024*1024) > LIMIT) {
throw "The file size exceed 500 MB";
}*/

let file : File = await getNonPodFile(this, [originURL, destinationURL, FUNCTION_NAME])

//let checkedDestinationURL = checkFileURL(destinationURL, file.name);
this.log.debug("Destination: " + destinationURL);

saveFileInContainer(
Expand Down Expand Up @@ -304,7 +295,6 @@ const overwrite = krl.Action(["originURL", "destinationURL", "doAutoAuth"],

let file : File = await getNonPodFile(this, [originURL, destinationURL, FUNCTION_NAME]);

//let checkedDestinationURL = checkFileURL(destinationURL, file.name);
this.log.debug("Destination: " + destinationURL);

overwriteFile(
Expand Down Expand Up @@ -576,47 +566,31 @@ const getPublicAccess = krl.Function(["resourceURL", "doAutoAuth"], async functi
}
});

const grantPublicAccess = krl.Action(["resourceURL", "doAutoAuth"], async function(resourceURL: string, doAutoAuth : Boolean = true) {
const setPublicAccess = krl.Action(["resourceURL", "read", "write", "append", "doAutoAuth"],
async function(resourceURL: string, read : boolean, write : boolean = false, append : boolean = false, doAutoAuth : Boolean = true) {
if (doAutoAuth) {
if (!await autoAuth(this, [])) {
throw MODULE_NAME + ":grantPublicAccess could not validate Pod access token.";
}
}
universalAccess.setPublicAccess(
resourceURL, // Resource
{ read: true, write: false }, // Access object
{ fetch: authFetch } // fetch function from authenticated session
).then((newAccess) => {
if (newAccess === null) {
this.log.debug("Could not load access details for this Resource.");
} else {
this.log.debug("Returned Public Access:: ", JSON.stringify(newAccess));
}
});
});
const removePublicAccess = krl.Action(["resourceURL", "doAutoAuth"], async function removeAccess(resourceURL: string, doAutoAuth : Boolean = true) {
if (doAutoAuth) {
if (!await autoAuth(this, [])) {
throw MODULE_NAME + ":removePublicAccess could not validate Pod access token.";
}
}
universalAccess.setPublicAccess(
resourceURL, // Resource
{ read: false, write: false }, // Access object
{ read: read, write: write, append: append }, // Access object
{ fetch: authFetch } // fetch function from authenticated session
).then((newAccess) => {
).then((newAccess) => {
if (newAccess === null) {
this.log.debug("Could not load access details for this Resource.");
} else {
this.log.debug("Returned Public Access:: ", JSON.stringify(newAccess));
}
});
});
});






const pods: krl.Module = {
connectStorage: connectStorage,
disconnectStorage: disconnectStorage,
Expand Down Expand Up @@ -647,8 +621,7 @@ const pods: krl.Module = {
grantAgentAccess: grantAgentAccess,
removeAgentAccess: removeAgentAccess,
getPublicAccess: getPublicAccess,
grantPublicAccess: grantPublicAccess,
removePublicAccess: removePublicAccess,
setPublicAccess: setPublicAccess,
}

export default pods;

0 comments on commit ba20d7f

Please sign in to comment.