Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Set azure table name
subClass.prototype.__table = options.table;
// Create an azure table client
var client = null;
if (options.account) {
// If we're setting up to fetch credentials for auth.taskcluster.net
assert(typeof(options.account) === 'string',
"Expected options.account to be a string, or undefined");
// Create auth client to fetch SAS from auth.taskcluster.net
var auth = new taskcluster.Auth({
credentials: options.credentials,
baseUrl: options.authBaseUrl
});
// Create azure table client with logic for fetch SAS
client = new azure.Table({
timeout: AZURE_TABLE_TIMEOUT,
agent: options.agent,
accountId: options.account,
minSASAuthExpiry: options.minSASAuthExpiry,
sas: function() {
return auth.azureTableSAS(
options.account,
options.table
).then(function(result) {
return result.sas;
});
}
});
} else {
// Create client using credentials already present
assert(options.credentials.accountName, "Missing accountName");
// read-write to grant read-only permissions as well
await req.authorize({
account,
table: tableName,
level,
levelIsReadOnly: level === 'read-only',
});
// Check that the account exists
if (!this.azureAccounts[account]) {
return res.reportError('ResourceNotFound',
`Account '${account}' not found, can't delegate access`);
}
// Construct client
let table = new azure.Table({
accountId: account,
accessKey: this.azureAccounts[account],
});
// Create table, ignore error, if it already exists
if (level === 'read-write') {
// only try to create if we haven't done so in this process recently
const key = `${account}/${tableName}`;
if (!tableLastCreated[key] || new Date() - tableLastCreated[key] > 6 * 3600 * 1000) {
try {
await table.createTable(tableName);
} catch (err) {
if (err.code !== 'TableAlreadyExists') {
throw err;
}
}
// Set azure table name
subClass.prototype.__table = options.table;
// Create an azure table client
var client = null;
if (options.account) {
// If we're setting up to fetch credentials for auth.taskcluster.net
assert(typeof(options.account) === 'string',
"Expected options.account to be a string, or undefined");
// Create auth client to fetch SAS from auth.taskcluster.net
var auth = new taskcluster.Auth({
credentials: options.credentials,
baseUrl: options.authBaseUrl
});
// Create azure table client with logic for fetch SAS
client = new azure.Table({
timeout: AZURE_TABLE_TIMEOUT,
agent: options.agent,
accountId: options.account,
minSASAuthExpiry: options.minSASAuthExpiry,
sas: function() {
return auth.azureTableSAS(
options.account,
options.table
).then(function(result) {
return result.sas;
});
}
});
} else {
// Create client using credentials already present
assert(options.credentials.accountName, "Missing accountName");
const backupTable = async ({azureCreds, s3, bucket, tableName, utils}) => {
const stream = new zlib.createGzip();
const table = new azure.Table(azureCreds);
// Versioning is enabled in the backups bucket so we just overwrite the
// previous backup every time. The bucket is configured to delete previous
// versions after N days, but the current version will never be deleted.
const upload = s3.upload({
Bucket: bucket,
Key: `${azureCreds.accountId}/table/${tableName}`,
Body: stream,
StorageClass: 'STANDARD_IA',
}).promise();
const processEntities = entities => entities.map(
entity => stream.write(JSON.stringify(entity) + '\n'));
let count = 0;
let nextUpdateCount = 1000;
if (!req.satisfies({
account: account,
table: tableName
})) {
return;
}
// Check that the account exists
if (!this.azureAccounts[account]) {
return res.status(404).json({
message: "Account '" + account + "' not found, can't delegate access"
});
}
// Construct client
var table = new azure.Table({
accountId: account,
accessKey: this.azureAccounts[account]
});
// Create table ignore error, if it already exists
try {
await table.createTable(tableName);
} catch (err) {
if (err.code !== 'TableAlreadyExists') {
throw err;
}
}
// Construct SAS
var expiry = new Date(Date.now() + 25 * 60 * 1000);
var sas = table.sas(tableName, {
if (!inmemory) {
inmemory = require('./inmemory'); // lazy-loaded
}
subClass.prototype.__table = options.tableName;
subClass.prototype.__filterBuilder = inmemory.appendFilter;
subClass.prototype.__aux = new inmemory.InMemoryWrapper(options.tableName);
subClass.prototype.__client = {};
return subClass;
}
// Set azure table name
subClass.prototype.__table = options.tableName;
// Create an azure table client
const client = new azure.Table(_.defaults({
timeout: AZURE_TABLE_TIMEOUT,
agent: options.agent,
}, options.credentials));
// Store reference to azure table client
subClass.prototype.__client = client;
// set the filter builder
subClass.prototype.__filterBuilder = entityfilters.appendFilter;
// Create table client wrapper, to record statistics and bind table name
subClass.prototype.__aux = {};
[
'createTable',
'deleteTable',
'getEntity',
let restoreTable = async ({azureCreds, s3, bucket, tableName, destTableName, versionId, utils}) => {
let table = new azure.Table(azureCreds);
await table.createTable(destTableName).catch(async err => {
if (err.code !== 'TableAlreadyExists') {
throw err;
}
if ((await table.queryEntities(destTableName, {top: 1})).entities.length > 0) {
throw new Error(`Refusing to restore table ${tableName} to ${destTableName}, ` +
'as the destination is not empty!');
}
});
try {
await s3.headObject({
Bucket: bucket,
Key: `${azureCreds.accountId}/table/${tableName}`,
VersionId: versionId,
}, async function(req, res) {
let account = req.params.account;
let continuationToken = req.query.continuationToken || null;
let table = new azure.Table({
accountId: account,
accessKey: this.azureAccounts[account],
});
let result = await table.queryTables({nextTableName: continuationToken});
let data = {tables: result.tables};
if (result.nextTableName) {
data.continuationToken = result.nextTableName;
}
return res.reply(data);
});