-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVaultController.php
More file actions
113 lines (95 loc) · 2.61 KB
/
VaultController.php
File metadata and controls
113 lines (95 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace SyncEngine\Controller\Admin;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\Service\Attribute\Required;
use SyncEngine\Controller\DefaultController;
use SyncEngine\Service\Vault;
class VaultController extends DefaultController
{
private Vault $vault;
#[Required]
public function setVault( Vault $vault ): void
{
$this->vault = $vault;
}
#[Route( '/json/secrets', name: 'json_secrets' )]
public function getSecrets(): JsonResponse
{
$secrets = $this->vault->get();
return $this->json( [
'success' => true,
'data' => array_keys( $secrets ),
] );
}
#[Route( '/json/secrets/export', name: 'json_secrets_export' )]
public function exportSecrets( Request $request ): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ADMIN');
$secrets = $this->vault->get( $request->get( 'key' ) );
return $this->json( [
'success' => true,
'data' => $secrets,
] );
}
#[Route( '/json/secrets/set', name: 'json_secrets_set' )]
public function setSecret( Request $request ): JsonResponse
{
$key = $request->get( 'key' );
$value = $request->get( 'value' );
$secrets = $this->vault->get();
if ( ! $key || ! $value ) {
$success = false;
} else {
$this->vault->set( $key, $value );
$success = $this->vault->persist();
if ( $success ) {
$secrets = $this->vault->get();
}
}
return $this->json( [
'success' => $success,
'data' => array_keys( $secrets ),
] );
}
#[Route( '/json/secrets/unset', name: 'json_secrets_unset' )]
public function unsetSecret( Request $request ): JsonResponse
{
$key = $request->get( 'key' );
$secrets = $this->vault->get();
if ( ! $key ) {
$success = false;
} else {
$this->vault->unset( $key );
$success = $this->vault->persist();
if ( $success ) {
$secrets = $this->vault->get();
}
}
return $this->json( [
'success' => $success,
'data' => array_keys( $secrets ),
] );
}
#[Route('system/vault', name: 'system_vault' )]
function renderVault( Request $request, Vault $vault ): Response
{
return $this->render( 'admin/system/vault.html.twig', [
'backlink' => $this->generateUrl( 'syncengine_system_index' ),
'header' => $this->trans( 'Vault' ),
'icon' => 'system-vault',
'breadcrumbs' => [
[
'link' => $this->generateUrl( 'syncengine_system_index' ),
'title' => $this->trans( 'System' ),
],
[
'title' => $this->trans( 'Vault' ),
'current' => true,
],
],
] );
}
}