How to use taskcluster-client - 10 common examples

To help you get started, we’ve selected a few taskcluster-client 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 / azure-entities / test / helper.js View on Github external
suiteSetup(async () => {
  credentials.accountId = process.env.AZURE_ACCOUNT;
  credentials.accessKey = process.env.AZURE_ACCOUNT_KEY;

  if (credentials.accountId && credentials.accessKey) {
    return;
  }

  // load credentials from the secret if running in CI
  if (process.env.TASKCLUSTER_PROXY_URL) {
    console.log('loading credentials from secret via TASKCLUSTER_PROXY_URL');
    const client = new taskcluster.Secrets({rootUrl: process.env.TASKCLUSTER_PROXY_URL});
    const res = await client.get('project/taskcluster/testing/azure');
    console.log(res.secret);
    credentials.accountId = res.secret.AZURE_ACCOUNT;
    credentials.accessKey = res.secret.AZURE_ACCOUNT_KEY;
    return;
  }

  console.error('set $AZURE_ACCOUNT and $AZURE_ACCOUNT_KEY to a testing Azure storage account.');
  process.exit(1);
});
github taskcluster / taskcluster / infrastructure / tooling / src / smoketest / checks / createClient.js View on Github external
run: async () => {
    const auth = new taskcluster.Auth(taskcluster.fromEnvVars());
    const randomId = taskcluster.slugid();

    let clientId = `project/taskcluster/smoketest/${randomId}`;
    const payload = {
      "expires": taskcluster.fromNowJSON('1 hour'),
      "description": `Create a client and use it ${clientId}`,
      "scopes": [`auth:reset-access-token:project/taskcluster/smoketest/${randomId}`],
    };
    const created = await auth.createClient(clientId, payload);

    // try using that new client
    const accessToken = created.accessToken;
    const auth2 = new taskcluster.Auth({
      rootUrl: process.env.TASKCLUSTER_ROOT_URL,
      credentials: {clientId, accessToken},
    });
    await auth2.resetAccessToken(clientId);
github mozilla-b2g / gaia / tests / taskcluster / lib / decorate_task.js View on Github external
function decorateTask(task, options) {
  task = template(task, options);

  // Shallow copy the task...
  var output = {};
  for (var key in task) {
    output[key] = task[key];
  }

  // Each task must have its own unique task id unless this is an
  // external hook. In the external case we expect
  // external systems to generate a taskId.
  if (!options.externalHook) {
    output.taskId = output.taskId || taskcluster.slugid();
  }

  // Taskcluster needs to know how to run the tasks these specify which
  // provisioning method and which worker type to run on.
  if (!options.externalHook) {
    output.task.created = new Date().toJSON();
  }
  output.task.metadata.source = 'http://todo.com/soon';

  // Ensure we are always using the correct scheduler so our tasks are routed
  // correctly...
  output.task.schedulerId = output.task.schedulerId || options.schedulerId ||
    'task-graph-scheduler';
  output.task.metadata.owner = 'dev-gaia@lists.mozilla.org';

  // Expire all tasks in 24 hours.
github taskcluster / taskcluster / infrastructure / tooling / src / smoketest / checks / createClient.js View on Github external
run: async () => {
    const auth = new taskcluster.Auth(taskcluster.fromEnvVars());
    const randomId = taskcluster.slugid();

    let clientId = `project/taskcluster/smoketest/${randomId}`;
    const payload = {
      "expires": taskcluster.fromNowJSON('1 hour'),
      "description": `Create a client and use it ${clientId}`,
      "scopes": [`auth:reset-access-token:project/taskcluster/smoketest/${randomId}`],
    };
    const created = await auth.createClient(clientId, payload);

    // try using that new client
    const accessToken = created.accessToken;
    const auth2 = new taskcluster.Auth({
      rootUrl: process.env.TASKCLUSTER_ROOT_URL,
      credentials: {clientId, accessToken},
    });
github taskcluster / taskcluster / libraries / testing / src / mockauth.js View on Github external
}, function(req, res) {
  // Get parameters
  var account = req.params.account;
  var table   = req.params.table;
  var ctx     = this;

  // Check that the client is authorized to access given account and table
  if (!req.satisfies({account: account, table: table})) {
    return;
  }

  // Check that the account exists
  if (!ctx.azureAccounts[account]) {
    // Try to fetch from auth, if not specified directly
    var auth = new taskcluster.Auth({
      credentials:      ctx.credentials,
      baseUrl:          ctx.authBaseUrl
    });
    return auth.azureTableSAS(account, table).then(function(result) {
      return res.reply(result);
    }, function() {
      return res.status(404).json({
        message:    "Account '" + account + "' not found, can't delegate access"
      });
    });
  }

  // Construct client
  var client = azureTable.createClient({
    accountName:    account,
    accountKey:     ctx.azureAccounts[account],
github taskcluster / mozilla-taskcluster / test / setup.js View on Github external
await commitPublisher.assertExchanges(
    PushExchange,
    RetriggerExchange,
    // Dummy exchange for test messages from treeherder...
    {
      config: {
        exchange: 'treeherder-job-actions'
      }
    }
  );

  // We only need the connection to assert the exchanges after that we can
  // shut it down...
  await commitPublisher.close();

  this.events = new (taskcluster.createClient(commitPublisher.toSchema(
    PushExchange,
    RetriggerExchange
  )))();

  this.treeherder = new THProject('try', {
    consumerKey: 'try',
    consumerSecret: 'try',
    baseUrl: this.config.treeherder.apiUrl
  });
});
github taskcluster / taskcluster / libraries / testing / src / pulse.js View on Github external
PulseTestReceiver.prototype.listenFor = function(name, binding) {
  // Check that the `name` haven't be used before in this test. Remember
  // that we reset this._promisedMessages before each test (via setup) in mocha.
  if (this._promisedMessages[name] !== undefined) {
    throw new Error('name: \'' + name + '\' have already been used in this test');
  }

  // Create new listener using the existing PulseConnection, so no new TCP
  // connection is opened, it just creates an AMQP channel within the existing
  // TCP connection, this is much faster.
  var listener = new taskcluster.PulseListener({
    connection: this._connection,
  });

  // Add listener to list so we can cleanup later
  this._listeners.push(listener);

  // Create a promise that we got a message
  var gotMessage = new Promise(function(accept, reject) {
    listener.on('message', accept);
    listener.on('error', reject);
  });

  // Insert the promise gotMessage into this._promisedMessages for name, so
  // that we can return it when `.waitFor(name)` is called
  this._promisedMessages[name] = gotMessage;
github taskcluster / mozilla-taskcluster / test / setup.js View on Github external
setup(function() {
  // Note listener is for messages/exchanges we generate...
  this.listener = new taskcluster.PulseListener({
    credentials: {
      connectionString: this.config.commitPublisher.connectionString
    }
  });

  // Pulse is for things external components generate...
  this.pulse = new taskcluster.PulseListener({
    credentials: {
      connectionString: this.config.treeherderTaskcluster.connectionString
    }
  });
});
github taskcluster / mozilla-taskcluster / test / setup.js View on Github external
setup(function() {
  // Note listener is for messages/exchanges we generate...
  this.listener = new taskcluster.PulseListener({
    credentials: {
      connectionString: this.config.commitPublisher.connectionString
    }
  });

  // Pulse is for things external components generate...
  this.pulse = new taskcluster.PulseListener({
    credentials: {
      connectionString: this.config.treeherderTaskcluster.connectionString
    }
  });
});
github taskcluster / taskcluster / libraries / testing / src / pulse.js View on Github external
var PulseTestReceiver = function(credentials, mocha) {
  var that = this;
  this._connection = new taskcluster.PulseConnection(credentials);
  this._listeners = null;
  this._promisedMessages = null;

  // **Note**, the functions below are mocha hooks. Ie. they are called by
  // mocha, that is also the reason that `PulseTestReceiver` only works in the
  // context of a mocha test.  Note that we assume mocha is in "tdd" mode.
  if (!mocha) {
    mocha = require('mocha');
  }

  // Before all tests we ask the pulseConnection to connect, why not it offers
  // slightly better performance, and we want tests to run fast
  mocha.suiteSetup(function() {
    return that._connection.connect();
  });