You are here

SecretInfo.php in Lockr 8.3

Same filename and directory in other branches
  1. 8.4 src/SecretInfo.php
  2. 4.x src/SecretInfo.php

Namespace

Drupal\lockr

File

src/SecretInfo.php
View source
<?php

namespace Drupal\lockr;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\key\KeyRepositoryInterface;
use Lockr\SecretInfoInterface;

/**
 * SecretInfo implements secret info for Lockr secrets.
 */
class SecretInfo implements SecretInfoInterface {

  /**
   * Simple config factory.
   *
   * @var ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Key repository.
   *
   * @var KeyRepositoryInterface
   */
  protected $keyRepository;

  /**
   * Constructs a new settings factory.
   *
   * @param ConfigFactoryInterface $config_factory
   *   The simple config factory.
   * @param KeyRepositoryInterface $key_repository
   *   The key respository.
   */
  public function __construct(ConfigFactoryInterface $config_factory, KeyRepositoryInterface $key_repository) {
    $this->configFactory = $config_factory;
    $this->keyRepository = $key_repository;
  }

  /**
   * {@inheritdoc}
   */
  public function getSecretInfo($name) {
    $config = $this->configFactory
      ->get('lockr.secret_info');
    $info = $config
      ->get($name);
    if (!$info) {
      $key = $this->keyRepository
        ->getKey($name);
      if ($key) {
        $provider = $key
          ->getKeyProvider();
        $config = $provider
          ->getConfiguration();
        if (isset($config['encoded'])) {
          return [
            'wrapping_key' => $config['encoded'],
          ];
        }
      }
    }
    return $info ?: [];
  }

  /**
   * {@inheritdoc}
   */
  public function setSecretInfo($name, array $info) {
    $config = $this->configFactory
      ->getEditable('lockr.secret_info');
    $config
      ->set($name, $info);
    $config
      ->save();
  }

  /**
   * {@inheritdoc}
   */
  public function getAllSecretInfo() {
    $config = $this->configFactory
      ->get('lockr.secret_info');
    return $config
      ->get();
  }

}

Classes

Namesort descending Description
SecretInfo SecretInfo implements secret info for Lockr secrets.