function PhpTufValidator::validateTuf

Flags messages if PHP-TUF is not installed and configured properly.

Parameters

string $dir: The directory to examine.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup[] The error messages, if any.

1 call to PhpTufValidator::validateTuf()
PhpTufValidator::validate in core/modules/package_manager/src/Validator/PhpTufValidator.php
Reacts to a stage event by validating PHP-TUF configuration as needed.

File

core/modules/package_manager/src/Validator/PhpTufValidator.php, line 104

Class

PhpTufValidator
Validates that PHP-TUF is installed and correctly configured.

Namespace

Drupal\package_manager\Validator

Code

private function validateTuf(string $dir) : array {
  $messages = [];
  // This setting will be removed without warning when no longer need.
  if ($this->settings
    ->get('package_manager_bypass_tuf', TRUE)) {
    return $messages;
  }
  if ($this->moduleHandler
    ->moduleExists('help')) {
    $help_url = Url::fromRoute('help.page', [
      'name' => 'package_manager',
    ])->setOption('fragment', 'package-manager-tuf-info')
      ->toString();
  }
  // The Composer plugin must be installed.
  $installed_packages = $this->composerInspector
    ->getInstalledPackagesList($dir);
  if (!isset($installed_packages[static::PLUGIN_NAME])) {
    $message = $this->t('The <code>@plugin</code> plugin is not installed.', [
      '@plugin' => static::PLUGIN_NAME,
    ]);
    if (isset($help_url)) {
      $message = $this->t('@message See <a href=":url">the help page</a> for more information on how to install the plugin.', [
        '@message' => $message,
        ':url' => $help_url,
      ]);
    }
    $messages[] = $message;
  }
  // And it has to be explicitly enabled.
  $allowed_plugins = $this->composerInspector
    ->getAllowPluginsConfig($dir);
  if ($allowed_plugins !== TRUE && empty($allowed_plugins[static::PLUGIN_NAME])) {
    $message = $this->t('The <code>@plugin</code> plugin is not listed as an allowed plugin.', [
      '@plugin' => static::PLUGIN_NAME,
    ]);
    if (isset($help_url)) {
      $message = $this->t('@message See <a href=":url">the help page</a> for more information on how to configure the plugin.', [
        '@message' => $message,
        ':url' => $help_url,
      ]);
    }
    $messages[] = $message;
  }
  // Confirm that all repositories we're configured to look at have opted into
  // TUF protection.
  foreach ($this->getRepositoryStatus($dir) as $url => $is_protected) {
    if ($is_protected) {
      continue;
    }
    $message = $this->t('TUF is not enabled for the <code>@url</code> repository.', [
      '@url' => $url,
    ]);
    if (isset($help_url)) {
      $message = $this->t('@message See <a href=":url">the help page</a> for more information on how to set up this repository.', [
        '@message' => $message,
        ':url' => $help_url,
      ]);
    }
    $messages[] = $message;
  }
  return $messages;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.