How to use the fast-azure-storage.Table function in fast-azure-storage

To help you get started, we’ve selected a few fast-azure-storage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taskcluster / taskcluster / libraries / testing / lib / entity.js View on Github external
// 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");
github taskcluster / taskcluster / services / auth / src / azure.js View on Github external
// 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;
        }
      }
github taskcluster / azure-entities / src / entity.js View on Github external
// 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");
github taskcluster / taskcluster / infrastructure / tooling / src / backup / backup.js View on Github external
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;
github taskcluster / taskcluster / services / auth / routes / api / v1.js View on Github external
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, {
github taskcluster / azure-entities / src / entity.js View on Github external
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',
github taskcluster / taskcluster / infrastructure / tooling / src / backup / restore.js View on Github external
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,
github taskcluster / taskcluster / services / auth / src / azure.js View on Github external
}, 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);
});

fast-azure-storage

Fast client library for azure storage services

MPL-2.0
Latest version published 11 months ago

Package Health Score

77 / 100
Full package analysis

Similar packages