Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getMetadata() {
// Get the project information from GCP
if (!dryRunMode) projectId = await google.auth.getProjectId();
if (!dryRunMode) zone_name = await getZoneName();
if (!dryRunMode) cluster_name = await getClusterName();
}
async function _get_recent_email(credentials_json, token_path, options = {}) {
const emails = [];
const query = _init_query(options);
// Load client secrets from a local file.
const content = fs.readFileSync(credentials_json);
const oAuth2Client = await gmail.authorize(JSON.parse(content), token_path);
const gmail_client = google.gmail({ version: "v1", oAuth2Client });
const gmail_emails = await gmail.get_recent_email(
gmail_client,
oAuth2Client,
query
);
for (const gmail_email of gmail_emails) {
const email = {
from: _get_header("From", gmail_email.payload.headers),
subject: _get_header("Subject", gmail_email.payload.headers),
receiver: _get_header("Delivered-To", gmail_email.payload.headers)
};
if (options.include_body) {
let email_body = {
html: "",
text: ""
};
function uploadDatabaseDump(auth) {
const drive = google.drive({ version: 'v3', auth });
// get file path from arguments
const [, , inputFilePath] = process.argv;
if (!inputFilePath) {
console.error('Error: No filename was specified in arguments');
process.exit(1);
}
drive.files.list(
{
q:
"name='Database Dumps' and mimeType='application/vnd.google-apps.folder'",
},
(err, listFileResponse) => {
if (err) {
throw err;
}
) {
throw new JovoError(
'Please add a valid keyFile object to the GoogleAssistant transaction config',
ErrorCode.ERR,
'jovo-platform-googleassistant',
);
}
/**
* DigitalGoods.ts needs the googleapis package to function.
* To reduce overall package size, googleapis wasn't added as a dependency.
* googleapis has to be manually installed
*/
try {
const googleapis = require('googleapis').google;
return googleapis.auth
.getClient({
keyFile: this.googleAssistant.config.transactions!.keyFile,
scopes: ['https://www.googleapis.com/auth/actions.purchases.digital'],
})
.then((client: any) => client.authorize()) // tslint:disable-line
.then((authorization: any) => authorization.access_token as string); // tslint:disable-line
} catch (e) {
console.log(e);
console.log(e.stack);
if (e.message === "Cannot find module 'googleapis'") {
return Promise.reject(
new JovoError(
e.message,
ErrorCode.ERR,
'jovo-platform-googleassistant',
undefined,
async function listVMs() {
// [START auth]
const authClient = await google.auth.getClient({
scopes: [
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/compute',
'https://www.googleapis.com/auth/compute.readonly',
],
});
// [END auth]
// [START list]
const projectId = await google.auth.getProjectId();
const result = await compute.instances.aggregatedList({
auth: authClient,
project: projectId,
});
const vms = result.data;
console.log('VMs:', vms);
console.log('Google credentials not set, skip Gdrive initialization.');
return;
}
const { token, secrets } = JSON.parse(process.env.GOOGLE_CREDENTIALS);
// Authorize a client with the loaded credentials, then call the
// Drive API.
const clientSecret = secrets.installed.client_secret;
const clientId = secrets.installed.client_id;
const redirectUrl = secrets.installed.redirect_uris[0];
const oauth2Client = new OAuth2(clientId, clientSecret, redirectUrl);
// Check if we have previously stored a token.
oauth2Client.setCredentials(token);
drive = google.drive({ version: 'v3', auth: oauth2Client });
}
const main = async () => {
const auth = await google.auth.getClient({ scopes: SCOPES });
const sheets = google.sheets({ version: 'v4', auth });
const token = (await fs.readFile('githubToken.json')).toString().trim();
const octokit = new Octokit({ auth: `token ${token}` });
const drive = google.drive({ version: 'v3', auth })
await deleteAllFiles(drive);
// const title = 'Statistics from GitHub and food survey for I/O talk';
// let id = await checkForSheet(drive, title);
// if (!id) {
// id = await createSpreadsheet(sheets, title);
// await writeHeader(sheets, id, 0);
// await addUser(drive, id, 'fhinkel.demo@gmail.com');
// await addUser(drive, id, 'GSuite.demos@gmail.com');
// }
// let cloneData = await numberOfClones(octokit);
// await appendCloneData(sheets, id, cloneData);
}
)
pointError.code = 'POINTS_OVER_MAXIMUM'
throw pointError
}
if (!point_types.includes(type)) {
const typeError = new Error(
`Invalid point type '${type}'. Please use one of ${point_types}.`
)
typeError.code = 'POINT_TYPE_DOES_NOT_EXIST'
throw typeError
}
users = users.split(',')
const sheets = google.sheets({ version: 'v4', auth })
var values = []
users.forEach(user => {
user = user.trim()
let { userInRoom, receiver, display_name, multipleUsers } = findReceiver(
room,
user
) // try to find user
// handle github users
const BASE_GITHUB_URL = 'https://github.com/'
if (user.split(BASE_GITHUB_URL)[1]) {
receiver = user
;(userInRoom = true), (multipleUsers = false)
}
var token = req.query.token;
var filename = req.query.filename || "temp_file";
// writing to the Firebase log https://firebase.google.com/docs/functions/writing-and-viewing-logs
console.log(filename);
// handling auth to write file to Drive
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2();
oauth2Client.setCredentials({
access_token: token
});
// setting Drive access
var drive = google.drive('v3');
var media = {
body: request(req.query.url) //stream!
};
// create file on Drive
drive.files.create({
resource: {'name': filename},
media: media,
fields: 'id',
auth: oauth2Client
}, function(err, file) {
if (err) {
// Handle error
console.log(err);
res.send(err);
tokenSession.getTokenInternal(function (tokenInternal) {
oauth2Client.setCredentials({
access_token: tokenSession.getGoogleToken()
});
var drive = google.drive({version: 'v2', auth: oauth2Client});
var people = google.people({version: 'v1', auth: oauth2Client});
people.people.get({ resourceName: 'people/me', personFields: 'emailAddresses,names' }, function (err, user) {
if (err || user == null) {
console.log('model.derivative.google.drive.integration:sentToTranslation:google.user.get => ' + err);
res.status(500).json({error: 'Cannot get Google user information, please try again.'});
return;
}
// ForgeSDK OSS Bucket Name: username + userId (no spaces, lower case)
// that way we have one bucket for each Google account using this application
var ossBucketKey =
config.credentials.client_id.toLowerCase() +
(
user.names[0].displayName.replace(/\W+/g, '') +