You are here

class ApigeeEdgeCommands in Apigee Edge 8

Drush 9 command file.

Hierarchy

  • class \Drupal\apigee_edge\Commands\ApigeeEdgeCommands extends \Drush\Commands\DrushCommands

Expanded class hierarchy of ApigeeEdgeCommands

1 file declares its use of ApigeeEdgeCommands
ApigeeEdgeCommandsTest.php in tests/src/Unit/Commands/ApigeeEdgeCommandsTest.php
1 string reference to 'ApigeeEdgeCommands'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses ApigeeEdgeCommands
apigee_edge.commands in ./drush.services.yml
\Drupal\apigee_edge\Commands\ApigeeEdgeCommands

File

src/Commands/ApigeeEdgeCommands.php, line 29

Namespace

Drupal\apigee_edge\Commands
View source
class ApigeeEdgeCommands extends DrushCommands {

  /**
   * The interoperability cli service.
   *
   * @var \Drupal\apigee_edge\CliServiceInterface
   */
  protected $cliService;

  /**
   * ApigeeEdgeCommands constructor.
   *
   * @param \Drupal\apigee_edge\CliServiceInterface $cli_service
   *   The CLI service which allows interoperability.
   */
  public function __construct(CliServiceInterface $cli_service = NULL) {
    parent::__construct();
    $this->cliService = $cli_service;
  }

  /**
   * Developer synchronization.
   *
   * @command apigee-edge:sync
   *
   * @usage drush apigee-edge:sync
   *   Starts the developer synchronization between
   *   the Developer Portal and the Apigee Edge Management Server.
   */
  public function sync() {
    $this->cliService
      ->sync($this
      ->io(), 'dt');
  }

  /**
   * Create a custom role in an Apigee organization for Drupal usage.
   *
   * Create a custom Apigee role that limits permissions for Drupal connections
   * to the Apigee API.
   *
   * @param string $org
   *   The Apigee Edge org to create the role in.
   * @param string $email
   *   An Apigee user email address with orgadmin role for this org.
   * @param array $options
   *   Drush options for the command.
   *
   * @option password
   *   Password for the Apigee orgadmin user. If not set, you will be prompted
   *   for the password.
   * @option base-url
   *   Base URL to use, defaults to public cloud URL:
   *   https://api.enterprise.apigee.com/v1.
   * @option role-name
   *   The role to create in the Apigee Edge org, defaults to "drupalportal".
   * @option $force
   *   Force running of permissions on a role that already exists, defaults
   *   to throwing an error message if role exists. Note that permissions are
   *   only added, any current permissions not not removed.
   * @usage drush create-edge-role myorg me@example.com
   *   Create "drupalportal" role as orgadmin me@example.com for org myorg.
   * @usage drush create-edge-role myorg me@example.com --role-name=portal
   *   Create role named "portal"
   * @usage drush create-edge-role myorg me@example.com --base-url=https://api.edge.example.com
   *   Create role on private Apigee Edge server "api.edge.example.com".
   * @usage drush create-edge-role myorg me@example.com --force
   *   Update permissions on "drupalportal" role even if role already exists.
   * @command apigee-edge:create-edge-role
   * @aliases create-edge-role
   */
  public function createEdgeRole(string $org, string $email, array $options = [
    'password' => NULL,
    'base-url' => NULL,
    'role-name' => NULL,
    'force' => FALSE,
  ]) {

    // Call the CLI Service.
    $this->cliService
      ->createEdgeRoleForDrupal($this
      ->io(), 'dt', $org, $email, $options['password'], $options['base-url'], $options['role-name'], $options['force']);
  }

  /**
   * Validate function for the createEdge method.
   *
   * @hook validate apigee-edge:create-edge-role
   */
  public function validateCreateEdgeRole(CommandData $commandData) {

    // If the user did not specify a password, then prompt for one.
    $password = $commandData
      ->input()
      ->getOption('password');
    $email = $commandData
      ->input()
      ->getArgument('email');
    if (empty($password)) {
      $password = $this
        ->io()
        ->askHidden(dt('Enter password for :email', [
        ':email' => $email,
      ]), function ($value) {
        return $value;
      });
      $commandData
        ->input()
        ->setOption('password', $password);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ApigeeEdgeCommands::$cliService protected property The interoperability cli service.
ApigeeEdgeCommands::createEdgeRole public function Create a custom role in an Apigee organization for Drupal usage.
ApigeeEdgeCommands::sync public function Developer synchronization.
ApigeeEdgeCommands::validateCreateEdgeRole public function Validate function for the createEdge method.
ApigeeEdgeCommands::__construct public function ApigeeEdgeCommands constructor.