Skip to content

A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.

1.2 KB
Raw Blame
'use strict';

const fs = require('node:fs');
const azureCli = require('../../lib/azure-cli');

azureCli.runAzureCli = function fakeAzureCli(args) {
  const cliArgs = Array.isArray(args) ? args : [];
  if (process.env.FAKE_AZ_LOG) {
    fs.appendFileSync(process.env.FAKE_AZ_LOG, `${cliArgs.join(' ')}\n`);
  }

  if (cliArgs[0] === 'account' && cliArgs[1] === 'show') {
    return `${process.env.FAKE_AZ_ACCOUNT_TENANT || ''}\n`;
  }

  if (cliArgs[0] === 'account' && cliArgs[1] === 'get-access-token') {
    const tenantIndex = cliArgs.indexOf('--tenant');
    const tenant = tenantIndex === -1 ? '' : cliArgs[tenantIndex + 1];
    const failing = (process.env.FAKE_AZ_FAIL_TENANTS || '').split(',').filter(Boolean);
    if (tenant && failing.includes(tenant)) {
      const error = new Error(`Fake Azure CLI rejected tenant ${tenant}`);
      error.status = 1;
      throw error;
    }
    if (process.env.FAKE_AZ_STATIC_TOKEN) {
      return `${process.env.FAKE_AZ_STATIC_TOKEN}\n`;
    }
    return `token-for:${tenant || 'active-account'}\n`;
  }

  const error = new Error(`Unexpected fake Azure CLI arguments: ${cliArgs.join(' ')}`);
  error.status = 1;
  throw error;
};