Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Console] [Framework] Add completion to secrets:set and fix secrets:remove #43626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
return;
}

$vault = $input->getOption('local') ? $this->localVault : $this->vault;
$vaultKeys = array_keys($this->vault->list(false));
$suggestions->suggestValues(array_intersect($vaultKeys, array_keys($vault->list(false))));
if ($input->getOption('local')) {
if (null === $this->localVault) {
return;
}
$vaultKeys = array_intersect($vaultKeys, array_keys($this->localVault->list(false)));
}

$suggestions->suggestValues($vaultKeys);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -137,4 +139,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return 0;
}

public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestArgumentValuesFor('name')) {
$suggestions->suggestValues(array_keys($this->vault->list(false)));
GromNaN marked this conversation as resolved.
Show resolved Hide resolved
}
wouterj marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Command;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Command\SecretsRemoveCommand;
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
use Symfony\Component\Console\Tester\CommandCompletionTester;

class SecretsRemoveCommandTest extends TestCase
{
/**
* @dataProvider provideCompletionSuggestions
*/
public function testComplete(bool $withLocalVault, array $input, array $expectedSuggestions)
{
$vault = $this->createMock(AbstractVault::class);
$vault->method('list')->willReturn(['SECRET' => null, 'OTHER_SECRET' => null]);
if ($withLocalVault) {
$localVault = $this->createMock(AbstractVault::class);
$localVault->method('list')->willReturn(['SECRET' => null]);
} else {
$localVault = null;
}
$command = new SecretsRemoveCommand($vault, $localVault);
$tester = new CommandCompletionTester($command);
$suggestions = $tester->complete($input);
$this->assertSame($expectedSuggestions, $suggestions);
}

public function provideCompletionSuggestions()
{
yield 'name' => [true, [''], ['SECRET', 'OTHER_SECRET']];
yield '--local name (with local vault)' => [true, ['--local', ''], ['SECRET']];
yield '--local name (without local vault)' => [false, ['--local', ''], []];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Command;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Command\SecretsSetCommand;
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
use Symfony\Component\Console\Tester\CommandCompletionTester;

class SecretsSetCommandTest extends TestCase
{
/**
* @dataProvider provideCompletionSuggestions
*/
public function testComplete(array $input, array $expectedSuggestions)
{
$vault = $this->createMock(AbstractVault::class);
$vault->method('list')->willReturn(['SECRET' => null, 'OTHER_SECRET' => null]);
$localVault = $this->createMock(AbstractVault::class);
$command = new SecretsSetCommand($vault, $localVault);
$tester = new CommandCompletionTester($command);
$suggestions = $tester->complete($input);
$this->assertSame($expectedSuggestions, $suggestions);
}

public function provideCompletionSuggestions()
{
yield 'name' => [[''], ['SECRET', 'OTHER_SECRET']];
yield '--local name (with local vault)' => [['--local', ''], ['SECRET', 'OTHER_SECRET']];
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.