Skip to content

Commit

Permalink
Merge pull request #303 from kexa-io/update-adrien-database-conf
Browse files Browse the repository at this point in the history
fix(workspace): environment var for admin mail
  • Loading branch information
aeppling authored Nov 27, 2024
2 parents 21f673a + 16941f2 commit fec41f4
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions Kexa/services/addOn/googleWorkspaceGathering.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ const path = require('path');
const {authenticate} = require('@google-cloud/local-auth');
const {google} = require('googleapis');
let currentConfig: googleWorkspaceConfig;
import { JWT } from 'google-auth-library';

/////////////////////////////////////////
////// LISTING CLOUD RESOURCES /////
/////////////////////////////////////////


//////////////////////////////////
// DELETE NOT READ ONLY AND TRY //
//////////////////////////////////
const SCOPES = [
'https://www.googleapis.com/auth/admin.directory.user',
'https://www.googleapis.com/auth/admin.directory.domain',
Expand Down Expand Up @@ -81,8 +77,8 @@ export async function collectData(googleWorkspaceConfig:googleWorkspaceConfig[])
try {
let prefix = config.prefix??(googleWorkspaceConfig.indexOf(config).toString());

const workspaceAdmin = await getConfigOrEnvVar(config, "WORKSPACEADMIN", prefix);
const workspaceEnvCredentials = await getConfigOrEnvVar(config, "WORKSPACECRED", prefix);
const workspaceToken = await getConfigOrEnvVar(config, "WORKSPACETOKEN", prefix);

if (workspaceEnvCredentials && workspaceEnvCredentials.includes(".json")) {
const workCred = getFile(JSON.parse(JSON.stringify(workspaceEnvCredentials)));
Expand All @@ -93,7 +89,7 @@ export async function collectData(googleWorkspaceConfig:googleWorkspaceConfig[])
}
if (process.env[googleWorkspaceConfig.indexOf(config)+"-WORKSPACETOKEN"])
writeStringToJsonFile(await getConfigOrEnvVar(config, "WORKSPACETOKEN", prefix), "./config/token_workspace.json");
let auth = await authorizeSP(); // for service account
let auth = await authorizeSP(workspaceAdmin);
if (workspaceEnvCredentials) {
if (workspaceEnvCredentials.includes(".json")) {
const workCred = getFile(JSON.parse(JSON.stringify(workspaceEnvCredentials)));
Expand Down Expand Up @@ -164,23 +160,11 @@ async function saveCredentials(client: any) {
await fs.writeFile(TOKEN_PATH, payload);
}

const authorizeWithToken = async (scopes: string[], user: string)=>{

const SRVC_ACCOUNT_CREDS = getFile(CREDENTIALS_PATH);

const auth = new google.auth.GoogleAuth({
credentials: SRVC_ACCOUNT_CREDS
// scopes: scopes
});
const client = await auth.getClient();
return client;
};

async function authorizeSP() {
async function authorizeSP(workspaceAdmin: string) {
const client = new google.auth.JWT({
keyFile: CREDENTIALS_PATH,
scopes: SCOPES,
subject: '[email protected]',
subject: workspaceAdmin
});

return client;
Expand Down

0 comments on commit fec41f4

Please sign in to comment.