0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 18:42:40 +00:00

Merge pull request #4352 from G-Ambatte/experimentalGoogleServiceAccountChange

Add Google service account to file permissions
This commit is contained in:
Víctor Losada Hernández
2025-11-24 17:52:21 +01:00
committed by GitHub

View File

@@ -6,6 +6,7 @@ import config from './config.js';
let serviceAuth; let serviceAuth;
let clientEmail;
if(!config.get('service_account')){ if(!config.get('service_account')){
const reset = '\x1b[0m'; // Reset to default style const reset = '\x1b[0m'; // Reset to default style
const yellow = '\x1b[33m'; // yellow color const yellow = '\x1b[33m'; // yellow color
@@ -15,6 +16,10 @@ if(!config.get('service_account')){
JSON.parse(config.get('service_account')) : JSON.parse(config.get('service_account')) :
config.get('service_account'); config.get('service_account');
if(keys?.client_email) {
clientEmail = keys.client_email;
}
try { try {
serviceAuth = googleDrive.auth.fromJSON(keys); serviceAuth = googleDrive.auth.fromJSON(keys);
serviceAuth.scopes = ['https://www.googleapis.com/auth/drive']; serviceAuth.scopes = ['https://www.googleapis.com/auth/drive'];
@@ -227,14 +232,30 @@ const GoogleActions = {
if(!obj) return; if(!obj) return;
if(clientEmail) {
await drive.permissions.create({
resource : {
type : 'user',
emailAddress : clientEmail,
role : 'writer'
},
fileId : obj.data.id,
fields : 'id',
})
.catch((err)=>{
console.log('Error adding Service Account permissions on Google Drive file');
console.error(err);
});
}
await drive.permissions.create({ await drive.permissions.create({
resource : { type : 'anyone', resource : { type : 'anyone',
role : 'writer' }, role : 'writer' },
fileId : obj.data.id, fileId : obj.data.id,
fields : 'id', fields : 'id',
}) })
.catch((err)=>{ .catch((err)=>{
console.log('Error updating permissions'); console.log('Error adding "Anyone" permissions on Google Drive file');
console.error(err); console.error(err);
}); });