Home > Net >  Is there a way to restrict which functions could be called through google.script.run?
Is there a way to restrict which functions could be called through google.script.run?

Time:02-23

I just deployed my first google apps script web app. However, I'm concerned about all the functions defined in the code.gs. They could be called by anyone with access to the dev console in chrome. They could call google.script.run on any of them.

Some of those functions are there only as a foundation to use in other functions (example below). Is there a way to restrict which functions could be called through google.script.run?

function openRentManagerDatabase (spreaSheetId) {
    return SpreadsheetApp.openByIspreadsheetId);
}

CodePudding user response:

Yes, you can do it.

add _after function name, that way it will become a private function and will become inaccessible for google.script.run.

It will look like this:-

function openRentManagerDatabase_(spreaSheetId) {
    return SpreadsheetApp.openByIspreadsheetId);
}

Do note that making it private means you can't run it directly from appscript editor by selecting it.

So when you want to run it by calling it through another function, you have to use _ everytime, just like this openRentManagerDatabase_().

Reference:

Private functions

  • Related