How to use the json-e function in json-e

To help you get started, we’ve selected a few json-e 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 / mozilla-taskcluster / src / jobs / taskcluster_graph.js View on Github external
revision: templateVariables.revision,
        comment: templateVariables.comment,
        pushlog_id: parseInt(templateVariables.pushlog_id, 10),
        pushdate: templateVariables.pushdate,
      },
      repository: {
        url: templateVariables.url,
        project: templateVariables.project,
        level: templateVariables.level,
      },
      now: new Date().toJSON(),
      as_slugid,
      ownTaskId: as_slugid('decision'),
    };

    let result = jsone(yaml.safeLoad(template), context);

    // https://bugzilla.mozilla.org/show_bug.cgi?id=1437562
    // change `repo:...:*` to `repo:...:branch:default` for old revisions
    // before this change landed in-tree.
    result.tasks[0].scopes = result.tasks[0].scopes.map(scope => {
      if (scope.startsWith('assume:repo:hg.mozilla.org/') && scope.endsWith(':*')) {
        return scope.replace(/:\*$/, ':branch:default')
      }
      return scope;
    });

    return result;
  }
github taskcluster / taskcluster / ui / src / views / Tasks / submitTaskAction.js View on Github external
const context = merge(
    {
      taskGroupId: task.taskGroupId,
      taskId: task.taskId,
      task,
      input,
    },
    actions.variables
  );

  if (action.kind === 'task') {
    const ownTaskId = nice();

    context.ownTaskId = ownTaskId;

    const newTask = jsone(action.task, context);

    await apolloClient.mutate({
      mutation: createTaskQuery,
      variables: {
        taskId: ownTaskId,
        task: {
          ...formatTaskMutation(newTask),
          // Call the queue with the decision task's scopes,
          // as directed by the action spec
          options: {
            authorizedScopes: taskGroup.scopes || [],
          },
        },
      },
    });
github taskcluster / taskcluster / src / views / Tasks / submitTaskAction.js View on Github external
const context = merge(
    {
      taskGroupId: task.taskGroupId,
      taskId: task.taskId,
      task,
      input,
    },
    actions.variables
  );

  if (action.kind === 'task') {
    const ownTaskId = nice();

    context.ownTaskId = ownTaskId;

    const newTask = jsone(action.task, context);

    await apolloClient.mutate({
      mutation: createTaskQuery,
      variables: {
        taskId: ownTaskId,
        task: {
          ...newTask,
          // Call the queue with the decision task's scopes,
          // as directed by the action spec
          options: {
            authorizedScopes: taskGroup.scopes || [],
          },
        },
      },
    });
github taskcluster / taskcluster-tools / src / views / UnifiedInspector / ActionsMenu.jsx View on Github external
const ownTaskId = nice();

      context.ownTaskId = ownTaskId;
      const newTask = jsone(action.task, context);
      // call the queue with the decision task's scopes, as directed by the action spec
      const actionsQueue = this.props.queue.use({
        authorizedScopes: this.props.decision.scopes || []
      });

      await actionsQueue.createTask(ownTaskId, newTask);

      return ownTaskId;
    }

    // action.kind === 'hook'
    const hookPayload = jsone(action.hookPayload, context);
    const { hookId, hookGroupId } = action;
    // verify that the decision task has the appropriate in-tree:action-hook:.. scope
    const expansion = await this.props.auth.expandScopes({
      scopes: this.props.decision.scopes
    });
    const expression = `in-tree:hook-action:${hookGroupId}/${hookId}`;

    if (!satisfiesExpression(expansion.scopes, expression)) {
      throw new Error(
        `Action is misconfigured: decision task's scopes do not satisfy ${expression}`
      );
    }

    const result = await this.props.hooks.triggerHook(
      hookGroupId,
      hookId,
github taskcluster / taskcluster / src / views / Tasks / submitTaskAction.js View on Github external
task: {
          ...newTask,
          // Call the queue with the decision task's scopes,
          // as directed by the action spec
          options: {
            authorizedScopes: taskGroup.scopes || [],
          },
        },
      },
    });

    return ownTaskId;
  }

  // Case where action.kind === 'hook'
  const hookPayload = jsone(action.hookPayload, context);
  const { hookId, hookGroupId } = action;
  // verify that the decision task has
  // the appropriate in-tree:action-hook:.. scope
  const {
    data: { expandScopes },
  } = await apolloClient.query({
    query: expandScopesQuery,
    variables: {
      scopes: taskGroup.scopes || [],
    },
  });
  const expression = `in-tree:hook-action:${hookGroupId}/${hookId}`;

  if (!satisfiesExpression(expandScopes, expression)) {
    throw new Error(
      `Action is misconfigured: decision task's scopes do not satisfy ${expression}`
github taskcluster / taskcluster-tools / src / views / UnifiedInspector / ActionsMenu.jsx View on Github external
const context = merge(
      {
        taskGroupId,
        taskId,
        task,
        input
      },
      actions.variables
    );

    if (action.kind === 'task') {
      const ownTaskId = nice();

      context.ownTaskId = ownTaskId;
      const newTask = jsone(action.task, context);
      // call the queue with the decision task's scopes, as directed by the action spec
      const actionsQueue = this.props.queue.use({
        authorizedScopes: this.props.decision.scopes || []
      });

      await actionsQueue.createTask(ownTaskId, newTask);

      return ownTaskId;
    }

    // action.kind === 'hook'
    const hookPayload = jsone(action.hookPayload, context);
    const { hookId, hookGroupId } = action;
    // verify that the decision task has the appropriate in-tree:action-hook:.. scope
    const expansion = await this.props.auth.expandScopes({
      scopes: this.props.decision.scopes
github mozilla / treeherder / ui / models / taskcluster.js View on Github external
const context = defaults(
      {},
      {
        taskGroupId: decisionTaskId,
        taskId: taskId || null,
        input,
      },
      staticActionVariables,
    );

    const queue = taskcluster.getQueue(currentRepo.tc_root_url, testMode);

    if (action.kind === 'task') {
      context.task = task;
      context.ownTaskId = actionTaskId;
      const actionTask = jsone(action.task, context);
      const decisionTask = await queue.task(decisionTaskId);
      const submitQueue = queue.use({ authorizedScopes: decisionTask.scopes });

      await submitQueue.createTask(actionTaskId, actionTask);

      return actionTaskId;
    }

    if (action.kind === 'hook') {
      const hookPayload = jsone(action.hookPayload, context);
      const { hookId, hookGroupId } = action;
      const auth = new Auth({ rootUrl: currentRepo.tc_root_url });

      const userCredentials = testMode
        ? taskcluster.getMockCredentials()
        : taskcluster.getCredentials(currentRepo.tc_root_url);
github mozilla / treeherder / ui / models / taskcluster.js View on Github external
const queue = taskcluster.getQueue(currentRepo.tc_root_url, testMode);

    if (action.kind === 'task') {
      context.task = task;
      context.ownTaskId = actionTaskId;
      const actionTask = jsone(action.task, context);
      const decisionTask = await queue.task(decisionTaskId);
      const submitQueue = queue.use({ authorizedScopes: decisionTask.scopes });

      await submitQueue.createTask(actionTaskId, actionTask);

      return actionTaskId;
    }

    if (action.kind === 'hook') {
      const hookPayload = jsone(action.hookPayload, context);
      const { hookId, hookGroupId } = action;
      const auth = new Auth({ rootUrl: currentRepo.tc_root_url });

      const userCredentials = testMode
        ? taskcluster.getMockCredentials()
        : taskcluster.getCredentials(currentRepo.tc_root_url);
      if (!userCredentials) {
        throw new Error(tcCredentialsMessage);
      }
      const hooks = new Hooks({
        rootUrl: currentRepo.tc_root_url,
        credentials: userCredentials.credentials,
      });
      const decisionTask = await queue.task(decisionTaskId);
      const expansion = await auth.expandScopes({
        scopes: decisionTask.scopes,

json-e

json parameterization module inspired from json-parameterization

MPL-2.0
Latest version published 2 months ago

Package Health Score

85 / 100
Full package analysis

Popular json-e functions