refactor: Improve parsing of commands for sudo in parseCommandsByLineForSudo
This commit is contained in:
@@ -1184,14 +1184,16 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null
|
|||||||
function parseCommandsByLineForSudo(Collection $commands, Server $server): array
|
function parseCommandsByLineForSudo(Collection $commands, Server $server): array
|
||||||
{
|
{
|
||||||
$commands = $commands->map(function ($line) {
|
$commands = $commands->map(function ($line) {
|
||||||
if (! str(trim($line))->startsWith([
|
if (
|
||||||
|
! str(trim($line))->startsWith([
|
||||||
'cd',
|
'cd',
|
||||||
'command',
|
'command',
|
||||||
'echo',
|
'echo',
|
||||||
'true',
|
'true',
|
||||||
'if',
|
'if',
|
||||||
'fi',
|
'fi',
|
||||||
])) {
|
])
|
||||||
|
) {
|
||||||
return "sudo $line";
|
return "sudo $line";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3863,9 +3865,11 @@ function convertComposeEnvironmentToArray($environment)
|
|||||||
{
|
{
|
||||||
$convertedServiceVariables = collect([]);
|
$convertedServiceVariables = collect([]);
|
||||||
if (isAssociativeArray($environment)) {
|
if (isAssociativeArray($environment)) {
|
||||||
|
// Example: $environment = ['FOO' => 'bar', 'BAZ' => 'qux'];
|
||||||
if ($environment instanceof Collection) {
|
if ($environment instanceof Collection) {
|
||||||
$changedEnvironment = collect([]);
|
$changedEnvironment = collect([]);
|
||||||
$environment->each(function ($value, $key) use ($changedEnvironment) {
|
$environment->each(function ($value, $key) use ($changedEnvironment) {
|
||||||
|
if (is_numeric($key)) {
|
||||||
$parts = explode('=', $value, 2);
|
$parts = explode('=', $value, 2);
|
||||||
if (count($parts) === 2) {
|
if (count($parts) === 2) {
|
||||||
$key = $parts[0];
|
$key = $parts[0];
|
||||||
@@ -3874,12 +3878,16 @@ function convertComposeEnvironmentToArray($environment)
|
|||||||
} else {
|
} else {
|
||||||
$changedEnvironment->put($key, $value);
|
$changedEnvironment->put($key, $value);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$changedEnvironment->put($key, $value);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $changedEnvironment;
|
return $changedEnvironment;
|
||||||
}
|
}
|
||||||
$convertedServiceVariables = $environment;
|
$convertedServiceVariables = $environment;
|
||||||
} else {
|
} else {
|
||||||
|
// Example: $environment = ['FOO=bar', 'BAZ=qux'];
|
||||||
foreach ($environment as $value) {
|
foreach ($environment as $value) {
|
||||||
$parts = explode('=', $value, 2);
|
$parts = explode('=', $value, 2);
|
||||||
$key = $parts[0];
|
$key = $parts[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user