Skip to content

Commit aec5f1d

Browse files
FEATURE: support alternative names for the prunner config file
1 parent 3582e51 commit aec5f1d

3 files changed

Lines changed: 61 additions & 10 deletions

File tree

Classes/Controller/ProxyController.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class ProxyController extends \Neos\Flow\Mvc\Controller\ActionController
2222
*/
2323
protected $directory;
2424

25+
/**
26+
* @Flow\InjectConfiguration(path="configFile")
27+
* @var string
28+
*/
29+
protected $configFile;
30+
2531
/**
2632
* @Flow\InjectConfiguration(path="jwtSecret")
2733
* @var string
@@ -56,9 +62,8 @@ public function indexAction(string $path, string $subpath)
5662
} else {
5763
try {
5864
// Try to parse prunner config to get JWT secret
59-
$config = Yaml::parseFile($this->directory . '/.prunner.yml');
60-
$jwtSecret = $config['jwt_secret'];
61-
} catch (ParseException $e) {
65+
$jwtSecret = $this->loadJwtSecretFromConfigFile();
66+
} catch (\RuntimeException $e) {
6267
$this->response->setContentType('application/json');
6368
$this->response->setStatusCode(500);
6469
return json_encode(['error' => 'Invalid prunner configuration (could not read JWT secret)']);
@@ -87,4 +92,26 @@ public function indexAction(string $path, string $subpath)
8792

8893
return $response->getBody();
8994
}
95+
96+
/**
97+
* @return string
98+
*/
99+
private function loadJwtSecretFromConfigFile(): string
100+
{
101+
if ($this->configFile && file_exists($this->configFile)) {
102+
$path = $this->configFile;
103+
} elseif ($this->directory && file_exists($this->directory . '/.prunner.yml')) {
104+
$path = $this->directory . '/.prunner.yml';
105+
} else {
106+
throw new \RuntimeException("Failed to locate prunner config file at " . $this->configFile . " or " . $this->directory . '/.prunner.yml');
107+
}
108+
try {
109+
// Try to parse prunner config to get JWT secret
110+
$config = Yaml::parseFile($path);
111+
$jwtSecret = $config['jwt_secret'];
112+
} catch (ParseException $e) {
113+
throw new \RuntimeException('Invalid prunner configuration (could not read JWT secret)');
114+
}
115+
return $jwtSecret;
116+
}
90117
}

Classes/PrunnerApiService.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class PrunnerApiService
3232
*/
3333
protected $directory;
3434

35+
/**
36+
* @Flow\InjectConfiguration(path="configFile")
37+
* @var string
38+
*/
39+
protected $configFile;
40+
3541
/**
3642
* @Flow\InjectConfiguration(path="jwtSecret")
3743
* @var string
@@ -103,13 +109,7 @@ public function apiCall(string $method, string $subpath, ?string $body): Respons
103109
if (!empty($this->jwtSecret)) {
104110
$jwtSecret = $this->jwtSecret;
105111
} else {
106-
try {
107-
// Try to parse prunner config to get JWT secret
108-
$config = Yaml::parseFile($this->directory . '/.prunner.yml');
109-
$jwtSecret = $config['jwt_secret'];
110-
} catch (ParseException $e) {
111-
throw new \RuntimeException('Invalid prunner configuration (could not read JWT secret)');
112-
}
112+
$jwtSecret = $this->loadJwtSecretFromConfigFile();
113113
}
114114

115115
// There are usecases where we want to call prunner from the CLI. We don't have an initialized user there, thus we
@@ -122,4 +122,25 @@ public function apiCall(string $method, string $subpath, ?string $body): Respons
122122
return $client->request($method, $url, ['headers' => ['Authorization' => 'Bearer ' . $authToken], 'body' => $body, 'http_errors' => false]);
123123
}
124124

125+
/**
126+
* @return string
127+
*/
128+
private function loadJwtSecretFromConfigFile(): string
129+
{
130+
if ($this->configFile && file_exists($this->configFile)) {
131+
$path = $this->configFile;
132+
} elseif ($this->directory && file_exists($this->directory . '/.prunner.yml')) {
133+
$path = $this->directory . '/.prunner.yml';
134+
} else {
135+
throw new \RuntimeException("Failed to locate prunner config file at " . $this->configFile . " or " . $this->directory . '/.prunner.yml');
136+
}
137+
try {
138+
// Try to parse prunner config to get JWT secret
139+
$config = Yaml::parseFile($path);
140+
$jwtSecret = $config['jwt_secret'];
141+
} catch (ParseException $e) {
142+
throw new \RuntimeException('Invalid prunner configuration (could not read JWT secret)');
143+
}
144+
return $jwtSecret;
145+
}
125146
}

Configuration/Settings.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ Flowpack:
33
# Base URL to prunner API
44
apiBaseUrl: 'http://localhost:9009/'
55
# Working directory of prunner for loading config
6+
# DEPRECATED: use configFile
67
directory: '%FLOW_PATH_ROOT%'
8+
# Path to the prunner config file to load the JWT secret for authentication
9+
configFile: '%FLOW_PATH_ROOT%/.prunner.yml'
710
# Explicitly set JWT secret if prunner config is not accessible
811
jwtSecret: ~
912

0 commit comments

Comments
 (0)