Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function leaseBlob(callback) {
// Create a blob client for interacting with the blob service from connection string
// How to create a storage connection string - http://msdn.microsoft.com/en-us/library/azure/ee758697.aspx
var blobService = storage.createBlobService(config.connectionString);
var containerName = "demoleaseblobcontainer-" + guid.v1();
var blobName = 'exclusive';
console.log('1. Create Container');
blobService.createContainerIfNotExists(containerName, function (error) {
if (error) return callback(error);
console.log('2. Create blob');
blobService.createBlockBlobFromText(containerName, blobName, 'blob created', function (error) {
if (error) return callback(error);
console.log('3. Acquire lease on blob');
blobService.acquireLease(containerName, blobName, { leaseDuration: 15 }, function (error, leaseResult) {
if (error) return callback(error);
constructor(account, secret, container, options = DEFAULT_OPTIONS) {
if (account && REQUIRED_BLOB_SERVICE_APIS.every(name => typeof account[name] === 'function')) {
// If account looks like a BlobService (with all of our required APIs), then use it
this._blobService = account;
container = secret;
options = container;
} else {
this._blobService = require('azure-storage').createBlobService(account, secret);
}
this.options = options;
this._blobServicePromised = promisifyObject(
this._blobService,
REQUIRED_BLOB_SERVICE_APIS
);
this.container = container;
this.promise = {};
[
'mkdir',
'open',
'readdir',
module.exports = ctx => {
let blob = az.createBlobService(process.env.MMLSparkStorage);
let gh = new ghAPI();
let timeStamp = new Date().toISOString()
.replace(/:[0-9][0-9]\.[0-9]+Z/, "").replace(/T/, " ");
let getPaged = (state, combine) => r =>
!gh.hasNextPage(r) ? Promise.resolve(combine(state, r.data))
: gh.getNextPage(r).then(getPaged(combine(state, r.data), combine));
let getAllContributors = getPaged([], (st,d) => st.concat(d.map(x => x.login)))
let getAllIssues = getPaged([[],[]], (st,d) =>
[st[0].concat(d.filter(x => !("pull_request" in x)).map(x => "#"+x.number)),
st[1].concat(d.filter(x => ("pull_request" in x)).map(x => "#"+x.number))])
// To initialize the append blob (delete the rest when doing this to avoid races):
// blob.createAppendBlobFromText("stats", "log", `initial text`,
// (err) => { if (err) ctx.done(err); else { ctx.log(">>> DONE!"); ctx.done(); }});
}
});
});
}
async function uploadFiles() {
const fileNames = listFilesInDirectory(mediaPath);
for (const fileName of fileNames) {
const blobName = path.basename(fileName).split(".")[0];
console.log(`Uploading file: ${blobName}`);
await upload(fileName, blobName);
}
}
const blobService = storage.createBlobService(connectionString);
uploadFiles()
.then(() => {
console.log("DONE");
process.exit();
})
.catch(error => {
console.log(error);
})
module.exports = function SkipperAzure( globalOptions ) {
globalOptions = globalOptions || {};
var blobService = azure.createBlobService( globalOptions.key,
globalOptions.secret );
var adapter = {
read: function( fd, cb ) {
var prefix = fd;
var res = blobService.createReadStream( globalOptions.container, prefix, function( err ) {
if ( err ) {
cb( err );
}
});
res.pipe(concat(function (data) {
return cb(null, data);
}));
function uploadFile(container, fileName, path, expiryMinutes) {
const client = azure.createBlobService(userFilesBlobAccountName, userFilesBlobAccountKey);
return new Promise((resolve, reject) => {
client.createContainerIfNotExists(container, (error) => {
if (error) return reject(error);
client.createBlockBlobFromLocalFile(container, fileName, path, (error) => {
if (error) return reject(error);
const expires = minutesFromNow(expiryMinutes);
const accessSignature = client.generateSharedAccessSignature(container, fileName, { AccessPolicy: { Expiry: expires, Permissions: READ } });
const url = client.getUrl(container, fileName, accessSignature, true);
resolve({
url,
expires
});
var doUpload = function () {
var blobService = azure.createBlobService();
var container = field.options.containerFormatter(item, file.name);
blobService.createContainerIfNotExists(container, { publicAccessLevel: 'blob' }, function (err) {
if (err) return callback(err);
blobService.createBlockBlobFromLocalFile(container, field.options.filenameFormatter(item, file.name), file.path, function (err, blob, res) {
if (err) return callback(err);
var fileData = {
filename: blob.blob,
size: file.size,
filetype: filetype,
etag: blob.etag,
container: container,
azureUseConnectionString = true;
}
if (!opts.containerName) missingParameters.push("containerName")
if (missingParameters.length > 0) {
throw new Error('Missing required parameter' + (missingParameters.length > 1 ? 's' : '') + ' from the options of MulterAzureStorage: ' + missingParameters.join(', '))
}
this.containerName = opts.containerName
this.fileName = opts.fileName
if(azureUseConnectionString){
this.blobService = azure.createBlobService(opts.azureStorageConnectionString)
} else {
this.blobService = azure.createBlobService(
opts.azureStorageAccount,
opts.azureStorageAccessKey)
}
let security = opts.containerSecurity || defaultSecurity
this.blobService.createContainerIfNotExists(this.containerName, { publicAccessLevel : security }, (err, result, response) => {
if (err) {
this.containerError = true
throw new Error('Cannot use container. Check if provided options are correct.')
}
this.containerCreated = true
const azure = require('azure-storage')
const config = require('../../config')
const blobService = config.AZURE_STORAGE_CONNECTION_STRING ? azure.createBlobService() : {
createBlockBlobFromText: () => { return { name: 'test_error.csv' } },
getBlobToText: () => 'text',
getBlobToStream: (container, blob, fStream, cb) => {
fStream.write('binary')
fStream.end()
cb()
},
createContainerIfNotExists: () => {}
}
const azureUploadFile = async (container, remoteFilename, text, streamLength) => {
await new Promise((resolve, reject) => {
blobService.createContainerIfNotExists(container, null, (error) => {
if (error) reject(error)
resolve()
})
constructor(connectionString: string) {
var self = this;
this.blobService = createBlobService(connectionString);
this.blobService.createContainerIfNotExists(this.containerId, (error: Error, result: BlobService.ContainerResult, response: ServiceResponse): void => {
//TODO: log
self.renewTimer = setInterval(this.renewLeases, 45, self);
});
}