Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
id: '',
resource: '',
references: [''],
requiredEngineVersion: '',
version: 0,
description: '',
isPublic: true,
isObjectEnabler: true,
},
authClientTwoLegged,
authToken,
);
// $ExpectType BucketsApi
const bucketsApi = new BucketsApi();
// $ExpectType Promise
bucketsApi.createBucket(
{
bucketKey: '',
policyKey: 'transient',
},
{},
authClientTwoLegged,
authToken,
);
// $ExpectType Promise
bucketsApi.deleteBucket('', authClientTwoLegged, authToken);
// $ExpectType Promise
bucketsApi.getBucketDetails('', authClientTwoLegged, authToken);
// $ExpectType Promise
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, '') +
user.resourceName.split('/')[1]
).toLowerCase();
var buckets = new ForgeSDK.BucketsApi();
var objects = new ForgeSDK.ObjectsApi();
var postBuckets = new ForgeSDK.PostBucketsPayload();
postBuckets.bucketKey = ossBucketKey;
postBuckets.policyKey = "transient"; // expires in 24h
buckets.createBucket(postBuckets, {}, null, tokenInternal).catch(function (err) {console.log(err);}).then(function () {
// need the Google file information to get the name...
drive.files.get({
fileId: googleFileId
}, function (err, fileInfo) {
var fileName = fileInfo.title;
var ossObjectName = googleFileId + '.' + re.exec(fileName)[1]; // googleId + fileExtension (required)
// at this point the bucket exists (either created or already there)
objects.getObjects(ossBucketKey, {'limit': 100}, null, tokenInternal).then(function (response) {
var alreadyTranslated = false;
var createApplicationBucket =function () {
// Ok, now it might be the first time we run that sample on this account key-pair
// and the bucket may not exists yet! so create it now otherwise we will get into trouble later.
var sdk =new ForgeSDK.BucketsApi () ;
sdk.getBucketDetails (config.bucket, oAuth2TwoLegged, oAuth2TwoLegged.getCredentials ())
.then (function (bucket) {
// We are all good! :)
console.log (config.bucket, 'present!') ;
})
.catch (function (error) {
console.error (config.bucket, 'does not exist?', error) ;
if ( error.statusCode === 404 ) {
console.log ('Creating bucket: ', config.bucket) ;
sdk.createBucket ({ bucketKey: config.bucket, policyKey: 'persistent' }, {}, oAuth2TwoLegged, oAuth2TwoLegged.getCredentials ())
.then (function (response) {
// We are all good now! :)
console.log (config.bucket, 'created! -') ;
})
.catch (function (error) {
console.error (config.bucket, 'could not be created! - ', error) ;
.then((oa2legged) => {
let ossBuckets = new ForgeAPI.BucketsApi();
return (ossBuckets.deleteBucket(bucketKey, oa2legged, oa2legged.getCredentials()));
})
.then((response) => { // eslint-disable-line no-unused-vars
function ExistOrCreate (bucketKey, oAuth2) {
console.log ('Check Bucket if bucket exists...') ;
var ossBuckets =new ForgeApis.BucketsApi () ;
return (ossBuckets.getBucketDetails (bucketKey, oAuth2, oAuth2.getCredentials ())
.then (function (results) {
return (results) ;
})
.catch (function (error) {
console.log ('Create Bucket...') ;
var opts ={
bucketKey: bucketKey,
policyKey: 'persistent'
} ;
var headers ={
xAdsRegion: 'US'
} ;
return (ossBuckets.createBucket (opts, headers, oAuth2, oAuth2.getCredentials ())) ;
})
) ;
constructor (config) {
super(config)
this._bucketsAPI = new Forge.BucketsApi()
this._objectsAPI = new Forge.ObjectsApi()
}
constructor (config) {
super(config)
this._bucketsAPI = new Forge.BucketsApi()
this._objectsAPI = new Forge.ObjectsApi()
}
.then((oa2legged) => {
let ossBuckets = new ForgeAPI.BucketsApi();
let opts = {
bucketKey: bucketKey,
policyKey: type
};
if (authid && access)
opts.allow = { authid: authid, access: access };
let headers = {
'xAdsRegion': region
};
return (ossBuckets.createBucket(opts, headers, oa2legged, oa2legged.getCredentials()));
})
.then((bucket) => {
.then((oa2legged) => {
let ossBuckets = new ForgeAPI.BucketsApi();
return (ossBuckets.getBuckets(opts, oa2legged, oa2legged.getCredentials()));
})
.then((buckets) => {