按照https://github.com/glennthehuman/encryption-bundle/blob/master/Resources/doc/index.md
中的说明进行操作我执行了:php bin/console jagilpe:encryption:user:generate_keys
但是我得到了:
在“ jagilpe:encryption:user”命名空间中没有定义命令。
因此,我检查了此folder structure 使用代码:
<?php
namespace Jagilpe\EncryptionBundle\Command;
use Doctrine\Common\Util\ClassUtils;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Jagilpe\EncryptionBundle\Entity\PKEncryptionEnabledUserInterface;
use Symfony\Component\Console\Helper\ProgressBar;
class CreateUserKeysCommand extends ContainerAwareCommand
{
protected function configure()
{
$this->setName('jagilpe:encryption:user:generate_keys')
->setDescription('Generates the encryption keys of a user')
->addArgument(
'usename',
InputArgument::OPTIONAL,
'The name of the user whose keys we want to create.'
)
->addOption(
'all',
null,
InputOption::VALUE_NONE,
'If the keys of all users should be generated.'
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// Input parameters
$userName = $input->getArgument('usename');
$allUsers = $input->getOption('all');
if (!$userName && !$allUsers) {
throw new \RuntimeException('Wrong parameters given');
}
if ($userName && $allUsers) {
throw new \RuntimeException('Ambiguous parameters given');
}
$users = $this->getUsers($userName);
$total = count($users);
$message = "Generating the encryption keys for $total users";
$output->writeln($message);
$progress = new ProgressBar($output, $total);
foreach ($users as $user) {
$this->generateKeys($user);
$this->saveUser($user);
$progress->advance();
}
$progress->finish();
$output->writeln('');
}
private function getUsers($userName)
{
$container = $this->getContainer();
$entityManager = $container->get('doctrine')->getManager();
$encryptionSettings = $container->getParameter('jagilpe_encryption.settings');
$userClasses = $encryptionSettings['user_classes'];
$users = array();
foreach ($userClasses as $userClass) {
$userRepo = $entityManager->getRepository($userClass);
if ($userName) {
$user = $userRepo->findOneBy(array('username' => $userName));
$users = array($user);
break;
}
else {
$users = array_merge($users, $userRepo->findAll());
}
}
return $users;
}
private function generateKeys(PKEncryptionEnabledUserInterface $user)
{
if (!$user->getPublicKey() || !$user->getPrivateKey()) {
$container = $this->getContainer();
$keyManager = $container->get('jagilpe_encryption.key_manager');
$keyManager->generateUserPKIKeys($user);
}
}
private function saveUser(PKEncryptionEnabledUserInterface $user)
{
$userClass = ClassUtils::getClass($user);
$userRepo = $this->getContainer()->get('doctrine')->getManager()->getRepository($userClass);
$userRepo->save($user);
}
}
这怎么了?
顺便说一句,我能够毫无问题地安装捆绑软件。可以正确访问源代码并在我自己的代码中使用。 我只是无法正确运行上述命令。 我还在自己的 Command 目录中创建了自己的命令,并且可以正确检测和执行它们。
答案 0 :(得分:0)
这个概念帮助我在symfony 4. *中从第三方供应商那里获得了有效的命令。
只需在services.yaml文件中注册所需的命令,即可开始使用
。LenovoTP220x Desktop # pip install Django==1.11
Collecting Django==1.11
Downloading https://files.pythonhosted.org/packages/47/a6/078ebcbd49b19e22fd560a2348cfc5cec9e5dcfe3c4fad8e64c9865135bb/Django-1.11-py2.py3-none-any.whl (6.9MB)
|████████████████████████████████| 6.9MB 6.5MB/s
Collecting pytz
Downloading https://files.pythonhosted.org/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB)
|████████████████████████████████| 512kB 3.6MB/s
ERROR: aldryn-django 1.6.11.1 requires pyOpenSSL, which is not installed.
ERROR: aldryn-django 1.6.11.1 has requirement Django==1.6.11, but you'll have django 1.11 which is incompatible.
Installing collected packages: pytz, Django
Successfully installed Django-1.11 pytz-2019.3
LenovoTP220x Desktop # pip install Django==1.6.11
Collecting Django==1.6.11
Using cached https://files.pythonhosted.org/packages/80/86/f52eec28e96fb211122424a3db696e7676ad3555c11027afd9fee9bb0d23/Django-1.6.11-py2.py3-none-any.whl
ERROR: aldryn-django 1.6.11.1 requires pyOpenSSL, which is not installed.
ERROR: django-storages 1.7.2 has requirement Django>=1.11, but you'll have django 1.6.11 which is incompatible.
ERROR: aldryn-sites 0.6.0 has requirement Django>=1.11, but you'll have django 1.6.11 which is incompatible.
Installing collected packages: Django
Found existing installation: Django 1.11
Uninstalling Django-1.11:
Successfully uninstalled Django-1.11
Successfully installed Django-1.6.11
LenovoTP220x Desktop # pip recommends
ERROR: unknown command "recommends"
LenovoTP220x Desktop # apt recommends
Usage: apt recommends [package]
LenovoTP220x Desktop # apt recommends pip
Error: package pip not found in APT cache!
LenovoTP220x Desktop # pip install Django==1.11
Collecting Django==1.11
Using cached https://files.pythonhosted.org/packages/47/a6/078ebcbd49b19e22fd560a2348cfc5cec9e5dcfe3c4fad8e64c9865135bb/Django-1.11-py2.py3-none-any.whl
Requirement already satisfied: pytz in /usr/local/lib/python3.5/dist-packages (from Django==1.11) (2019.3)
ERROR: aldryn-django 1.6.11.1 requires pyOpenSSL, which is not installed.
ERROR: aldryn-django 1.6.11.1 has requirement Django==1.6.11, but you'll have django 1.11 which is incompatible.
Installing collected packages: Django
Found existing installation: Django 1.6.11
Uninstalling Django-1.6.11:
Successfully uninstalled Django-1.6.11
Successfully installed Django-1.11
LenovoTP220x Desktop # pip install pyOpenSSL
Collecting pyOpenSSL
Using cached https://files.pythonhosted.org/packages/01/c8/ceb170d81bd3941cbeb9940fc6cc2ef2ca4288d0ca8929ea4db5905d904d/pyOpenSSL-19.0.0-py2.py3-none-any.whl
Requirement already satisfied: six>=1.5.2 in /usr/lib/python3/dist-packages (from pyOpenSSL) (1.10.0)
Collecting cryptography>=2.3
Downloading https://files.pythonhosted.org/packages/ca/9a/7cece52c46546e214e10811b36b2da52ce1ea7fa203203a629b8dfadad53/cryptography-2.8-cp34-abi3-manylinux2010_x86_64.whl (2.3MB)
|████████████████████████████████| 2.3MB 4.2MB/s
Collecting cffi!=1.11.3,>=1.8
Downloading https://files.pythonhosted.org/packages/a8/8d/986e0c4e2aa3b24db56a0affc50d1a379150e3c4da45d51d549dc2697d53/cffi-1.13.2-cp35-cp35m-manylinux1_x86_64.whl (397kB)
|████████████████████████████████| 399kB 8.4MB/s
Collecting pycparser
Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)
|████████████████████████████████| 163kB 8.6MB/s
Building wheels for collected packages: pycparser
Building wheel for pycparser (setup.py) ... done
Created wheel for pycparser: filename=pycparser-2.19-py2.py3-none-any.whl size=112043 sha256=ba9d8603f660ccef070cc7eeaa471ae98b9f134393fc9e2400764e5559235ca4
Stored in directory: /root/.cache/pip/wheels/f2/9a/90/de94f8556265ddc9d9c8b271b0f63e57b26fb1d67a45564511
Successfully built pycparser
ERROR: aldryn-django 1.6.11.1 has requirement Django==1.6.11, but you'll have django 1.11 which is incompatible.
Installing collected packages: pycparser, cffi, cryptography, pyOpenSSL
Found existing installation: cryptography 1.2.3
Uninstalling cryptography-1.2.3:
Successfully uninstalled cryptography-1.2.3
Successfully installed cffi-1.13.2 cryptography-2.8 pyOpenSSL-19.0.0 pycparser-2.19
LenovoTP220x Desktop # pip install Django==1.6.11
Collecting Django==1.6.11
Using cached https://files.pythonhosted.org/packages/80/86/f52eec28e96fb211122424a3db696e7676ad3555c11027afd9fee9bb0d23/Django-1.6.11-py2.py3-none-any.whl
ERROR: aldryn-sites 0.6.0 has requirement Django>=1.11, but you'll have django 1.6.11 which is incompatible.
ERROR: django-storages 1.7.2 has requirement Django>=1.11, but you'll have django 1.6.11 which is incompatible.
Installing collected packages: Django
Found existing installation: Django 1.11
Uninstalling Django-1.11:
Successfully uninstalled Django-1.11
Successfully installed Django-1.6.11