How to use the taskcluster-lib-urls.api function in taskcluster-lib-urls

To help you get started, we’ve selected a few taskcluster-lib-urls 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 / src / fakeauth.js View on Github external
exports.start = function(clients, {rootUrl}={}) {
  assert(rootUrl, 'rootUrl option is required');
  const authPath = url.parse(libUrls.api(rootUrl, 'auth', 'v1', '/authenticate-hawk')).pathname;
  nock(rootUrl, {encodedQueryParams: true, allowUnmocked: true})
    .persist()
    .filteringRequestBody(/.*/, '*')
    .post(authPath, '*')
    .reply(200, function(uri, body) {
      let scopes = [];
      let from = 'client config';
      let ext = null;
      let clientId = null;
      if (body.authorization) {
        let authorization = hawk.utils.parseAuthorizationHeader(body.authorization);
        clientId = authorization.id;
        scopes = clients[clientId];
        ext = authorization.ext;
      } else {
        // The following is a hacky reproduction of the bewit logic in
github taskcluster / taskcluster / clients / client-web / src / WebListener.js View on Github external
async connect() {
    if (this.isConnected()) {
      return Promise.resolve();
    }

    const socketUrl = api(
      this.options.rootUrl,
      'events',
      'v1',
      '/listen/websocket'
    ).replace('http', 'ws');

    this.socket = new WebSocket(socketUrl);
    this.socket.addEventListener('message', this.handleMessage);
    this.socket.addEventListener('error', this.handleError);
    this.socket.addEventListener('close', this.handleClose);

    await new Promise((resolve, reject) => {
      this.socket.addEventListener('error', reject);
      this.socket.addEventListener('close', reject);
      this.socket.addEventListener('open', () => {
        // Remove event handler for error and close
github taskcluster / taskcluster / libraries / api / src / api.js View on Github external
express(app) {
    // generate the appropriate path for this service, based on the rootUrl
    const path = url.parse(
      libUrls.api(this.options.rootUrl, this.builder.serviceName, this.builder.apiVersion, '')).path;
    app.use(path, this.router());
  }
}
github taskcluster / taskcluster / clients / client / src / client.js View on Github external
}
      // Substitute parameters into route
      let endpoint = entry.route.replace(/<([^<>]+)>/g, function(text, arg) {
        let index = entry.args.indexOf(arg);
        if (index !== -1) {
          let param = args[index];
          if (typeof param !== 'string' && typeof param !== 'number') {
            throw new Error('URL parameter ' + arg + ' must be a string, but ' +
                            'we received a: ' + typeof param);
          }
          return encodeURIComponent(param);
        }
        return text; // Preserve original
      });
      // Create url for the request
      let url = tcUrl.api(this._options.rootUrl, this._options.serviceName, this._options.serviceVersion, endpoint);
      // Add payload if one is given
      let payload = undefined;
      if (entry.input) {
        payload = args[nb_args - 1];
      }
      // Find query string options (if present)
      let query = args[nb_args] || null;
      if (query) {
        _.keys(query).forEach(function(key) {
          if (!_.includes(optKeys, key)) {
            throw new Error('Function ' + entry.name + ' takes options: ' +
                            optKeys.join(', ') + ' but was given ' + key);
          }
        });
      }
github taskcluster / taskcluster / clients / client / src / client.js View on Github external
let query = args[N] || '';
    if (query) {
      _.keys(query).forEach(function(key) {
        if (!_.includes(optKeys, key)) {
          throw new Error('Function ' + entry.name + ' takes options: ' +
                            optKeys.join(', ') + ' but was given ' + key);
        }
      });

      query = querystring.stringify(query);
      if (query.length > 0) {
        query = '?' + query;
      }
    }

    return tcUrl.api(this._options.rootUrl, this._options.serviceName, this._options.serviceVersion, endpoint) + query;
  };

taskcluster-lib-urls

Build urls for taskcluster resources.

MPL-2.0
Latest version published 4 years ago

Package Health Score

54 / 100
Full package analysis

Similar packages