diff --git a/README.md b/README.md index 96df2ee..05d3ca3 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,17 @@ FilamentEnvEditorPlugin::make() ->slug('env-editor') ``` +### Hiding keys + +Some keys you may consider to be particularly sensitive and don't wish to expose them, even through this package. You can hide them through this interface: + +```php +FilamentEnvEditorPlugin::make() + ->hideKeys('APP_KEY', 'BCRYPT_ROUNDS') +``` ### Authorization + If you would like to prevent certain users from accessing the logs page, you should add a `authorize` callback in the FilamentLEnvEditorPlugin chain. ```php diff --git a/src/FilamentEnvEditorPlugin.php b/src/FilamentEnvEditorPlugin.php index 07a5f8b..ada5e3c 100644 --- a/src/FilamentEnvEditorPlugin.php +++ b/src/FilamentEnvEditorPlugin.php @@ -25,6 +25,11 @@ class FilamentEnvEditorPlugin implements Plugin protected string|\Closure $slug = 'env-editor'; + /** + * @var list + */ + protected array $hideKeys = []; + public function getId(): string { return 'filament-env-editor'; @@ -134,4 +139,21 @@ public function getSlug(): string { return $this->evaluate($this->slug); } + + public function hideKeys(string ...$keys): static + { + $this->hideKeys = $keys; + + return $this; + } + + /** + * Retrieves the list of environment keys that should be hidden from the UI. + * + * @return list + */ + public function getHiddenKeys(): array + { + return $this->hideKeys; + } } diff --git a/src/Pages/Actions/Backups/UploadBackupAction.php b/src/Pages/Actions/Backups/UploadBackupAction.php index 99d0d42..8556d58 100644 --- a/src/Pages/Actions/Backups/UploadBackupAction.php +++ b/src/Pages/Actions/Backups/UploadBackupAction.php @@ -20,7 +20,7 @@ protected function setUp(): void $this->form([ FileUpload::make('file')->saveUploadedFileUsing(static function ( BaseFileUpload $component, - TemporaryUploadedFile $file + TemporaryUploadedFile $file, ): ?string { $backupsPath = app(EnvEditor::class)->getFilesManager()->getBackupsDir(); diff --git a/src/Pages/ViewEnv.php b/src/Pages/ViewEnv.php index 440369b..396fd13 100644 --- a/src/Pages/ViewEnv.php +++ b/src/Pages/ViewEnv.php @@ -110,21 +110,25 @@ private function getFirstTab(): array ->filter(fn (EntryObj $obj) => !$obj->isSeparator()) ->groupBy('group') ->map(function (Collection $group) { - $fields = $group->map(function (EntryObj $obj) { - return Forms\Components\Group::make([ - Forms\Components\Actions::make([ - EditAction::make("edit_{$obj->key}")->setEntry($obj), - DeleteAction::make("delete_{$obj->key}")->setEntry($obj), - ])->alignEnd(), - Forms\Components\Placeholder::make($obj->key) - ->label('') - ->content(new HtmlString("{$obj->getAsEnvLine()}")) - ->columnSpan(4), - ])->columns(5); - }); + $fields = $group + ->reject(fn (EntryObj $obj) => $this->shouldHideEnvVariable($obj->key)) + ->map(function (EntryObj $obj) { + return Forms\Components\Group::make([ + Forms\Components\Actions::make([ + EditAction::make("edit_{$obj->key}")->setEntry($obj), + DeleteAction::make("delete_{$obj->key}")->setEntry($obj), + ])->alignEnd(), + Forms\Components\Placeholder::make($obj->key) + ->label('') + ->content(new HtmlString("{$obj->getAsEnvLine()}")) + ->columnSpan(4), + ])->columns(5); + }); return Forms\Components\Section::make()->schema($fields->all())->columns(1); - })->all(); + }) + ->filter(fn (Forms\Components\Section $s) => $s->hasChildComponentContainer(true)) + ->all(); $header = Forms\Components\Group::make([ Forms\Components\Actions::make([ @@ -135,6 +139,11 @@ private function getFirstTab(): array return [$header, ...$envData]; } + private function shouldHideEnvVariable(string $key): bool + { + return in_array($key, FilamentEnvEditorPlugin::get()->getHiddenKeys()); + } + /** * @return list */