Skip to content

Commit cd444f2

Browse files
committed
Refactored Decrypt class to only decrypt requested config value during execution
1 parent cc01304 commit cd444f2

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/Action/Decrypt.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,13 @@
77

88
class Decrypt
99
{
10-
protected $secEnv;
10+
protected $configkey;
1111

1212
function __construct()
1313
{
1414
$configkey = (new ConfigKey)->get();
1515

16-
if (!empty($configkey)) {
17-
18-
$configfile = (new ConfigFile)->get();
19-
20-
!empty($configkey) && count($configfile) && $crypt = new Encrypter($configkey);
21-
22-
$secEnv = [];
23-
24-
foreach ($configfile as $key => $value) {
25-
//exclude config values that are arrays and test for ENC: prefix in each value
26-
if (!is_array($value) && strpos($value, "ENC:") === 0) {
27-
//Decrypt values with ENC: prefix
28-
$secEnv[$key] = $crypt->decrypt(substr($value, 4));
29-
}
30-
}
31-
32-
$this->secEnv = $secEnv;
33-
}
16+
!empty($configkey) && $this->configkey = $configkey;
3417
}
3518

3619
/**
@@ -42,6 +25,16 @@ function __construct()
4225
*/
4326
public function get($name)
4427
{
45-
return isset($this->secEnv[$name]) ? $this->secEnv[$name] : null;
28+
$configfile = (new ConfigFile)->get();
29+
30+
if (!empty($this->configkey) && count($configfile)) {
31+
32+
$crypt = new Encrypter($this->configkey);
33+
34+
return !empty($configfile[$name]) && !is_array($configfile[$name]) && strpos($configfile[$name], "ENC:") === 0 ?
35+
$crypt->decrypt(substr($configfile[$name], 4)) :
36+
null;
37+
}
38+
return null;
4639
}
4740
}

0 commit comments

Comments
 (0)