@@ -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}
0 commit comments