Skip to content

Commit 80e2f32

Browse files
committed
more tests
1 parent e4c8d24 commit 80e2f32

11 files changed

Lines changed: 1206 additions & 63 deletions

src/Commands/CopyCommand.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CopyCommand extends BaseCommand
1919

2020
public $description = 'Copy a secret between stages or vaults';
2121

22-
public function process(): int
22+
public function process()
2323
{
2424
$key = $this->key();
2525

@@ -69,15 +69,8 @@ public function process(): int
6969
$destinationVault->set($key, $sourceSecret->value(), $sourceSecret->isSecure());
7070

7171
$this->info("Successfully copied secret [{$key}] from {$sourceContext->toString()} to {$destinationContext->toString()}");
72-
73-
return self::SUCCESS;
74-
7572
} catch (SecretNotFoundException $e) {
76-
$this->error("Source secret [{$key}] not found in {$sourceContext->toString()}");
77-
return self::FAILURE;
78-
} catch (\Exception $e) {
79-
$this->error("Copy failed: {$e->getMessage()}");
80-
return self::FAILURE;
73+
return $this->error("Source secret [{$key}] not found in {$sourceContext->toString()}");
8174
}
8275
}
8376

src/Commands/DeleteCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DeleteCommand extends BaseCommand
1515

1616
public $description = 'Delete a stage secret from a specified vault';
1717

18-
public function process(): int
18+
public function process()
1919
{
2020
$key = $this->key();
2121
$context = $this->context();
@@ -40,9 +40,7 @@ public function process(): int
4040
);
4141

4242
if (! $confirmed) {
43-
$this->info('Secret deletion cancelled.');
44-
45-
return self::SUCCESS;
43+
return $this->info('Secret deletion cancelled.');
4644
}
4745
}
4846

@@ -51,7 +49,5 @@ public function process(): int
5149

5250
$this->newLine();
5351
$this->info("Secret [{$key}] has been permanently deleted from vault [{$context->vault}] in stage [{$context->stage}].");
54-
55-
return self::SUCCESS;
5652
}
5753
}

src/Commands/DiffCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,20 @@ public function process()
3232
}
3333

3434
if (empty($vaults)) {
35-
$this->error('No vaults available for comparison.');
36-
return self::FAILURE;
35+
return $this->error('No vaults available for comparison.');
3736
}
3837

3938
if (empty($stages)) {
40-
$this->error('No stages available for comparison.');
41-
return self::FAILURE;
39+
return $this->error('No stages available for comparison.');
4240
}
4341

4442
$diffService = new DiffService;
4543
$diffs = spin(fn () => $diffService->compare($vaults, $stages), 'Gathering secrets for comparison...');
4644

4745
if ($diffs->isNotEmpty()) {
4846
$this->displayTable($diffs, $vaults, $stages, $diffService);
49-
return self::SUCCESS;
5047
} else {
5148
$this->info('No secrets found in any of the specified vault/stage combinations.');
52-
return self::SUCCESS;
5349
}
5450
}
5551

src/Commands/ImportCommand.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use function Laravel\Prompts\table;
1010
use function Laravel\Prompts\text;
1111

12-
class ImportCommand extends AbstractCommand
12+
class ImportCommand extends BaseCommand
1313
{
14-
public $signature = 'keep:import {from? : Env file to import from}
14+
public $signature = 'import {from? : Env file to import from}
1515
{--overwrite : Overwrite existing secrets}
1616
{--skip-existing : Skip existing secrets}
1717
{--dry-run : Show what would be imported without actually importing} '
@@ -22,7 +22,7 @@ class ImportCommand extends AbstractCommand
2222

2323
public $description = 'Import a .env file and store as stage secrets in a specified vault';
2424

25-
public function process(): int
25+
public function process()
2626
{
2727
if ($this->option('overwrite') && $this->option('skip-existing')) {
2828
$this->error('You cannot use --overwrite and --skip-existing together.');
@@ -32,9 +32,7 @@ public function process(): int
3232

3333
$envFilePath = $this->argument('from') ?? text('Path to .env file', required: true);
3434
if (! file_exists($envFilePath) || ! is_readable($envFilePath)) {
35-
$this->error("Env file [$envFilePath] does not exist or is not readable.");
36-
37-
return self::FAILURE;
35+
return $this->error("Env file [$envFilePath] does not exist or is not readable.");
3836
}
3937

4038
$env = new Env(file_get_contents($envFilePath));
@@ -64,8 +62,6 @@ public function process(): int
6462
if ($this->option('dry-run')) {
6563
$this->info('This was a dry run. No secrets were imported.');
6664
}
67-
68-
return self::SUCCESS;
6965
}
7066

7167
protected function canImport(SecretCollection $importSecrets, SecretCollection $vaultSecrets): bool

src/Commands/ListCommand.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ class ListCommand extends BaseCommand
1414

1515
public $description = 'Get the list of stage secrets in a specified vault';
1616

17-
public function process(): int
17+
public function process()
1818
{
1919
$format = $this->option('format');
2020

2121
if (!in_array($format, ['table', 'env', 'json'])) {
22-
$this->error('Invalid format option. Supported formats are: table, json, env.');
23-
return self::FAILURE;
22+
return $this->error('Invalid format option. Supported formats are: table, json, env.');
2423
}
2524

2625
$context = $this->context();
@@ -38,7 +37,5 @@ public function process(): int
3837
'env' => $this->line($secrets->toEnvString()),
3938
'json' => $this->line($secrets->only(['key', 'value', 'revision'])->toJson(JSON_PRETTY_PRINT)),
4039
};
41-
42-
return self::SUCCESS;
4340
}
4441
}

src/Commands/MergeCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use STS\Keep\Facades\Keep;
1010
use function Laravel\Prompts\text;
1111

12-
class MergeCommand extends AbstractCommand
12+
class MergeCommand extends BaseCommand
1313
{
14-
public $signature = 'keep:merge {template? : Template env file with placeholders}
14+
public $signature = 'merge {template? : Template env file with placeholders}
1515
{--overlay= : Optional env file to overlay on top of the template}
1616
{--output= : File where to save the output (defaults to stdout)}
1717
{--overwrite : Overwrite the output file if it exists}
@@ -53,14 +53,12 @@ public function process(): int
5353
}
5454

5555
$this->line($contents);
56-
57-
return self::SUCCESS;
5856
}
5957

6058
protected function prepareTemplateContents(): bool
6159
{
6260
$template = $this->argument('template')
63-
?? config('keep.template')
61+
?? Keep::getSetting('template')
6462
?? text('Template file with placeholders', required: true);
6563

6664
if (! file_exists($template) || ! is_readable($template)) {

src/Commands/VerifyCommand.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
use function Laravel\Prompts\spin;
1010
use function Laravel\Prompts\table;
1111

12-
class VerifyCommand extends AbstractCommand
12+
class VerifyCommand extends BaseCommand
1313
{
14-
public $signature = 'keep:verify
14+
public $signature = 'verify
1515
{--context= : Comma-separated list of contexts to verify (e.g., "vault1:stage1,vault2:stage2")}
1616
{--vault= : Test only this vault}
1717
{--stage= : Test only this stage}';
1818

1919
public $description = 'Verify vault access permissions for reading, writing, listing, and deleting secrets';
2020

21-
public function process(): int
21+
public function process()
2222
{
2323
$results = spin(function () {
2424
// If --context is provided, use specific contexts
@@ -34,11 +34,11 @@ public function process(): int
3434
}
3535

3636
// Otherwise use existing logic
37-
$vaults = $this->option('vault') ? [$this->option('vault')] : Keep::available();
38-
$stages = $this->option('stage') ? [$this->option('stage')] : Keep::stages();
37+
$vaults = $this->option('vault') ? [$this->option('vault')] : Keep::getConfiguredVaults();
38+
$stages = $this->option('stage') ? [$this->option('stage')] : Keep::getStages();
3939
$results = [];
4040

41-
foreach ($vaults as $vaultName) {
41+
foreach ($vaults as $vaultName => $config) {
4242
foreach ($stages as $stage) {
4343
$results[] = $this->verifyVaultStage($vaultName, $stage);
4444
}
@@ -47,13 +47,11 @@ public function process(): int
4747
}, 'Checking vault access permissions...');
4848

4949
$this->displayResults($results);
50-
51-
return self::SUCCESS;
5250
}
5351

5452
protected function verifyVaultStage(string $vaultName, string $stage): array
5553
{
56-
$vault = Keep::vault($vaultName)->forStage($stage);
54+
$vault = Keep::vault($vaultName, $stage);
5755
$testKey = 'keep-verify-'.Str::random(8);
5856

5957
$result = [

src/KeepApplication.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,7 @@ public function __construct(protected KeepInstall $install)
5252
$this->add((new Commands\ExportCommand()));
5353

5454
$this->add((new Commands\DiffCommand()));
55-
56-
57-
// TODO: Refactor these Laravel commands to Symfony Console:
58-
// - AbstractCommand.php (base class needs complete rewrite)
59-
// - ListCommand.php (needs Symfony Console refactor)
60-
// - GetCommand.php (needs Symfony Console refactor)
61-
// - SetCommand.php (needs Symfony Console refactor)
62-
// - DeleteCommand.php (needs Symfony Console refactor)
63-
// - HistoryCommand.php (needs Symfony Console refactor)
64-
// - DiffCommand.php (needs Symfony Console refactor)
65-
// - MergeCommand.php (needs Symfony Console refactor)
66-
// - ExportCommand.php (needs Symfony Console refactor)
67-
// - ImportCommand.php (needs Symfony Console refactor)
68-
// - VerifyCommand.php (needs Symfony Console refactor)
69-
// - CopyCommand.php (needs Symfony Console refactor)
55+
$this->add((new Commands\VerifyCommand()));
7056
}
7157

7258
public function getManager(): KeepManager

0 commit comments

Comments
 (0)