You are here

public function AcquiaContenthubCommands::contenthubRegenerateSecret in Acquia Content Hub 8

Regenerates the Shared Secret used for Webhook Verification.

@command acquia:contenthub-regenerate-secret @aliases ach-regsec,acquia-contenthub-regenerate-secret

File

src/Commands/AcquiaContenthubCommands.php, line 499

Class

AcquiaContenthubCommands
A Drush commandfile.

Namespace

Drupal\acquia_contenthub\Commands

Code

public function contenthubRegenerateSecret() {

  /** @var \Drupal\acquia_contenthub\Client\ClientManager $client_manager */
  $client_manager = \Drupal::service('acquia_contenthub.client_manager');
  $warning_message = "Are you sure you want to REGENERATE your shared-secret in the Content Hub?\n" . "*************************************************************************************\n" . "PROCEED WITH CAUTION. THIS COULD POTENTIALLY LEAD TO HAVING SOME SITES OUT OF SYNC.\n" . "Make sure you have ALL your sites correctly configured to receive webhooks before attempting to do this.\n" . "For more information, check https://docs.acquia.com/content-hub/known-issues.\n" . "*************************************************************************************\n";
  if ($this
    ->io()
    ->confirm($warning_message)) {
    if ($client_manager
      ->isConnected()) {
      $output = $client_manager
        ->createRequest('regenerateSharedSecret');
    }
    else {
      throw new \Exception(dt('Error trying to connect to the Content Hub. Make sure this site is registered to Content hub.'));
    }
    if ($output) {
      $this
        ->output()
        ->writeln("Your Shared Secret has been regenerated. All clients who have registered to received webhooks are being notified of this change.\n");
    }
    else {
      throw new \Exception(dt("Error trying to regenerate the shared-secret in your subscription. Try again later."));
    }
  }
}