Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(workspace): environment var for admin mail #303

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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